qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v7 RESEND 0/5] i386: Support SMP Cache Topology
@ 2025-01-10 14:51 Zhao Liu
  2025-01-10 14:51 ` [PATCH v7 RESEND 1/5] hw/core/machine: Reject thread level cache Zhao Liu
                   ` (7 more replies)
  0 siblings, 8 replies; 12+ messages in thread
From: Zhao Liu @ 2025-01-10 14:51 UTC (permalink / raw)
  To: Paolo Bonzini, Philippe Mathieu-Daudé,
	Daniel P . Berrangé, Markus Armbruster, Igor Mammedov,
	Michael S . Tsirkin, Richard Henderson, Eduardo Habkost,
	Marcel Apfelbaum, Yanan Wang, Jonathan Cameron, Alireza Sanaee,
	Sia Jee Heng
  Cc: qemu-devel, kvm, 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.

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/20241219083237.265419-1-zhao1.liu@intel.com/
[2]: Gap of cache per thread for ARM: https://lore.kernel.org/qemu-devel/20250110114100.00002296@huawei.com/T/#m50c37fa5d372feac8e607c279cd446da3e22a12c
[3]: ARM smp-cache: https://lore.kernel.org/qemu-devel/20250102152012.1049-1-alireza.sanaee@huawei.com/
[4]: API disscussion: https://lore.kernel.org/qemu-devel/8734ndj33j.fsf@pond.sub.org/

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(-)

-- 
2.34.1



^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v7 RESEND 1/5] hw/core/machine: Reject thread level cache
  2025-01-10 14:51 [PATCH v7 RESEND 0/5] i386: Support SMP Cache Topology Zhao Liu
@ 2025-01-10 14:51 ` Zhao Liu
  2025-02-06  9:42   ` Philippe Mathieu-Daudé
  2025-01-10 14:51 ` [PATCH v7 RESEND 2/5] i386/cpu: Support module level cache topology Zhao Liu
                   ` (6 subsequent siblings)
  7 siblings, 1 reply; 12+ messages in thread
From: Zhao Liu @ 2025-01-10 14:51 UTC (permalink / raw)
  To: Paolo Bonzini, Philippe Mathieu-Daudé,
	Daniel P . Berrangé, Markus Armbruster, Igor Mammedov,
	Michael S . Tsirkin, Richard Henderson, Eduardo Habkost,
	Marcel Apfelbaum, Yanan Wang, Jonathan Cameron, Alireza Sanaee,
	Sia Jee Heng
  Cc: qemu-devel, kvm, 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.

Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
---
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(+)

