Skip to contentSkip to conversation

Introduce hybrid CPU topology

RFC In review Zhao Liu 9 participants 113 messages Feb 13, 2023 – Aug 4, 2023 Page 2 of 2

Subsystems (7)
lore
Share & tools
lore
author
#91 lore raw

Re: [RFC 41/52] machine: Introduce core_type() hook

In reply to wangyanan (Y) via
Quoted 40 lines · wangyanan (Y)

Date: Thu, 16 Feb 2023 20:15:23 +0800
From: "wangyanan (Y)" <[email protected]>
Subject: Re: [RFC 41/52] machine: Introduce core_type() hook

Hi Zhao,

Quoted 33 lines · Zhao Liu

From: Zhao Liu <[email protected]>

Since supported core types are architecture specific, we need this hook to allow archs define its own parsing or validation method.

As the example, add the x86 core_type() which will be used in "-hybrid" parameter parsing.

---
  hw/core/machine-topo.c | 14 ++++++++++++++
  hw/core/machine.c      |  1 +
  hw/i386/x86.c          | 15 +++++++++++++++
  include/hw/boards.h    |  7 +++++++
  4 files changed, 37 insertions(+)
hw/core/machine-topo.c +9 -0
index 12c05510c1b5..f9ab08a1252e 100644
@@ -352,3 +352,17 @@ void machine_parse_smp_config(MachineState *ms,
          return;
      }
  }
