[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC 12/41] hw/core/topo: Add helpers to traverse the CPU topology tree
From: |
Zhao Liu |
Subject: |
[RFC 12/41] hw/core/topo: Add helpers to traverse the CPU topology tree |
Date: |
Thu, 30 Nov 2023 22:41:34 +0800 |
From: Zhao Liu <zhao1.liu@intel.com>
The topology devices will be organized as a topology tree. Each topology
device may have many topology children with lower topology level.
Add the helpers to traverse the CPU topology tree.
Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
---
hw/core/cpu-topo.c | 41 ++++++++++++++++++++++++++++++++++++++
include/hw/core/cpu-topo.h | 13 ++++++++++++
2 files changed, 54 insertions(+)
diff --git a/hw/core/cpu-topo.c b/hw/core/cpu-topo.c
index cba2dc747e74..687a4cc566ec 100644
--- a/hw/core/cpu-topo.c
+++ b/hw/core/cpu-topo.c
@@ -318,3 +318,44 @@ static void cpu_topo_register_types(void)
}
type_init(cpu_topo_register_types)
+
+static int do_cpu_topo_child_foreach(CPUTopoState *topo,
+ unsigned long *levels,
+ topo_fn fn, void *opaque,
+ bool recurse)
+{
+ CPUTopoState *child;
+ int ret = TOPO_FOREACH_CONTINUE;
+
+ QTAILQ_FOREACH(child, &topo->children, sibling) {
+ if (!levels || (levels && test_bit(CPU_TOPO_LEVEL(child), levels))) {
+ ret = fn(child, opaque);
+ if (ret == TOPO_FOREACH_END || ret == TOPO_FOREACH_ERR) {
+ break;
+ } else if (ret == TOPO_FOREACH_SIBLING) {
+ continue;
+ }
+ }
+
+ if (recurse) {
+ ret = do_cpu_topo_child_foreach(child, levels, fn, opaque,
recurse);
+ if (ret != TOPO_FOREACH_CONTINUE) {
+ break;
+ }
+ }
+ }
+ return ret;
+}
+
+int cpu_topo_child_foreach(CPUTopoState *topo, unsigned long *levels,
+ topo_fn fn, void *opaque)
+{
+ return do_cpu_topo_child_foreach(topo, levels, fn, opaque, false);
+}
+
+int cpu_topo_child_foreach_recursive(CPUTopoState *topo,
+ unsigned long *levels,
+ topo_fn fn, void *opaque)
+{
+ return do_cpu_topo_child_foreach(topo, levels, fn, opaque, true);
+}
diff --git a/include/hw/core/cpu-topo.h b/include/hw/core/cpu-topo.h
index 1ffdb0be6d38..453bacbb558b 100644
--- a/include/hw/core/cpu-topo.h
+++ b/include/hw/core/cpu-topo.h
@@ -90,4 +90,17 @@ struct CPUTopoState {
#define CPU_TOPO_LEVEL(topo) (CPU_TOPO_GET_CLASS(topo)->level)
+#define TOPO_FOREACH_SIBLING 2
+#define TOPO_FOREACH_END 1
+#define TOPO_FOREACH_CONTINUE 0
+#define TOPO_FOREACH_ERR -1
+
+typedef int (*topo_fn)(CPUTopoState *topo, void *opaque);
+
+int cpu_topo_child_foreach(CPUTopoState *topo, unsigned long *levels,
+ topo_fn fn, void *opaque);
+int cpu_topo_child_foreach_recursive(CPUTopoState *topo,
+ unsigned long *levels,
+ topo_fn fn, void *opaque);
+
#endif /* CPU_TOPO_H */
--
2.34.1
- [RFC 05/41] qdev: Set device parent and id after setting properties, (continued)
- [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, 2023/11/30
- [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 <=
- [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
- [RFC 25/41] hw/cpu/book: Abstract cpu-book level as topology device, Zhao Liu, 2023/11/30
- [RFC 34/41] hw/core/topo: Implement user-child to collect topology device from cli, Zhao Liu, 2023/11/30
- [RFC 35/41] hw/i386: Make x86_cpu_new() private in x86.c, Zhao Liu, 2023/11/30
- [RFC 37/41] hw/i386: Allow i386 to create new CPUs from QOM topology, Zhao Liu, 2023/11/30
- [RFC 38/41] hw/i386: Wrap apic id and topology sub ids assigning as helpers, Zhao Liu, 2023/11/30
- [RFC 01/41] qdev: Introduce new device category to cover basic topology device, Zhao Liu, 2023/11/30