Skip to contentSkip to conversation

i386: Support SMP Cache Topology

PATCH RESEND In review Zhao Liu 4 participants 12 messages Jan 10, 2025 – Feb 19, 2025 KVM

lore
Share & tools
lore

Zhao Liu

author
#0 lore raw

v7 cover i386: Support SMP Cache Topology

Hi folks,

This is my v7 resend version (updated the commit message of origin v7's Patch 1).

Compared with v6 [1], v7 dropped the "thread" level cache topology (cache per thread):

- Patch 1 is the new patch to reject "thread" parameter for smp-cache.
- Ptach 2 dropped cache per thread support.
(Others remain unchanged.)

There're several reasons:

* Currently, neither i386 nor ARM have real hardware support for per- thread cache.
* ARM can't support thread level cache in device tree. [2].

So it is unnecessary to support it at this moment, even though per- thread cache might have potential scheduling benefits for VMs without CPU affinity.

In the future, if there is a clear demand for this feature, the correct approach would be to add a new control field in MachineClass.smp_props and enable it only for the machines that require it.

This series is based on the master branch at commit aa3a285b5bc5 ("Merge tag 'mem-2024-12-21' of https://github.com/davidhildenbrand/qemu into staging").

Smp-cache support of ARM side can be found at [3].

Background
==========

The x86 and ARM (RISCV) need to allow user to configure cache properties (current only topology):
* For x86, the default cache topology model (of max/host CPU) does not always match the Host's real physical cache topology. Performance can increase when the configured virtual topology is closer to the physical topology than a default topology would be.
* For ARM, QEMU can't get the cache topology information from the CPU registers, then user configuration is necessary. Additionally, the cache information is also needed for MPAM emulation (for TCG) to build the right PPTT. (Originally from Jonathan)

About smp-cache
===============

The API design has been discussed heavily in [4].

Now, smp-cache is implemented as a array integrated in -machine. Though -machine currently can't support JSON format, this is the one of the directions of future.

An example is as follows:

smp_cache=smp-cache.0.cache=l1i,smp-cache.0.topology=core,smp-cache.1.cache=l1d,smp-cache.1.topology=core,smp-cache.2.cache=l2,smp-cache.2.topology=module,smp-cache.3.cache=l3,smp-cache.3.topology=die

"cache" specifies the cache that the properties will be applied on. This field is the combination of cache level and cache type. Now it supports "l1d" (L1 data cache), "l1i" (L1 instruction cache), "l2" (L2 unified cache) and "l3" (L3 unified cache).

"topology" field accepts CPU topology levels including "core", "module", "cluster", "die", "socket", "book", "drawer" and a special value "default". (Note, now, in v7, smp-cache doesn't support "thread".)

The "default" is introduced to make it easier for libvirt to set a default parameter value without having to care about the specific machine (because currently there is no proper way for machine to expose supported topology levels and caches).

If "default" is set, then the cache topology will follow the architecture's default cache topology model. If other CPU topology level is set, the cache will be shared at corresponding CPU topology level.

[1]: Patch v6: https://lore.kernel.org/qemu-devel/[email protected]/
[2]: Gap of cache per thread for ARM: https://lore.kernel.org/qemu-devel/[email protected]/T/#m50c37fa5d372feac8e607c279cd446da3e22a12c
[3]: ARM smp-cache: https://lore.kernel.org/qemu-devel/[email protected]/
[4]: API disscussion: https://lore.kernel.org/qemu-devel/[email protected]/

Thanks and Best Regards,
Zhao
---
Alireza Sanaee (1):
i386/cpu: add has_caches flag to check smp_cache configuration

Zhao Liu (4):
hw/core/machine: Reject thread level cache i386/cpu: Support module level cache topology i386/cpu: Update cache topology with machine's configuration i386/pc: Support cache topology in -machine for PC machine

 hw/core/machine-smp.c |  9 ++++++
 hw/i386/pc.c          |  4 +++
 include/hw/boards.h   |  3 ++
 qemu-options.hx       | 30 +++++++++++++++++-
 target/i386/cpu.c     | 71 ++++++++++++++++++++++++++++++++++++++++++-
 5 files changed, 115 insertions(+), 2 deletions(-)
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH RESEND v7 1/5 hw/core/machine: Reject thread level cache

Currently, neither i386 nor ARM have real hardware support for per- thread cache, and there is no clear demand for this specific cache topology.

Additionally, since ARM even can't support this special cache topology in device tree, it is unnecessary to support it at this moment, even though per-thread cache might have potential scheduling benefits for VMs without CPU affinity.

Therefore, disable thread-level cache topology in the general machine part. At present, i386 has not enabled SMP cache, so disabling the thread parameter does not pose compatibility issues.

In the future, if there is a clear demand for this feature, the correct approach would be to add a new control field in MachineClass.smp_props and enable it only for the machines that require it.

---
Changes since Patch v6:
* New commit to reject "thread" parameter when parse smp-cache.

---
 hw/core/machine-smp.c | 7 +++++++
 1 file changed, 7 insertions(+)
hw/core/machine-smp.c +7 -0
index b954eb849027..4e020c358b66 100644
@@ -321,6 +321,13 @@ bool machine_parse_smp_cache(MachineState *ms,
             return false;
         }
 
+        if (props->topology == CPU_TOPOLOGY_LEVEL_THREAD) {
+            error_setg(errp,
+                       "%s level cache not supported by this machine",
+                       CpuTopologyLevel_str(props->topology));
+            return false;
+        }
+
         if (!machine_check_topo_support(ms, props->topology, errp)) {
             return false;
         }
Signature · 1 line
2.34.1
Reviewed-by on v7 1/5
#2 lore raw

Re: [PATCH v7 RESEND 1/5] hw/core/machine: Reject thread level cache

Quoted 17 lines · Zhao Liu

Currently, neither i386 nor ARM have real hardware support for per- thread cache, and there is no clear demand for this specific cache topology.

Additionally, since ARM even can't support this special cache topology in device tree, it is unnecessary to support it at this moment, even though per-thread cache might have potential scheduling benefits for VMs without CPU affinity.

Therefore, disable thread-level cache topology in the general machine part. At present, i386 has not enabled SMP cache, so disabling the thread parameter does not pose compatibility issues.

In the future, if there is a clear demand for this feature, the correct approach would be to add a new control field in MachineClass.smp_props and enable it only for the machines that require it.

Quoted 7 lines

---
Changes since Patch v6:
* New commit to reject "thread" parameter when parse smp-cache.

---
  hw/core/machine-smp.c | 7 +++++++
  1 file changed, 7 insertions(+)
author
#3 lore raw

PATCH RESEND v7 2/5 i386/cpu: Support module level cache topology

In reply to Zhao Liu

Allow cache to be defined at the module level. This increases flexibility for x86 users to customize their cache topology.

---
Changes since Patch v6:
* Dropped "thread" level cache topology support.

---
 target/i386/cpu.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
target/i386/cpu.c +4 -1
index 660ddafc28b5..4728373fdf03 100644
@@ -247,6 +247,9 @@ static uint32_t max_thread_ids_for_cache(X86CPUTopoInfo *topo_info,
     case CPU_TOPOLOGY_LEVEL_CORE:
         num_ids = 1 << apicid_core_offset(topo_info);
         break;
+    case CPU_TOPOLOGY_LEVEL_MODULE:
+        num_ids = 1 << apicid_module_offset(topo_info);
+        break;
     case CPU_TOPOLOGY_LEVEL_DIE:
         num_ids = 1 << apicid_die_offset(topo_info);
         break;
@@ -255,7 +258,7 @@ static uint32_t max_thread_ids_for_cache(X86CPUTopoInfo *topo_info,
         break;
     default:
         /*
-         * Currently there is no use case for THREAD and MODULE, so use
+         * Currently there is no use case for THREAD, so use
          * assert directly to facilitate debugging.
          */
         g_assert_not_reached();
Signature · 1 line
2.34.1
author
#4 lore raw

PATCH RESEND v7 3/5 i386/cpu: Update cache topology with machine's configuration

In reply to Zhao Liu

User will configure smp cache topology via -machine smp-cache.

For this case, update the x86 CPUs' cache topology with user's configuration in MachineState.

---
Changes since Patch v3:
* Updated MachineState.smp_cache to consume "default" level and did a check to ensure topological hierarchical relationships are correct.

---
 target/i386/cpu.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 67 insertions(+)
target/i386/cpu.c +67 -0
index 4728373fdf03..b6d6c4b96d49 100644
@@ -7758,6 +7758,64 @@ static void x86_cpu_hyperv_realize(X86CPU *cpu)
     cpu->hyperv_limits[2] = 0;
 }
 
+#ifndef CONFIG_USER_ONLY
+static bool x86_cpu_update_smp_cache_topo(MachineState *ms, X86CPU *cpu,
+                                          Error **errp)
+{
+    CPUX86State *env = &cpu->env;
+    CpuTopologyLevel level;
+
+    level = machine_get_cache_topo_level(ms, CACHE_LEVEL_AND_TYPE_L1D);
+    if (level != CPU_TOPOLOGY_LEVEL_DEFAULT) {
+        env->cache_info_cpuid4.l1d_cache->share_level = level;
+        env->cache_info_amd.l1d_cache->share_level = level;
+    } else {
+        machine_set_cache_topo_level(ms, CACHE_LEVEL_AND_TYPE_L1D,
+            env->cache_info_cpuid4.l1d_cache->share_level);
+        machine_set_cache_topo_level(ms, CACHE_LEVEL_AND_TYPE_L1D,
+            env->cache_info_amd.l1d_cache->share_level);
+    }
+
+    level = machine_get_cache_topo_level(ms, CACHE_LEVEL_AND_TYPE_L1I);
+    if (level != CPU_TOPOLOGY_LEVEL_DEFAULT) {
+        env->cache_info_cpuid4.l1i_cache->share_level = level;
+        env->cache_info_amd.l1i_cache->share_level = level;
+    } else {
+        machine_set_cache_topo_level(ms, CACHE_LEVEL_AND_TYPE_L1I,
+            env->cache_info_cpuid4.l1i_cache->share_level);
+        machine_set_cache_topo_level(ms, CACHE_LEVEL_AND_TYPE_L1I,
+            env->cache_info_amd.l1i_cache->share_level);
+    }
+
+    level = machine_get_cache_topo_level(ms, CACHE_LEVEL_AND_TYPE_L2);
+    if (level != CPU_TOPOLOGY_LEVEL_DEFAULT) {
+        env->cache_info_cpuid4.l2_cache->share_level = level;
+        env->cache_info_amd.l2_cache->share_level = level;
+    } else {
+        machine_set_cache_topo_level(ms, CACHE_LEVEL_AND_TYPE_L2,
+            env->cache_info_cpuid4.l2_cache->share_level);
+        machine_set_cache_topo_level(ms, CACHE_LEVEL_AND_TYPE_L2,
+            env->cache_info_amd.l2_cache->share_level);
+    }
+
+    level = machine_get_cache_topo_level(ms, CACHE_LEVEL_AND_TYPE_L3);
+    if (level != CPU_TOPOLOGY_LEVEL_DEFAULT) {
+        env->cache_info_cpuid4.l3_cache->share_level = level;
+        env->cache_info_amd.l3_cache->share_level = level;
+    } else {
+        machine_set_cache_topo_level(ms, CACHE_LEVEL_AND_TYPE_L3,
+            env->cache_info_cpuid4.l3_cache->share_level);
+        machine_set_cache_topo_level(ms, CACHE_LEVEL_AND_TYPE_L3,
+            env->cache_info_amd.l3_cache->share_level);
+    }
+
+    if (!machine_check_smp_cache(ms, errp)) {
+        return false;
+    }
+    return true;
+}
+#endif
+
 static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
 {
     CPUState *cs = CPU(dev);
@@ -7982,6 +8040,15 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
 
 #ifndef CONFIG_USER_ONLY
     MachineState *ms = MACHINE(qdev_get_machine());
+
+    /*
+     * TODO: Add a SMPCompatProps.has_caches flag to avoid useless updates
+     * if user didn't set smp_cache.
+     */
+    if (!x86_cpu_update_smp_cache_topo(ms, cpu, errp)) {
+        return;
+    }
+
     qemu_register_reset(x86_cpu_machine_reset_cb, cpu);
 
     if (cpu->env.features[FEAT_1_EDX] & CPUID_APIC || ms->smp.cpus > 1) {
Signature · 1 line
2.34.1
author
#5 lore raw

PATCH RESEND v7 4/5 i386/pc: Support cache topology in -machine for PC machine

In reply to Zhao Liu

Allow user to configure l1d, l1i, l2 and l3 cache topologies for PC machine.

Additionally, add the document of "-machine smp-cache" in qemu-options.hx.

---
Changes since Patch v6:
* Deleted the "thread" level from the allowed topology level parameters in the doc.

Changes since Patch v3:
* Described the omitting cache will use "default" level and described the default cache topology model of i386 PC machine. (Daniel)

---
 hw/i386/pc.c    |  4 ++++
 qemu-options.hx | 30 +++++++++++++++++++++++++++++-
 2 files changed, 33 insertions(+), 1 deletion(-)
hw/i386/pc.c +4 -0
index 53a2f226d038..b9b83d1936ae 100644
@@ -1797,6 +1797,10 @@ static void pc_machine_class_init(ObjectClass *oc, void *data)
     mc->nvdimm_supported = true;
     mc->smp_props.dies_supported = true;
     mc->smp_props.modules_supported = true;
+    mc->smp_props.cache_supported[CACHE_LEVEL_AND_TYPE_L1D] = true;
+    mc->smp_props.cache_supported[CACHE_LEVEL_AND_TYPE_L1I] = true;
+    mc->smp_props.cache_supported[CACHE_LEVEL_AND_TYPE_L2] = true;
+    mc->smp_props.cache_supported[CACHE_LEVEL_AND_TYPE_L3] = true;
     mc->default_ram_id = "pc.ram";
     pcmc->default_smbios_ep_type = SMBIOS_ENTRY_POINT_TYPE_AUTO;
 
qemu-options.hx +29 -1
index cc694d3b890c..60894fe2b52b 100644
@@ -39,7 +39,8 @@ DEF("machine", HAS_ARG, QEMU_OPTION_machine, \
     "                memory-encryption=@var{} memory encryption object to use (default=none)\n"
     "                hmat=on|off controls ACPI HMAT support (default=off)\n"
     "                memory-backend='backend-id' specifies explicitly provided backend for main RAM (default=none)\n"
-    "                cxl-fmw.0.targets.0=firsttarget,cxl-fmw.0.targets.1=secondtarget,cxl-fmw.0.size=size[,cxl-fmw.0.interleave-granularity=granularity]\n",
+    "                cxl-fmw.0.targets.0=firsttarget,cxl-fmw.0.targets.1=secondtarget,cxl-fmw.0.size=size[,cxl-fmw.0.interleave-granularity=granularity]\n"
+    "                smp-cache.0.cache=cachename,smp-cache.0.topology=topologylevel\n",
     QEMU_ARCH_ALL)
 SRST
 ``-machine [type=]name[,prop=value[,...]]``
@@ -159,6 +160,33 @@ SRST
         ::
 
             -machine cxl-fmw.0.targets.0=cxl.0,cxl-fmw.0.targets.1=cxl.1,cxl-fmw.0.size=128G,cxl-fmw.0.interleave-granularity=512
+
+    ``smp-cache.0.cache=cachename,smp-cache.0.topology=topologylevel``
+        Define cache properties for SMP system.
+
+        ``cache=cachename`` specifies the cache that the properties will be
+        applied on. This field is the combination of cache level and cache
+        type. It supports ``l1d`` (L1 data cache), ``l1i`` (L1 instruction
+        cache), ``l2`` (L2 unified cache) and ``l3`` (L3 unified cache).
+
+        ``topology=topologylevel`` sets the cache topology level. It accepts
+        CPU topology levels including ``core``, ``module``, ``cluster``, ``die``,
+        ``socket``, ``book``, ``drawer`` and a special value ``default``. If
+        ``default`` is set, then the cache topology will follow the architecture's
+        default cache topology model. If another topology level is set, the cache
+        will be shared at corresponding CPU topology level. For example,
+        ``topology=core`` makes the cache shared by all threads within a core.
+        The omitting cache will default to using the ``default`` level.
+
+        The default cache topology model for an i386 PC machine is as follows:
+        ``l1d``, ``l1i``, and ``l2`` caches are per ``core``, while the ``l3``
+        cache is per ``die``.
+
+        Example:
+
+        ::
+
+            -machine smp-cache.0.cache=l1d,smp-cache.0.topology=core,smp-cache.1.cache=l1i,smp-cache.1.topology=core
 ERST
 
 DEF("M", HAS_ARG, QEMU_OPTION_M,
Signature · 1 line
2.34.1
author
#6 lore raw

PATCH RESEND v7 5/5 i386/cpu: add has_caches flag to check smp_cache configuration

In reply to Zhao Liu

From: Alireza Sanaee <[email protected]>

Add has_caches flag to SMPCompatProps, which helps in avoiding extra checks for every single layer of caches in x86 (and ARM in future).

---
Note: Picked from Alireza's series with the changes:
* Moved the flag to SMPCompatProps with a new name "has_caches". This way, it remains consistent with the function and style of "has_clusters" in SMPCompatProps.
* Dropped my previous TODO with the new flag.
---
Changes since Patch v2:
* Picked a new patch frome Alireza's ARM smp-cache series.

---
 hw/core/machine-smp.c |  2 ++
 include/hw/boards.h   |  3 +++
 target/i386/cpu.c     | 11 +++++------
 3 files changed, 10 insertions(+), 6 deletions(-)
hw/core/machine-smp.c +2 -0
index 4e020c358b66..0be0ac044c22 100644
@@ -332,6 +332,8 @@ bool machine_parse_smp_cache(MachineState *ms,
             return false;
         }
     }
+
+    mc->smp_props.has_caches = true;
     return true;
 }
 
include/hw/boards.h +3 -0
index 2ad711e56dbe..97125b027070 100644
@@ -156,6 +156,8 @@ typedef struct {
  * @modules_supported - whether modules are supported by the machine
  * @cache_supported - whether cache (l1d, l1i, l2 and l3) configuration are
  *                    supported by the machine
+ * @has_caches - whether cache properties are explicitly specified in the
+ *               user provided smp-cache configuration
  */
 typedef struct {
     bool prefer_sockets;
@@ -166,6 +168,7 @@ typedef struct {
     bool drawers_supported;
     bool modules_supported;
     bool cache_supported[CACHE_LEVEL_AND_TYPE__MAX];
+    bool has_caches;
 } SMPCompatProps;
 
 /**
target/i386/cpu.c +5 -6
index b6d6c4b96d49..7bc619236680 100644
@@ -8040,13 +8040,12 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
 
 #ifndef CONFIG_USER_ONLY
     MachineState *ms = MACHINE(qdev_get_machine());
+    MachineClass *mc = MACHINE_GET_CLASS(ms);
 
-    /*
-     * TODO: Add a SMPCompatProps.has_caches flag to avoid useless updates
-     * if user didn't set smp_cache.
-     */
-    if (!x86_cpu_update_smp_cache_topo(ms, cpu, errp)) {
-        return;
+    if (mc->smp_props.has_caches) {
+        if (!x86_cpu_update_smp_cache_topo(ms, cpu, errp)) {
+            return;
+        }
     }
 
     qemu_register_reset(x86_cpu_machine_reset_cb, cpu);
Signature · 1 line
2.34.1
Reviewed-by on the v7 series
#7 lore raw
In reply to Zhao Liu
Quoted 22 lines · Zhao Liu

Hi folks,

This is my v7 resend version (updated the commit message of origin v7's Patch 1).

Compared with v6 [1], v7 dropped the "thread" level cache topology (cache per thread):

- Patch 1 is the new patch to reject "thread" parameter for smp-cache.
- Ptach 2 dropped cache per thread support.
(Others remain unchanged.)

There're several reasons:

* Currently, neither i386 nor ARM have real hardware support for per- thread cache.
* ARM can't support thread level cache in device tree. [2].

So it is unnecessary to support it at this moment, even though per- thread cache might have potential scheduling benefits for VMs without CPU affinity.

Quoted 8 lines

In the future, if there is a clear demand for this feature, the correct approach would be to add a new control field in MachineClass.smp_props and enable it only for the machines that require it.

This series is based on the master branch at commit aa3a285b5bc5 ("Merge tag 'mem-2024-12-21' of https://github.com/davidhildenbrand/qemu into staging").

pc things:

Quoted 75 lines

Smp-cache support of ARM side can be found at [3].

Background
==========

The x86 and ARM (RISCV) need to allow user to configure cache properties (current only topology):
* For x86, the default cache topology model (of max/host CPU) does not always match the Host's real physical cache topology. Performance can increase when the configured virtual topology is closer to the physical topology than a default topology would be.
* For ARM, QEMU can't get the cache topology information from the CPU registers, then user configuration is necessary. Additionally, the cache information is also needed for MPAM emulation (for TCG) to build the right PPTT. (Originally from Jonathan)

About smp-cache
===============

The API design has been discussed heavily in [4].

Now, smp-cache is implemented as a array integrated in -machine. Though -machine currently can't support JSON format, this is the one of the directions of future.

An example is as follows:

smp_cache=smp-cache.0.cache=l1i,smp-cache.0.topology=core,smp-cache.1.cache=l1d,smp-cache.1.topology=core,smp-cache.2.cache=l2,smp-cache.2.topology=module,smp-cache.3.cache=l3,smp-cache.3.topology=die

"cache" specifies the cache that the properties will be applied on. This field is the combination of cache level and cache type. Now it supports "l1d" (L1 data cache), "l1i" (L1 instruction cache), "l2" (L2 unified cache) and "l3" (L3 unified cache).

"topology" field accepts CPU topology levels including "core", "module", "cluster", "die", "socket", "book", "drawer" and a special value "default". (Note, now, in v7, smp-cache doesn't support "thread".)

The "default" is introduced to make it easier for libvirt to set a default parameter value without having to care about the specific machine (because currently there is no proper way for machine to expose supported topology levels and caches).

If "default" is set, then the cache topology will follow the architecture's default cache topology model. If other CPU topology level is set, the cache will be shared at corresponding CPU topology level.

[1]: Patch v6: https://lore.kernel.org/qemu-devel/[email protected]/
[2]: Gap of cache per thread for ARM: https://lore.kernel.org/qemu-devel/[email protected]/T/#m50c37fa5d372feac8e607c279cd446da3e22a12c
[3]: ARM smp-cache: https://lore.kernel.org/qemu-devel/[email protected]/
[4]: API disscussion: https://lore.kernel.org/qemu-devel/[email protected]/

Thanks and Best Regards,
Zhao
---
Alireza Sanaee (1):
i386/cpu: add has_caches flag to check smp_cache configuration

Zhao Liu (4):
hw/core/machine: Reject thread level cache i386/cpu: Support module level cache topology i386/cpu: Update cache topology with machine's configuration i386/pc: Support cache topology in -machine for PC machine

 hw/core/machine-smp.c |  9 ++++++
 hw/i386/pc.c          |  4 +++
 include/hw/boards.h   |  3 ++
 qemu-options.hx       | 30 +++++++++++++++++-
 target/i386/cpu.c     | 71 ++++++++++++++++++++++++++++++++++++++++++-
 5 files changed, 115 insertions(+), 2 deletions(-)
Signature · 1 line
2.34.1
#8 lore raw
In reply to Zhao Liu
Quoted 4 lines · Zhao Liu

Hi folks,

This is my v7 resend version (updated the commit message of origin v7's Patch 1).

If anything changed, even if it's just a commit message, make it a new version, not a resend, to avoid confusion. Next time :)

[...]

author
#9 lore raw
Quoted 8 lines · Markus Armbruster

Date: Wed, 05 Feb 2025 13:32:19 +0100
From: Markus Armbruster <[email protected]>
Subject: Re: [PATCH v7 RESEND 0/5] i386: Support SMP Cache Topology

Quoted 2 lines · Zhao Liu

Hi folks,

Quoted 7 lines
Quoted 2 lines

This is my v7 resend version (updated the commit message of origin v7's Patch 1).

If anything changed, even if it's just a commit message, make it a new version, not a resend, to avoid confusion. Next time :)

[...]

Thanks Markus! I'll keep in my mind about this :-).

author
#10 lore raw
In reply to Zhao Liu

Hi Paolo,

A kindly ping. (I dropped the cache per thread; do you think this version is ok?)

Thanks,
Zhao

Quoted 112 lines · Zhao Liu

Date: Fri, 10 Jan 2025 22:51:10 +0800
From: Zhao Liu <[email protected]>
Subject: [PATCH v7 RESEND 0/5] i386: Support SMP Cache Topology
X-Mailer: git-send-email 2.34.1

Hi folks,

This is my v7 resend version (updated the commit message of origin v7's Patch 1).

Compared with v6 [1], v7 dropped the "thread" level cache topology (cache per thread):

- Patch 1 is the new patch to reject "thread" parameter for smp-cache.
- Ptach 2 dropped cache per thread support.
(Others remain unchanged.)

There're several reasons:

* Currently, neither i386 nor ARM have real hardware support for per- thread cache.
* ARM can't support thread level cache in device tree. [2].

So it is unnecessary to support it at this moment, even though per- thread cache might have potential scheduling benefits for VMs without CPU affinity.

In the future, if there is a clear demand for this feature, the correct approach would be to add a new control field in MachineClass.smp_props and enable it only for the machines that require it.

This series is based on the master branch at commit aa3a285b5bc5 ("Merge tag 'mem-2024-12-21' of https://github.com/davidhildenbrand/qemu into staging").

Smp-cache support of ARM side can be found at [3].

Background
==========

The x86 and ARM (RISCV) need to allow user to configure cache properties (current only topology):
* For x86, the default cache topology model (of max/host CPU) does not always match the Host's real physical cache topology. Performance can increase when the configured virtual topology is closer to the physical topology than a default topology would be.
* For ARM, QEMU can't get the cache topology information from the CPU registers, then user configuration is necessary. Additionally, the cache information is also needed for MPAM emulation (for TCG) to build the right PPTT. (Originally from Jonathan)

About smp-cache
===============

The API design has been discussed heavily in [4].

Now, smp-cache is implemented as a array integrated in -machine. Though -machine currently can't support JSON format, this is the one of the directions of future.

An example is as follows:

smp_cache=smp-cache.0.cache=l1i,smp-cache.0.topology=core,smp-cache.1.cache=l1d,smp-cache.1.topology=core,smp-cache.2.cache=l2,smp-cache.2.topology=module,smp-cache.3.cache=l3,smp-cache.3.topology=die

"cache" specifies the cache that the properties will be applied on. This field is the combination of cache level and cache type. Now it supports "l1d" (L1 data cache), "l1i" (L1 instruction cache), "l2" (L2 unified cache) and "l3" (L3 unified cache).

"topology" field accepts CPU topology levels including "core", "module", "cluster", "die", "socket", "book", "drawer" and a special value "default". (Note, now, in v7, smp-cache doesn't support "thread".)

The "default" is introduced to make it easier for libvirt to set a default parameter value without having to care about the specific machine (because currently there is no proper way for machine to expose supported topology levels and caches).

If "default" is set, then the cache topology will follow the architecture's default cache topology model. If other CPU topology level is set, the cache will be shared at corresponding CPU topology level.

[1]: Patch v6: https://lore.kernel.org/qemu-devel/[email protected]/
[2]: Gap of cache per thread for ARM: https://lore.kernel.org/qemu-devel/[email protected]/T/#m50c37fa5d372feac8e607c279cd446da3e22a12c
[3]: ARM smp-cache: https://lore.kernel.org/qemu-devel/[email protected]/
[4]: API disscussion: https://lore.kernel.org/qemu-devel/[email protected]/

Thanks and Best Regards,
Zhao
---
Alireza Sanaee (1):
i386/cpu: add has_caches flag to check smp_cache configuration

Zhao Liu (4):
hw/core/machine: Reject thread level cache i386/cpu: Support module level cache topology i386/cpu: Update cache topology with machine's configuration i386/pc: Support cache topology in -machine for PC machine

 hw/core/machine-smp.c |  9 ++++++
 hw/i386/pc.c          |  4 +++
 include/hw/boards.h   |  3 ++
 qemu-options.hx       | 30 +++++++++++++++++-
 target/i386/cpu.c     | 71 ++++++++++++++++++++++++++++++++++++++++++-
 5 files changed, 115 insertions(+), 2 deletions(-)
Signature · 1 line
2.34.1
author
#11 lore raw

Hi Paolo,

A gentle poke. I plan to add cache models for Intel CPUs and extend this smp_cache interface after this series. :-)

(The 1st patch of general machine has been picked by Phili.)

Thanks,
Zhao

Quoted 20 lines
Quoted 19 lines

Alireza Sanaee (1):
i386/cpu: add has_caches flag to check smp_cache configuration

Zhao Liu (4):
hw/core/machine: Reject thread level cache i386/cpu: Support module level cache topology i386/cpu: Update cache topology with machine's configuration i386/pc: Support cache topology in -machine for PC machine

 hw/core/machine-smp.c |  9 ++++++
 hw/i386/pc.c          |  4 +++
 include/hw/boards.h   |  3 ++
 qemu-options.hx       | 30 +++++++++++++++++-
 target/i386/cpu.c     | 71 ++++++++++++++++++++++++++++++++++++++++++-
 5 files changed, 115 insertions(+), 2 deletions(-)
Signature · 1 line
2.34.1