+
+/*
+ * machine_parse_hybrid_core_type: the default hook to parse hybrid core
+ *                                 type corresponding to the coretype
+ *                                 string option.
+ */
+int machine_parse_hybrid_core_type(MachineState *ms, const char *coretype)
+{
+    if (strcmp(coretype, "") == 0 || strcmp(coretype, "none") == 0) {
Quoted 8 lines

hw/core/machine-topo.c void machine_parse_smp_config(MachineState *ms, · line 368

Quoted 5 lines
hw/core/machine-topo.c +5 -0
+        return 0;
+    }
+
+    return -1;
+}

Is it possible that coretype can be NULL?
What would *coretype be if the users don't explicitly specify coretype in the command line?

At present, the coretype field cannot be omitted, which requires other code changes to support omission (if omission is required in the future, there should be an arch-specific method to supplement the default coretype at the same time).

Quoted 26 lines
Quoted 26 lines
hw/core/machine.c +1 -0
index fad990f49b03..acc32b3be5f6 100644
@@ -926,6 +926,7 @@ static void machine_class_init(ObjectClass *oc, void *data)
       * On Linux, each node's border has to be 8MB aligned
       */
      mc->numa_mem_align_shift = 23;
+    mc->core_type = machine_parse_hybrid_core_type;
      object_class_property_add_str(oc, "kernel",
          machine_get_kernel, machine_set_kernel);
hw/i386/x86.c +8 -0
index f381fdc43180..f58a90359170 100644
@@ -1569,6 +1569,20 @@ static void machine_set_sgx_epc(Object *obj, Visitor *v, const char *name,
      qapi_free_SgxEPCList(list);
  }
+static int x86_parse_hybrid_core_type(MachineState *ms, const char *coretype)
+{
+    X86HybridCoreType type;
+
+    if (strcmp(coretype, "atom") == 0) {
+        type = INTEL_ATOM_TYPE;
+    } else if (strcmp(coretype, "core") == 0) {
+        type = INTEL_CORE_TYPE;
Quoted 8 lines

hw/i386/x86.c static void machine_set_sgx_epc(Object *obj, Visitor *v, const char *name, · line 1582

Quoted 3 lines
hw/i386/x86.c +3 -0
+    } else {
+        type = INVALID_HYBRID_TYPE;
+    }

What about:
INTEL_CORE_TYPE_ATOM
INTEL_CORE_TYPE_CORE
X86_CORE_TYPE_UNKNOWN ?
just a suggestion.

It looks better! Thanks.

Quoted 47 lines

Thanks,
Yanan

Quoted 43 lines
hw/i386/x86.c +4 -0
+    return type;
+}
+
  static void x86_machine_initfn(Object *obj)
  {
      X86MachineState *x86ms = X86_MACHINE(obj);
@@ -1596,6 +1610,7 @@ static void x86_machine_class_init(ObjectClass *oc, void *data)
      x86mc->save_tsc_khz = true;
      x86mc->fwcfg_dma_enabled = true;
      nc->nmi_monitor_handler = x86_nmi;
+    mc->core_type = x86_parse_hybrid_core_type;
      object_class_property_add(oc, X86_MACHINE_SMM, "OnOffAuto",
          x86_machine_get_smm, x86_machine_set_smm,
include/hw/boards.h +7 -0
index 9364c90d5f1a..34ec035b5c9f 100644
@@ -36,6 +36,7 @@ void machine_set_cpu_numa_node(MachineState *machine,
                                 Error **errp);
  void machine_parse_smp_config(MachineState *ms,
                                const SMPConfiguration *config, Error **errp);
+int machine_parse_hybrid_core_type(MachineState *ms, const char *coretype);
  /**
   * machine_class_allow_dynamic_sysbus_dev: Add type to list of valid devices
@@ -199,6 +200,11 @@ typedef struct {
   *    Return the type of KVM corresponding to the kvm-type string option or
   *    computed based on other criteria such as the host kernel capabilities.
   *    kvm-type may be NULL if it is not needed.
+ * @core_type:
+ *    Return the type of hybrid cores corresponding to the coretype string
+ *    option. The default hook only accept "none" or "" since the most generic
+ *    core topology should not specify any specific core type. Each arch can
+ *    define its own core_type() hook to override the default one.
   * @numa_mem_supported:
   *    true if '--numa node.mem' option is supported and false otherwise
   * @hotplug_allowed:
@@ -237,6 +243,7 @@ struct MachineClass {
      void (*reset)(MachineState *state, ShutdownCause reason);
      void (*wakeup)(MachineState *state);
      int (*kvm_type)(MachineState *machine, const char *arg);
+    int (*core_type)(MachineState *state, const char *type);
      BlockInterfaceType block_default_type;
      int units_per_default_bus;
#92 lore raw

Re: [RFC 41/52] machine: Introduce core_type() hook

Quoted 49 lines · Zhao Liu
Quoted 40 lines · wangyanan (Y)

Date: Thu, 16 Feb 2023 20:15:23 +0800
From: "wangyanan (Y)" <[email protected]>
Subject: Re: [RFC 41/52] machine: Introduce core_type() hook

Hi Zhao,

Quoted 33 lines · Zhao Liu

From: Zhao Liu <[email protected]>

Since supported core types are architecture specific, we need this hook to allow archs define its own parsing or validation method.

As the example, add the x86 core_type() which will be used in "-hybrid" parameter parsing.

---
   hw/core/machine-topo.c | 14 ++++++++++++++
   hw/core/machine.c      |  1 +
   hw/i386/x86.c          | 15 +++++++++++++++
   include/hw/boards.h    |  7 +++++++
   4 files changed, 37 insertions(+)
hw/core/machine-topo.c +9 -0
index 12c05510c1b5..f9ab08a1252e 100644
@@ -352,3 +352,17 @@ void machine_parse_smp_config(MachineState *ms,
           return;
       }
   }
+
+/*
+ * machine_parse_hybrid_core_type: the default hook to parse hybrid core
+ *                                 type corresponding to the coretype
+ *                                 string option.
+ */
+int machine_parse_hybrid_core_type(MachineState *ms, const char *coretype)
+{
+    if (strcmp(coretype, "") == 0 || strcmp(coretype, "none") == 0) {
Quoted 8 lines

hw/core/machine-topo.c void machine_parse_smp_config(MachineState *ms, · line 368

Quoted 5 lines
hw/core/machine-topo.c +5 -0
+        return 0;
+    }
+
+    return -1;
+}

Is it possible that coretype can be NULL?
What would *coretype be if the users don't explicitly specify coretype in the command line?

Quoted 4 lines

At present, the coretype field cannot be omitted, which requires other code changes to support omission (if omission is required in the future, there should be an arch-specific method to supplement the default coretype at the same time).

IIUC, we may need to support the handling of omission case at the beginning. Not all archs have/need the core type concept when they support hybrid, and if an arch does not have the core type concept, it's best to forbid it in the CLI and leave the handling to the generic machine_parse_hybrid_core_type and the arch-specific core_type hook should be NULL.

Thanks,
Yanan

Quoted 82 lines
Quoted 27 lines
Quoted 27 lines
hw/core/machine.c +1 -0
index fad990f49b03..acc32b3be5f6 100644
@@ -926,6 +926,7 @@ static void machine_class_init(ObjectClass *oc, void *data)
        * On Linux, each node's border has to be 8MB aligned
        */
       mc->numa_mem_align_shift = 23;
+    mc->core_type = machine_parse_hybrid_core_type;
       object_class_property_add_str(oc, "kernel",
           machine_get_kernel, machine_set_kernel);
hw/i386/x86.c +8 -0
index f381fdc43180..f58a90359170 100644
@@ -1569,6 +1569,20 @@ static void machine_set_sgx_epc(Object *obj, Visitor *v, const char *name,
       qapi_free_SgxEPCList(list);
   }
+static int x86_parse_hybrid_core_type(MachineState *ms, const char *coretype)
+{
+    X86HybridCoreType type;
+
+    if (strcmp(coretype, "atom") == 0) {
+        type = INTEL_ATOM_TYPE;
+    } else if (strcmp(coretype, "core") == 0) {
+        type = INTEL_CORE_TYPE;
Quoted 8 lines

hw/i386/x86.c static void machine_set_sgx_epc(Object *obj, Visitor *v, const char *name, · line 1582

Quoted 3 lines
hw/i386/x86.c +3 -0
+    } else {
+        type = INVALID_HYBRID_TYPE;
+    }

What about:
INTEL_CORE_TYPE_ATOM
INTEL_CORE_TYPE_CORE
X86_CORE_TYPE_UNKNOWN ?
just a suggestion.

It looks better! Thanks.

Quoted 45 lines

Thanks,
Yanan

Quoted 43 lines
hw/i386/x86.c +4 -0
+    return type;
+}
+
   static void x86_machine_initfn(Object *obj)
   {
       X86MachineState *x86ms = X86_MACHINE(obj);
@@ -1596,6 +1610,7 @@ static void x86_machine_class_init(ObjectClass *oc, void *data)
       x86mc->save_tsc_khz = true;
       x86mc->fwcfg_dma_enabled = true;
       nc->nmi_monitor_handler = x86_nmi;
+    mc->core_type = x86_parse_hybrid_core_type;
       object_class_property_add(oc, X86_MACHINE_SMM, "OnOffAuto",
           x86_machine_get_smm, x86_machine_set_smm,
include/hw/boards.h +7 -0
index 9364c90d5f1a..34ec035b5c9f 100644
@@ -36,6 +36,7 @@ void machine_set_cpu_numa_node(MachineState *machine,
                                  Error **errp);
   void machine_parse_smp_config(MachineState *ms,
                                 const SMPConfiguration *config, Error **errp);
+int machine_parse_hybrid_core_type(MachineState *ms, const char *coretype);
   /**
    * machine_class_allow_dynamic_sysbus_dev: Add type to list of valid devices
@@ -199,6 +200,11 @@ typedef struct {
    *    Return the type of KVM corresponding to the kvm-type string option or
    *    computed based on other criteria such as the host kernel capabilities.
    *    kvm-type may be NULL if it is not needed.
+ * @core_type:
+ *    Return the type of hybrid cores corresponding to the coretype string
+ *    option. The default hook only accept "none" or "" since the most generic
+ *    core topology should not specify any specific core type. Each arch can
+ *    define its own core_type() hook to override the default one.
    * @numa_mem_supported:
    *    true if '--numa node.mem' option is supported and false otherwise
    * @hotplug_allowed:
@@ -237,6 +243,7 @@ struct MachineClass {
       void (*reset)(MachineState *state, ShutdownCause reason);
       void (*wakeup)(MachineState *state);
       int (*kvm_type)(MachineState *machine, const char *arg);
+    int (*core_type)(MachineState *state, const char *type);
       BlockInterfaceType block_default_type;
       int units_per_default_bus;
author
#93 lore raw

RFC 42/52 hw/machine: Add hybrid_supported in generic topo properties

In reply to Zhao Liu

From: Zhao Liu <[email protected]>

Since hybrid cpu topology configuration can benefit not only x86, but also other architectures/platforms that have supported (in real machines) or will support hybrid CPU topology, "-hybrid" can be generic.

So add the generic topology property to configure if support hybrid cpu topology for architectures/platforms in SmpCompatProps.

Also rename SmpCompatProps to TopoCompatProps to make this structure more generic for both smp topology and hybrid topology.

---
 include/hw/boards.h | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
include/hw/boards.h +11 -4
index 34ec035b5c9f..17be3485e823 100644
@@ -127,19 +127,26 @@ typedef struct {
 } CPUArchIdList;
 
 /**
- * SMPCompatProps:
- * @prefer_sockets - whether sockets are preferred over cores in smp parsing
+ * TopoCompatProps:
+ * @hybrid_support - whether hybrid cpu topology are supported by machine.
+ *                   Note that hybrid cpu topology requires to specify the
+ *                   topology of each core so that there will no longer be
+ *                   a default core topology, thus prefer_sockets won't work
+ *                   when hybrid_support is enabled.
+ * @prefer_sockets - whether sockets are preferred over cores in smp parsing.
+ *                   Not work when hybrid_support is enabled.
  * @dies_supported - whether dies are supported by the machine
  * @clusters_supported - whether clusters are supported by the machine
  * @has_clusters - whether clusters are explicitly specified in the user
  *                 provided SMP configuration
  */
 typedef struct {
+    bool hybrid_supported;
     bool prefer_sockets;
     bool dies_supported;
     bool clusters_supported;
     bool has_clusters;
-} SMPCompatProps;
+} TopoCompatProps;
 
 /**
  * MachineClass:
@@ -281,7 +288,7 @@ struct MachineClass {
     bool nvdimm_supported;
     bool numa_mem_supported;
     bool auto_enable_numa;
-    SMPCompatProps smp_props;
+    TopoCompatProps smp_props;
     const char *default_ram_id;
 
     HotplugHandler *(*get_hotplug_handler)(MachineState *machine,
Signature · 1 line
2.34.1
#94 lore raw

Re: [RFC 42/52] hw/machine: Add hybrid_supported in generic topo properties

Hi Zhao,

Quoted 22 lines · Zhao Liu

From: Zhao Liu <[email protected]>

Since hybrid cpu topology configuration can benefit not only x86, but also other architectures/platforms that have supported (in real machines) or will support hybrid CPU topology, "-hybrid" can be generic.

So add the generic topology property to configure if support hybrid cpu topology for architectures/platforms in SmpCompatProps.

Also rename SmpCompatProps to TopoCompatProps to make this structure more generic for both smp topology and hybrid topology.

---
  include/hw/boards.h | 15 +++++++++++----
  1 file changed, 11 insertions(+), 4 deletions(-)
include/hw/boards.h +0 -0
index 34ec035b5c9f..17be3485e823 100644

include/hw/boards.h typedef struct { · line 131

Quoted 7 lines
include/hw/boards.h +2 -2
@@ -127,19 +127,26 @@ typedef struct {
  } CPUArchIdList;
 
  /**
- * SMPCompatProps:
- * @prefer_sockets - whether sockets are preferred over cores in smp parsing
+ * TopoCompatProps:
+ * @hybrid_support - whether hybrid cpu topology are supported by machine.

inconsistent with the name in the definition below.

Quoted 10 lines
include/hw/boards.h +6 -0
+ *                   Note that hybrid cpu topology requires to specify the
+ *                   topology of each core so that there will no longer be
+ *                   a default core topology, thus prefer_sockets won't work
+ *                   when hybrid_support is enabled.
+ * @prefer_sockets - whether sockets are preferred over cores in smp parsing.
+ *                   Not work when hybrid_support is enabled.
   * @dies_supported - whether dies are supported by the machine
   * @clusters_supported - whether clusters are supported by the machine
   * @has_clusters - whether clusters are explicitly specified in the user
   *                 provided SMP configuration

include/hw/boards.h typedef struct { · line 150

Quoted 10 lines
include/hw/boards.h +2 -1
   */
  typedef struct {
+    bool hybrid_supported;
      bool prefer_sockets;
      bool dies_supported;
      bool clusters_supported;
      bool has_clusters;
-} SMPCompatProps;
+} TopoCompatProps;
 

Also here. "Rename SMPCompatProps to TopoCompatProps and move it to cpu-topology.h and adapt the code" should be organized in one or more separate patches, being pre-patches together with the conversion of CpuTopology before. And put the "hybrid_supported" extension into another patch. Would this make it easier to review?

Thanks,
Yanan

Quoted 11 lines
include/hw/boards.h +1 -1
  /**
   * MachineClass:
@@ -281,7 +288,7 @@ struct MachineClass {
      bool nvdimm_supported;
      bool numa_mem_supported;
      bool auto_enable_numa;
-    SMPCompatProps smp_props;
+    TopoCompatProps smp_props;
      const char *default_ram_id;
 
      HotplugHandler *(*get_hotplug_handler)(MachineState *machine,
author
#95 lore raw

Re: [RFC 42/52] hw/machine: Add hybrid_supported in generic topo properties

Quoted 25 lines · wangyanan (Y)

Date: Tue, 14 Feb 2023 09:46:50 +0800
From: "wangyanan (Y)" <[email protected]>
Subject: Re: [RFC 42/52] hw/machine: Add hybrid_supported in generic topo
properties

Hi Zhao,

Quoted 17 lines · Zhao Liu

From: Zhao Liu <[email protected]>

Since hybrid cpu topology configuration can benefit not only x86, but also other architectures/platforms that have supported (in real machines) or will support hybrid CPU topology, "-hybrid" can be generic.

So add the generic topology property to configure if support hybrid cpu topology for architectures/platforms in SmpCompatProps.

Also rename SmpCompatProps to TopoCompatProps to make this structure more generic for both smp topology and hybrid topology.

---
  include/hw/boards.h | 15 +++++++++++----
  1 file changed, 11 insertions(+), 4 deletions(-)
Quoted 12 lines

include/hw/boards.h typedef struct { · line 130

Quoted 11 lines
include/hw/boards.h +2 -2
index 34ec035b5c9f..17be3485e823 100644
@@ -127,19 +127,26 @@ typedef struct {
  } CPUArchIdList;
  /**
- * SMPCompatProps:
- * @prefer_sockets - whether sockets are preferred over cores in smp parsing
+ * TopoCompatProps:
+ * @hybrid_support - whether hybrid cpu topology are supported by machine.

inconsistent with the name in the definition below.

Thanks! Will fix.

Quoted 15 lines
Quoted 15 lines
include/hw/boards.h +7 -0
+ *                   Note that hybrid cpu topology requires to specify the
+ *                   topology of each core so that there will no longer be
+ *                   a default core topology, thus prefer_sockets won't work
+ *                   when hybrid_support is enabled.
+ * @prefer_sockets - whether sockets are preferred over cores in smp parsing.
+ *                   Not work when hybrid_support is enabled.
   * @dies_supported - whether dies are supported by the machine
   * @clusters_supported - whether clusters are supported by the machine
   * @has_clusters - whether clusters are explicitly specified in the user
   *                 provided SMP configuration
   */
  typedef struct {
+    bool hybrid_supported;
      bool prefer_sockets;
      bool dies_supported;
Quoted 8 lines

include/hw/boards.h typedef struct { · line 149

Quoted 4 lines
include/hw/boards.h +1 -1
      bool clusters_supported;
      bool has_clusters;
-} SMPCompatProps;
+} TopoCompatProps;

Also here. "Rename SMPCompatProps to TopoCompatProps and move it to cpu-topology.h and adapt the code" should be organized in one or more separate patches, being pre-patches together with the conversion of CpuTopology before.

Do you think TopoCompatProps/SMPCompatProps should also be moved into cpu-topology.h? It seems that SMPCompatProps is a collection of properties of MachineClass.

Quoted 2 lines

And put the "hybrid_supported"
extension into another patch. Would this make it easier to review?

Yes, I agree. Thanks!

Zhao

Quoted 14 lines

Thanks,
Yanan

Quoted 10 lines
include/hw/boards.h +1 -1
  /**
   * MachineClass:
@@ -281,7 +288,7 @@ struct MachineClass {
      bool nvdimm_supported;
      bool numa_mem_supported;
      bool auto_enable_numa;
-    SMPCompatProps smp_props;
+    TopoCompatProps smp_props;
      const char *default_ram_id;
      HotplugHandler *(*get_hotplug_handler)(MachineState *machine,
#96 lore raw

Re: [RFC 42/52] hw/machine: Add hybrid_supported in generic topo properties

Quoted 63 lines · Zhao Liu
Quoted 25 lines · wangyanan (Y)

Date: Tue, 14 Feb 2023 09:46:50 +0800
From: "wangyanan (Y)" <[email protected]>
Subject: Re: [RFC 42/52] hw/machine: Add hybrid_supported in generic topo
properties

Hi Zhao,

Quoted 17 lines · Zhao Liu

From: Zhao Liu <[email protected]>

Since hybrid cpu topology configuration can benefit not only x86, but also other architectures/platforms that have supported (in real machines) or will support hybrid CPU topology, "-hybrid" can be generic.

So add the generic topology property to configure if support hybrid cpu topology for architectures/platforms in SmpCompatProps.

Also rename SmpCompatProps to TopoCompatProps to make this structure more generic for both smp topology and hybrid topology.

---
   include/hw/boards.h | 15 +++++++++++----
   1 file changed, 11 insertions(+), 4 deletions(-)
Quoted 12 lines

include/hw/boards.h typedef struct { · line 130

Quoted 11 lines
include/hw/boards.h +2 -2
index 34ec035b5c9f..17be3485e823 100644
@@ -127,19 +127,26 @@ typedef struct {
   } CPUArchIdList;
   /**
- * SMPCompatProps:
- * @prefer_sockets - whether sockets are preferred over cores in smp parsing
+ * TopoCompatProps:
+ * @hybrid_support - whether hybrid cpu topology are supported by machine.

inconsistent with the name in the definition below.

Thanks! Will fix.

Quoted 15 lines
Quoted 15 lines
include/hw/boards.h +7 -0
+ *                   Note that hybrid cpu topology requires to specify the
+ *                   topology of each core so that there will no longer be
+ *                   a default core topology, thus prefer_sockets won't work
+ *                   when hybrid_support is enabled.
+ * @prefer_sockets - whether sockets are preferred over cores in smp parsing.
+ *                   Not work when hybrid_support is enabled.
    * @dies_supported - whether dies are supported by the machine
    * @clusters_supported - whether clusters are supported by the machine
    * @has_clusters - whether clusters are explicitly specified in the user
    *                 provided SMP configuration
    */
   typedef struct {
+    bool hybrid_supported;
       bool prefer_sockets;
       bool dies_supported;
Quoted 8 lines

include/hw/boards.h typedef struct { · line 149

Quoted 4 lines
include/hw/boards.h +1 -1
       bool clusters_supported;
       bool has_clusters;
-} SMPCompatProps;
+} TopoCompatProps;

Also here. "Rename SMPCompatProps to TopoCompatProps and move it to cpu-topology.h and adapt the code" should be organized in one or more separate patches, being pre-patches together with the conversion of CpuTopology before.

Quoted 3 lines

Do you think TopoCompatProps/SMPCompatProps should also be moved into cpu-topology.h? It seems that SMPCompatProps is a collection of properties of MachineClass.

TopoCompatProps holds properties all about CPU topology, I think we can do this, cpu-topology.h will be included in boards.h any way. But it's ups to you whether to do this.😉

Thanks,
Yanan

Quoted 18 lines
Quoted 2 lines

And put the "hybrid_supported"
extension into another patch. Would this make it easier to review?

Yes, I agree. Thanks!

Zhao

Quoted 12 lines

Thanks,
Yanan

Quoted 10 lines
include/hw/boards.h +1 -1
   /**
    * MachineClass:
@@ -281,7 +288,7 @@ struct MachineClass {
       bool nvdimm_supported;
       bool numa_mem_supported;
       bool auto_enable_numa;
-    SMPCompatProps smp_props;
+    TopoCompatProps smp_props;
       const char *default_ram_id;
       HotplugHandler *(*get_hotplug_handler)(MachineState *machine,
author
#97 lore raw

Re: [RFC 42/52] hw/machine: Add hybrid_supported in generic topo properties

Quoted 69 lines · wangyanan (Y)

Date: Thu, 16 Feb 2023 20:28:37 +0800
From: "wangyanan (Y)" <[email protected]>
Subject: Re: [RFC 42/52] hw/machine: Add hybrid_supported in generic topo
properties

Quoted 63 lines · Zhao Liu
Quoted 25 lines · wangyanan (Y)

Date: Tue, 14 Feb 2023 09:46:50 +0800
From: "wangyanan (Y)" <[email protected]>
Subject: Re: [RFC 42/52] hw/machine: Add hybrid_supported in generic topo
properties

Hi Zhao,

Quoted 17 lines · Zhao Liu

From: Zhao Liu <[email protected]>

Since hybrid cpu topology configuration can benefit not only x86, but also other architectures/platforms that have supported (in real machines) or will support hybrid CPU topology, "-hybrid" can be generic.

So add the generic topology property to configure if support hybrid cpu topology for architectures/platforms in SmpCompatProps.

Also rename SmpCompatProps to TopoCompatProps to make this structure more generic for both smp topology and hybrid topology.

---
   include/hw/boards.h | 15 +++++++++++----
   1 file changed, 11 insertions(+), 4 deletions(-)
Quoted 12 lines

include/hw/boards.h typedef struct { · line 130

Quoted 11 lines
include/hw/boards.h +2 -2
index 34ec035b5c9f..17be3485e823 100644
@@ -127,19 +127,26 @@ typedef struct {
   } CPUArchIdList;
   /**
- * SMPCompatProps:
- * @prefer_sockets - whether sockets are preferred over cores in smp parsing
+ * TopoCompatProps:
+ * @hybrid_support - whether hybrid cpu topology are supported by machine.

inconsistent with the name in the definition below.

Thanks! Will fix.

Quoted 23 lines
Quoted 9 lines
include/hw/boards.h +6 -0
+ *                   Note that hybrid cpu topology requires to specify the
+ *                   topology of each core so that there will no longer be
+ *                   a default core topology, thus prefer_sockets won't work
+ *                   when hybrid_support is enabled.
+ * @prefer_sockets - whether sockets are preferred over cores in smp parsing.
+ *                   Not work when hybrid_support is enabled.
    * @dies_supported - whether dies are supported by the machine
    * @clusters_supported - whether clusters are supported by the machine
    * @has_clusters - whether clusters are explicitly specified in the user

include/hw/boards.h typedef struct { · line 149

Quoted 10 lines
include/hw/boards.h +2 -1
    *                 provided SMP configuration
    */
   typedef struct {
+    bool hybrid_supported;
       bool prefer_sockets;
       bool dies_supported;
       bool clusters_supported;
       bool has_clusters;
-} SMPCompatProps;
+} TopoCompatProps;

Also here. "Rename SMPCompatProps to TopoCompatProps and move it to cpu-topology.h and adapt the code" should be organized in one or more separate patches, being pre-patches together with the conversion of CpuTopology before.

Quoted 6 lines
Quoted 3 lines

Do you think TopoCompatProps/SMPCompatProps should also be moved into cpu-topology.h? It seems that SMPCompatProps is a collection of properties of MachineClass.

TopoCompatProps holds properties all about CPU topology, I think we can do this, cpu-topology.h will be included in boards.h any way. But it's ups to you whether to do this.😉

Yeah, it makes sense to manage all topologically related. So I will, thanks!

Quoted 22 lines

Thanks,
Yanan

Quoted 18 lines
Quoted 2 lines

And put the "hybrid_supported"
extension into another patch. Would this make it easier to review?

Yes, I agree. Thanks!

Zhao

Quoted 12 lines

Thanks,
Yanan

Quoted 10 lines
include/hw/boards.h +1 -1
   /**
    * MachineClass:
@@ -281,7 +288,7 @@ struct MachineClass {
       bool nvdimm_supported;
       bool numa_mem_supported;
       bool auto_enable_numa;
-    SMPCompatProps smp_props;
+    TopoCompatProps smp_props;
       const char *default_ram_id;
       HotplugHandler *(*get_hotplug_handler)(MachineState *machine,
author
#98 lore raw

RFC 43/52 hw/machine: Rename MachineClass.smp_props to MachineClass.topo_props

In reply to Zhao Liu

From: Zhao Liu <[email protected]>

MachineClass.topo_props is better to be compatible with both hybrid topology and smp topology properties.

---
 hw/acpi/aml-build.c         |  2 +-
 hw/arm/virt.c               |  6 +++---
 hw/core/machine-topo.c      | 12 ++++++------
 hw/i386/pc.c                |  4 ++--
 hw/i386/pc_piix.c           |  2 +-
 hw/i386/pc_q35.c            |  2 +-
 hw/ppc/spapr.c              |  2 +-
 hw/s390x/s390-virtio-ccw.c  |  2 +-
 include/hw/boards.h         |  2 +-
 tests/unit/test-smp-parse.c | 12 ++++++------
 10 files changed, 23 insertions(+), 23 deletions(-)
hw/acpi/aml-build.c +1 -1
index 693bd8833d10..51634cfd2776 100644
@@ -2030,7 +2030,7 @@ void build_pptt(GArray *table_data, BIOSLinker *linker, MachineState *ms,
                 0, socket_id, NULL, 0);
         }
 
-        if (mc->smp_props.clusters_supported && mc->smp_props.has_clusters) {
+        if (mc->topo_props.clusters_supported && mc->topo_props.has_clusters) {
             if (cpus->cpus[n].props.cluster_id != cluster_id) {
                 assert(cpus->cpus[n].props.cluster_id > cluster_id);
                 cluster_id = cpus->cpus[n].props.cluster_id;
hw/arm/virt.c +3 -3
index ae65ba2c929c..5f0517423d8f 100644
@@ -2687,7 +2687,7 @@ static const CPUArchIdList *virt_possible_cpu_arch_ids(MachineState *ms)
         ms->possible_cpus->cpus[n].arch_id =
             virt_cpu_mp_affinity(vms, n);
 
-        assert(!mc->smp_props.dies_supported);
+        assert(!mc->topo_props.dies_supported);
         ms->possible_cpus->cpus[n].props.has_socket_id = true;
         ms->possible_cpus->cpus[n].props.socket_id =
             n / (smp_clusters * smp_cores * smp_threads);
@@ -3029,7 +3029,7 @@ static void virt_machine_class_init(ObjectClass *oc, void *data)
     hc->unplug_request = virt_machine_device_unplug_request_cb;
     hc->unplug = virt_machine_device_unplug_cb;
     mc->nvdimm_supported = true;
-    mc->smp_props.clusters_supported = true;
+    mc->topo_props.clusters_supported = true;
     mc->auto_enable_numa_with_memhp = true;
     mc->auto_enable_numa_with_memdev = true;
     mc->default_ram_id = "mach-virt.ram";
@@ -3280,7 +3280,7 @@ static void virt_machine_6_1_options(MachineClass *mc)
 
     virt_machine_6_2_options(mc);
     compat_props_add(mc->compat_props, hw_compat_6_1, hw_compat_6_1_len);
-    mc->smp_props.prefer_sockets = true;
+    mc->topo_props.prefer_sockets = true;
     vmc->no_cpu_topology = true;
 
     /* qemu ITS was introduced with 6.2 */
hw/core/machine-topo.c +6 -6
index f9ab08a1252e..8540b473b8db 100644
@@ -187,11 +187,11 @@ static char *cpu_hierarchy_to_string(MachineState *ms)
 
     g_string_append_printf(s, "sockets (%u)", machine_topo_get_sockets(ms));
 
-    if (mc->smp_props.dies_supported) {
+    if (mc->topo_props.dies_supported) {
         g_string_append_printf(s, " * dies (%u)", machine_topo_get_dies(ms));
     }
 
-    if (mc->smp_props.clusters_supported) {
+    if (mc->topo_props.clusters_supported) {
         g_string_append_printf(s, " * clusters (%u)",
                                machine_topo_get_clusters(ms));
     }
@@ -256,11 +256,11 @@ void machine_parse_smp_config(MachineState *ms,
      * If not supported by the machine, a topology parameter must be
      * omitted or specified equal to 1.
      */
-    if (!mc->smp_props.dies_supported && dies > 1) {
+    if (!mc->topo_props.dies_supported && dies > 1) {
         error_setg(errp, "dies not supported by this machine's CPU topology");
         return;
     }
-    if (!mc->smp_props.clusters_supported && clusters > 1) {
+    if (!mc->topo_props.clusters_supported && clusters > 1) {
         error_setg(errp, "clusters not supported by this machine's CPU topology");
         return;
     }
@@ -276,7 +276,7 @@ void machine_parse_smp_config(MachineState *ms,
     } else {
         maxcpus = maxcpus > 0 ? maxcpus : cpus;
 
-        if (mc->smp_props.prefer_sockets) {
+        if (mc->topo_props.prefer_sockets) {
             /* prefer sockets over cores before 6.2 */
             if (sockets == 0) {
                 cores = cores > 0 ? cores : 1;
@@ -315,7 +315,7 @@ void machine_parse_smp_config(MachineState *ms,
     ms->topo.smp.cores = cores;
     ms->topo.smp.threads = threads;
 
-    mc->smp_props.has_clusters = config->has_clusters;
+    mc->topo_props.has_clusters = config->has_clusters;
 
     /* sanity-check of the computed topology */
     if (sockets * dies * clusters * cores * threads != maxcpus) {
hw/i386/pc.c +2 -2
index c329df56ebd2..9a7ee0affd87 100644
@@ -1928,8 +1928,8 @@ static void pc_machine_class_init(ObjectClass *oc, void *data)
     hc->unplug = pc_machine_device_unplug_cb;
     mc->default_cpu_type = TARGET_DEFAULT_CPU_TYPE;
     mc->nvdimm_supported = true;
-    mc->smp_props.dies_supported = true;
-    mc->smp_props.clusters_supported = true;
+    mc->topo_props.dies_supported = true;
+    mc->topo_props.clusters_supported = true;
     mc->default_ram_id = "pc.ram";
 
     object_class_property_add(oc, PC_MACHINE_MAX_RAM_BELOW_4G, "size",
hw/i386/pc_piix.c +1 -1
index df64dd8dcc66..ce725b3d2927 100644
@@ -513,7 +513,7 @@ static void pc_i440fx_6_1_machine_options(MachineClass *m)
     pc_i440fx_6_2_machine_options(m);
     compat_props_add(m->compat_props, hw_compat_6_1, hw_compat_6_1_len);
     compat_props_add(m->compat_props, pc_compat_6_1, pc_compat_6_1_len);
-    m->smp_props.prefer_sockets = true;
+    m->topo_props.prefer_sockets = true;
 }
 
 DEFINE_I440FX_MACHINE(v6_1, "pc-i440fx-6.1", NULL,
hw/i386/pc_q35.c +1 -1
index 66cd718b7081..94352f2b8ea8 100644
@@ -432,7 +432,7 @@ static void pc_q35_6_1_machine_options(MachineClass *m)
     pc_q35_6_2_machine_options(m);
     compat_props_add(m->compat_props, hw_compat_6_1, hw_compat_6_1_len);
     compat_props_add(m->compat_props, pc_compat_6_1, pc_compat_6_1_len);
-    m->smp_props.prefer_sockets = true;
+    m->topo_props.prefer_sockets = true;
 }
 
 DEFINE_Q35_MACHINE(v6_1, "pc-q35-6.1", NULL,
hw/ppc/spapr.c +1 -1
index 6faad75afd70..b2e2420af870 100644
@@ -4801,7 +4801,7 @@ static void spapr_machine_6_1_class_options(MachineClass *mc)
     spapr_machine_6_2_class_options(mc);
     compat_props_add(mc->compat_props, hw_compat_6_1, hw_compat_6_1_len);
     smc->pre_6_2_numa_affinity = true;
-    mc->smp_props.prefer_sockets = true;
+    mc->topo_props.prefer_sockets = true;
 }
 
 DEFINE_SPAPR_MACHINE(6_1, "6.1", false);
hw/s390x/s390-virtio-ccw.c +1 -1
index 9b5020a0d395..28cc3c048d78 100644
@@ -912,7 +912,7 @@ static void ccw_machine_6_1_class_options(MachineClass *mc)
 {
     ccw_machine_6_2_class_options(mc);
     compat_props_add(mc->compat_props, hw_compat_6_1, hw_compat_6_1_len);
-    mc->smp_props.prefer_sockets = true;
+    mc->topo_props.prefer_sockets = true;
 }
 DEFINE_CCW_MACHINE(6_1, "6.1", false);
 
include/hw/boards.h +1 -1
index 17be3485e823..48444ab7275b 100644
@@ -288,7 +288,7 @@ struct MachineClass {
     bool nvdimm_supported;
     bool numa_mem_supported;
     bool auto_enable_numa;
-    TopoCompatProps smp_props;
+    TopoCompatProps topo_props;
     const char *default_ram_id;
 
     HotplugHandler *(*get_hotplug_handler)(MachineState *machine,
tests/unit/test-smp-parse.c +6 -6
index d6816f109084..b6dd5fafd3dd 100644
@@ -500,11 +500,11 @@ static void smp_parse_test(MachineState *ms, SMPTestData *data, bool is_valid)
 {
     MachineClass *mc = MACHINE_GET_CLASS(ms);
 
-    mc->smp_props.prefer_sockets = true;
+    mc->topo_props.prefer_sockets = true;
     check_parse(ms, &data->config, &data->expect_prefer_sockets,
                 data->expect_error, is_valid);
 
-    mc->smp_props.prefer_sockets = false;
+    mc->topo_props.prefer_sockets = false;
     check_parse(ms, &data->config, &data->expect_prefer_cores,
                 data->expect_error, is_valid);
 }
@@ -512,12 +512,12 @@ static void smp_parse_test(MachineState *ms, SMPTestData *data, bool is_valid)
 /* The parsed results of the unsupported parameters should be 1 */
 static void unsupported_params_init(const MachineClass *mc, SMPTestData *data)
 {
-    if (!mc->smp_props.dies_supported) {
+    if (!mc->topo_props.dies_supported) {
         data->expect_prefer_sockets.smp.dies = 1;
         data->expect_prefer_cores.smp.dies = 1;
     }
 
-    if (!mc->smp_props.clusters_supported) {
+    if (!mc->topo_props.clusters_supported) {
         data->expect_prefer_sockets.smp.clusters = 1;
         data->expect_prefer_cores.smp.clusters = 1;
     }
@@ -553,14 +553,14 @@ static void machine_with_dies_class_init(ObjectClass *oc, void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);
 
-    mc->smp_props.dies_supported = true;
+    mc->topo_props.dies_supported = true;
 }
 
 static void machine_with_clusters_class_init(ObjectClass *oc, void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);
 
-    mc->smp_props.clusters_supported = true;
+    mc->topo_props.clusters_supported = true;
 }
 
 static void test_generic_valid(const void *opaque)
Signature · 1 line
2.34.1
author
#99 lore raw

RFC 44/52 machine: Add "-hybrid" parsing rule

In reply to Zhao Liu

From: Zhao Liu <[email protected]>

The "-hybrid" format is like:
-hybrid socket,sockets=n
-hybrid die,dies=n
-hybrid cluster,clusters=n
-hybrid core,cores=n,type=core_type[,threads=threads]
[,clusterid=cluster]

For example:
-hybrid socket,sockets=1
-hybrid die,dies=1
-hybrid cluster,clusters=4
-hybrid core,cores=1,coretype="core",threads=2,clusterid=0-1 -hybrid core,cores=1,coretype="core",threads=2,clusterid=0-1,clusterid=3 -hybrid core,cores=4,coretype="atom",threads=1,clusterid=3

In order to support "-hybrid core" can be inserted into the specified cluster, introduce HybridCorePack to pack HybridCore and help to parse "-hybrid core" command. HybridCorePack will be used to build core level topology later.

Since hybrid cpu topology allocates memory by g_malloc0(), free the memory when machine finalizes.

---
 hw/core/machine-topo.c        | 259 ++++++++++++++++++++++++++++++++++
 hw/core/machine.c             |   4 +
 include/hw/boards.h           |   4 +
 include/hw/cpu/cpu-topology.h |  23 +++
 4 files changed, 290 insertions(+)
hw/core/machine-topo.c +259 -0
index 8540b473b8db..6e4a9ec1495d 100644
@@ -366,3 +366,262 @@ int machine_parse_hybrid_core_type(MachineState *ms, const char *coretype)
 
     return -1;
 }
+
+static void parse_hybrid_socket(MachineState *ms,
+                                const HybridSocketOptions *config,
+                                Error **errp)
+{
+    if (ms->topo.hybrid.sockets != 1) {
+        error_setg(errp, "socket cannot be set repeatedly");
+        return;
+    }
+
+    /*
+     * Since sockets = 0 is deprecated CPU topology for -smp,
+     * now -hybrid returns error directly.
+     */
+    if (!config->sockets) {
+        error_setg(errp, "Invalid sockets. sockets mustn't be zero");
+        return;
+    }
+
+    ms->topo.hybrid.sockets = config->sockets;
+
+    /*
+     * Even though we require that the "socket" must be set before the "core",
+     * in order to simplify the code logic, we do not check the order of the
+     * "socket" subcommand. Instead, multiply the "sockets" for the cpus and
+     * max_cpus here as a compensation measure.
+     */
+    ms->topo.cpus *= ms->topo.hybrid.sockets;
+    ms->topo.max_cpus *= ms->topo.hybrid.sockets;
+}
+
+static void parse_hybrid_die(MachineState *ms,
+                             const HybridDieOptions *config, Error **errp)
+{
+    MachineClass *mc = MACHINE_GET_CLASS(ms);
+
+    if (ms->topo.hybrid.dies != 1) {
+        error_setg(errp, "die cannot be set repeatedly");
+        return;
+    }
+
+    /*
+     * Since dies = 0 is deprecated CPU topology for -smp,
+     * now -hybrid returns error directly.
+     */
+    if (!config->dies) {
+        error_setg(errp, "Invalid dies. dies mustn't be zero");
+        return;
+    }
+    if (!mc->topo_props.dies_supported && config->dies > 1) {
+        error_setg(errp, "dies not supported by this machine's CPU topology");
+        return;
+    }
+
+    ms->topo.hybrid.dies = config->dies;
+
+    /*
+     * Even though we require that the "die" must be set before the "core",
+     * in order to simplify the code logic, we do not check the order of the
+     * "die" subcommand. Instead, multiply the "dies" for the cpus and
+     * max_cpus here as a compensation measure.
+     */
+    ms->topo.cpus *= ms->topo.hybrid.dies;
+    ms->topo.max_cpus *= ms->topo.hybrid.dies;
+}
+
+static void parse_hybrid_cluster(MachineState *ms,
+                                 const HybridClusterOptions *config,
+                                 Error **errp)
+{
+    MachineClass *mc = MACHINE_GET_CLASS(ms);
+
+    if (ms->topo.hybrid.cluster_list != NULL) {
+        error_setg(errp, "The cluster configuration "
+                   "clusters=%" PRIu32 " should be provided before"
+                   "core configuration", config->clusters);
+        return;
+    }
+
+    /*
+     * Since clusters = 0 is deprecated CPU topology for -smp,
+     * now -hybrid returns error directly.
+     */
+    if (!config->clusters) {
+        error_setg(errp, "Invalid clusters. clusters mustn't be zero");
+        return;
+    }
+
+    if (!mc->topo_props.clusters_supported && config->clusters > 1) {
+        error_setg(errp, "clusters not supported by this "
+                   "machine's CPU topology");
+        return;
+    }
+
+    mc->topo_props.has_clusters = true;
+
+    ms->topo.hybrid.clusters = config->clusters;
+    ms->topo.hybrid.cluster_list = g_malloc0(sizeof(HybridCluster) *
+                                             ms->topo.hybrid.clusters);
+
+    for (int i = 0; i < ms->topo.hybrid.clusters; i++) {
+        QSLIST_INIT(&ms->topo.hybrid.cluster_list[i].core_pack_list);
+    }
+}
+
+static void insert_core_into_cluster(MachineState *ms,
+                                     HybridCluster *cluster,
+                                     const HybridCoreOptions *config,
+                                     Error **errp)
+{
+    MachineClass *mc = MACHINE_GET_CLASS(ms);
+    HybridCorePack *core_pack;
+    int ret;
+
+    /*
+     * Since cores = 0 or threads = 0 is deprecated CPU topology for
+     * -smp, now -hybrid return error directly.
+     */
+    if (!config->cores) {
+        error_setg(errp, "Invalid cores. cores=%u mustn't be zero",
+                   config->cores);
+        return;
+    }
+    if (config->has_threads && !config->threads) {
+        error_setg(errp, "Invalid threads. threads=%u mustn't be zero",
+                   config->threads);
+        return;
+    }
+
+    core_pack = g_malloc0(sizeof(*core_pack));
+    core_pack->core_num = config->cores;
+    core_pack->core.threads = config->has_threads ? config->threads : 1;
+
+    ret = mc->core_type(ms, config->coretype);
+    if (!ret) {
+        error_setg(errp, "Invalid coretype=%s", config->coretype);
+    }
+    core_pack->core.core_type = ret;
+
+    QSLIST_INSERT_HEAD(&cluster->core_pack_list, core_pack, node);
+    cluster->cores += core_pack->core_num;
+
+    /*
+     * Note here we just multiply by "dies" and "sockets" other that
+     * "clusters".
+     *
+     * This function caculates cluster's topology one by one, and different
+     * cluster in the same die may have different topology. So we can't
+     * multiply by "clusters". But for current hybrid topology support, we
+     * suppose sockets and dies are same. So "sockets" and "dies" should be
+     * considerred.
+     */
+    ms->topo.cpus += core_pack->core.threads * core_pack->core_num *
+                     ms->topo.hybrid.dies * ms->topo.hybrid.sockets;
+    /*
+     * Because of the "-hybrid" format limitation, before all the cores are
+     * configured, the cpus and max_cpus cannot be obtained. At the same
+     * time, because of heterogeneous, if user wants to specify the online
+     * cpus, user must subdivide it into a specific core. So currently,
+     * temporarily limit max_cpus to be consistent with cpus.
+     *
+     * TODO: Consider adding more complete online cpus configuration support
+     * in the future.
+     */
+    ms->topo.max_cpus = ms->topo.cpus;
+}
+
+static void parse_hybrid_core(MachineState *ms,
+                              const HybridCoreOptions *config, Error **errp)
+{
+    if (!ms->topo.hybrid.cluster_list) {
+        if (config->has_clusterid) {
+            error_setg(errp, "The core configuration clusterid "
+                       "should be provided after"
+                       "cluster configuration");
+            return;
+        }
+        /* Set 1 cluster per die by default. */
+        ms->topo.hybrid.clusters = 1;
+        ms->topo.hybrid.cluster_list = g_malloc0(sizeof(HybridCluster) *
+                                                 ms->topo.hybrid.clusters);
+        QSLIST_INIT(&ms->topo.hybrid.cluster_list[0].core_pack_list);
+    }
+
+    if (config->has_clusterid) {
+        for (uint32List *clusterid = config->clusterid; clusterid;
+             clusterid = clusterid->next) {
+            if (clusterid->value >= ms->topo.hybrid.clusters) {
+                error_setg(errp, "Invalid clusterid. "
+                           "clusterid=%" PRIu32 " is out of range "
+                           "(only %" PRIu32 "clusters)",
+                           clusterid->value, ms->topo.hybrid.clusters);
+                return;
+            }
+            insert_core_into_cluster(ms,
+                &ms->topo.hybrid.cluster_list[clusterid->value], config, errp);
+        }
+    } else {
+        for (int i = 0; i < ms->topo.hybrid.clusters; i++) {
+            insert_core_into_cluster(ms,
+                &ms->topo.hybrid.cluster_list[i], config, errp);
+        }
+    }
+}
+
+void set_hybrid_options(MachineState *ms,
+                        const HybridOptions *config,
+                        Error **errp)
+{
+    MachineClass *mc = MACHINE_GET_CLASS(ms);
+
+    if (!mc->topo_props.hybrid_supported) {
+        error_setg(errp, "hybrid topology not supported "
+                   "by this machine's CPU");
+        return;
+    }
+
+    switch (config->type) {
+    case HYBRID_OPTIONS_TYPE_SOCKET:
+        parse_hybrid_socket(ms, &config->u.socket, errp);
+        break;
+    case HYBRID_OPTIONS_TYPE_DIE:
+        parse_hybrid_die(ms, &config->u.die, errp);
+        break;
+    case HYBRID_OPTIONS_TYPE_CLUSTER:
+        parse_hybrid_cluster(ms, &config->u.cluster, errp);
+        break;
+    case HYBRID_OPTIONS_TYPE_CORE:
+        parse_hybrid_core(ms, &config->u.core, errp);
+        break;
+    default:
+        abort();
+    }
+}
+
+void machine_free_hybrid_topology(MachineState *ms)
+{
+    HybridCluster *cluster;
+    HybridCorePack *core_pack;
+    HybridCorePack *tmp;
+
+    if (ms->topo.hybrid.clusters) {
+        for (int i = 0; i < ms->topo.hybrid.clusters; i++) {
+            cluster = &ms->topo.hybrid.cluster_list[i];
+
+            /*
+             * TODO: Temporarily free core_pack_list here. When the
+             * building of core_list array is supported, it will be
+             * freeed there.
+             */
+            QSLIST_FOREACH_SAFE(core_pack, &cluster->core_pack_list,
+                                node, tmp) {
+                QSLIST_REMOVE_HEAD(&cluster->core_pack_list, node);
+                g_free(core_pack);
+            }
+        }
+        g_free(ms->topo.hybrid.cluster_list);
+    }
+}
hw/core/machine.c +4 -0
index acc32b3be5f6..f2c6aac4ef94 100644
@@ -1122,6 +1122,10 @@ static void machine_finalize(Object *obj)
     g_free(ms->device_memory);
     g_free(ms->nvdimms_state);
     g_free(ms->numa_state);
+
+    if (!machine_topo_is_smp(ms)) {
+        machine_free_hybrid_topology(ms);
+    }
 }
 
 bool machine_usb(MachineState *machine)
include/hw/boards.h +4 -0
index 48444ab7275b..09b93c17a245 100644
@@ -37,6 +37,10 @@ void machine_set_cpu_numa_node(MachineState *machine,
 void machine_parse_smp_config(MachineState *ms,
                               const SMPConfiguration *config, Error **errp);
 int machine_parse_hybrid_core_type(MachineState *ms, const char *coretype);
+void set_hybrid_options(MachineState *ms,
+                        const HybridOptions *config,
+                        Error **errp);
+void machine_free_hybrid_topology(MachineState *ms);
 
 /**
  * machine_class_allow_dynamic_sysbus_dev: Add type to list of valid devices
include/hw/cpu/cpu-topology.h +23 -0
index 829f98d3a73f..eef752d5168d 100644
@@ -52,15 +52,38 @@ typedef struct HybridCore {
     unsigned int core_type;
 } HybridCore;
 
+/**
+ * HybridCorePack - Wrapper of HybridCore to pack the same
+ *                  cores in one cluster.
+ *
+ * HybridCorePack is used for `-hybrid` parsing and will help to build
+ * core_list array.
+ *
+ * @core_num: the number of threads in one core.
+ * @core: the specific core information of current core pack.
+ * @node: the singly-linked list node of current core pack. This node
+ *        is added to the core_pack_list of a cluster which the current
+ *        core pack belongs to.
+ */
+typedef struct HybridCorePack {
+    unsigned int core_num;
+    HybridCore core;
+    QSLIST_ENTRY(HybridCorePack) node;
+} HybridCorePack;
+
 /**
  * HybridCluster - hybrid cluster topology defination:
  * @cores: the number of cores in current cluster.
  * @core_list: the array includes all the cores that belong to current
  *             cluster.
+ * @core_pack_list: the list that links all the core packs that belong to
+ *                  current cluster. It is used for `-hybrid` parsing and
+ *                  will help to build core_list array.
  */
 typedef struct HybridCluster {
     unsigned int cores;
     HybridCore *core_list;
+    QSLIST_HEAD(, HybridCorePack) core_pack_list;
 } HybridCluster;
 
 /**
Signature · 1 line
2.34.1
author
#100 lore raw

RFC 45/52 hw/machine: Add hybrid cpu topology validation

In reply to Zhao Liu

From: Zhao Liu <[email protected]>

Because of the "-hybrid" format, in the process of parsing the command line, we cannot know exactly the complete topology details until all the hybrid commands have been parsed, so we cannot verify the hybrid topology during the parsing process.

Thus validate the hybrid topology before machine running. At this moment, the hybrid topology must have been parsed.

---
 hw/core/machine-topo.c | 126 +++++++++++++++++++++++++++++++++++++++++
 hw/core/machine.c      |   4 ++
 include/hw/boards.h    |   1 +
 3 files changed, 131 insertions(+)
hw/core/machine-topo.c +126 -0
index 6e4a9ec1495d..2cf71cc466aa 100644
@@ -625,3 +625,129 @@ void machine_free_hybrid_topology(MachineState *ms)
         g_free(ms->topo.hybrid.cluster_list);
     }
 }
+
+/*
+ * Report information of a machine's supported CPU hybrid topology
+ * hierarchy. Topology members will be ordered in the string as:
+ * sockets (%u) * dies (%u) * ( cluster0:[ core0:[ cores (type: %s, %u) *
+ * threads (%u) ] + ... + core_n:[ cores (type: %s, %u) * threads (%u) ] ] +
+ * ... + cluster_m:[ core0:[ cores (type: %s, %u) * threads (%u) ] + ... +
+ * core_m:[ cores (type: %s, %u) * threads (%u)) ] ].
+ */
+static char *hybrid_cpu_hierarchy_to_string(MachineState *ms)
+{
+    HybridCluster *cluster;
+    HybridCorePack *core_pack;
+    MachineClass *mc = MACHINE_GET_CLASS(ms);
+    GString *s = g_string_new(NULL);
+
+    g_string_append_printf(s, "sockets (%u)", ms->topo.hybrid.sockets);
+
+    if (mc->topo_props.dies_supported) {
+        g_string_append_printf(s, " * dies (%u)", ms->topo.hybrid.dies);
+    }
+
+    if (ms->topo.hybrid.cluster_list != NULL) {
+        g_string_append_printf(s, " * ( ");
+        for (int i = 0; i < ms->topo.hybrid.clusters; i++) {
+            if (i) {
+                g_string_append_printf(s, " + ");
+            }
+            if (mc->topo_props.clusters_supported) {
+                g_string_append_printf(s, "cluster%u ", i);
+            }
+            if (ms->topo.hybrid.cluster_list[i].cores) {
+                int core_idx = 0;
+                cluster = &ms->topo.hybrid.cluster_list[i];
+
+                QSLIST_FOREACH(core_pack, &cluster->core_pack_list, node) {
+                    if (!core_idx) {
+                        g_string_append_printf(
+                            s, "%s ",
+                            mc->topo_props.clusters_supported ?
+                            ":[" : "[");
+                    } else {
+                        g_string_append_printf(s, " + ");
+                    }
+                    g_string_append_printf(
+                        s, "core%u:[ cores (type: %u, "
+                        "num: %u) * threads (%u) ]",
+                        core_idx++, core_pack->core.core_type,
+                        core_pack->core_num, core_pack->core.threads);
+                }
+                if (mc->topo_props.clusters_supported) {
+                    g_string_append_printf(s, " ] ");
+                }
+            }
+        }
+        g_string_append_printf(s, " )");
+    }
+
+    return g_string_free(s, false);
+}
+
+void machine_validate_hybrid_topology(MachineState *ms, Error **errp)
+{
+    MachineClass *mc = MACHINE_GET_CLASS(ms);
+    HybridCluster *cluster;
+
+    if (ms->topo.max_cpus == 0) {
+        /*
+         * Cores are not set, and maybe clusters are also not set.
+         * At present, since the coretype cannot be omitted, the core
+         * level must be specified.
+         *
+         * TODO: Support coretype and core level can be omitted.
+         */
+        g_autofree char *topo_msg = hybrid_cpu_hierarchy_to_string(ms);
+        error_setg(errp, "Invalid hybrid CPU topology: Lack "
+                   "of core configuration, unable to generate "
+                   "valid topology: %s", topo_msg);
+        exit(1);
+    } else {
+        /*
+         * Though currently max_cpus equals to cpus, still check cpus here
+         * as the complete code logic.
+         *
+         * TODO: Consider adding more complete online cpus configuration
+         * support in the future.
+         *
+         * Since cpus = 0 is deprecated CPU topology for smp, now -hybrid
+         * returns error directly.
+         */
+        if (ms->topo.cpus == 0) {
+            error_setg(errp, "Must set at least one cpu online");
+            exit(1);
+        }
+    }
+
+    /* Each cluster need at least one core. */
+    for (int i = 0; i < ms->topo.hybrid.clusters; i++) {
+        cluster = &ms->topo.hybrid.cluster_list[i];
+
+        if (!cluster->cores) {
+            g_autofree char *topo_msg = hybrid_cpu_hierarchy_to_string(ms);
+            error_setg(errp, "Invalid hybrid CPU topology: no core is "
+                       "specified for cluster (id: %d), unable to "
+                       "generate valid topology: %s",
+                       i, topo_msg);
+            exit(1);
+        }
+    }
+
+    if (ms->topo.cpus < mc->min_cpus) {
+        g_autofree char *topo_msg = hybrid_cpu_hierarchy_to_string(ms);
+        error_setg(errp, "Invalid Hybrid CPUs %d. The min CPUs "
+                   "supported by machine '%s' is %d. Topology: %s",
+                   ms->topo.cpus, mc->name, mc->min_cpus, topo_msg);
+        exit(1);
+    }
+
+    if (ms->topo.max_cpus > mc->max_cpus) {
+        g_autofree char *topo_msg = hybrid_cpu_hierarchy_to_string(ms);
+        error_setg(errp, "Invalid Hybrid CPUs %d. The max CPUs "
+                   "supported by machine '%s' is %d. Topology: %s",
+                   ms->topo.max_cpus, mc->name, mc->max_cpus, topo_msg);
+        exit(1);
+    }
+}
hw/core/machine.c +4 -0
index f2c6aac4ef94..630934317e3c 100644
@@ -1327,6 +1327,10 @@ void machine_run_board_init(MachineState *machine, const char *mem_path, Error *
         }
     }
 
+    if (!machine_topo_is_smp(machine)) {
+        machine_validate_hybrid_topology(machine, errp);
+    }
+
     if (machine->memdev) {
         ram_addr_t backend_size = object_property_get_uint(OBJECT(machine->memdev),
                                                            "size",  &error_abort);
include/hw/boards.h +1 -0
index 09b93c17a245..9156982e4de6 100644
@@ -41,6 +41,7 @@ void set_hybrid_options(MachineState *ms,
                         const HybridOptions *config,
                         Error **errp);
 void machine_free_hybrid_topology(MachineState *ms);
+void machine_validate_hybrid_topology(MachineState *ms, Error **errp);
 
 /**
  * machine_class_allow_dynamic_sysbus_dev: Add type to list of valid devices
Signature · 1 line
2.34.1
author
#101 lore raw

RFC 46/52 hw/machine: build core level hybrid topology form HybridCorePack

In reply to Zhao Liu

From: Zhao Liu <[email protected]>

After verifying the hybrid topology, we need to convert the topology structure of the core level from a single linked list to an array, so that we can make full use of the core-id to quickly access the corresponding core.

---
 hw/core/machine-topo.c | 48 ++++++++++++++++++++++++++++++++----------
 hw/core/machine.c      |  1 +
 include/hw/boards.h    |  1 +
 3 files changed, 39 insertions(+), 11 deletions(-)
hw/core/machine-topo.c +37 -11
index 2cf71cc466aa..ebd2c40396a2 100644
@@ -604,22 +604,13 @@ void set_hybrid_options(MachineState *ms,
 void machine_free_hybrid_topology(MachineState *ms)
 {
     HybridCluster *cluster;
-    HybridCorePack *core_pack;
-    HybridCorePack *tmp;
 
     if (ms->topo.hybrid.clusters) {
         for (int i = 0; i < ms->topo.hybrid.clusters; i++) {
             cluster = &ms->topo.hybrid.cluster_list[i];
 
-            /*
-             * TODO: Temporarily free core_pack_list here. When the
-             * building of core_list array is supported, it will be
-             * freeed there.
-             */
-            QSLIST_FOREACH_SAFE(core_pack, &cluster->core_pack_list,
-                                node, tmp) {
-                QSLIST_REMOVE_HEAD(&cluster->core_pack_list, node);
-                g_free(core_pack);
+            if (cluster->core_list != NULL) {
+                g_free(cluster->core_list);
             }
         }
         g_free(ms->topo.hybrid.cluster_list);
@@ -751,3 +742,38 @@ void machine_validate_hybrid_topology(MachineState *ms, Error **errp)
         exit(1);
     }
 }
+
+void machine_consolidate_hybrid_topology(MachineState *ms)
+{
+    HybridCluster *cluster;
+    HybridCorePack *core_pack;
+    HybridCorePack *tmp;
+    int core_num;
+
+    for (int i = 0; i < ms->topo.hybrid.clusters; i++) {
+        cluster = &ms->topo.hybrid.cluster_list[i];
+        cluster->core_list = g_malloc0(sizeof(HybridCore) * cluster->cores);
+
+        core_num = cluster->cores;
+        QSLIST_FOREACH_SAFE(core_pack, &cluster->core_pack_list, node, tmp) {
+            QSLIST_REMOVE_HEAD(&cluster->core_pack_list, node);
+
+            /*
+             * Here we add cores in "reverse order" because core_pack_list uses
+             * "QSLIST_INSERT_HEAD()" to collect the cores in the "-hybrid"
+             * command line in reverse order.
+             *
+             * The "reverse order" here can ensure that the growth of core-id
+             * is consistent with the order of adding cores in "-hybrid".
+             */
+            for (int j = 0; j < core_pack->core_num; j++) {
+                cluster->core_list[core_num - j - 1].core_type =
+                    core_pack->core.core_type;
+                cluster->core_list[core_num - j - 1].threads =
+                    core_pack->core.threads;
+            }
+            core_num -= core_pack->core_num;
+            g_free(core_pack);
+        }
+    }
+}
hw/core/machine.c +1 -0
index 630934317e3c..08a0c117ce1b 100644
@@ -1329,6 +1329,7 @@ void machine_run_board_init(MachineState *machine, const char *mem_path, Error *
 
     if (!machine_topo_is_smp(machine)) {
         machine_validate_hybrid_topology(machine, errp);
+        machine_consolidate_hybrid_topology(machine);
     }
 
     if (machine->memdev) {
include/hw/boards.h +1 -0
index 9156982e4de6..0f865c21e2a8 100644
@@ -42,6 +42,7 @@ void set_hybrid_options(MachineState *ms,
                         Error **errp);
 void machine_free_hybrid_topology(MachineState *ms);
 void machine_validate_hybrid_topology(MachineState *ms, Error **errp);
+void machine_consolidate_hybrid_topology(MachineState *ms);
 
 /**
  * machine_class_allow_dynamic_sysbus_dev: Add type to list of valid devices
Signature · 1 line
2.34.1
author
#102 lore raw

RFC 47/52 hw/machine: Use opts_visitor to parse hybrid topo

In reply to Zhao Liu

From: Zhao Liu <[email protected]>

Because of the "-hybrid" format, it cannot be defined as the machine property to use input_visitor to parse as what "-smp" did.

So here we use opts_visitor to parse hybrid topology.

---
 hw/core/machine-topo.c | 36 +++++++++++++++++++++++++++++++++---
 include/hw/boards.h    |  4 +---
 2 files changed, 34 insertions(+), 6 deletions(-)
hw/core/machine-topo.c +33 -3
index ebd2c40396a2..9e37de04ce75 100644
@@ -20,6 +20,8 @@
 #include "qemu/osdep.h"
 #include "hw/boards.h"
 #include "qapi/error.h"
+#include "qapi/opts-visitor.h"
+#include "qapi/qapi-visit-machine.h"
 
 unsigned int machine_topo_get_sockets(const MachineState *ms)
 {
@@ -571,9 +573,9 @@ static void parse_hybrid_core(MachineState *ms,
     }
 }
 
-void set_hybrid_options(MachineState *ms,
-                        const HybridOptions *config,
-                        Error **errp)
+static void set_hybrid_options(MachineState *ms,
+                               const HybridOptions *config,
+                               Error **errp)
 {
     MachineClass *mc = MACHINE_GET_CLASS(ms);
 
@@ -601,6 +603,34 @@ void set_hybrid_options(MachineState *ms,
     }
 }
 
+static int parse_hybrid(void *opaque, QemuOpts *opts, Error **errp)
+{
+    g_autoptr(HybridOptions) config = NULL;
+    MachineState *ms = MACHINE(opaque);
+    Error *err = NULL;
+    Visitor *v = opts_visitor_new(opts);
+
+    visit_type_HybridOptions(v, NULL, &config, errp);
+    visit_free(v);
+    if (!config) {
+        return -1;
+    }
+
+    set_hybrid_options(ms, config, &err);
+
+    if (err) {
+        error_propagate(errp, err);
+        return -1;
+    }
+
+    return 0;
+}
+
+void parse_hybrid_opts(MachineState *ms)
+{
+    qemu_opts_foreach(qemu_find_opts("hybrid"), parse_hybrid, ms, &error_fatal);
+}
+
 void machine_free_hybrid_topology(MachineState *ms)
 {
     HybridCluster *cluster;
include/hw/boards.h +1 -3
index 0f865c21e2a8..0395990139bc 100644
@@ -37,9 +37,7 @@ void machine_set_cpu_numa_node(MachineState *machine,
 void machine_parse_smp_config(MachineState *ms,
                               const SMPConfiguration *config, Error **errp);
 int machine_parse_hybrid_core_type(MachineState *ms, const char *coretype);
-void set_hybrid_options(MachineState *ms,
-                        const HybridOptions *config,
-                        Error **errp);
+void parse_hybrid_opts(MachineState *ms);
 void machine_free_hybrid_topology(MachineState *ms);
 void machine_validate_hybrid_topology(MachineState *ms, Error **errp);
 void machine_consolidate_hybrid_topology(MachineState *ms);
Signature · 1 line
2.34.1
author
#103 lore raw

RFC 48/52 machine: Support "-hybrid" command

In reply to Zhao Liu

From: Zhao Liu <[email protected]>

Add "-hybrid" command parsing.

And now we have reason to move MachineState.topo initialization to its original place [1], because we can't know whcih topologies should be initialized before collecting all commands.

If "-hybrid" is set, initialize MachineState.topo as hybrid topology. Otherwise, use smp topology as default.

[1]: 8b0e484 (machine: move SMP initialization from vl.c)

---
 hw/core/machine-topo.c | 41 ++++++++++++++++++++++++++++++++++++++++-
 hw/core/machine.c      | 11 -----------
 include/hw/boards.h    |  1 +
 qemu-options.hx        |  7 +++++++
 softmmu/vl.c           | 33 +++++++++++++++++++++++++++++++++
 5 files changed, 81 insertions(+), 12 deletions(-)
hw/core/machine-topo.c +40 -1
index 9e37de04ce75..f38b8c683026 100644
@@ -177,6 +177,33 @@ unsigned int machine_topo_get_threads_per_socket(const MachineState *ms)
     return ms->topo.max_cpus / sockets;
 }
 
+void machine_init_topology_default(MachineState *ms, bool smp)
+{
+    MachineClass *mc = MACHINE_GET_CLASS(ms);
+
+    if (smp) {
+        /* default to mc->default_cpus */
+        ms->topo.cpus = mc->default_cpus;
+        ms->topo.max_cpus = mc->default_cpus;
+
+        ms->topo.topo_type = CPU_TOPO_TYPE_SMP;
+        ms->topo.smp.sockets = 1;
+        ms->topo.smp.dies = 1;
+        ms->topo.smp.clusters = 1;
+        ms->topo.smp.cores = 1;
+        ms->topo.smp.threads = 1;
+    } else {
+        ms->topo.cpus = 0;
+        ms->topo.max_cpus = 0;
+
+        ms->topo.topo_type = CPU_TOPO_TYPE_HYBRID;
+        ms->topo.hybrid.sockets = 1;
+        ms->topo.hybrid.dies = 1;
+        ms->topo.hybrid.clusters = 1;
+        ms->topo.hybrid.cluster_list = NULL;
+    }
+}
+
 /*
  * Report information of a machine's supported CPU topology hierarchy.
  * Topology members will be ordered from the largest to the smallest
@@ -231,6 +258,12 @@ void machine_parse_smp_config(MachineState *ms,
                               const SMPConfiguration *config, Error **errp)
 {
     MachineClass *mc = MACHINE_GET_CLASS(ms);
+
+    if (!machine_topo_is_smp(ms)) {
+        error_setg(errp, "Cannot set smp and hybrid at the same time");
+        return;
+    }
+
     unsigned cpus    = config->has_cpus ? config->cpus : 0;
     unsigned sockets = config->has_sockets ? config->sockets : 0;
     unsigned dies    = config->has_dies ? config->dies : 0;
@@ -608,8 +641,14 @@ static int parse_hybrid(void *opaque, QemuOpts *opts, Error **errp)
     g_autoptr(HybridOptions) config = NULL;
     MachineState *ms = MACHINE(opaque);
     Error *err = NULL;
-    Visitor *v = opts_visitor_new(opts);
+    Visitor *v;
+
+    if (machine_topo_is_smp(ms)) {
+        error_setg(errp, "Cannot set hybrid and smp at the same time");
+        return -1;
+    }
 
+    v = opts_visitor_new(opts);
     visit_type_HybridOptions(v, NULL, &config, errp);
     visit_free(v);
     if (!config) {
hw/core/machine.c +0 -11
index 08a0c117ce1b..212749f984d6 100644
@@ -1093,17 +1093,6 @@ static void machine_initfn(Object *obj)
                                         "Table (HMAT)");
     }
 
-    /* default to mc->default_cpus */
-    ms->topo.cpus = mc->default_cpus;
-    ms->topo.max_cpus = mc->default_cpus;
-
-    ms->topo.topo_type = CPU_TOPO_TYPE_SMP;
-    ms->topo.smp.sockets = 1;
-    ms->topo.smp.dies = 1;
-    ms->topo.smp.clusters = 1;
-    ms->topo.smp.cores = 1;
-    ms->topo.smp.threads = 1;
-
     machine_copy_boot_config(ms, &(BootConfiguration){ 0 });
 }
 
include/hw/boards.h +1 -0
index 0395990139bc..c93bb1206244 100644
@@ -41,6 +41,7 @@ void parse_hybrid_opts(MachineState *ms);
 void machine_free_hybrid_topology(MachineState *ms);
 void machine_validate_hybrid_topology(MachineState *ms, Error **errp);
 void machine_consolidate_hybrid_topology(MachineState *ms);
+void machine_init_topology_default(MachineState *ms, bool smp);
 
 /**
  * machine_class_allow_dynamic_sysbus_dev: Add type to list of valid devices
qemu-options.hx +7 -0
index 3caf9da4c3af..8987972a8d5f 100644
@@ -5605,6 +5605,13 @@ SRST
             (qemu) qom-set /objects/iothread1 poll-max-ns 100000
 ERST
 
+DEF("hybrid", HAS_ARG, QEMU_OPTION_hybrid,
+    "-hybrid socket,sockets=n"
+    "-hybrid die,dies=n"
+    "-hybrid cluster,clusters=n"
+    "-hybrid core,cores=n,coretype=core_type[,threads=threads][,clusterid=cluster]",
+    QEMU_ARCH_ALL)
+
 
 HXCOMM This is the last statement. Insert new options before this line!
 
softmmu/vl.c +33 -0
index 0547ad390f52..ce5e021006f8 100644
@@ -500,6 +500,13 @@ static QemuOptsList qemu_action_opts = {
     },
 };
 
+static QemuOptsList qemu_hybrid_opts = {
+    .name = "hybrid",
+    .implied_opt_name = "type",
+    .head = QTAILQ_HEAD_INITIALIZER(qemu_hybrid_opts.head),
+    .desc = { { 0 } } /* validated with OptsVisitor */
+};
+
 const char *qemu_get_vm_name(void)
 {
     return qemu_name;
@@ -2010,6 +2017,17 @@ static void parse_memory_options(void)
     loc_pop(&loc);
 }
 
+static void qemu_machine_init_topology(MachineState *machine)
+{
+    bool is_smp = true;
+    QemuOptsList *list = qemu_find_opts("hybrid");
+
+    if (!QTAILQ_EMPTY(&list->head)) {
+        is_smp = false;
+    }
+    machine_init_topology_default(machine, is_smp);
+}
+
 static void qemu_create_machine(QDict *qdict)
 {
     MachineClass *machine_class = select_machine(qdict, &error_fatal);
@@ -2038,6 +2056,12 @@ static void qemu_create_machine(QDict *qdict)
         qemu_set_hw_version(machine_class->hw_version);
     }
 
+    /*
+     * Initialize cpu topology. If hybrid is set, initialize as hybrid
+     * topology. Otherwise, initialize as smp topology.
+     */
+    qemu_machine_init_topology(current_machine);
+
     /*
      * Get the default machine options from the machine if it is not already
      * specified either by the configuration file or by the command line.
@@ -2667,6 +2691,7 @@ void qemu_init(int argc, char **argv)
     qemu_add_opts(&qemu_semihosting_config_opts);
     qemu_add_opts(&qemu_fw_cfg_opts);
     qemu_add_opts(&qemu_action_opts);
+    qemu_add_opts(&qemu_hybrid_opts);
     module_call_init(MODULE_INIT_OPTS);
 
     error_init(argv[0]);
@@ -3489,6 +3514,13 @@ void qemu_init(int argc, char **argv)
             case QEMU_OPTION_nouserconfig:
                 /* Nothing to be parsed here. Especially, do not error out below. */
                 break;
+            case QEMU_OPTION_hybrid:
+                opts = qemu_opts_parse_noisily(qemu_find_opts("hybrid"),
+                                               optarg, true);
+                if (!opts) {
+                    exit(1);
+                }
+                break;
             default:
                 if (os_parse_cmd_args(popt->index, optarg)) {
                     error_report("Option not supported in this build");
@@ -3598,6 +3630,7 @@ void qemu_init(int argc, char **argv)
 
     qemu_resolve_machine_memdev();
     parse_numa_opts(current_machine);
+    parse_hybrid_opts(current_machine);
 
     if (vmstate_dump_file) {
         /* dump and exit */
Signature · 1 line
2.34.1
author
#104 lore raw

RFC 49/52 i386/pc: Support hybrid cpu topology

In reply to Zhao Liu

From: Zhao Liu <[email protected]>

Allow i386/pc to set hybrid cpu topology with "-hybrid" commands.

---
 hw/i386/pc.c | 1 +
 1 file changed, 1 insertion(+)
hw/i386/pc.c +1 -0
index 9a7ee0affd87..5cd45921205c 100644
@@ -1928,6 +1928,7 @@ static void pc_machine_class_init(ObjectClass *oc, void *data)
     hc->unplug = pc_machine_device_unplug_cb;
     mc->default_cpu_type = TARGET_DEFAULT_CPU_TYPE;
     mc->nvdimm_supported = true;
+    mc->topo_props.hybrid_supported = true;
     mc->topo_props.dies_supported = true;
     mc->topo_props.clusters_supported = true;
     mc->default_ram_id = "pc.ram";
Signature · 1 line
2.34.1
author
#105 lore raw

RFC 50/52 qemu-options: Add the document of hybrid command

In reply to Zhao Liu

From: Zhao Liu <[email protected]>

Added the detailed introduction to the four hybrid options with specific examples.

---
 qemu-options.hx | 77 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 77 insertions(+)
qemu-options.hx +77 -0
index 8987972a8d5f..2bc7a5ed51ed 100644
@@ -5611,7 +5611,84 @@ DEF("hybrid", HAS_ARG, QEMU_OPTION_hybrid,
     "-hybrid cluster,clusters=n"
     "-hybrid core,cores=n,coretype=core_type[,threads=threads][,clusterid=cluster]",
     QEMU_ARCH_ALL)
+SRST
+``-hybrid socket,sockets=n``
+  \
+``-hybrid die,dies=n``
+  \
+``-hybrid cluster,clusters=n``
+  \
+``-hybrid core,cores=n,coretype=core_type[,threads=threads][,clusterid=cluster]``
+    Define a hybrid cpu topology. Currently, only i386 PC machine supports this command.
+
+    There're 4 levels need to be configured: socket, die, cluster and core. And the
+    thread level is included in core level configuration.
+
+    Hybrid and smp cannot be set at the same time.
+
+    As for now, hybrid cpu topology only supports differences between the core and cluster
+    levels (please note the differences between clusters is caused by containing different
+    cores), and it assumes threads, dies and sockets are the same.
+
+    These four level options must be written in the order of "socket, die, cluster, core".
+
+    For example, the following options assigns 12 VCPUs which contains 8 Intel Atom cores
+    and 2 Intel Core cores.
+
+    ::
+
+        -hybrid socket,sockets=1    \
+        -hybrid die,dies=1          \
+        -hybrid cluster,clusters=4  \
+        -hybrid core,cores=1,coretype="core",threads=2,clusterid=0-1    \
+        -hybrid core,cores=4,coretype="atom",threads=1,clusterid=2-3
+
+    '\ ``socket``\ ' option is used to configure how many sockets in the machine. Here
+    '\ ``sockets``\ ' means the number of sockets in the machine. If this option is not
+    set, the default is only 1 socket.
+
+    For example:
+
+    ::
+
+        -hybrid socket,sockets=1
 
+    '\ ``die``\ ' option is used to configure how many dies in one socket. Here
+    '\ ``dies``\ ' means the number of dies in one socket. If this option is not
+    set, the default is only 1 die per socket.
+
+    For example:
+
+    ::
+
+        -hybrid die,dies=1
+
+    '\ ``cluster``\ ' option is used to configure how many clusters in one die. Here
+    '\ ``clusters``\ ' means the number of clusters in one die. If this option is not
+    set, the default is only 1 cluster per die.
+
+    For example:
+
+    ::
+
+        -hybrid cluster,clusters=1
+
+    '\ ``core``\ ' option is used to configure hybrid core topology. Here '\ ``cores``\ '
+    means the number of current type cores in one cluster. '\ ``coretype``\ ' means the
+    type of the current core. '\ ``threads``\ ' means how many threads in one current type
+    core (the default is 1 thread per current core). And '\ ``clusterid``\ ' means the cluster
+    index list that the current type core belongs to (the default is all clusters have current
+    type cores). This option cannot be omitted.
+
+    For i386 PC machine, the supported '\ ``coretype``\ ' are "atom" and "core".
+
+    For example (clusters=4):
+
+    ::
+
+        -hybrid core,cores=1,coretype="core",threads=2,clusterid=0-1,clusterid=3    \
+        -hybrid core,cores=4,coretype="atom",threads=1,clusterid=2
+ERST
 
 HXCOMM This is the last statement. Insert new options before this line!
 
Signature · 1 line
2.34.1
author
#106 lore raw

RFC 51/52 qapi: Expose CPU topology info in query_cpus_fast

In reply to Zhao Liu

From: Zhao Liu <[email protected]>

The topology type and core type are useful to users, so expose them in query_cpus_fast.

Since the hybrid core is pre-set and does not support hotplug for the entire core, the topology type and core type are not exposed in query-hotpluggable-cpus.

---
 hw/core/machine-qmp-cmds.c | 11 +++++++++++
 hw/core/machine-topo.c     |  5 +++++
 include/hw/boards.h        |  5 +++++
 qapi/machine.json          | 19 +++++++++++++++++--
 4 files changed, 38 insertions(+), 2 deletions(-)
hw/core/machine-qmp-cmds.c +11 -0
index 44b5da888024..6be7148a8374 100644
@@ -67,6 +67,17 @@ CpuInfoFastList *qmp_query_cpus_fast(Error **errp)
             value->props = props;
         }
 
+        if (mc->cpu_index_to_core_type) {
+            CpuTopoInfo *topo;
+            const char *core_type;
+
+            topo = g_malloc0(sizeof(CpuTopoInfo));
+            topo->topo_type = machine_topo_get_type(ms);
+            core_type = mc->cpu_index_to_core_type(ms, cpu->cpu_index);
+            topo->core_type = g_strdup(core_type);
+            value->topo = topo;
+        }
+
         value->target = target;
         if (target == SYS_EMU_TARGET_S390X) {
             cpustate_to_cpuinfo_s390(&value->u.s390x, cpu);
hw/core/machine-topo.c +5 -0
index f38b8c683026..f0ff550a2519 100644
@@ -177,6 +177,11 @@ unsigned int machine_topo_get_threads_per_socket(const MachineState *ms)
     return ms->topo.max_cpus / sockets;
 }
 
+CpuTopoType machine_topo_get_type(const MachineState *ms)
+{
+    return ms->topo.topo_type;
+}
+
 void machine_init_topology_default(MachineState *ms, bool smp)
 {
     MachineClass *mc = MACHINE_GET_CLASS(ms);
include/hw/boards.h +5 -0
index c93bb1206244..d925e8af9ed6 100644
@@ -239,6 +239,8 @@ typedef struct {
  *    purposes only.
  *    Applies only to default memory backend, i.e., explicit memory backend
  *    wasn't used.
+ * @cpu_index_to_core_type:
+ *    Return the core_type of specified CPU with @cpu_index.
  */
 struct MachineClass {
     /*< private >*/
@@ -305,6 +307,8 @@ struct MachineClass {
     const CPUArchIdList *(*possible_cpu_arch_ids)(MachineState *machine);
     int64_t (*get_default_cpu_node_id)(const MachineState *ms, int idx);
     ram_addr_t (*fixup_ram_size)(ram_addr_t size);
+    const char *(*cpu_index_to_core_type)(MachineState *machine,
+                                          unsigned cpu_index);
 };
 
 /**
@@ -496,5 +500,6 @@ unsigned int machine_topo_get_cores_by_idx(const MachineState *ms,
                                            unsigned int cpu_index);
 unsigned int machine_topo_get_cores_per_socket(const MachineState *ms);
 unsigned int machine_topo_get_threads_per_socket(const MachineState *ms);
+CpuTopoType machine_topo_get_type(const MachineState *ms);
 
 #endif
qapi/machine.json +17 -2
index 931c6dea9819..e86778b7a777 100644
@@ -40,7 +40,6 @@
 # @CpuTopoType:
 #
 # An enumeration of cpu topology type
-# TODO: Expose topology type in query-cpus-fast
 #
 # Since: 8.0
 ##
@@ -48,6 +47,21 @@
   'prefix': 'CPU_TOPO_TYPE',
   'data': [ 'smp', 'hybrid' ] }
 
+##
+# @CpuTopoInfo:
+#
+# Additional information about basic CPU topology
+#
+# @topo-type: the type of CPU topology
+#
+# @core-type: the type of CPU core
+#
+# Since: 8.0
+##
+{ 'struct' : 'CpuTopoInfo',
+  'data'   : { 'topo-type': 'CpuTopoType',
+               'core-type': 'str'} }
+
 ##
 # @CpuS390State:
 #
@@ -95,7 +109,8 @@
                       'qom-path'     : 'str',
                       'thread-id'    : 'int',
                       '*props'       : 'CpuInstanceProperties',
-                      'target'       : 'SysEmuTarget' },
+                      'target'       : 'SysEmuTarget',
+                      '*topo'         : 'CpuTopoInfo' },
   'discriminator' : 'target',
   'data'          : { 's390x'        : 'CpuInfoS390' } }
 
Signature · 1 line
2.34.1
author
#107 lore raw

RFC 52/52 i386: Support cpu_index_to_core_type() for x86

In reply to Zhao Liu

From: Zhao Liu <[email protected]>

The cpu_index_to_core_type() of MachineClass is implemented in x86 to obtain the string name of core type, so that users can get the basic topology information (topology type and core type) of x86 machine (currently, only PC machine) in query_cpus_fast.

---
 hw/i386/x86.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)
hw/i386/x86.c +33 -0
index f58a90359170..67318a527c6c 100644
@@ -1583,6 +1583,38 @@ static int x86_parse_hybrid_core_type(MachineState *ms, const char *coretype)
     return type;
 }
 
+static const char *x86_cpu_index_to_hybrid_core_type(MachineState *machine,
+                                                     unsigned cpu_index)
+{
+    CPUState *cs;
+
+    if (machine_topo_is_smp(machine)) {
+        return NULL;
+    }
+
+    CPU_FOREACH(cs) {
+        X86CPU *cpu = X86_CPU(cs);
+        CPUX86State *env = &cpu->env;
+
+        if (cs->cpu_index == cpu_index) {
+            const char *core_type;
+
+            switch (env->hybrid_core_type) {
+            case INTEL_ATOM_TYPE:
+                core_type = "atom";
+                break;
+            case INTEL_CORE_TYPE:
+                core_type = "core";
+                break;
+            default:
+                abort();
+            }
+            return core_type;
+        }
+    }
+    return NULL;
+}
+
 static void x86_machine_initfn(Object *obj)
 {
     X86MachineState *x86ms = X86_MACHINE(obj);
@@ -1611,6 +1643,7 @@ static void x86_machine_class_init(ObjectClass *oc, void *data)
     x86mc->fwcfg_dma_enabled = true;
     nc->nmi_monitor_handler = x86_nmi;
     mc->core_type = x86_parse_hybrid_core_type;
+    mc->cpu_index_to_core_type = x86_cpu_index_to_hybrid_core_type;
 
     object_class_property_add(oc, X86_MACHINE_SMM, "OnOffAuto",
         x86_machine_get_smm, x86_machine_set_smm,
Signature · 1 line
2.34.1
#108 lore raw
In reply to Zhao Liu
Quoted 47 lines · Zhao Liu

From: Zhao Liu <[email protected]>

Hi list,

This RFC series is to introduce hybrid topology in QEMU, and is based on our previous patches about cluster support for x86 [1] ([PATCH RESEND 00/18] Support smp.clusters for x86).

Though our cluster support patches [1] has not yet accepted, we are still posting the hybrid topology support patches in advance, hoping to get discussion and feedbacks.

In this RFC series, we mainly have the following work:
* Introduce the new cpu topology under heterogeneous architecture, which we called "hybrid" cpu topology.
- since the name "hmp" is already used in QEMU and "hybrid" is also a synonym for heterogeneous.
* Reorganized the relevant topology information in qemu to adapt to the hybrid topology.
* Introduce a new command "hybrid", which allows user to set a custom hybrid topology.
- currently limited to custom cluster and custom core
* Support hybrid topology in i386 PC machine.
* Expose basic topology information (topology type and core type) in query_cpus_fast.

We hope that the hybrid topology can be general enough to be compatible with the needs of hybrids with various architectures in the future.

Welcome your feedbacks!

# 1. Background

Heterogeneous computing refers to systems that use more than one kind of processor or cores [2]. Now there are more and more heterogeneous computing architectures, typically including arm's big.LITTLE [3] and intel hybrid architecture [4].

The development of heterogeneous computing brings new challenges to virtualization. The first problem we face is how to support the vCPU topology under the heterogeneous architecture.

Here, to distinguish it from "smp" cpu topology, we call it "hybrid" cpu topology.

Quoted 7 lines

# 2. Motivation

In a typical hybrid system, different types of core may have different capabilities. This difference may be reflected in different capacities, performance or power efficiencies, and even different instruction-per- cycle (IPC) capabilities. The direct consequence of these differences is to affect the performance of the workload.

This elides a use case for heterogeneous computing under emulation where different cores can have totally different ISA's. We already support emulation models where we have varying classes of the same ISA, for example xlnx-zyncmp supports 4 A profile and 2 R profile Arm chips.

I've glanced over the patch set and I don't think there is any direct clash with that as this is mainly about representing the topology for x86 non-emulation accelerators but I just want ensure we don't end up stepping on each others toes.

Quoted 6 lines

For a virtual machines, vCPUs are just threads, although we can bind vCPUs to different cores to benefit from the different advantages of these physical cores, it's obviously not enough since CPU topology (and cache topology) will still have a significant impact on scheduling performance.

<snip>

Quoted 33 lines

## 3.3. "-hybrid" command

For hybrid cpu topology configuration, the original "-smp" lack of flexibility to expand, and unables to customize different cores.

So we introduce "-hybrid" command and implement it as the multi- line command. The multi-line command format is more complex than the single-line one, but it can bring stronger scalability and intuitiveness. In the future, it can also be easily extended to more heterogeneous topology levels.

"-hybrid" command is as follows:

(quoted diff) +0 -4
-hybrid socket,sockets=n
-hybrid die,dies=n
-hybrid cluster,clusters=n
-hybrid core,cores=n,type=core_type[,threads=threads]
        [,clusterid=cluster]

Here, we first define the corresponding qapi options for these 4 topology levels: core, cluster, die and socket.

We doesn't need a thread level since thread doesn't have different type.

For example:

(quoted diff) +0 -5
-hybrid socket,sockets=1
-hybrid die,dies=1
-hybrid cluster,clusters=4
-hybrid core,cores=1,coretype="core",threads=2,clusterid=0-2
-hybrid core,cores=4,coretype="atom",threads=1
Quoted 7 lines

Here we can build a hybrid cpu topology, which has 1 socket, 1 die per socket, 4 clusters per die. And in each die, every clusters has 4 "atom" core with 1 threads, and cluster0, cluster1 and cluster2 have 1 "core" cores with 2 threads.

Please note this example is not an actual machine topology, but it shows the powerful flexibility of "hybrid" command.

Is there any intention to apply this command to emulation or will it only be for hardware virtualisation? For example the x86 translator should be capable of emulating two different classes of x86 with different subsets of instructions. It requires ensuring each CPU is assigned to the correct TYPE_CPU_CLUSTER so we don't re-use TBs from the "wrong" CPU.

<snip>

Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro
author
#109 lore raw
Quoted 62 lines · Alex Bennée

Date: Mon, 13 Feb 2023 10:14:22 +0000
From: Alex Bennée <[email protected]>
Subject: Re: [RFC 00/52] Introduce hybrid CPU topology

Quoted 47 lines · Zhao Liu

From: Zhao Liu <[email protected]>

Hi list,

This RFC series is to introduce hybrid topology in QEMU, and is based on our previous patches about cluster support for x86 [1] ([PATCH RESEND 00/18] Support smp.clusters for x86).

Though our cluster support patches [1] has not yet accepted, we are still posting the hybrid topology support patches in advance, hoping to get discussion and feedbacks.

In this RFC series, we mainly have the following work:
* Introduce the new cpu topology under heterogeneous architecture, which we called "hybrid" cpu topology.
- since the name "hmp" is already used in QEMU and "hybrid" is also a synonym for heterogeneous.
* Reorganized the relevant topology information in qemu to adapt to the hybrid topology.
* Introduce a new command "hybrid", which allows user to set a custom hybrid topology.
- currently limited to custom cluster and custom core
* Support hybrid topology in i386 PC machine.
* Expose basic topology information (topology type and core type) in query_cpus_fast.

We hope that the hybrid topology can be general enough to be compatible with the needs of hybrids with various architectures in the future.

Welcome your feedbacks!

# 1. Background

Heterogeneous computing refers to systems that use more than one kind of processor or cores [2]. Now there are more and more heterogeneous computing architectures, typically including arm's big.LITTLE [3] and intel hybrid architecture [4].

The development of heterogeneous computing brings new challenges to virtualization. The first problem we face is how to support the vCPU topology under the heterogeneous architecture.

Here, to distinguish it from "smp" cpu topology, we call it "hybrid" cpu topology.

Quoted 7 lines

# 2. Motivation

In a typical hybrid system, different types of core may have different capabilities. This difference may be reflected in different capacities, performance or power efficiencies, and even different instruction-per- cycle (IPC) capabilities. The direct consequence of these differences is to affect the performance of the workload.

Quoted 4 lines

This elides a use case for heterogeneous computing under emulation where different cores can have totally different ISA's. We already support emulation models where we have varying classes of the same ISA, for example xlnx-zyncmp supports 4 A profile and 2 R profile Arm chips.

This is emulation mode, so you also need to define heterogeneous CPU topology in this case, right?

Quoted 5 lines

I've glanced over the patch set and I don't think there is any direct clash with that as this is mainly about representing the topology for x86 non-emulation accelerators but I just want ensure we don't end up stepping on each others toes.

Yes, this is for non-emulation case.

Quoted 46 lines
Quoted 7 lines

For a virtual machines, vCPUs are just threads, although we can bind vCPUs to different cores to benefit from the different advantages of these physical cores, it's obviously not enough since CPU topology (and cache topology) will still have a significant impact on scheduling performance.

<snip>

Quoted 38 lines

## 3.3. "-hybrid" command

For hybrid cpu topology configuration, the original "-smp" lack of flexibility to expand, and unables to customize different cores.

So we introduce "-hybrid" command and implement it as the multi- line command. The multi-line command format is more complex than the single-line one, but it can bring stronger scalability and intuitiveness. In the future, it can also be easily extended to more heterogeneous topology levels.

"-hybrid" command is as follows:

(quoted diff) +0 -4
-hybrid socket,sockets=n
-hybrid die,dies=n
-hybrid cluster,clusters=n
-hybrid core,cores=n,type=core_type[,threads=threads]
        [,clusterid=cluster]

Here, we first define the corresponding qapi options for these 4 topology levels: core, cluster, die and socket.

We doesn't need a thread level since thread doesn't have different type.

For example:

(quoted diff) +0 -5
-hybrid socket,sockets=1
-hybrid die,dies=1
-hybrid cluster,clusters=4
-hybrid core,cores=1,coretype="core",threads=2,clusterid=0-2
-hybrid core,cores=4,coretype="atom",threads=1

Here we can build a hybrid cpu topology, which has 1 socket, 1 die per socket, 4 clusters per die. And in each die, every clusters has 4 "atom" core with 1 threads, and cluster0, cluster1 and cluster2 have 1 "core" cores with 2 threads.

Quoted 7 lines
Quoted 2 lines

Please note this example is not an actual machine topology, but it shows the powerful flexibility of "hybrid" command.

Is there any intention to apply this command to emulation or will it only be for hardware virtualisation? For example the x86 translator should be capable of emulating two different classes of x86 with different subsets of instructions.

We have not considered the hybrid case in emulation mode, and the current hybrid CPUs of intel are same-ISA.

Quoted 3 lines

It requires ensuring each CPU is
assigned to the correct TYPE_CPU_CLUSTER so we don't re-use TBs from the "wrong" CPU.

From my understanding, this also seems like the topology of heterogeneous core and heterogeneous cluster.

Zhao

Quoted 6 lines

<snip>

Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro
#110 lore raw
In reply to Zhao Liu
Quoted 34 lines · Zhao Liu

From: Zhao Liu <[email protected]>
## 3.3. "-hybrid" command

For hybrid cpu topology configuration, the original "-smp" lack of flexibility to expand, and unables to customize different cores.

So we introduce "-hybrid" command and implement it as the multi- line command. The multi-line command format is more complex than the single-line one, but it can bring stronger scalability and intuitiveness. In the future, it can also be easily extended to more heterogeneous topology levels.

"-hybrid" command is as follows:

(quoted diff) +0 -4
-hybrid socket,sockets=n
-hybrid die,dies=n
-hybrid cluster,clusters=n
-hybrid core,cores=n,type=core_type[,threads=threads]
        [,clusterid=cluster]

Here, we first define the corresponding qapi options for these 4 topology levels: core, cluster, die and socket.

We doesn't need a thread level since thread doesn't have different type.

For example:

(quoted diff) +0 -5
-hybrid socket,sockets=1
-hybrid die,dies=1
-hybrid cluster,clusters=4
-hybrid core,cores=1,coretype="core",threads=2,clusterid=0-2
-hybrid core,cores=4,coretype="atom",threads=1
Quoted 4 lines

Here we can build a hybrid cpu topology, which has 1 socket, 1 die per socket, 4 clusters per die. And in each die, every clusters has 4 "atom" core with 1 threads, and cluster0, cluster1 and cluster2 have 1 "core" cores with 2 threads.

How will this interact with the -cpu parameter. Presumably we now need two distinct -cpu parameters, one for the 'core' CPU model and one for the 'atom' CPU model ?

Quoted 2 lines

Please note this example is not an actual machine topology, but it shows the powerful flexibility of "hybrid" command.

IIUC the functionality offered by -hybrid should be a superset of the -smp functionality. IOW, -smp ought to be possible to re-implement -smp as an alias for -hybrid, such that internally code only ever has to deal with the modern approach. Having to keep support for both -smp and -hybrid throughout the code is undesirable IMHO. Keeping the compat at the CLI parsing level limits the burden.

As a more general thought, rather than introducing a new top level command line argument -hybrid, I'm thinking we should possibly just define this all using QOM and thus re-use the existing -object argument.

I'm also finding the above example command lines quite difficult to understand, as there is alot of implicit linkage and expansion between the different levels. With devices we're much more explicitly with the parent/child relationships, and have to express everything with no automatic expansion, linking it all together via the id=/bus= properties. This is quite a bit more verbose, but it is also very effective at letting us express arbitrarily complex relationships.

I think it would be worth exploring that approach for the CPU topology expression too.

If we followed the more explicit device approach to modelling then instead of:

-cpu core,...
-cpu atom,...
-hybrid socket,sockets=1
-hybrid die,dies=1
-hybrid cluster,clusters=4
-hybrid core,cores=1,coretype="core",threads=2,clusterid=0-2 -hybrid core,cores=4,coretype="atom",threads=1

we would end up with something like

-object cpu-socket,id=sock0
-object cpu-die,id=die0,parent=sock0
-object cpu-cluster,id=cluster0,parent=die0
-object cpu-cluster,id=cluster1,parent=die0
-object cpu-cluster,id=cluster2,parent=die0
-object cpu-cluster,id=cluster3,parent=die0
-object x86-cpu-model-atom,id=cpu0,parent=cluster0 -object x86-cpu-model-atom,id=cpu1,parent=cluster0 -object x86-cpu-model-atom,id=cpu2,parent=cluster0 -object x86-cpu-model-atom,id=cpu3,parent=cluster0 -object x86-cpu-model-core,id=cpu4,parent=cluster0,threads=2 -object x86-cpu-model-atom,id=cpu5,parent=cluster1 -object x86-cpu-model-atom,id=cpu6,parent=cluster1 -object x86-cpu-model-atom,id=cpu7,parent=cluster1 -object x86-cpu-model-atom,id=cpu8,parent=cluster1 -object x86-cpu-model-core,id=cpu9,parent=cluster1,threads=2 -object x86-cpu-model-atom,id=cpu10,parent=cluster2 -object x86-cpu-model-atom,id=cpu11,parent=cluster2 -object x86-cpu-model-atom,id=cpu12,parent=cluster2 -object x86-cpu-model-atom,id=cpu13,parent=cluster2 -object x86-cpu-model-core,id=cpu14,parent=cluster2,threads=2 -object x86-cpu-model-atom,id=cpu15,parent=cluster3 -object x86-cpu-model-atom,id=cpu16,parent=cluster3 -object x86-cpu-model-atom,id=cpu17,parent=cluster3 -object x86-cpu-model-atom,id=cpu18,parent=cluster3 -object x86-cpu-model-core,id=cpu19,parent=cluster3,threads=2

The really obvious downside is that it is much more verbose.

This example only has 20 CPUs. For a VM with say 1000 CPUs this will be very big, but that doesn't neccesarily make it wrong.

On the flipside

* It is really clear exactly how many CPUs I've added

* The relationship between the topology levels is clear

* Every CPU has a unique ID given that can be used in later QMP commands

* Whether or not 'threads' are permitted is now a property of the specific CPU model implementation, not the global config. IOW we can express that some CPU models allowing for threads, and some don't.

* The -cpu arg is also obsoleted, replaced by the -object x86-cpu-model-core. This might facilitate the modelling of machines with CPUs from different architectures.

We could potentially compress the leaf node level by expressing how many instances of an object we want. it we want. ie, define a more convenient shorthand syntax to creating many instances of an object. so eg

-object-set $TYPE,$PROPS,idbase=foo,count=4

would be functionally identical to

-object $TYPE,$PROPS,id=foo.0
-object $TYPE,$PROPS,id=foo.1
-object $TYPE,$PROPS,id=foo.2
-object $TYPE,$PROPS,id=foo.3

QEMU just expands it and creates all the objects internally.

So the huge example I have above for 20 cpus would become much
shorter: e.g.

-object cpu-socket,id=sock0
-object cpu-die,id=die0,parent=sock0
-object cpu-cluster,id=cluster0,parent=die0
-object cpu-cluster,id=cluster1,parent=die0
-object cpu-cluster,id=cluster2,parent=die0
-object cpu-cluster,id=cluster3,parent=die0
-object-set x86-cpu-core-atom,idbase=cpu0,parent=cluster0,count=4 -object-set x86-cpu-core-core,id=cpu1,parent=cluster0,threads=2,count=1 -object-set x86-cpu-core-atom,idbase=cpu2,parent=cluster1,count=4 -object-set x86-cpu-core-core,id=cpu3,parent=cluster1,threads=2,count=1 -object-set x86-cpu-core-atom,idbase=cpu4,parent=cluster2,count=4 -object-set x86-cpu-core-core,id=cpu5,parent=cluster2,threads=2,count=1 -object-set x86-cpu-core-atom,idbase=cpu6,parent=cluster3,count=4 -object-set x86-cpu-core-core,id=cpu7,parent=cluster3,threads=2,count=1

IOW, the size of the CLI config only depends on the number of elements in the hierarchy, and is independant of the number of leaf CPU cores.

Obviously in describing all of the above, I've ignored any complexity of dealing with our existing code implementation and pain of getting it converted to the new model.

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
author
#111 lore raw
Quoted 39 lines · Daniel P. Berrangé

Date: Mon, 13 Feb 2023 13:38:28 +0000
From: "Daniel P. Berrangé" <[email protected]>
Subject: Re: [RFC 00/52] Introduce hybrid CPU topology

Quoted 34 lines · Zhao Liu

From: Zhao Liu <[email protected]>
## 3.3. "-hybrid" command

For hybrid cpu topology configuration, the original "-smp" lack of flexibility to expand, and unables to customize different cores.

So we introduce "-hybrid" command and implement it as the multi- line command. The multi-line command format is more complex than the single-line one, but it can bring stronger scalability and intuitiveness. In the future, it can also be easily extended to more heterogeneous topology levels.

"-hybrid" command is as follows:

(quoted diff) +0 -4
-hybrid socket,sockets=n
-hybrid die,dies=n
-hybrid cluster,clusters=n
-hybrid core,cores=n,type=core_type[,threads=threads]
        [,clusterid=cluster]

Here, we first define the corresponding qapi options for these 4 topology levels: core, cluster, die and socket.

We doesn't need a thread level since thread doesn't have different type.

For example:

(quoted diff) +0 -5
-hybrid socket,sockets=1
-hybrid die,dies=1
-hybrid cluster,clusters=4
-hybrid core,cores=1,coretype="core",threads=2,clusterid=0-2
-hybrid core,cores=4,coretype="atom",threads=1
Quoted 8 lines
Quoted 4 lines

Here we can build a hybrid cpu topology, which has 1 socket, 1 die per socket, 4 clusters per die. And in each die, every clusters has 4 "atom" core with 1 threads, and cluster0, cluster1 and cluster2 have 1 "core" cores with 2 threads.

How will this interact with the -cpu parameter. Presumably we now need two distinct -cpu parameters, one for the 'core' CPU model and one for the 'atom' CPU model ?

(About this explanation for core type, also CC Philippe again)

For intel's hybrid, the core type is not a specific cpu model, and it refers CPUID.1AH, sounds like a flag to distinguish between "core" and "atom". For example, Alder Lake (not defined in QEMU yet) is a CPU model, the Alder Lake CPU can be "core" or "atom".

Although the real "core" and "atom" have different microarchitectures, they belong to the same CPU model and have the same ISA, and the difference that the software layer can recognize is whether the encode in CPUID.1AH is "core" type or "atom" type.

I think this is also the difference between intel hybrid and other heterogeneous architectures. IIUC the heterogeneity of arm contains different CPU models, while intel hybrid only marks the cpu as "core" or "atom" in the same CPU model.

I think this difference between intel hybrid and other heterogeneous can be distinguished by different handling methods of mc->core_type() which can be defined by other arch to check "coretype" field [1].

For x86, mc->core_type() asks "coretype" as "core" or "atom" and treat it as a hybrid "flag". But for other arch, who contains different CPU models in heterogeneous (maybe arm), its mc->coretype asks for the correct cpu model.

In this sense, x86 does not need a different "-cpu" to correspond to core/atom, and even "-cpu" can be set to "host" (ie, -cpu host). But other arch, who contains different CPU models in heterogeneous, needs to support distinct -cpu parameters.

Do you think it is appropriate to use arch-specific mc->coretype to handle different requirements for CPU model/core type?

[1]: [RFC 41/52] machine: Introduce core_type() hook,

     https://lists.gnu.org/archive/html/qemu-devel/2023-02/msg03244.html
Quoted 8 lines
Quoted 3 lines

Please note this example is not an actual machine topology, but it shows the powerful flexibility of "hybrid" command.

IIUC the functionality offered by -hybrid should be a superset of the -smp functionality. IOW, -smp ought to be possible to re-implement -smp as an alias for -hybrid, such that internally code only ever has to deal with the modern approach.

Yes, I agree.

Quoted 5 lines

Having to
keep support for both -smp and -hybrid throughout the code is undesirable IMHO. Keeping the compat at the CLI parsing level limits the burden.

"-hybrid" is introduced as a completely different implementation from "-smp", for these 2 reasons:

1. Single-line commands can be very complex, and it is more difficult to identify the relationship between different levels.

2. smp is implemented as the property of machine [2] and I don't have a good way to define "hybrid" also as a property since I need to use opts_visitor for multi-line commands instead of input_visitor.

[2]: fe68090: machine: add smp compound property.

Quoted 49 lines

As a more general thought, rather than introducing a new top level command line argument -hybrid, I'm thinking we should possibly just define this all using QOM and thus re-use the existing -object argument.

I'm also finding the above example command lines quite difficult to understand, as there is alot of implicit linkage and expansion between the different levels. With devices we're much more explicitly with the parent/child relationships, and have to express everything with no automatic expansion, linking it all together via the id=/bus= properties. This is quite a bit more verbose, but it is also very effective at letting us express arbitrarily complex relationships.

I think it would be worth exploring that approach for the CPU topology expression too.

If we followed the more explicit device approach to modelling then instead of:

-cpu core,...
-cpu atom,...
-hybrid socket,sockets=1
-hybrid die,dies=1
-hybrid cluster,clusters=4
-hybrid core,cores=1,coretype="core",threads=2,clusterid=0-2 -hybrid core,cores=4,coretype="atom",threads=1

we would end up with something like

-object cpu-socket,id=sock0
-object cpu-die,id=die0,parent=sock0
-object cpu-cluster,id=cluster0,parent=die0 -object cpu-cluster,id=cluster1,parent=die0 -object cpu-cluster,id=cluster2,parent=die0 -object cpu-cluster,id=cluster3,parent=die0 -object x86-cpu-model-atom,id=cpu0,parent=cluster0 -object x86-cpu-model-atom,id=cpu1,parent=cluster0 -object x86-cpu-model-atom,id=cpu2,parent=cluster0 -object x86-cpu-model-atom,id=cpu3,parent=cluster0 -object x86-cpu-model-core,id=cpu4,parent=cluster0,threads=2 -object x86-cpu-model-atom,id=cpu5,parent=cluster1 -object x86-cpu-model-atom,id=cpu6,parent=cluster1 -object x86-cpu-model-atom,id=cpu7,parent=cluster1 -object x86-cpu-model-atom,id=cpu8,parent=cluster1 -object x86-cpu-model-core,id=cpu9,parent=cluster1,threads=2 -object x86-cpu-model-atom,id=cpu10,parent=cluster2 -object x86-cpu-model-atom,id=cpu11,parent=cluster2

Quoted 8 lines

-object x86-cpu-model-atom,id=cpu12,parent=cluster2 -object x86-cpu-model-atom,id=cpu13,parent=cluster2 -object x86-cpu-model-core,id=cpu14,parent=cluster2,threads=2 -object x86-cpu-model-atom,id=cpu15,parent=cluster3 -object x86-cpu-model-atom,id=cpu16,parent=cluster3 -object x86-cpu-model-atom,id=cpu17,parent=cluster3 -object x86-cpu-model-atom,id=cpu18,parent=cluster3 -object x86-cpu-model-core,id=cpu19,parent=cluster3,threads=2

Given that x86 hybrid currently has the same cpu model and "core"/"atom" is not CPU model, so the -object still needs a coretype fields to specify "core" or "atom", right?

Given an example of "-cpu host":

-cpu host,...
-hybrid socket,sockets=1
-hybrid die,dies=1
-hybrid cluster,clusters=4
-hybrid core,cores=1,coretype="core",threads=2,clusterid=0-2 -hybrid core,cores=4,coretype="atom",threads=1

It occurred to me that there may be two conversion formats for qom.

The one with "coretype" field like:

-object x86-cpu-model-host,coretype="atom",id=cpu0,parent=cluster0 -object x86-cpu-model-host,coretype="core",id=cpu1,parent=cluster0

or another format like "x86-cpu-model-[real model name]-[core type]":

-object x86-cpu-model-host-atom,id=cpu0,parent=cluster0 -object x86-cpu-model-host-core,id=cpu1,parent=cluster0

Can qom support the parsing of the second naming format?

At the same time, I understand that for other architectures, there is no need to consider the issue of core type, just specify different heterogeneous CPU models.

Quoted 13 lines

The really obvious downside is that it is much more verbose.

This example only has 20 CPUs. For a VM with say 1000 CPUs this will be very big, but that doesn't neccesarily make it wrong.

On the flipside

* It is really clear exactly how many CPUs I've added

* The relationship between the topology levels is clear

Quoted 7 lines

* Every CPU has a unique ID given that can be used in later QMP commands

* Whether or not 'threads' are permitted is now a property of the specific CPU model implementation, not the global config. IOW we can express that some CPU models allowing for threads, and some don't.

Will this way break the smp property of machine (the above mentioned [2])?

If so, IIUC we still need keep smp code to support this smp format:

"-machine smp.{cores,threads,cpu,...}",

but we can mark this smp format as deprecated and at some point completely remove the smp code and replace it with the qom implementation, right?

Quoted 25 lines

* The -cpu arg is also obsoleted, replaced by the -object x86-cpu-model-core. This might facilitate the modelling of machines with CPUs from different architectures.

We could potentially compress the leaf node level by expressing how many instances of an object we want. it we want. ie, define a more convenient shorthand syntax to creating many instances of an object. so eg

-object-set $TYPE,$PROPS,idbase=foo,count=4

would be functionally identical to

-object $TYPE,$PROPS,id=foo.0
-object $TYPE,$PROPS,id=foo.1
-object $TYPE,$PROPS,id=foo.2
-object $TYPE,$PROPS,id=foo.3

QEMU just expands it and creates all the objects internally.

So the huge example I have above for 20 cpus would become much
shorter: e.g.

Quoted 14 lines

-object cpu-socket,id=sock0
-object cpu-die,id=die0,parent=sock0
-object cpu-cluster,id=cluster0,parent=die0
-object cpu-cluster,id=cluster1,parent=die0
-object cpu-cluster,id=cluster2,parent=die0
-object cpu-cluster,id=cluster3,parent=die0
-object-set x86-cpu-core-atom,idbase=cpu0,parent=cluster0,count=4 -object-set x86-cpu-core-core,id=cpu1,parent=cluster0,threads=2,count=1 -object-set x86-cpu-core-atom,idbase=cpu2,parent=cluster1,count=4 -object-set x86-cpu-core-core,id=cpu3,parent=cluster1,threads=2,count=1 -object-set x86-cpu-core-atom,idbase=cpu4,parent=cluster2,count=4 -object-set x86-cpu-core-core,id=cpu5,parent=cluster2,threads=2,count=1 -object-set x86-cpu-core-atom,idbase=cpu6,parent=cluster3,count=4 -object-set x86-cpu-core-core,id=cpu7,parent=cluster3,threads=2,count=1

What's difference between "id" and "idbase"?

Quoted 7 lines

IOW, the size of the CLI config only depends on the number of elements in the hierarchy, and is independant of the number of leaf CPU cores.

Obviously in describing all of the above, I've ignored any complexity of dealing with our existing code implementation and pain of getting it converted to the new model.

Thanks and sounds cool! I think I need some time to study this way.

Zhao

Quoted 8 lines

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
author
#112 lore raw
In reply to Daniel P. Berrangé

Hi Daniel and folks,

Let me pick up this thread again to discuss some updates from my work on QOM CPU topology. I would like to know if I'm on the right track. :-)

Quoted 1 line · Daniel P. Berrangé

[snip]

Quoted 67 lines

IIUC the functionality offered by -hybrid should be a superset of the -smp functionality. IOW, -smp ought to be possible to re-implement -smp as an alias for -hybrid, such that internally code only ever has to deal with the modern approach. Having to keep support for both -smp and -hybrid throughout the code is undesirable IMHO. Keeping the compat at the CLI parsing level limits the burden.

As a more general thought, rather than introducing a new top level command line argument -hybrid, I'm thinking we should possibly just define this all using QOM and thus re-use the existing -object argument.

I'm also finding the above example command lines quite difficult to understand, as there is alot of implicit linkage and expansion between the different levels. With devices we're much more explicitly with the parent/child relationships, and have to express everything with no automatic expansion, linking it all together via the id=/bus= properties. This is quite a bit more verbose, but it is also very effective at letting us express arbitrarily complex relationships.

I think it would be worth exploring that approach for the CPU topology expression too.

If we followed the more explicit device approach to modelling then instead of:

-cpu core,...
-cpu atom,...
-hybrid socket,sockets=1
-hybrid die,dies=1
-hybrid cluster,clusters=4
-hybrid core,cores=1,coretype="core",threads=2,clusterid=0-2 -hybrid core,cores=4,coretype="atom",threads=1

we would end up with something like

-object cpu-socket,id=sock0
-object cpu-die,id=die0,parent=sock0
-object cpu-cluster,id=cluster0,parent=die0
-object cpu-cluster,id=cluster1,parent=die0
-object cpu-cluster,id=cluster2,parent=die0
-object cpu-cluster,id=cluster3,parent=die0
-object x86-cpu-model-atom,id=cpu0,parent=cluster0 -object x86-cpu-model-atom,id=cpu1,parent=cluster0 -object x86-cpu-model-atom,id=cpu2,parent=cluster0 -object x86-cpu-model-atom,id=cpu3,parent=cluster0 -object x86-cpu-model-core,id=cpu4,parent=cluster0,threads=2 -object x86-cpu-model-atom,id=cpu5,parent=cluster1 -object x86-cpu-model-atom,id=cpu6,parent=cluster1 -object x86-cpu-model-atom,id=cpu7,parent=cluster1 -object x86-cpu-model-atom,id=cpu8,parent=cluster1 -object x86-cpu-model-core,id=cpu9,parent=cluster1,threads=2 -object x86-cpu-model-atom,id=cpu10,parent=cluster2 -object x86-cpu-model-atom,id=cpu11,parent=cluster2 -object x86-cpu-model-atom,id=cpu12,parent=cluster2 -object x86-cpu-model-atom,id=cpu13,parent=cluster2 -object x86-cpu-model-core,id=cpu14,parent=cluster2,threads=2 -object x86-cpu-model-atom,id=cpu15,parent=cluster3 -object x86-cpu-model-atom,id=cpu16,parent=cluster3 -object x86-cpu-model-atom,id=cpu17,parent=cluster3 -object x86-cpu-model-atom,id=cpu18,parent=cluster3 -object x86-cpu-model-core,id=cpu19,parent=cluster3,threads=2

Quoted 1 line

The really obvious downside is that it is much more verbose.

I find the "core" and "cluster" already have the abstraction as the device, and Andreas also tried to abstract "socket" as the device.

So I find in this QOM way, all CPU topology levels should be abstracted to devices and created via "-device". And I also need to extend "cluster" device to support VM case as a general CPU topology abstraction, not only just used in TCG emulation.

I've done a preliminary POC so far, where I can create the CPU topology via "-device", and also added the ability to create the "child" relationship in "-device" (since neither the "link" relationship nor the bus looks like a good representation of the CPU hierarchy).

There's an example:

-device cpu-socket,id=sock0 \
-device cpu-die,id=die0,parent=sock0 \
-device cpu-die,id=die1,parent=sock0 \
-device cpu-cluster,id=cluster0,parent=die0 \
-device cpu-cluster,id=cluster1,parent=die0 \
-device cpu-cluster,id=cluster2,parent=die1 \
-device x86-intel-core,id=core0,parent=cluster0,threads=3 \
-device x86-intel-atom,id=core1,parent=cluster0,threads=2 \
-device x86-core,id=core2,parent=cluster1,threads=1 \
-device x86-intel-core,id=core3,parent=cluster2,threads=5 \

with the above format, I could build the the more accurate canonical path for CPUs like this:

(QEMU) query-hotpluggable-cpus

{
    "arguments": {},
    "execute": "query-hotpluggable-cpus"
}
{
    "return": [
        {
            "props": {
                "cluster-id": 0,
                "core-id": 0,
                "die-id": 1,
                "socket-id": 0,
                "thread-id": 4
            },
            "qom-path": "/machine/peripheral/cpu-slot/sock0/die1/cluster2/core3/host-x86_64-cpu[10]",
            "type": "host-x86_64-cpu",
            "vcpus-count": 1
        },
        {
            "props": {
                "cluster-id": 0,
                "core-id": 0,
                "die-id": 1,
                "socket-id": 0,
                "thread-id": 3
            },
            "qom-path": "/machine/peripheral/cpu-slot/sock0/die1/cluster2/core3/host-x86_64-cpu[9]",
            "type": "host-x86_64-cpu",
            "vcpus-count": 1
        },
        {
            "props": {
                "cluster-id": 0,
                "core-id": 0,
                "die-id": 1,
                "socket-id": 0,
                "thread-id": 2
            },
            "qom-path": "/machine/peripheral/cpu-slot/sock0/die1/cluster2/core3/host-x86_64-cpu[8]",
            "type": "host-x86_64-cpu",
            "vcpus-count": 1
        },
        {
            "props": {
                "cluster-id": 0,
                "core-id": 0,
                "die-id": 1,
                "socket-id": 0,
                "thread-id": 1
            },
            "qom-path": "/machine/peripheral/cpu-slot/sock0/die1/cluster2/core3/host-x86_64-cpu[7]",
            "type": "host-x86_64-cpu",
            "vcpus-count": 1
        },
        {
            "props": {
                "cluster-id": 0,
                "core-id": 0,
                "die-id": 1,
                "socket-id": 0,
                "thread-id": 0
            },
            "qom-path": "/machine/peripheral/cpu-slot/sock0/die1/cluster2/core3/host-x86_64-cpu[6]",
            "type": "host-x86_64-cpu",
            "vcpus-count": 1
        },
        {
            "props": {
                "cluster-id": 1,
                "core-id": 0,
                "die-id": 0,
                "socket-id": 0,
                "thread-id": 0
            },
            "qom-path": "/machine/peripheral/cpu-slot/sock0/die0/cluster1/core2/host-x86_64-cpu[5]",
            "type": "host-x86_64-cpu",
            "vcpus-count": 1
        },
        {
            "props": {
                "cluster-id": 0,
                "core-id": 1,
                "die-id": 0,
                "socket-id": 0,
                "thread-id": 1
            },
            "qom-path": "/machine/peripheral/cpu-slot/sock0/die0/cluster0/core1/host-x86_64-cpu[4]",
            "type": "host-x86_64-cpu",
            "vcpus-count": 1
        },
        {
            "props": {
                "cluster-id": 0,
                "core-id": 1,
                "die-id": 0,
                "socket-id": 0,
                "thread-id": 0
            },
            "qom-path": "/machine/peripheral/cpu-slot/sock0/die0/cluster0/core1/host-x86_64-cpu[3]",
            "type": "host-x86_64-cpu",
            "vcpus-count": 1
        },
        {
            "props": {
                "cluster-id": 0,
                "core-id": 0,
                "die-id": 0,
                "socket-id": 0,
                "thread-id": 2
            },
            "qom-path": "/machine/peripheral/cpu-slot/sock0/die0/cluster0/core0/host-x86_64-cpu[2]",
            "type": "host-x86_64-cpu",
            "vcpus-count": 1
        },
        {
            "props": {
                "cluster-id": 0,
                "core-id": 0,
                "die-id": 0,
                "socket-id": 0,
                "thread-id": 1
            },
            "qom-path": "/machine/peripheral/cpu-slot/sock0/die0/cluster0/core0/host-x86_64-cpu[1]",
            "type": "host-x86_64-cpu",
            "vcpus-count": 1
        },
        {
            "props": {
                "cluster-id": 0,
                "core-id": 0,
                "die-id": 0,
                "socket-id": 0,
                "thread-id": 0
            },
            "qom-path": "/machine/peripheral/cpu-slot/sock0/die0/cluster0/core0/host-x86_64-cpu[0]",
            "type": "host-x86_64-cpu",
            "vcpus-count": 1
        }
    ]
}

Of course, I'm still a bit far from the full QOM topology support, but would like to hear comments at the POC stage as well! :-)

Thanks and BR,
Zhao

Quoted 72 lines

This example only has 20 CPUs. For a VM with say 1000 CPUs this will be very big, but that doesn't neccesarily make it wrong.

On the flipside

* It is really clear exactly how many CPUs I've added

* The relationship between the topology levels is clear

* Every CPU has a unique ID given that can be used in later QMP commands

* Whether or not 'threads' are permitted is now a property of the specific CPU model implementation, not the global config. IOW we can express that some CPU models allowing for threads, and some don't.

* The -cpu arg is also obsoleted, replaced by the -object x86-cpu-model-core. This might facilitate the modelling of machines with CPUs from different architectures.

We could potentially compress the leaf node level by expressing how many instances of an object we want. it we want. ie, define a more convenient shorthand syntax to creating many instances of an object. so eg

-object-set $TYPE,$PROPS,idbase=foo,count=4

would be functionally identical to

-object $TYPE,$PROPS,id=foo.0
-object $TYPE,$PROPS,id=foo.1
-object $TYPE,$PROPS,id=foo.2
-object $TYPE,$PROPS,id=foo.3

QEMU just expands it and creates all the objects internally.

So the huge example I have above for 20 cpus would become much
shorter: e.g.

-object cpu-socket,id=sock0
-object cpu-die,id=die0,parent=sock0
-object cpu-cluster,id=cluster0,parent=die0
-object cpu-cluster,id=cluster1,parent=die0
-object cpu-cluster,id=cluster2,parent=die0
-object cpu-cluster,id=cluster3,parent=die0
-object-set x86-cpu-core-atom,idbase=cpu0,parent=cluster0,count=4 -object-set x86-cpu-core-core,id=cpu1,parent=cluster0,threads=2,count=1 -object-set x86-cpu-core-atom,idbase=cpu2,parent=cluster1,count=4 -object-set x86-cpu-core-core,id=cpu3,parent=cluster1,threads=2,count=1 -object-set x86-cpu-core-atom,idbase=cpu4,parent=cluster2,count=4 -object-set x86-cpu-core-core,id=cpu5,parent=cluster2,threads=2,count=1 -object-set x86-cpu-core-atom,idbase=cpu6,parent=cluster3,count=4 -object-set x86-cpu-core-core,id=cpu7,parent=cluster3,threads=2,count=1

IOW, the size of the CLI config only depends on the number of elements in the hierarchy, and is independant of the number of leaf CPU cores.

Obviously in describing all of the above, I've ignored any complexity of dealing with our existing code implementation and pain of getting it converted to the new model.

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|