diff mbox series

[RFC,46/52] hw/machine: build core level hybrid topology form HybridCorePack

Message ID 20230213095035.158240-47-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>

After verifying the hybrid topology, we need to convert the topology
structure of the core level from a single linked list to an array,
so that we can make full use of the core-id to quickly access the
corresponding core.

Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
---
 hw/core/machine-topo.c | 48 ++++++++++++++++++++++++++++++++----------
 hw/core/machine.c      |  1 +
 include/hw/boards.h    |  1 +
 3 files changed, 39 insertions(+), 11 deletions(-)
diff mbox series

Patch

diff --git a/hw/core/machine-topo.c b/hw/core/machine-topo.c
index 2cf71cc466aa..ebd2c40396a2 100644
--- a/hw/core/machine-topo.c
+++ b/hw/core/machine-topo.c
@@ -604,22 +604,13 @@  void set_hybrid_options(MachineState *ms,
 void machine_free_hybrid_topology(MachineState *ms)
 {
     HybridCluster *cluster;
-    HybridCorePack *core_pack;
-    HybridCorePack *tmp;
 
     if (ms->topo.hybrid.clusters) {
         for (int i = 0; i < ms->topo.hybrid.clusters; i++) {
             cluster = &ms->topo.hybrid.cluster_list[i];
 
-            /*
-             * TODO: Temporarily free core_pack_list here. When the
-             * building of core_list array is supported, it will be
-             * freeed there.
-             */
-            QSLIST_FOREACH_SAFE(core_pack, &cluster->core_pack_list,
-                                node, tmp) {
-                QSLIST_REMOVE_HEAD(&cluster->core_pack_list, node);
-                g_free(core_pack);
+            if (cluster->core_list != NULL) {
+                g_free(cluster->core_list);
             }
         }
         g_free(ms->topo.hybrid.cluster_list);
@@ -751,3 +742,38 @@  void machine_validate_hybrid_topology(MachineState *ms, Error **errp)
         exit(1);
     }
 }
+
+void machine_consolidate_hybrid_topology(MachineState *ms)
+{
+    HybridCluster *cluster;
+    HybridCorePack *core_pack;
+    HybridCorePack *tmp;
+    int core_num;
+
+    for (int i = 0; i < ms->topo.hybrid.clusters; i++) {
+        cluster = &ms->topo.hybrid.cluster_list[i];
+        cluster->core_list = g_malloc0(sizeof(HybridCore) * cluster->cores);
+
+        core_num = cluster->cores;
+        QSLIST_FOREACH_SAFE(core_pack, &cluster->core_pack_list, node, tmp) {
+            QSLIST_REMOVE_HEAD(&cluster->core_pack_list, node);
+
+            /*
+             * Here we add cores in "reverse order" because core_pack_list uses
+             * "QSLIST_INSERT_HEAD()" to collect the cores in the "-hybrid"
+             * command line in reverse order.
+             *
+             * The "reverse order" here can ensure that the growth of core-id
+             * is consistent with the order of adding cores in "-hybrid".
+             */
+            for (int j = 0; j < core_pack->core_num; j++) {
+                cluster->core_list[core_num - j - 1].core_type =
+                    core_pack->core.core_type;
+                cluster->core_list[core_num - j - 1].threads =
+                    core_pack->core.threads;
+            }
+            core_num -= core_pack->core_num;
+            g_free(core_pack);
+        }
+    }
+}
diff --git a/hw/core/machine.c b/hw/core/machine.c
index 630934317e3c..08a0c117ce1b 100644
--- a/hw/core/machine.c
+++ b/hw/core/machine.c
@@ -1329,6 +1329,7 @@  void machine_run_board_init(MachineState *machine, const char *mem_path, Error *
 
     if (!machine_topo_is_smp(machine)) {
         machine_validate_hybrid_topology(machine, errp);
+        machine_consolidate_hybrid_topology(machine);
     }
 
     if (machine->memdev) {
diff --git a/include/hw/boards.h b/include/hw/boards.h
index 9156982e4de6..0f865c21e2a8 100644
--- a/include/hw/boards.h
+++ b/include/hw/boards.h
@@ -42,6 +42,7 @@  void set_hybrid_options(MachineState *ms,
                         Error **errp);
 void machine_free_hybrid_topology(MachineState *ms);
 void machine_validate_hybrid_topology(MachineState *ms, Error **errp);
+void machine_consolidate_hybrid_topology(MachineState *ms);
 
 /**
  * machine_class_allow_dynamic_sysbus_dev: Add type to list of valid devices