[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC 28/41] hw/core/slot: Maintain the core queue in CPU slot
From: |
Zhao Liu |
Subject: |
[RFC 28/41] hw/core/slot: Maintain the core queue in CPU slot |
Date: |
Thu, 30 Nov 2023 22:41:50 +0800 |
From: Zhao Liu <zhao1.liu@intel.com>
Maintain the cores queue at cpu-slot to facilitate direct traversal
of all cores.
Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
---
hw/core/cpu-slot.c | 43 ++++++++++++++++++++++++++++++++++++++
include/hw/core/cpu-slot.h | 9 ++++++++
include/hw/cpu/core.h | 2 ++
3 files changed, 54 insertions(+)
diff --git a/hw/core/cpu-slot.c b/hw/core/cpu-slot.c
index 5aef5b0189c2..a6b7d98dea18 100644
--- a/hw/core/cpu-slot.c
+++ b/hw/core/cpu-slot.c
@@ -22,6 +22,40 @@
#include "hw/core/cpu-slot.h"
+static void cpu_slot_add_topo_info(CPUTopoState *root, CPUTopoState *child)
+{
+ CPUSlot *slot = CPU_SLOT(root);
+ CPUTopoLevel level = CPU_TOPO_LEVEL(child);
+
+ if (level == CPU_TOPO_CORE) {
+ QTAILQ_INSERT_TAIL(&slot->cores, CPU_CORE(child), node);
+ }
+ return;
+}
+
+static void cpu_slot_del_topo_info(CPUTopoState *root, CPUTopoState *child)
+{
+ CPUSlot *slot = CPU_SLOT(root);
+ CPUTopoLevel level = CPU_TOPO_LEVEL(child);
+
+ if (level == CPU_TOPO_CORE) {
+ QTAILQ_REMOVE(&slot->cores, CPU_CORE(child), node);
+ }
+ return;
+}
+
+static void cpu_slot_update_topo_info(CPUTopoState *root, CPUTopoState *child,
+ bool is_realize)
+{
+ g_assert(child->parent);
+
+ if (is_realize) {
+ cpu_slot_add_topo_info(root, child);
+ } else {
+ cpu_slot_del_topo_info(root, child);
+ }
+}
+
static void cpu_slot_class_init(ObjectClass *oc, void *data)
{
DeviceClass *dc = DEVICE_CLASS(oc);
@@ -31,12 +65,21 @@ static void cpu_slot_class_init(ObjectClass *oc, void *data)
dc->user_creatable = false;
tc->level = CPU_TOPO_ROOT;
+ tc->update_topo_info = cpu_slot_update_topo_info;
+}
+
+static void cpu_slot_instance_init(Object *obj)
+{
+ CPUSlot *slot = CPU_SLOT(obj);
+
+ QTAILQ_INIT(&slot->cores);
}
static const TypeInfo cpu_slot_type_info = {
.name = TYPE_CPU_SLOT,
.parent = TYPE_CPU_TOPO,
.class_init = cpu_slot_class_init,
+ .instance_init = cpu_slot_instance_init,
.instance_size = sizeof(CPUSlot),
};
diff --git a/include/hw/core/cpu-slot.h b/include/hw/core/cpu-slot.h
index 718c8ecaa751..d2a1160562be 100644
--- a/include/hw/core/cpu-slot.h
+++ b/include/hw/core/cpu-slot.h
@@ -22,17 +22,26 @@
#define CPU_SLOT_H
#include "hw/core/cpu-topo.h"
+#include "hw/cpu/core.h"
#include "hw/qdev-core.h"
#define TYPE_CPU_SLOT "cpu-slot"
OBJECT_DECLARE_SIMPLE_TYPE(CPUSlot, CPU_SLOT)
+/**
+ * CPUSlot:
+ * @cores: Queue consisting of all the cores in the topology tree
+ * where the cpu-slot is the root. cpu-slot can maintain similar
+ * queues for other topology levels to facilitate traversal
+ * when necessary.
+ */
struct CPUSlot {
/*< private >*/
CPUTopoState parent_obj;
/*< public >*/
+ QTAILQ_HEAD(, CPUCore) cores;
};
#endif /* CPU_SLOT_H */
diff --git a/include/hw/cpu/core.h b/include/hw/cpu/core.h
index 591240861efb..65dc10931190 100644
--- a/include/hw/cpu/core.h
+++ b/include/hw/cpu/core.h
@@ -40,6 +40,8 @@ struct CPUCore {
* "-device"/"device_add"?
*/
int plugged_threads;
+
+ QTAILQ_ENTRY(CPUCore) node;
};
#endif
--
2.34.1
- [RFC 07/41] qdev: Introduce parent option in -device, (continued)
- [RFC 07/41] qdev: Introduce parent option in -device, Zhao Liu, 2023/11/30
- [RFC 30/41] hw/core/slot: Check topology child to be added under CPU slot, Zhao Liu, 2023/11/30
- [RFC 04/41] qom/object: Introduce helper to resolve path from non-direct parent, Zhao Liu, 2023/11/30
- [RFC 06/41] qdev: Introduce user-child interface to collect devices from -device, Zhao Liu, 2023/11/30
- [RFC 09/41] hw/core/topo: Support topology index for topology device, Zhao Liu, 2023/11/30
- [RFC 10/41] hw/core/topo: Add virtual method to update topology info for parent, Zhao Liu, 2023/11/30
- [RFC 16/41] PPC/ppc-core: Limit plugged-threads and nr-threads to be equal, Zhao Liu, 2023/11/30
- [RFC 24/41] hw/cpu/socket: Abstract cpu-socket level as topology device, Zhao Liu, 2023/11/30
- [RFC 26/41] hw/cpu/drawer: Abstract cpu-drawer level as topology device, Zhao Liu, 2023/11/30
- [RFC 15/41] hw/cpu/core: Allow to configure plugged threads for cpu-core, Zhao Liu, 2023/11/30
- [RFC 28/41] hw/core/slot: Maintain the core queue in CPU slot,
Zhao Liu <=
- [RFC 33/41] hw/machine: Validate smp topology tree without -smp, Zhao Liu, 2023/11/30
- [RFC 36/41] hw/i386: Allow x86_cpu_new() to specify parent for new CPU, Zhao Liu, 2023/11/30
- [RFC 39/41] hw/i386: Add the interface to search parent for QOM topology, Zhao Liu, 2023/11/30
- [RFC 40/41] hw/i386: Support QOM topology, Zhao Liu, 2023/11/30
- [RFC 41/41] hw/i386: Cleanup non-QOM topology support, Zhao Liu, 2023/11/30