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>,
"Cédric Le Goater" <clg@kaod.org>,
"Nicholas Piggin" <npiggin@gmail.com>,
"Frédéric Barrat" <fbarrat@linux.ibm.com>,
"Daniel Henrique Barboza" <danielhb413@gmail.com>,
"David Gibson" <david@gibson.dropbear.id.au>,
"Harsh Prateek Bora" <harshpb@linux.ibm.com>,
"Markus Armbruster" <armbru@redhat.com>,
"Marcelo Tosatti" <mtosatti@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-ppc@nongnu.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 07/15] hw/core/cpu: Convert CPU from general device to topology device
Date: Thu, 19 Sep 2024 09:55:25 +0800 [thread overview]
Message-ID: <20240919015533.766754-8-zhao1.liu@intel.com> (raw)
In-Reply-To: <20240919015533.766754-1-zhao1.liu@intel.com>
Convert CPU to topology device then it can be added into topology tree.
Because CPU then inherits properties and settings of topology device,
make the following changes to take into account the special case for CPU:
* Omit setting category since topology device has already set.
* Make realize() of topology device as the parent realize().
* Clean up some cases that assume parent obj is DeviceState and access
parent_obj directly.
* Set CPU's topology level as thread.
* And one complex change: mask bus_type as NULL.
- This is because for the arches don't support topology tree,
there's no CPU bus bridge so that CPUs of these arches can't be
created. So, only the CPU with arch supporting topology tree
should override the bus_type field.
* Further, support cpu_create() for the CPU with bus_type.
- This is a corner case, some arch CPUs may set bus_type, and
cpu_create() would be called in system emulation case (e.g., none
machine). To handle such case, try to find the machine's CPU bus
in cpu_create().
Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
---
accel/kvm/kvm-all.c | 4 ++--
hw/core/cpu-common.c | 42 +++++++++++++++++++++++++++++++++++++-----
include/hw/core/cpu.h | 7 +++++--
target/ppc/kvm.c | 2 +-
4 files changed, 45 insertions(+), 10 deletions(-)
diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
index beb1988d12cf..48c040f6861d 100644
--- a/accel/kvm/kvm-all.c
+++ b/accel/kvm/kvm-all.c
@@ -4173,7 +4173,7 @@ static void query_stats(StatsResultList **result, StatsTarget target,
break;
case STATS_TARGET_VCPU:
add_stats_entry(result, STATS_PROVIDER_KVM,
- cpu->parent_obj.canonical_path,
+ DEVICE(cpu)->canonical_path,
stats_list);
break;
default:
@@ -4265,7 +4265,7 @@ static void query_stats_cb(StatsResultList **result, StatsTarget target,
stats_args.names = names;
stats_args.errp = errp;
CPU_FOREACH(cpu) {
- if (!apply_str_list_filter(cpu->parent_obj.canonical_path, targets)) {
+ if (!apply_str_list_filter(DEVICE(cpu)->canonical_path, targets)) {
continue;
}
query_stats_vcpu(cpu, &stats_args);
diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c
index 7982ecd39a53..08f2d536ff6d 100644
--- a/hw/core/cpu-common.c
+++ b/hw/core/cpu-common.c
@@ -57,7 +57,19 @@ CPUState *cpu_create(const char *typename)
{
Error *err = NULL;
CPUState *cpu = CPU(object_new(typename));
- if (!qdev_realize(DEVICE(cpu), NULL, &err)) {
+ BusState *bus = NULL;
+
+ if (DEVICE_GET_CLASS(cpu)->bus_type) {
+ MachineState *ms;
+
+ ms = (MachineState *)object_dynamic_cast(qdev_get_machine(),
+ TYPE_MACHINE);
+ if (ms) {
+ bus = BUS(&ms->topo->bus);
+ }
+ }
+
+ if (!qdev_realize(DEVICE(cpu), bus, &err)) {
error_report_err(err);
object_unref(OBJECT(cpu));
exit(EXIT_FAILURE);
@@ -196,6 +208,12 @@ static void cpu_common_realizefn(DeviceState *dev, Error **errp)
{
CPUState *cpu = CPU(dev);
Object *machine = qdev_get_machine();
+ CPUClass *cc = CPU_GET_CLASS(cpu);
+
+ cc->parent_realize(dev, errp);
+ if (*errp) {
+ return;
+ }
/* qdev_get_machine() can return something that's not TYPE_MACHINE
* if this is one of the user-only emulators; in that case there's
@@ -302,6 +320,7 @@ static void cpu_common_class_init(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
ResettableClass *rc = RESETTABLE_CLASS(klass);
+ CPUTopoClass *tc = CPU_TOPO_CLASS(klass);
CPUClass *k = CPU_CLASS(klass);
k->parse_features = cpu_common_parse_features;
@@ -309,9 +328,6 @@ static void cpu_common_class_init(ObjectClass *klass, void *data)
k->has_work = cpu_common_has_work;
k->gdb_read_register = cpu_common_gdb_read_register;
k->gdb_write_register = cpu_common_gdb_write_register;
- set_bit(DEVICE_CATEGORY_CPU, dc->categories);
- dc->realize = cpu_common_realizefn;
- dc->unrealize = cpu_common_unrealizefn;
rc->phases.hold = cpu_common_reset_hold;
cpu_class_init_props(dc);
/*
@@ -319,11 +335,27 @@ static void cpu_common_class_init(ObjectClass *klass, void *data)
* IRQs, adding reset handlers, halting non-first CPUs, ...
*/
dc->user_creatable = false;
+ /*
+ * CPU is the minimum granularity for hotplug in most case, and
+ * often its hotplug handler is ultimately decided by the machine.
+ * For generality, set this flag to avoid blocking possible hotplug
+ * support.
+ */
+ dc->hotpluggable = true;
+ device_class_set_parent_realize(dc, cpu_common_realizefn,
+ &k->parent_realize);
+ dc->unrealize = cpu_common_unrealizefn;
+ /*
+ * Avoid archs that do not support topology device trees from
+ * encountering error when creating CPUs.
+ */
+ dc->bus_type = NULL;
+ tc->level = CPU_TOPOLOGY_LEVEL_THREAD;
}
static const TypeInfo cpu_type_info = {
.name = TYPE_CPU,
- .parent = TYPE_DEVICE,
+ .parent = TYPE_CPU_TOPO,
.instance_size = sizeof(CPUState),
.instance_init = cpu_common_initfn,
.instance_finalize = cpu_common_finalize,
diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index 1c9c775df658..d7268bcb48cb 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -20,6 +20,7 @@
#ifndef QEMU_CPU_H
#define QEMU_CPU_H
+#include "hw/cpu/cpu-topology.h"
#include "hw/qdev-core.h"
#include "disas/dis-asm.h"
#include "exec/breakpoint.h"
@@ -144,7 +145,7 @@ struct SysemuCPUOps;
*/
struct CPUClass {
/*< private >*/
- DeviceClass parent_class;
+ CPUTopoClass parent_class;
/*< public >*/
ObjectClass *(*class_by_name)(const char *cpu_model);
@@ -189,6 +190,8 @@ struct CPUClass {
int reset_dump_flags;
int gdb_num_core_regs;
bool gdb_stop_before_watchpoint;
+
+ DeviceRealize parent_realize;
};
/*
@@ -456,7 +459,7 @@ struct qemu_work_item;
*/
struct CPUState {
/*< private >*/
- DeviceState parent_obj;
+ CPUTopoState parent_obj;
/* cache to avoid expensive CPU_GET_CLASS */
CPUClass *cc;
/*< public >*/
diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c
index 907dba60d1b5..b3cc42e545af 100644
--- a/target/ppc/kvm.c
+++ b/target/ppc/kvm.c
@@ -2351,7 +2351,7 @@ static void alter_insns(uint64_t *word, uint64_t flags, bool on)
static bool kvmppc_cpu_realize(CPUState *cs, Error **errp)
{
int ret;
- const char *vcpu_str = (cs->parent_obj.hotplugged == true) ?
+ const char *vcpu_str = (DEVICE(cs)->hotplugged == true) ?
"hotplug" : "create";
cs->cpu_index = cpu_get_free_index();
--
2.34.1
next prev parent reply other threads:[~2024-09-19 1:41 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-19 1:55 [RFC v2 00/15] qom-topo: Abstract CPU Topology Level to Topology Device Zhao Liu
2024-09-19 1:55 ` [RFC v2 01/15] qdev: Add pointer to BusChild in DeviceState Zhao Liu
2024-09-19 1:55 ` [RFC v2 02/15] qdev: Add the interface to reparent the device Zhao Liu
2024-09-19 1:55 ` [RFC v2 03/15] hw/cpu: Introduce CPU topology device and CPU bus Zhao Liu
2024-09-19 1:55 ` [RFC v2 04/15] hw/cpu: Introduce CPU slot to manage CPU topology Zhao Liu
2024-09-19 1:55 ` [RFC v2 05/15] qdev: Add method in BusClass to customize device index Zhao Liu
2024-09-19 1:55 ` [RFC v2 06/15] hw/core: Create CPU slot in MachineState to manage CPU topology tree Zhao Liu
2024-09-19 1:55 ` Zhao Liu [this message]
2024-09-19 1:55 ` [RFC v2 08/15] hw/cpu/core: Convert cpu-core from general device to topology device Zhao Liu
2024-09-19 1:55 ` [RFC v2 09/15] hw/cpu: Abstract module/die/socket levels as topology devices Zhao Liu
2024-09-19 1:55 ` [RFC v2 10/15] hw/machine: Build smp topology tree from -smp Zhao Liu
2024-09-19 1:55 ` [RFC v2 11/15] hw/core: Support topology tree in none machine for compatibility Zhao Liu
2024-09-19 1:55 ` [RFC v2 12/15] hw/i386: Allow i386 to create new CPUs in topology tree Zhao Liu
2024-09-19 1:55 ` [RFC v2 13/15] system/qdev-monitor: Introduce bus-finder interface for compatibility with bus-less plug behavior Zhao Liu
2024-09-19 1:55 ` [RFC v2 14/15] i386/cpu: Support CPU plugged in topology tree via bus-finder Zhao Liu
2024-09-19 1:55 ` [RFC v2 15/15] i386: Support topology device tree 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=20240919015533.766754-8-zhao1.liu@intel.com \
--to=zhao1.liu@intel.com \
--cc=alex.bennee@linaro.org \
--cc=armbru@redhat.com \
--cc=berrange@redhat.com \
--cc=clg@kaod.org \
--cc=danielhb413@gmail.com \
--cc=dapeng1.mi@linux.intel.com \
--cc=david@gibson.dropbear.id.au \
--cc=eduardo@habkost.net \
--cc=fbarrat@linux.ibm.com \
--cc=harshpb@linux.ibm.com \
--cc=imammedo@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=marcel.apfelbaum@gmail.com \
--cc=mst@redhat.com \
--cc=mtosatti@redhat.com \
--cc=npiggin@gmail.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=philmd@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
--cc=richard.henderson@linaro.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).