diff --git a/hw/core/machine-smp.c b/hw/core/machine-smp.c
index b954eb849027..4e020c358b66 100644
--- a/hw/core/machine-smp.c
+++ b/hw/core/machine-smp.c
@@ -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;
         }
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v7 RESEND 2/5] i386/cpu: Support module level cache topology
  2025-01-10 14:51 [PATCH v7 RESEND 0/5] i386: Support SMP Cache Topology Zhao Liu
  2025-01-10 14:51 ` [PATCH v7 RESEND 1/5] hw/core/machine: Reject thread level cache Zhao Liu
@ 2025-01-10 14:51 ` Zhao Liu
  2025-01-10 14:51 ` [PATCH v7 RESEND 3/5] i386/cpu: Update cache topology with machine's configuration Zhao Liu
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 12+ messages in thread
From: Zhao Liu @ 2025-01-10 14:51 UTC (permalink / raw)
  To: Paolo Bonzini, Philippe Mathieu-Daudé,
	Daniel P . Berrangé, Markus Armbruster, Igor Mammedov,
	Michael S . Tsirkin, Richard Henderson, Eduardo Habkost,
	Marcel Apfelbaum, Yanan Wang, Jonathan Cameron, Alireza Sanaee,
	Sia Jee Heng
  Cc: qemu-devel, kvm, Zhao Liu, Yongwei Ma

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

Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
Tested-by: Yongwei Ma <yongwei.ma@intel.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
Changes since Patch v6:
 * Dropped "thread" level cache topology support.
---
 target/i386/cpu.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 660ddafc28b5..4728373fdf03 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -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();
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v7 RESEND 3/5] i386/cpu: Update cache topology with machine's configuration
  2025-01-10 14:51 [PATCH v7 RESEND 0/5] i386: Support SMP Cache Topology Zhao Liu
  2025-01-10 14:51 ` [PATCH v7 RESEND 1/5] hw/core/machine: Reject thread level cache Zhao Liu
  2025-01-10 14:51 ` [PATCH v7 RESEND 2/5] i386/cpu: Support module level cache topology Zhao Liu
@ 2025-01-10 14:51 ` Zhao Liu
  2025-01-10 14:51 ` [PATCH v7 RESEND 4/5] i386/pc: Support cache topology in -machine for PC machine Zhao Liu
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 12+ messages in thread
From: Zhao Liu @ 2025-01-10 14:51 UTC (permalink / raw)
  To: Paolo Bonzini, Philippe Mathieu-Daudé,
	Daniel P . Berrangé, Markus Armbruster, Igor Mammedov,
	Michael S . Tsirkin, Richard Henderson, Eduardo Habkost,
	Marcel Apfelbaum, Yanan Wang, Jonathan Cameron, Alireza Sanaee,
	Sia Jee Heng
  Cc: qemu-devel, kvm, Zhao Liu, Yongwei Ma

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.

Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
Tested-by: Yongwei Ma <yongwei.ma@intel.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
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(+)

diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 4728373fdf03..b6d6c4b96d49 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -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) {
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v7 RESEND 4/5] i386/pc: Support cache topology in -machine for PC machine
  2025-01-10 14:51 [PATCH v7 RESEND 0/5] i386: Support SMP Cache Topology Zhao Liu
                   ` (2 preceding siblings ...)
  2025-01-10 14:51 ` [PATCH v7 RESEND 3/5] i386/cpu: Update cache topology with machine's configuration Zhao Liu
@ 2025-01-10 14:51 ` Zhao Liu
  2025-01-10 14:51 ` [PATCH v7 RESEND 5/5] i386/cpu: add has_caches flag to check smp_cache configuration Zhao Liu
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 12+ messages in thread
From: Zhao Liu @ 2025-01-10 14:51 UTC (permalink / raw)
  To: Paolo Bonzini, Philippe Mathieu-Daudé,
	Daniel P . Berrangé, Markus Armbruster, Igor Mammedov,
	Michael S . Tsirkin, Richard Henderson, Eduardo Habkost,
	Marcel Apfelbaum, Yanan Wang, Jonathan Cameron, Alireza Sanaee,
	Sia Jee Heng
  Cc: qemu-devel, kvm, Zhao Liu, Yongwei Ma

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.

Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
Tested-by: Yongwei Ma <yongwei.ma@intel.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
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(-)

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 53a2f226d038..b9b83d1936ae 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -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;
 
diff --git a/qemu-options.hx b/qemu-options.hx
index cc694d3b890c..60894fe2b52b 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -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,
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v7 RESEND 5/5] i386/cpu: add has_caches flag to check smp_cache configuration
  2025-01-10 14:51 [PATCH v7 RESEND 0/5] i386: Support SMP Cache Topology Zhao Liu
                   ` (3 preceding siblings ...)
  2025-01-10 14:51 ` [PATCH v7 RESEND 4/5] i386/pc: Support cache topology in -machine for PC machine Zhao Liu
@ 2025-01-10 14:51 ` Zhao Liu
  2025-01-15  8:46 ` [PATCH v7 RESEND 0/5] i386: Support SMP Cache Topology Michael S. Tsirkin
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 12+ messages in thread
From: Zhao Liu @ 2025-01-10 14:51 UTC (permalink / raw)
  To: Paolo Bonzini, Philippe Mathieu-Daudé,
	Daniel P . Berrangé, Markus Armbruster, Igor Mammedov,
	Michael S . Tsirkin, Richard Henderson, Eduardo Habkost,
	Marcel Apfelbaum, Yanan Wang, Jonathan Cameron, Alireza Sanaee,
	Sia Jee Heng
  Cc: qemu-devel, kvm, Zhao Liu

From: Alireza Sanaee <alireza.sanaee@huawei.com>

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

Signed-off-by: Alireza Sanaee <alireza.sanaee@huawei.com>
Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
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(-)

diff --git a/hw/core/machine-smp.c b/hw/core/machine-smp.c
index 4e020c358b66..0be0ac044c22 100644
--- a/hw/core/machine-smp.c
+++ b/hw/core/machine-smp.c
@@ -332,6 +332,8 @@ bool machine_parse_smp_cache(MachineState *ms,
             return false;
         }
     }
+
+    mc->smp_props.has_caches = true;
     return true;
 }
 
diff --git a/include/hw/boards.h b/include/hw/boards.h
index 2ad711e56dbe..97125b027070 100644
--- a/include/hw/boards.h
+++ b/include/hw/boards.h
@@ -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;
 
 /**
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index b6d6c4b96d49..7bc619236680 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -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);
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH v7 RESEND 0/5] i386: Support SMP Cache Topology
  2025-01-10 14:51 [PATCH v7 RESEND 0/5] i386: Support SMP Cache Topology Zhao Liu
                   ` (4 preceding siblings ...)
  2025-01-10 14:51 ` [PATCH v7 RESEND 5/5] i386/cpu: add has_caches flag to check smp_cache configuration Zhao Liu
@ 2025-01-15  8:46 ` Michael S. Tsirkin
  2025-02-05 12:32 ` Markus Armbruster
  2025-02-06  9:21 ` Zhao Liu
  7 siblings, 0 replies; 12+ messages in thread
