[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC 31/41] hw/machine: Plug cpu-slot into machine to maintain topology
From: |
Zhao Liu |
Subject: |
[RFC 31/41] hw/machine: Plug cpu-slot into machine to maintain topology tree |
Date: |
Thu, 30 Nov 2023 22:41:53 +0800 |
From: Zhao Liu <zhao1.liu@intel.com>
Add a cpu-slot in machine as the root of topology tree to maintain the
QOM topology.
Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
---
hw/core/cpu-slot.c | 31 +++++++++++++++++++++++++++++++
include/hw/boards.h | 2 ++
include/hw/core/cpu-slot.h | 7 +++++++
system/vl.c | 2 ++
4 files changed, 42 insertions(+)
diff --git a/hw/core/cpu-slot.c b/hw/core/cpu-slot.c
index 2a796ad5b6e7..4b148440ed3d 100644
--- a/hw/core/cpu-slot.c
+++ b/hw/core/cpu-slot.c
@@ -20,6 +20,7 @@
#include "qemu/osdep.h"
+#include "hw/boards.h"
#include "hw/core/cpu-slot.h"
#include "qapi/error.h"
@@ -165,3 +166,33 @@ static void cpu_slot_register_types(void)
}
type_init(cpu_slot_register_types)
+
+void machine_plug_cpu_slot(MachineState *ms)
+{
+ MachineClass *mc = MACHINE_GET_CLASS(ms);
+
+ ms->topo = CPU_SLOT(qdev_new(TYPE_CPU_SLOT));
+
+ object_property_add_child(container_get(OBJECT(ms), "/peripheral"),
+ "cpu-slot", OBJECT(ms->topo));
+ DEVICE(ms->topo)->id = g_strdup_printf("%s", "cpu-slot");
+
+ qdev_realize_and_unref(DEVICE(ms->topo), NULL, &error_abort);
+ ms->topo->ms = ms;
+
+ if (!mc->smp_props.clusters_supported) {
+ clear_bit(CPU_TOPO_CLUSTER, ms->topo->supported_levels);
+ }
+
+ if (!mc->smp_props.dies_supported) {
+ clear_bit(CPU_TOPO_DIE, ms->topo->supported_levels);
+ }
+
+ if (!mc->smp_props.books_supported) {
+ clear_bit(CPU_TOPO_BOOK, ms->topo->supported_levels);
+ }
+
+ if (!mc->smp_props.drawers_supported) {
+ clear_bit(CPU_TOPO_DRAWER, ms->topo->supported_levels);
+ }
+}
diff --git a/include/hw/boards.h b/include/hw/boards.h
index da85f86efb91..81a7b04ece86 100644
--- a/include/hw/boards.h
+++ b/include/hw/boards.h
@@ -10,6 +10,7 @@
#include "qemu/module.h"
#include "qom/object.h"
#include "hw/core/cpu.h"
+#include "hw/core/cpu-slot.h"
#define TYPE_MACHINE_SUFFIX "-machine"
@@ -398,6 +399,7 @@ struct MachineState {
AccelState *accelerator;
CPUArchIdList *possible_cpus;
CpuTopology smp;
+ CPUSlot *topo;
struct NVDIMMState *nvdimms_state;
struct NumaState *numa_state;
};
diff --git a/include/hw/core/cpu-slot.h b/include/hw/core/cpu-slot.h
index 7bf51988afb3..1361af4ccfc0 100644
--- a/include/hw/core/cpu-slot.h
+++ b/include/hw/core/cpu-slot.h
@@ -78,6 +78,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(CPUSlot, CPU_SLOT)
* when necessary.
* @stat: Statistical topology information for topology tree.
* @supported_levels: Supported topology levels for topology tree.
+ * @ms: Machine in which this cpu-slot is plugged.
*/
struct CPUSlot {
/*< private >*/
@@ -87,6 +88,12 @@ struct CPUSlot {
QTAILQ_HEAD(, CPUCore) cores;
CPUTopoStat stat;
DECLARE_BITMAP(supported_levels, USER_AVAIL_LEVEL_NUM);
+ MachineState *ms;
};
+#define MACHINE_CORE_FOREACH(ms, core) \
+ QTAILQ_FOREACH((core), &(ms)->topo->cores, node)
+
+void machine_plug_cpu_slot(MachineState *ms);
+
#endif /* CPU_SLOT_H */
diff --git a/system/vl.c b/system/vl.c
index 65add2fb2460..637f708d2265 100644
--- a/system/vl.c
+++ b/system/vl.c
@@ -2128,6 +2128,8 @@ static void qemu_create_machine(QDict *qdict)
false, &error_abort);
qobject_unref(default_opts);
}
+
+ machine_plug_cpu_slot(current_machine);
}
static int global_init_func(void *opaque, QemuOpts *opts, Error **errp)
--
2.34.1
- [RFC 00/41] qom-topo: Abstract Everything about CPU Topology, Zhao Liu, 2023/11/30
- [RFC 02/41] qdev: Allow qdev_device_add() to add specific category device, Zhao Liu, 2023/11/30
- [RFC 05/41] qdev: Set device parent and id after setting properties, Zhao Liu, 2023/11/30
- [RFC 08/41] hw/core/topo: Introduce CPU topology device abstraction, Zhao Liu, 2023/11/30
- [RFC 18/41] hw/cpu/cluster: Rename CPUClusterState to CPUCluster, Zhao Liu, 2023/11/30
- [RFC 29/41] hw/core/slot: Statistics topology information in CPU slot, Zhao Liu, 2023/11/30
- [RFC 31/41] hw/machine: Plug cpu-slot into machine to maintain topology tree,
Zhao Liu <=
- [RFC 32/41] hw/machine: Build smp topology tree from -smp, Zhao Liu, 2023/11/30
- [RFC 13/41] hw/core/cpu: Convert CPU from general device to topology device, Zhao Liu, 2023/11/30
- [RFC 17/41] hw/cpu/core: Convert cpu-core from general device to topology device, Zhao Liu, 2023/11/30
- [RFC 03/41] system: Create base category devices from cli before board initialization, Zhao Liu, 2023/11/30
- [RFC 11/41] hw/core/topo: Add virtual method to check topology child, Zhao Liu, 2023/11/30
- [RFC 12/41] hw/core/topo: Add helpers to traverse the CPU topology tree, Zhao Liu, 2023/11/30
- [RFC 14/41] PPC/ppc-core: Offload core-id to PPC specific core abstarction, Zhao Liu, 2023/11/30
- [RFC 19/41] hw/cpu/cluster: Wrap TCG related ops and props into CONFIG_TCG, Zhao Liu, 2023/11/30
- [RFC 20/41] hw/cpu/cluster: Descript cluster is not only used for TCG in comment, Zhao Liu, 2023/11/30
- [RFC 23/41] hw/cpu/die: Abstract cpu-die level as topology device, Zhao Liu, 2023/11/30