@@ -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);
+ }
+ }
+}
@@ -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) {
@@ -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