@@ -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),
};
@@ -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 */
@@ -40,6 +40,8 @@ struct CPUCore {
* "-device"/"device_add"?
*/
int plugged_threads;
+
+ QTAILQ_ENTRY(CPUCore) node;
};
#endif