From: Zhao Liu <zhao1.liu@intel.com>
To: "Daniel P . Berrangé" <berrange@redhat.com>,
"Igor Mammedov" <imammedo@redhat.com>,
"Eduardo Habkost" <eduardo@habkost.net>,
"Marcel Apfelbaum" <marcel.apfelbaum@gmail.com>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>,
"Yanan Wang" <wangyanan55@huawei.com>,
"Michael S . Tsirkin" <mst@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Richard Henderson" <richard.henderson@linaro.org>,
"Sergio Lopez" <slp@redhat.com>,
"Jason Wang" <jasowang@redhat.com>,
"Stefano Stabellini" <sstabellini@kernel.org>,
"Anthony PERARD" <anthony@xenproject.org>,
"Paul Durrant" <paul@xen.org>,
"Edgar E . Iglesias" <edgar.iglesias@gmail.com>,
"Eric Blake" <eblake@redhat.com>,
"Markus Armbruster" <armbru@redhat.com>,
"Alex Bennée" <alex.bennee@linaro.org>,
"Peter Maydell" <peter.maydell@linaro.org>
Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, qemu-arm@nongnu.org,
Zhenyu Wang <zhenyu.z.wang@intel.com>,
Dapeng Mi <dapeng1.mi@linux.intel.com>,
Yongwei Ma <yongwei.ma@intel.com>, Zhao Liu <zhao1.liu@intel.com>
Subject: [RFC v2 08/12] hw/i386: Use get_max_topo_by_level() to get topology information
Date: Thu, 19 Sep 2024 14:11:24 +0800 [thread overview]
Message-ID: <20240919061128.769139-9-zhao1.liu@intel.com> (raw)
In-Reply-To: <20240919061128.769139-1-zhao1.liu@intel.com>
To honor the custom topology case and generate correct APIC ID for
hybrid CPU topology, Use get_max_topo_by_level() to get topology
information instead of accessing MachineState.smp directly.
Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
---
hw/i386/x86-common.c | 19 +++++++++++++------
hw/i386/x86.c | 20 +++++++++++++-------
2 files changed, 26 insertions(+), 13 deletions(-)
diff --git a/hw/i386/x86-common.c b/hw/i386/x86-common.c
index 75d4b2f3d43a..58591e015569 100644
--- a/hw/i386/x86-common.c
+++ b/hw/i386/x86-common.c
@@ -202,11 +202,15 @@ void x86_cpus_init(X86MachineState *x86ms, int default_cpu_version)
static void x86_fixup_topo_ids(MachineState *ms, X86CPU *cpu)
{
+ int max_modules, max_dies;
+
+ max_modules = get_max_topo_by_level(ms, CPU_TOPOLOGY_LEVEL_MODULE);
+ max_dies = get_max_topo_by_level(ms, CPU_TOPOLOGY_LEVEL_DIE);
/*
* die-id was optional in QEMU 4.0 and older, so keep it optional
* if there's only one die per socket.
*/
- if (cpu->module_id < 0 && ms->smp.modules == 1) {
+ if (cpu->module_id < 0 && max_modules == 1) {
cpu->module_id = 0;
}
@@ -214,7 +218,7 @@ static void x86_fixup_topo_ids(MachineState *ms, X86CPU *cpu)
* module-id was optional in QEMU 9.0 and older, so keep it optional
* if there's only one module per die.
*/
- if (cpu->die_id < 0 && ms->smp.dies == 1) {
+ if (cpu->die_id < 0 && max_dies == 1) {
cpu->die_id = 0;
}
}
@@ -393,6 +397,7 @@ void x86_cpu_pre_plug(HotplugHandler *hotplug_dev,
MachineState *ms = MACHINE(hotplug_dev);
X86MachineState *x86ms = X86_MACHINE(hotplug_dev);
X86CPUTopoInfo topo_info;
+ int max_modules, max_dies;
if (!object_dynamic_cast(OBJECT(cpu), ms->cpu_type)) {
error_setg(errp, "Invalid CPU type, expected cpu type: '%s'",
@@ -413,13 +418,15 @@ void x86_cpu_pre_plug(HotplugHandler *hotplug_dev,
init_topo_info(&topo_info, x86ms);
- if (ms->smp.modules > 1) {
- env->nr_modules = ms->smp.modules;
+ max_modules = get_max_topo_by_level(ms, CPU_TOPOLOGY_LEVEL_MODULE);
+ if (max_modules > 1) {
+ env->nr_modules = max_modules;
set_bit(CPU_TOPOLOGY_LEVEL_MODULE, env->avail_cpu_topo);
}
- if (ms->smp.dies > 1) {
- env->nr_dies = ms->smp.dies;
+ max_dies = get_max_topo_by_level(ms, CPU_TOPOLOGY_LEVEL_DIE);
+ if (max_dies > 1) {
+ env->nr_dies = max_dies;
set_bit(CPU_TOPOLOGY_LEVEL_DIE, env->avail_cpu_topo);
}
diff --git a/hw/i386/x86.c b/hw/i386/x86.c
index cdf7b81ad0e3..55904b545d84 100644
--- a/hw/i386/x86.c
+++ b/hw/i386/x86.c
@@ -44,16 +44,20 @@ void init_topo_info(X86CPUTopoInfo *topo_info,
{
MachineState *ms = MACHINE(x86ms);
- topo_info->dies_per_pkg = ms->smp.dies;
+ topo_info->dies_per_pkg =
+ get_max_topo_by_level(ms, CPU_TOPOLOGY_LEVEL_DIE);
/*
* Though smp.modules means the number of modules in one cluster,
* i386 doesn't support cluster level so that the smp.clusters
* always defaults to 1, therefore using smp.modules directly is
* fine here.
*/
- topo_info->modules_per_die = ms->smp.modules;
- topo_info->cores_per_module = ms->smp.cores;
- topo_info->threads_per_core = ms->smp.threads;
+ topo_info->modules_per_die =
+ get_max_topo_by_level(ms, CPU_TOPOLOGY_LEVEL_MODULE);
+ topo_info->cores_per_module =
+ get_max_topo_by_level(ms, CPU_TOPOLOGY_LEVEL_CORE);
+ topo_info->threads_per_core =
+ get_max_topo_by_level(ms, CPU_TOPOLOGY_LEVEL_THREAD);
}
/*
@@ -103,7 +107,7 @@ static const CPUArchIdList *x86_possible_cpu_arch_ids(MachineState *ms)
X86MachineState *x86ms = X86_MACHINE(ms);
unsigned int max_cpus = ms->smp.max_cpus;
X86CPUTopoInfo topo_info;
- int i;
+ int i, max_dies, max_modules;
if (ms->possible_cpus) {
/*
@@ -120,6 +124,8 @@ static const CPUArchIdList *x86_possible_cpu_arch_ids(MachineState *ms)
init_topo_info(&topo_info, x86ms);
+ max_dies = get_max_topo_by_level(ms, CPU_TOPOLOGY_LEVEL_DIE);
+ max_modules = get_max_topo_by_level(ms, CPU_TOPOLOGY_LEVEL_MODULE);
for (i = 0; i < ms->possible_cpus->len; i++) {
X86CPUTopoIDs topo_ids;
@@ -131,11 +137,11 @@ static const CPUArchIdList *x86_possible_cpu_arch_ids(MachineState *ms)
&topo_info, &topo_ids);
ms->possible_cpus->cpus[i].props.has_socket_id = true;
ms->possible_cpus->cpus[i].props.socket_id = topo_ids.pkg_id;
- if (ms->smp.dies > 1) {
+ if (max_dies > 1) {
ms->possible_cpus->cpus[i].props.has_die_id = true;
ms->possible_cpus->cpus[i].props.die_id = topo_ids.die_id;
}
- if (ms->smp.modules > 1) {
+ if (max_modules > 1) {
ms->possible_cpus->cpus[i].props.has_module_id = true;
ms->possible_cpus->cpus[i].props.module_id = topo_ids.module_id;
}
--
2.34.1
next prev parent reply other threads:[~2024-09-19 5:56 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-19 6:11 [RFC v2 00/12] Introduce Hybrid CPU Topology via Custom Topology Tree Zhao Liu
2024-09-19 6:11 ` [RFC v2 01/12] qdev: Allow qdev_device_add() to add specific category device Zhao Liu
2024-10-08 9:14 ` Jonathan Cameron via
2024-10-09 6:09 ` Zhao Liu
2024-09-19 6:11 ` [RFC v2 02/12] qdev: Introduce new device category to cover basic topology device Zhao Liu
2024-09-19 6:11 ` [RFC v2 03/12] system/vl: Create CPU topology devices from CLI early Zhao Liu
2024-10-08 9:50 ` Jonathan Cameron via
2024-10-09 6:31 ` Zhao Liu
2024-10-08 9:55 ` Jonathan Cameron via
2024-10-09 6:11 ` Zhao Liu
2024-09-19 6:11 ` [RFC v2 04/12] hw/core/machine: Split machine initialization around qemu_add_cli_devices_early() Zhao Liu
2024-09-19 6:11 ` [RFC v2 05/12] hw/core/machine: Introduce custom CPU topology with max limitations Zhao Liu
2024-10-08 10:16 ` Jonathan Cameron via
2024-09-19 6:11 ` [RFC v2 06/12] hw/cpu: Constrain CPU topology tree with max_limit Zhao Liu
2024-09-19 6:11 ` [RFC v2 07/12] hw/core: Re-implement topology helpers to honor max limitations Zhao Liu
2024-09-19 6:11 ` Zhao Liu [this message]
2024-09-19 6:11 ` [RFC v2 09/12] i386: Introduce x86 CPU core abstractions Zhao Liu
2024-09-19 6:11 ` [RFC v2 10/12] i386/cpu: Support Intel hybrid CPUID Zhao Liu
2024-09-19 6:11 ` [RFC v2 11/12] i386/machine: Split machine initialization after CPU creation into post_init() Zhao Liu
2024-09-19 6:11 ` [RFC v2 12/12] i386: Support custom topology for microvm, pc-i440fx and pc-q35 Zhao Liu
2024-10-08 10:30 ` [RFC v2 00/12] Introduce Hybrid CPU Topology via Custom Topology Tree Jonathan Cameron via
2024-10-09 6:01 ` Zhao Liu
2024-10-09 6:51 ` Zhao Liu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240919061128.769139-9-zhao1.liu@intel.com \
--to=zhao1.liu@intel.com \
--cc=alex.bennee@linaro.org \
--cc=anthony@xenproject.org \
--cc=armbru@redhat.com \
--cc=berrange@redhat.com \
--cc=dapeng1.mi@linux.intel.com \
--cc=eblake@redhat.com \
--cc=edgar.iglesias@gmail.com \
--cc=eduardo@habkost.net \
--cc=imammedo@redhat.com \
--cc=jasowang@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=marcel.apfelbaum@gmail.com \
--cc=mst@redhat.com \
--cc=paul@xen.org \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=philmd@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=slp@redhat.com \
--cc=sstabellini@kernel.org \
--cc=wangyanan55@huawei.com \
--cc=yongwei.ma@intel.com \
--cc=zhenyu.z.wang@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).