[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC 07/52] hw/core/machine: Add the new topology support in MachineStat
From: |
Zhao Liu |
Subject: |
[RFC 07/52] hw/core/machine: Add the new topology support in MachineState |
Date: |
Mon, 13 Feb 2023 17:49:50 +0800 |
From: Zhao Liu <zhao1.liu@intel.com>
Add MachineState.topo to represent CPU topology, and initialize this
field as smp topology.
Also collect topology information from MachineState.topo in
machine_get_smp().
Additionally, check the validity of MachineState.topo instead of
MachineState.smp.
Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
---
hw/core/machine-topo.c | 26 +++++++++++++++++---------
hw/core/machine.c | 23 ++++++++++++++++-------
include/hw/boards.h | 2 ++
3 files changed, 35 insertions(+), 16 deletions(-)
diff --git a/hw/core/machine-topo.c b/hw/core/machine-topo.c
index 8066d2c46bef..7223f73f99b0 100644
--- a/hw/core/machine-topo.c
+++ b/hw/core/machine-topo.c
@@ -31,18 +31,18 @@ static char *cpu_hierarchy_to_string(MachineState *ms)
MachineClass *mc = MACHINE_GET_CLASS(ms);
GString *s = g_string_new(NULL);
- g_string_append_printf(s, "sockets (%u)", ms->smp.sockets);
+ g_string_append_printf(s, "sockets (%u)", ms->topo.smp.sockets);
if (mc->smp_props.dies_supported) {
- g_string_append_printf(s, " * dies (%u)", ms->smp.dies);
+ g_string_append_printf(s, " * dies (%u)", ms->topo.smp.dies);
}
if (mc->smp_props.clusters_supported) {
- g_string_append_printf(s, " * clusters (%u)", ms->smp.clusters);
+ g_string_append_printf(s, " * clusters (%u)", ms->topo.smp.clusters);
}
- g_string_append_printf(s, " * cores (%u)", ms->smp.cores);
- g_string_append_printf(s, " * threads (%u)", ms->smp.threads);
+ g_string_append_printf(s, " * cores (%u)", ms->topo.smp.cores);
+ g_string_append_printf(s, " * threads (%u)", ms->topo.smp.threads);
return g_string_free(s, false);
}
@@ -159,6 +159,14 @@ void machine_parse_smp_config(MachineState *ms,
ms->smp.threads = threads;
ms->smp.max_cpus = maxcpus;
+ ms->topo.cpus = cpus;
+ ms->topo.max_cpus = maxcpus;
+ ms->topo.smp.sockets = sockets;
+ ms->topo.smp.dies = dies;
+ ms->topo.smp.clusters = clusters;
+ ms->topo.smp.cores = cores;
+ ms->topo.smp.threads = threads;
+
mc->smp_props.has_clusters = config->has_clusters;
/* sanity-check of the computed topology */
@@ -180,18 +188,18 @@ void machine_parse_smp_config(MachineState *ms,
return;
}
- if (ms->smp.cpus < mc->min_cpus) {
+ if (ms->topo.cpus < mc->min_cpus) {
error_setg(errp, "Invalid SMP CPUs %d. The min CPUs "
"supported by machine '%s' is %d",
- ms->smp.cpus,
+ ms->topo.cpus,
mc->name, mc->min_cpus);
return;
}
- if (ms->smp.max_cpus > mc->max_cpus) {
+ if (ms->topo.max_cpus > mc->max_cpus) {
error_setg(errp, "Invalid SMP CPUs %d. The max CPUs "
"supported by machine '%s' is %d",
- ms->smp.max_cpus,
+ ms->topo.max_cpus,
mc->name, mc->max_cpus);
return;
}
diff --git a/hw/core/machine.c b/hw/core/machine.c
index f73fc4c45c41..56e796c18873 100644
--- a/hw/core/machine.c
+++ b/hw/core/machine.c
@@ -829,13 +829,13 @@ static void machine_get_smp(Object *obj, Visitor *v,
const char *name,
{
MachineState *ms = MACHINE(obj);
SMPConfiguration *config = &(SMPConfiguration){
- .has_cpus = true, .cpus = ms->smp.cpus,
- .has_sockets = true, .sockets = ms->smp.sockets,
- .has_dies = true, .dies = ms->smp.dies,
- .has_clusters = true, .clusters = ms->smp.clusters,
- .has_cores = true, .cores = ms->smp.cores,
- .has_threads = true, .threads = ms->smp.threads,
- .has_maxcpus = true, .maxcpus = ms->smp.max_cpus,
+ .has_cpus = true, .cpus = ms->topo.cpus,
+ .has_sockets = true, .sockets = ms->topo.smp.sockets,
+ .has_dies = true, .dies = ms->topo.smp.dies,
+ .has_clusters = true, .clusters = ms->topo.smp.clusters,
+ .has_cores = true, .cores = ms->topo.smp.cores,
+ .has_threads = true, .threads = ms->topo.smp.threads,
+ .has_maxcpus = true, .maxcpus = ms->topo.max_cpus,
};
if (!visit_type_SMPConfiguration(v, name, &config, &error_abort)) {
@@ -1101,6 +1101,15 @@ static void machine_initfn(Object *obj)
ms->smp.cores = 1;
ms->smp.threads = 1;
+ ms->topo.cpus = mc->default_cpus;
+ ms->topo.max_cpus = mc->default_cpus;
+ ms->topo.topo_type = CPU_TOPO_TYPE_SMP;
+ ms->topo.smp.sockets = 1;
+ ms->topo.smp.dies = 1;
+ ms->topo.smp.clusters = 1;
+ ms->topo.smp.cores = 1;
+ ms->topo.smp.threads = 1;
+
machine_copy_boot_config(ms, &(BootConfiguration){ 0 });
}
diff --git a/include/hw/boards.h b/include/hw/boards.h
index 6fbbfd56c808..0a61855499e3 100644
--- a/include/hw/boards.h
+++ b/include/hw/boards.h
@@ -10,6 +10,7 @@
#include "qemu/module.h"
#include "qom/object.h"
#include "hw/core/cpu.h"
+#include "hw/cpu/cpu-topology.h"
#define TYPE_MACHINE_SUFFIX "-machine"
@@ -360,6 +361,7 @@ struct MachineState {
AccelState *accelerator;
CPUArchIdList *possible_cpus;
CpuTopology smp;
+ GeneralCpuTopology topo; /* TODO: Completely replace MachineState.smp */
struct NVDIMMState *nvdimms_state;
struct NumaState *numa_state;
};
--
2.34.1
[RFC 07/52] hw/core/machine: Add the new topology support in MachineState,
Zhao Liu <=
[RFC 08/52] machine: Add helpers to get cpu topology info from MachineState.topo, Zhao Liu, 2023/02/13
[RFC 09/52] hw/machine: Introduce core type for hybrid topology, Zhao Liu, 2023/02/13