diff mbox series

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

Message ID 20230213095035.158240-52-zhao1.liu@linux.intel.com
State New
Headers show
Series Introduce hybrid CPU topology | expand

Commit Message

Zhao Liu Feb. 13, 2023, 9:50 a.m. UTC
From: Zhao Liu <zhao1.liu@intel.com>

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.

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

Patch

diff --git a/hw/core/machine-qmp-cmds.c b/hw/core/machine-qmp-cmds.c
index 44b5da888024..6be7148a8374 100644
--- a/hw/core/machine-qmp-cmds.c
+++ b/hw/core/machine-qmp-cmds.c
@@ -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);
diff --git a/hw/core/machine-topo.c b/hw/core/machine-topo.c
index f38b8c683026..f0ff550a2519 100644
--- a/hw/core/machine-topo.c
+++ b/hw/core/machine-topo.c
@@ -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);
diff --git a/include/hw/boards.h b/include/hw/boards.h
index c93bb1206244..d925e8af9ed6 100644
--- a/include/hw/boards.h
+++ b/include/hw/boards.h
@@ -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
diff --git a/qapi/machine.json b/qapi/machine.json
index 931c6dea9819..e86778b7a777 100644
--- a/qapi/machine.json
+++ b/qapi/machine.json
@@ -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' } }