Skip to contentSkip to conversation

targte-i386: Add virtual L3 cache support

PATCH RESEND Superseded Longpeng(Mike) 2 participants 4 messages Sep 5, 2016 – Sep 8, 2016

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v4 cover targte-i386: Add virtual L3 cache support

This patchset add virtual L3 cache support.

For KVM's linux guest, this will reduces amouts of IPIs under some workloads. In our experiments(vm:1*socket,8*cores,2threads workload:SAP-HANA-PB-testsuite), this reduces 85% guest's resched-IPIs, and the performance improves 7.2%~33.1%.

---
Changes since v3:
- add 2.8 machine: because 2.7 was released.
- makes the commit message more clearly.

Changes since v2:
- add more useful commit mesage.
- rename "compat-cache" to "l3-cache-shared".

Changes since v1:
- fix the compat problem: set compat_props on PC_COMPAT_2_7.
- fix a "intentionally introducde bug": make intel's and amd's consistently.
- fix the CPUID.(EAX=4, ECX=3):EAX[25:14].
- test the performance if vcpus running on sparate sockets: with L3 cache,

    the performance improves 7.2%~33.1%(avg: 15.7%).

---
Longpeng(Mike) (2):
pc: Add 2.8 machine
target-i386: present virtual L3 cache info for vcpus

 hw/i386/pc_piix.c    | 16 +++++++++++++---
 hw/i386/pc_q35.c     | 13 +++++++++++--
 include/hw/compat.h  |  2 ++
 include/hw/i386/pc.h | 12 ++++++++++++
 target-i386/cpu.c    | 49 ++++++++++++++++++++++++++++++++++++++++++++-----
 target-i386/cpu.h    |  6 ++++++
 6 files changed, 88 insertions(+), 10 deletions(-)
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH RESEND v4 1/2 pc: Add 2.8 machine

---
 hw/i386/pc_piix.c    | 16 +++++++++++++---
 hw/i386/pc_q35.c     | 13 +++++++++++--
 include/hw/compat.h  |  2 ++
 include/hw/i386/pc.h |  3 +++
 4 files changed, 29 insertions(+), 5 deletions(-)
hw/i386/pc_piix.c +13 -3
index a07dc81..0308fee 100644
@@ -438,13 +438,25 @@ static void pc_i440fx_machine_options(MachineClass *m)
     m->default_display = "std";
 }
 
-static void pc_i440fx_2_7_machine_options(MachineClass *m)
+static void pc_i440fx_2_8_machine_options(MachineClass *m)
 {
     pc_i440fx_machine_options(m);
     m->alias = "pc";
     m->is_default = 1;
 }
 
+DEFINE_I440FX_MACHINE(v2_8, "pc-i440fx-2.8", NULL,
+                      pc_i440fx_2_8_machine_options);
+
+
+static void pc_i440fx_2_7_machine_options(MachineClass *m)
+{
+    pc_i440fx_2_8_machine_options(m);
+    m->is_default = 0;
+    m->alias = NULL;
+    SET_MACHINE_COMPAT(m, PC_COMPAT_2_7);
+}
+
 DEFINE_I440FX_MACHINE(v2_7, "pc-i440fx-2.7", NULL,
                       pc_i440fx_2_7_machine_options);
 
@@ -453,8 +465,6 @@ static void pc_i440fx_2_6_machine_options(MachineClass *m)
 {
     PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
     pc_i440fx_2_7_machine_options(m);
-    m->is_default = 0;
-    m->alias = NULL;
     pcmc->legacy_cpu_hotplug = true;
     SET_MACHINE_COMPAT(m, PC_COMPAT_2_6);
 }
hw/i386/pc_q35.c +11 -2
index c0b9961..9559b81 100644
@@ -292,12 +292,22 @@ static void pc_q35_machine_options(MachineClass *m)
     m->has_dynamic_sysbus = true;
 }
 
-static void pc_q35_2_7_machine_options(MachineClass *m)
+static void pc_q35_2_8_machine_options(MachineClass *m)
 {
     pc_q35_machine_options(m);
     m->alias = "q35";
 }
 
+DEFINE_Q35_MACHINE(v2_8, "pc-q35-2.8", NULL,
+                   pc_q35_2_8_machine_options);
+
+static void pc_q35_2_7_machine_options(MachineClass *m)
+{
+    pc_q35_2_8_machine_options(m);
+    m->alias = NULL;
+    SET_MACHINE_COMPAT(m, PC_COMPAT_2_7);
+}
+
 DEFINE_Q35_MACHINE(v2_7, "pc-q35-2.7", NULL,
                    pc_q35_2_7_machine_options);
 
@@ -305,7 +315,6 @@ static void pc_q35_2_6_machine_options(MachineClass *m)
 {
     PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
     pc_q35_2_7_machine_options(m);
-    m->alias = NULL;
     pcmc->legacy_cpu_hotplug = true;
     SET_MACHINE_COMPAT(m, PC_COMPAT_2_6);
 }
include/hw/compat.h +2 -0
index 7ee7299..779f687 100644
@@ -1,6 +1,8 @@
 #ifndef HW_COMPAT_H
 #define HW_COMPAT_H
 
