@@ -376,14 +376,16 @@ bool machine_parse_smp_cache(MachineState *ms,
return true;
}
-unsigned int machine_topo_get_cores_per_socket(const MachineState *ms)
+unsigned int machine_topo_get_cores_per_socket_old(const MachineState *ms)
{
+ assert(!ms->topo);
return ms->smp.cores * ms->smp.modules * ms->smp.clusters * ms->smp.dies;
}
-unsigned int machine_topo_get_threads_per_socket(const MachineState *ms)
+unsigned int machine_topo_get_threads_per_socket_old(const MachineState *ms)
{
- return ms->smp.threads * machine_topo_get_cores_per_socket(ms);
+ assert(!ms->topo);
+ return ms->smp.threads * machine_topo_get_cores_per_socket_old(ms);
}
CpuTopologyLevel machine_get_cache_topo_level(const MachineState *ms,
@@ -204,6 +204,8 @@ static int get_smp_info_by_level(const CpuTopology *smp_info,
return smp_info->cores;
case CPU_TOPOLOGY_LEVEL_MODULE:
return smp_info->modules;
+ case CPU_TOPOLOGY_LEVEL_CLUSTER:
+ return smp_info->clusters;
case CPU_TOPOLOGY_LEVEL_DIE:
return smp_info->dies;
case CPU_TOPOLOGY_LEVEL_SOCKET:
@@ -356,6 +358,22 @@ int get_max_topo_by_level(const MachineState *ms, CpuTopologyLevel level)
return ms->topo->stat.entries[level].max_limit;
}
+unsigned int machine_topo_get_cores_per_socket(const MachineState *ms)
+{
+ int cores = 1, i;
+
+ for (i = CPU_TOPOLOGY_LEVEL_CORE; i < CPU_TOPOLOGY_LEVEL_SOCKET; i++) {
+ cores *= get_max_topo_by_level(ms, i);
+ }
+ return cores;
+}
+
+unsigned int machine_topo_get_threads_per_socket(const MachineState *ms)
+{
+ return get_max_topo_by_level(ms, CPU_TOPOLOGY_LEVEL_THREAD) *
+ machine_topo_get_cores_per_socket(ms);
+}
+
bool machine_parse_custom_topo_config(MachineState *ms,
const SMPConfiguration *config,
Error **errp)
@@ -48,8 +48,13 @@ void machine_parse_smp_config(MachineState *ms,
bool machine_parse_smp_cache(MachineState *ms,
const SmpCachePropertiesList *caches,
Error **errp);
-unsigned int machine_topo_get_cores_per_socket(const MachineState *ms);
-unsigned int machine_topo_get_threads_per_socket(const MachineState *ms);
+/*
+ * TODO: Drop these old helpers when cpu-slot.c could be compiled for
+ * test-smp-parse. Pls use machine_topo_get_cores_per_socket() and
+ * machine_topo_get_threads_per_socket() instead.
+ */
+unsigned int machine_topo_get_cores_per_socket_old(const MachineState *ms);
+unsigned int machine_topo_get_threads_per_socket_old(const MachineState *ms);
CpuTopologyLevel machine_get_cache_topo_level(const MachineState *ms,
CacheLevelAndType cache);
void machine_memory_devices_init(MachineState *ms, hwaddr base, uint64_t size);
@@ -81,6 +81,8 @@ struct CPUSlot {
void machine_plug_cpu_slot(MachineState *ms);
bool machine_create_topo_tree(MachineState *ms, Error **errp);
int get_max_topo_by_level(const MachineState *ms, CpuTopologyLevel level);
+unsigned int machine_topo_get_cores_per_socket(const MachineState *ms);
+unsigned int machine_topo_get_threads_per_socket(const MachineState *ms);
bool machine_parse_custom_topo_config(MachineState *ms,
const SMPConfiguration *config,
Error **errp);
@@ -667,7 +667,7 @@ void qemu_init_vcpu(CPUState *cpu)
MachineState *ms = MACHINE(qdev_get_machine());
cpu->nr_cores = machine_topo_get_cores_per_socket(ms);
- cpu->nr_threads = ms->smp.threads;
+ cpu->nr_threads = get_max_topo_by_level(ms, CPU_TOPOLOGY_LEVEL_THREAD);
cpu->stopped = true;
cpu->random_seed = qemu_guest_random_seed_thread_part1();
@@ -801,8 +801,8 @@ static void check_parse(MachineState *ms, const SMPConfiguration *config,
/* call the generic parser */
machine_parse_smp_config(ms, config, &err);
- ms_threads_per_socket = machine_topo_get_threads_per_socket(ms);
- ms_cores_per_socket = machine_topo_get_cores_per_socket(ms);
+ ms_threads_per_socket = machine_topo_get_threads_per_socket_old(ms);
+ ms_cores_per_socket = machine_topo_get_cores_per_socket_old(ms);
output_topo_str = cpu_topology_to_string(&ms->smp,
ms_threads_per_socket,
ms_cores_per_socket,
For custom topology case, the valid and reliable topology information be obtained from topology max limitations. Therefore, re-implement machine_topo_get_cores_per_socket() and machine_topo_get_threads_per_socket() to consider the custom topology case. And further, use the wrapped helper to set CPUState.nr_threads/ nr_cores, avoiding topology mismatches in custom topology scenarios. Additionally, since test-smp-parse needs more stubs to compile with cpu-slot.c, keep the old helpers for test-smp-parse' use for now. The legacy old helpers will be cleaned up when full compilation support is added later on. Signed-off-by: Zhao Liu <zhao1.liu@intel.com> --- hw/core/machine-smp.c | 8 +++++--- hw/cpu/cpu-slot.c | 18 ++++++++++++++++++ include/hw/boards.h | 9 +++++++-- include/hw/cpu/cpu-slot.h | 2 ++ system/cpus.c | 2 +- tests/unit/test-smp-parse.c | 4 ++-- 6 files changed, 35 insertions(+), 8 deletions(-)