From: Michael S. Tsirkin @ 2025-01-15  8:46 UTC (permalink / raw)
  To: Zhao Liu
  Cc: Paolo Bonzini, Philippe Mathieu-Daudé,
	Daniel P . Berrangé, Markus Armbruster, Igor Mammedov,
	Richard Henderson, Eduardo Habkost, Marcel Apfelbaum, Yanan Wang,
	Jonathan Cameron, Alireza Sanaee, Sia Jee Heng, qemu-devel, kvm

On Fri, Jan 10, 2025 at 10:51:10PM +0800, Zhao Liu wrote:
> 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").

pc things:

Reviewed-by: Michael S. Tsirkin <mst@redhat.com>



> 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/20241219083237.265419-1-zhao1.liu@intel.com/
> [2]: Gap of cache per thread for ARM: https://lore.kernel.org/qemu-devel/20250110114100.00002296@huawei.com/T/#m50c37fa5d372feac8e607c279cd446da3e22a12c
> [3]: ARM smp-cache: https://lore.kernel.org/qemu-devel/20250102152012.1049-1-alireza.sanaee@huawei.com/
> [4]: API disscussion: https://lore.kernel.org/qemu-devel/8734ndj33j.fsf@pond.sub.org/
> 
> 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(-)
> 
> -- 
> 2.34.1



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v7 RESEND 0/5] i386: Support SMP Cache Topology
  2025-01-10 14:51 [PATCH v7 RESEND 0/5] i386: Support SMP Cache Topology Zhao Liu
                   ` (5 preceding siblings ...)
  2025-01-15  8:46 ` [PATCH v7 RESEND 0/5] i386: Support SMP Cache Topology Michael S. Tsirkin
@ 2025-02-05 12:32 ` Markus Armbruster
  2025-02-06  9:17   ` Zhao Liu
  2025-02-06  9:21 ` Zhao Liu
  7 siblings, 1 reply; 12+ messages in thread
From: Markus Armbruster @ 2025-02-05 12:32 UTC (permalink / raw)
  To: Zhao Liu
  Cc: Paolo Bonzini, Philippe Mathieu-Daudé,
	Daniel P . Berrangé, Igor Mammedov, Michael S . Tsirkin,
	Richard Henderson, Eduardo Habkost, Marcel Apfelbaum, Yanan Wang,
	Jonathan Cameron, Alireza Sanaee, Sia Jee Heng, qemu-devel, kvm

Zhao Liu <zhao1.liu@intel.com> writes:

> 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 :)

[...]



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v7 RESEND 0/5] i386: Support SMP Cache Topology
  2025-02-05 12:32 ` Markus Armbruster