+#define HW_COMPAT_2_7
+
 #define HW_COMPAT_2_6 \
     {\
         .driver   = "virtio-mmio",\
include/hw/i386/pc.h +3 -0
index 74c175c..bd42cc7 100644
@@ -367,6 +367,9 @@ int e820_add_entry(uint64_t, uint64_t, uint32_t);
 int e820_get_num_entries(void);
 bool e820_get_entry(int, uint32_t, uint64_t *, uint64_t *);
 
+#define PC_COMPAT_2_7 \
+    HW_COMPAT_2_7
+
 #define PC_COMPAT_2_6 \
     HW_COMPAT_2_6 \
     {\
Signature · 1 line
1.8.3.1
#2 lore raw

Re: [Qemu-devel] [PATCH RESEND v4 1/2] pc: Add 2.8 machine

include/hw/compat.h line 5

Quoted 7 lines · Longpeng(Mike)

+++ b/include/hw/compat.h

include/hw/compat.h +2 -0
@@ -1,6 +1,8 @@
 #ifndef HW_COMPAT_H
 #define HW_COMPAT_H
 
+#define HW_COMPAT_2_7
+

This is already defined (due to the s390 2.8 machine)

#3 lore raw

PATCH RESEND v4 2/2 target-i386: present virtual L3 cache info for vcpus

In reply to Longpeng(Mike)

Some software algorithms are based on the hardware's cache info, for example, for x86 linux kernel, when cpu1 want to wakeup a task on cpu2, cpu1 will trigger a resched IPI and told cpu2 to do the wakeup if they don't share low level cache. Oppositely, cpu1 will access cpu2's runqueue directly if they share llc. The relevant linux-kernel code as bellow:

	static void ttwu_queue(struct task_struct *p, int cpu)
	{
		struct rq *rq = cpu_rq(cpu);
		......
		if (... && !cpus_share_cache(smp_processor_id(), cpu)) {
			......
			ttwu_queue_remote(p, cpu); /* will trigger RES IPI */
			return;
		}
		......
		ttwu_do_activate(rq, p, 0); /* access target's rq directly */
		......
	}

In real hardware, the cpus on the same socket share L3 cache, so one won't trigger a resched IPIs when wakeup a task on others. But QEMU doesn't present a virtual L3 cache info for VM, then the linux guest will trigger lots of RES IPIs under some workloads even if the virtual cpus belongs to the same virtual socket.

For KVM, there will be lots of vmexit due to guest send IPIs.
The workload is a SAP HANA's testsuite, we run it one round(about 40 minuates) and observe the (Suse11sp3)Guest's amounts of RES IPIs which triggering during the period:
No-L3 With-L3(applied this patch)
cpu0: 363890 44582
cpu1: 373405 43109
cpu2: 340783 43797
cpu3: 333854 43409
cpu4: 327170 40038
cpu5: 325491 39922
cpu6: 319129 42391
cpu7: 306480 41035
cpu8: 161139 32188
cpu9: 164649 31024
cpu10: 149823 30398
cpu11: 149823 32455
cpu12: 164830 35143
cpu13: 172269 35805
cpu14: 179979 33898
cpu15: 194505 32754
avg: 268963.6 40129.8

The VM's topology is "1*socket 8*cores 2*threads".
After present virtual L3 cache info for VM, the amounts of RES IPIs in guest reduce 85%.

For KVM, vcpus send IPIs will cause vmexit which is expensive, so it can cause severe performance degradation. We had tested the overall system performance if vcpus actually run on sparate physical socket. With L3 cache, the performance improves 7.2%~33.1%(avg:15.7%).

---
 include/hw/i386/pc.h |  9 +++++++++
 target-i386/cpu.c    | 49 ++++++++++++++++++++++++++++++++++++++++++++-----
 target-i386/cpu.h    |  6 ++++++
 3 files changed, 59 insertions(+), 5 deletions(-)
include/hw/i386/pc.h +9 -0
index bd42cc7..9e08d0e 100644
@@ -367,7 +367,16 @@ int e820_add_entry(uint64_t, uint64_t, uint32_t);
 int e820_get_num_entries(void);
 bool e820_get_entry(int, uint32_t, uint64_t *, uint64_t *);
 
+#define PC_COMPAT_2_8 \
+    {\
+        .driver   = TYPE_X86_CPU,\
+        .property = "l3-cache-shared",\
+        .value    = "off",\
+    },
+
+
 #define PC_COMPAT_2_7 \
+    PC_COMPAT_2_8 \
     HW_COMPAT_2_7
 
 #define PC_COMPAT_2_6 \
target-i386/cpu.c +44 -5

95 lines not on this page · raw message

target-i386/cpu.h +6 -0
index 65615c0..a8c42cc 100644
@@ -1202,6 +1202,12 @@ struct X86CPU {
      */
     bool enable_lmce;
 
+    /* Compatibility bits for old machine types.
+     * If true present virtual l3 cache for VM, the vcpus in the same virtual
+     * socket share an virtual l3 cache.
+     */
+    bool enable_l3_cache_shared;
+
     /* Compatibility bits for old machine types: */
     bool enable_cpuid_0xb;
 
Signature · 1 line
1.8.3.1