Skip to contentSkip to conversation

targte-i386: Add virtual L3 cache support

PATCH New Longpeng(Mike) 1 participant 3 messages Sep 7, 2016

lore
Share & tools
lore
#0 lore raw

v5 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,2*threads workload:SAP-HANA-PB-testsuite), this reduces 85% guest's resched-IPIs, and the performance improves 7.2%~33.1%.

---
Chandes since v4:
- rename "l3-cache-shared" to "l3-cache"

Changes since v3:
- add 2.8 machine(2.7 was released), set compat_props on PC_COMPAT_2_8
- 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/i386/pc.h | 12 ++++++++++++
 target-i386/cpu.c    | 49 ++++++++++++++++++++++++++++++++++++++++++++-----
 target-i386/cpu.h    |  6 ++++++
 5 files changed, 86 insertions(+), 10 deletions(-)
Signature · 1 line
1.8.3.1
#2 lore raw

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

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..079a957 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",\
+        .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 cf14bcb..bb3ffda 100644
@@ -1207,6 +1207,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;
+
     /* Compatibility bits for old machine types: */
     bool enable_cpuid_0xb;
 
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH v5 1/2 pc: Add 2.8 machine

In reply to Longpeng(Mike)

This will used by the next patch.

---
 hw/i386/pc_piix.c    | 16 +++++++++++++---
 hw/i386/pc_q35.c     | 13 +++++++++++--
 include/hw/i386/pc.h |  3 +++
 3 files changed, 27 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/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