@ 2025-02-06  9:17   ` Zhao Liu
  0 siblings, 0 replies; 12+ messages in thread
From: Zhao Liu @ 2025-02-06  9:17 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: Paolo Bonzini, Philippe Mathieu-Daudé,
	Daniel P . Berrangé, Igor Mammedov, Michael S . Tsirkin,
	Richard Henderson, Eduardo Habkost, Marcel Apfelbaum, Yanan Wang,
	Jonathan Cameron, Alireza Sanaee, Sia Jee Heng, qemu-devel, kvm

On Wed, Feb 05, 2025 at 01:32:19PM +0100, Markus Armbruster wrote:
> Date: Wed, 05 Feb 2025 13:32:19 +0100
> From: Markus Armbruster <armbru@redhat.com>
> Subject: Re: [PATCH v7 RESEND 0/5] i386: Support SMP Cache Topology
> 
> Zhao Liu <zhao1.liu@intel.com> writes:
> 
> > 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 :)
> 
> [...]

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



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v7 RESEND 0/5] i386: Support SMP Cache Topology
  2025-01-10 14:51 [PATCH v7 RESEND 0/5] i386: Support SMP Cache Topology Zhao Liu
                   ` (6 preceding siblings ...)
  2025-02-05 12:32 ` Markus Armbruster
@ 2025-02-06  9:21 ` Zhao Liu
  2025-02-19  8:59   ` Zhao Liu
  7 siblings, 1 reply; 12+ messages in thread
From: Zhao Liu @ 2025-02-06  9:21 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Philippe Mathieu-Daudé, Daniel P . Berrangé,
	Markus Armbruster, Igor Mammedov, Michael S . Tsirkin,
	Richard Henderson, Eduardo Habkost, Marcel Apfelbaum, Yanan Wang,
	Jonathan Cameron, Alireza Sanaee, Sia Jee Heng, qemu-devel, kvm

Hi Paolo,

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

Thanks,
Zhao

On Fri, Jan 10, 2025 at 10:51:10PM +0800, Zhao Liu wrote:
> Date: Fri, 10 Jan 2025 22:51:10 +0800
> From: Zhao Liu <zhao1.liu@intel.com>
> 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/20241219083237.265419-1-zhao1.liu@intel.com/
> [2]: Gap of cache per thread for ARM: https://lore.kernel.org/qemu-devel/20250110114100.00002296@huawei.com/T/#m50c37fa5d372feac8e607c279cd446da3e22a12c
> [3]: ARM smp-cache: https://lore.kernel.org/qemu-devel/20250102152012.1049-1-alireza.sanaee@huawei.com/
> [4]: API disscussion: https://lore.kernel.org/qemu-devel/8734ndj33j.fsf@pond.sub.org/
> 
> 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(-)
> 
> -- 
> 2.34.1
> 


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v7 RESEND 1/5] hw/core/machine: Reject thread level cache
  2025-01-10 14:51 ` [PATCH v7 RESEND 1/5] hw/core/machine: Reject thread level cache Zhao Liu
@ 2025-02-06  9:42   ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 12+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-02-06  9:42 UTC (permalink / raw)
  To: Zhao Liu, Paolo Bonzini, Daniel P . Berrangé,
	Markus Armbruster, Igor Mammedov, Michael S . Tsirkin,
	Richard Henderson, Eduardo Habkost, Marcel Apfelbaum, Yanan Wang,
	Jonathan Cameron, Alireza Sanaee, Sia Jee Heng
  Cc: qemu-devel, kvm

On 10/1/25 15:51, Zhao Liu wrote:
> 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.
> 
> Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
> ---
> 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(+)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v7 RESEND 0/5] i386: Support SMP Cache Topology
  2025-02-06  9:21 ` Zhao Liu
@ 2025-02-19  8:59   ` Zhao Liu
  0 siblings, 0 replies; 12+ messages in thread
From: Zhao Liu @ 2025-02-19  8:59 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: Philippe Mathieu-Daud�, qemu-devel

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

> > 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(-)
> > 
> > -- 
> > 2.34.1
> > 
> 


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2025-02-19  8:40 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-10 14:51 [PATCH v7 RESEND 0/5] i386: Support SMP Cache Topology Zhao Liu
2025-01-10 14:51 ` [PATCH v7 RESEND 1/5] hw/core/machine: Reject thread level cache Zhao Liu
2025-02-06  9:42   ` Philippe Mathieu-Daudé
2025-01-10 14:51 ` [PATCH v7 RESEND 2/5] i386/cpu: Support module level cache topology Zhao Liu
2025-01-10 14:51 ` [PATCH v7 RESEND 3/5] i386/cpu: Update cache topology with machine's configuration Zhao Liu
2025-01-10 14:51 ` [PATCH v7 RESEND 4/5] i386/pc: Support cache topology in -machine for PC machine Zhao Liu
2025-01-10 14:51 ` [PATCH v7 RESEND 5/5] i386/cpu: add has_caches flag to check smp_cache configuration Zhao Liu
2025-01-15  8:46 ` [PATCH v7 RESEND 0/5] i386: Support SMP Cache Topology Michael S. Tsirkin
2025-02-05 12:32 ` Markus Armbruster
2025-02-06  9:17   ` Zhao Liu
2025-02-06  9:21 ` Zhao Liu
2025-02-19  8:59   ` Zhao Liu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).