From: Zhao Liu <zhao1.liu@linux.intel.com>
To: "Paolo Bonzini" <pbonzini@redhat.com>,
"Alex Bennée" <alex.bennee@linaro.org>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>,
"Eduardo Habkost" <eduardo@habkost.net>,
"Marcel Apfelbaum" <marcel.apfelbaum@gmail.com>,
"Yanan Wang" <wangyanan55@huawei.com>,
"Richard Henderson" <richard.henderson@linaro.org>,
"Michael S . Tsirkin" <mst@redhat.com>,
"Jason Wang" <jasowang@redhat.com>,
"Nicholas Piggin" <npiggin@gmail.com>,
"Daniel Henrique Barboza" <danielhb413@gmail.com>,
"Igor Mammedov" <imammedo@redhat.com>,
"Cédric Le Goater" <clg@kaod.org>,
"Frédéric Barrat" <fbarrat@linux.ibm.com>,
"David Gibson" <david@gibson.dropbear.id.au>,
"Harsh Prateek Bora" <harshpb@linux.ibm.com>,
"Stefano Stabellini" <sstabellini@kernel.org>,
"Anthony Perard" <anthony.perard@citrix.com>,
"Paul Durrant" <paul@xen.org>,
"Gerd Hoffmann" <kraxel@redhat.com>,
"Peter Maydell" <peter.maydell@linaro.org>,
"Alistair Francis" <alistair@alistair23.me>,
"Edgar E . Iglesias" <edgar.iglesias@gmail.com>,
"Daniel P . Berrangé" <berrange@redhat.com>,
"Bin Meng" <bin.meng@windriver.com>,
"Palmer Dabbelt" <palmer@dabbelt.com>,
"Weiwei Li" <liwei1518@gmail.com>,
"Liu Zhiwei" <zhiwei_liu@linux.alibaba.com>,
qemu-devel@nongnu.org, kvm@vger.kernel.org, qemu-ppc@nongnu.org,
xen-devel@lists.xenproject.org, qemu-arm@nongnu.org,
qemu-riscv@nongnu.org, qemu-s390x@nongnu.org
Cc: Nina Schoetterl-Glausch <nsg@linux.ibm.com>,
Thomas Huth <thuth@redhat.com>, Zhiyuan Lv <zhiyuan.lv@intel.com>,
Zhenyu Wang <zhenyu.z.wang@intel.com>,
Yongwei Ma <yongwei.ma@intel.com>, Zhao Liu <zhao1.liu@intel.com>
Subject: [RFC 17/41] hw/cpu/core: Convert cpu-core from general device to topology device
Date: Thu, 30 Nov 2023 22:41:39 +0800 [thread overview]
Message-ID: <20231130144203.2307629-18-zhao1.liu@linux.intel.com> (raw)
In-Reply-To: <20231130144203.2307629-1-zhao1.liu@linux.intel.com>
From: Zhao Liu <zhao1.liu@intel.com>
Convert cpu-core to topology device then user could create core level
topology from cli and later the cpu-cores could be added into topology
tree.
In addition, mark the common cpu-core as DEVICE_CATEGORY_CPU_DEF
category to indicate it belongs to the basic CPU definition and should
be created from cli before board initialization.
But since PPC supports CPU hotplug at core granularity, ppc-core should
be created after board initialization. Thus, mask the category flag
DEVICE_CATEGORY_CPU_DEF for ppc-core.
Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
---
hw/cpu/core.c | 19 ++++++++++++++++---
hw/ppc/pnv_core.c | 6 +++++-
hw/ppc/ppc_core.c | 5 +++++
hw/ppc/spapr_cpu_core.c | 7 ++++++-
include/hw/cpu/core.h | 13 +++++++++++--
include/hw/ppc/pnv_core.h | 1 +
include/hw/ppc/spapr_cpu_core.h | 1 +
7 files changed, 45 insertions(+), 7 deletions(-)
diff --git a/hw/cpu/core.c b/hw/cpu/core.c
index 15546b5b2339..261b15fa8171 100644
--- a/hw/cpu/core.c
+++ b/hw/cpu/core.c
@@ -27,6 +27,7 @@ static void core_prop_set_nr_threads(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp)
{
CPUCore *core = CPU_CORE(obj);
+ CPUTopoState *topo = CPU_TOPO(obj);
int64_t value;
if (!visit_type_int(v, name, &value, errp)) {
@@ -34,6 +35,7 @@ static void core_prop_set_nr_threads(Object *obj, Visitor *v, const char *name,
}
core->nr_threads = value;
+ topo->max_children = core->nr_threads;
}
static void core_prop_set_plugged_threads(Object *obj, Visitor *v,
@@ -53,6 +55,7 @@ static void core_prop_set_plugged_threads(Object *obj, Visitor *v,
static void cpu_core_instance_init(Object *obj)
{
CPUCore *core = CPU_CORE(obj);
+ CPUTopoState *topo = CPU_TOPO(obj);
/*
* Only '-device something-cpu-core,help' can get us there before
@@ -64,11 +67,14 @@ static void cpu_core_instance_init(Object *obj)
}
core->plugged_threads = -1;
+ /* Core's child can only be the thread. */
+ topo->child_level = CPU_TOPO_THREAD;
}
static void cpu_core_realize(DeviceState *dev, Error **errp)
{
CPUCore *core = CPU_CORE(dev);
+ CPUCoreClass *cc = CPU_CORE_GET_CLASS(core);
if (core->plugged_threads > core->nr_threads) {
error_setg(errp, "Plugged threads (plugged-threads: %d) must "
@@ -78,25 +84,32 @@ static void cpu_core_realize(DeviceState *dev, Error **errp)
} else if (core->plugged_threads == -1) {
core->plugged_threads = core->nr_threads;
}
+
+ cc->parent_realize(dev, errp);
}
static void cpu_core_class_init(ObjectClass *oc, void *data)
{
DeviceClass *dc = DEVICE_CLASS(oc);
+ CPUTopoClass *tc = CPU_TOPO_CLASS(oc);
+ CPUCoreClass *cc = CPU_CORE_CLASS(oc);
- set_bit(DEVICE_CATEGORY_CPU, dc->categories);
+ set_bit(DEVICE_CATEGORY_CPU_DEF, dc->categories);
object_class_property_add(oc, "nr-threads", "int", core_prop_get_nr_threads,
core_prop_set_nr_threads, NULL, NULL);
object_class_property_add(oc, "plugged-threads", "int", NULL,
core_prop_set_plugged_threads, NULL, NULL);
- dc->realize = cpu_core_realize;
+ device_class_set_parent_realize(dc, cpu_core_realize, &cc->parent_realize);
+
+ tc->level = CPU_TOPO_CORE;
}
static const TypeInfo cpu_core_type_info = {
.name = TYPE_CPU_CORE,
- .parent = TYPE_DEVICE,
+ .parent = TYPE_CPU_TOPO,
.abstract = true,
.class_init = cpu_core_class_init,
+ .class_size = sizeof(CPUCoreClass),
.instance_size = sizeof(CPUCore),
.instance_init = cpu_core_instance_init,
};
diff --git a/hw/ppc/pnv_core.c b/hw/ppc/pnv_core.c
index 8b75739697d1..315b823e7d38 100644
--- a/hw/ppc/pnv_core.c
+++ b/hw/ppc/pnv_core.c
@@ -334,6 +334,7 @@ static void pnv_core_unrealize(DeviceState *dev)
{
PnvCore *pc = PNV_CORE(dev);
CPUCore *cc = CPU_CORE(dev);
+ PnvCoreClass *pcc = PNV_CORE_GET_CLASS(pc);
int i;
qemu_unregister_reset(pnv_core_reset, pc);
@@ -342,6 +343,8 @@ static void pnv_core_unrealize(DeviceState *dev)
pnv_core_cpu_unrealize(pc, pc->threads[i]);
}
g_free(pc->threads);
+
+ pcc->parent_unrealize(dev);
}
static Property pnv_core_properties[] = {
@@ -380,11 +383,12 @@ static void pnv_core_class_init(ObjectClass *oc, void *data)
DeviceClass *dc = DEVICE_CLASS(oc);
PnvCoreClass *pcc = PNV_CORE_CLASS(oc);
- dc->unrealize = pnv_core_unrealize;
device_class_set_props(dc, pnv_core_properties);
dc->user_creatable = false;
device_class_set_parent_realize(dc, pnv_core_realize,
&pcc->parent_realize);
+ device_class_set_parent_unrealize(dc, pnv_core_unrealize,
+ &pcc->parent_unrealize);
}
#define DEFINE_PNV_CORE_TYPE(family, cpu_model) \
diff --git a/hw/ppc/ppc_core.c b/hw/ppc/ppc_core.c
index 3857f3150052..0a700d6a5b42 100644
--- a/hw/ppc/ppc_core.c
+++ b/hw/ppc/ppc_core.c
@@ -72,6 +72,11 @@ static void powerpc_core_class_init(ObjectClass *oc, void *data)
DeviceClass *dc = DEVICE_CLASS(oc);
PowerPCCoreClass *ppc_class = POWERPC_CORE_CLASS(oc);
+ /*
+ * PPC cores support hotplug and must be created after
+ * qemu_init_board().
+ */
+ clear_bit(DEVICE_CATEGORY_CPU_DEF, dc->categories);
object_class_property_add(oc, "core-id", "int",
powerpc_core_prop_get_core_id,
powerpc_core_prop_set_core_id,
diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c
index 5533a386f350..c965c213ab14 100644
--- a/hw/ppc/spapr_cpu_core.c
+++ b/hw/ppc/spapr_cpu_core.c
@@ -235,6 +235,7 @@ static void spapr_delete_vcpu(PowerPCCPU *cpu)
static void spapr_cpu_core_unrealize(DeviceState *dev)
{
SpaprCpuCore *sc = SPAPR_CPU_CORE(OBJECT(dev));
+ SpaprCpuCoreClass *scc = SPAPR_CPU_CORE_GET_CLASS(sc);
CPUCore *cc = CPU_CORE(dev);
int i;
@@ -254,6 +255,8 @@ static void spapr_cpu_core_unrealize(DeviceState *dev)
}
g_free(sc->threads);
qemu_unregister_reset(spapr_cpu_core_reset_handler, sc);
+
+ scc->parent_unrealize(dev);
}
static bool spapr_realize_vcpu(PowerPCCPU *cpu, SpaprMachineState *spapr,
@@ -366,12 +369,14 @@ static void spapr_cpu_core_class_init(ObjectClass *oc, void *data)
DeviceClass *dc = DEVICE_CLASS(oc);
SpaprCpuCoreClass *scc = SPAPR_CPU_CORE_CLASS(oc);
- dc->unrealize = spapr_cpu_core_unrealize;
dc->reset = spapr_cpu_core_reset;
device_class_set_props(dc, spapr_cpu_core_properties);
+ dc->hotpluggable = true;
scc->cpu_type = data;
device_class_set_parent_realize(dc, spapr_cpu_core_realize,
&scc->parent_realize);
+ device_class_set_parent_unrealize(dc, spapr_cpu_core_unrealize,
+ &scc->parent_unrealize);
}
#define DEFINE_SPAPR_CPU_CORE_TYPE(cpu_model) \
diff --git a/include/hw/cpu/core.h b/include/hw/cpu/core.h
index 87d50151ab01..591240861efb 100644
--- a/include/hw/cpu/core.h
+++ b/include/hw/cpu/core.h
@@ -10,15 +10,24 @@
#define HW_CPU_CORE_H
#include "hw/qdev-core.h"
+#include "hw/core/cpu-topo.h"
#include "qom/object.h"
#define TYPE_CPU_CORE "cpu-core"
-OBJECT_DECLARE_SIMPLE_TYPE(CPUCore, CPU_CORE)
+OBJECT_DECLARE_TYPE(CPUCore, CPUCoreClass, CPU_CORE)
+
+struct CPUCoreClass {
+ /*< private >*/
+ CPUTopoClass parent_class;
+
+ /*< public >*/
+ DeviceRealize parent_realize;
+};
struct CPUCore {
/*< private >*/
- DeviceState parent_obj;
+ CPUTopoState parent_obj;
/*< public >*/
int core_id;
diff --git a/include/hw/ppc/pnv_core.h b/include/hw/ppc/pnv_core.h
index 3b9edf69f9fb..ca04461c8531 100644
--- a/include/hw/ppc/pnv_core.h
+++ b/include/hw/ppc/pnv_core.h
@@ -51,6 +51,7 @@ struct PnvCoreClass {
uint64_t xscom_size;
DeviceRealize parent_realize;
+ DeviceUnrealize parent_unrealize;
};
#define PNV_CORE_TYPE_SUFFIX "-" TYPE_PNV_CORE
diff --git a/include/hw/ppc/spapr_cpu_core.h b/include/hw/ppc/spapr_cpu_core.h
index dabdbd4bcbc9..46cf68fc8859 100644
--- a/include/hw/ppc/spapr_cpu_core.h
+++ b/include/hw/ppc/spapr_cpu_core.h
@@ -39,6 +39,7 @@ struct SpaprCpuCoreClass {
const char *cpu_type;
DeviceRealize parent_realize;
+ DeviceUnrealize parent_unrealize;
};
const char *spapr_get_cpu_core_type(const char *cpu_type);
--
2.34.1
next prev parent reply other threads:[~2023-11-30 14:40 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-30 14:41 [RFC 00/41] qom-topo: Abstract Everything about CPU Topology Zhao Liu
2023-11-30 14:41 ` [RFC 01/41] qdev: Introduce new device category to cover basic topology device Zhao Liu
2023-11-30 14:41 ` [RFC 02/41] qdev: Allow qdev_device_add() to add specific category device Zhao Liu
2023-11-30 14:41 ` [RFC 03/41] system: Create base category devices from cli before board initialization Zhao Liu
2023-11-30 14:41 ` [RFC 04/41] qom/object: Introduce helper to resolve path from non-direct parent Zhao Liu
2023-11-30 14:41 ` [RFC 05/41] qdev: Set device parent and id after setting properties Zhao Liu
2023-11-30 14:41 ` [RFC 06/41] qdev: Introduce user-child interface to collect devices from -device Zhao Liu
2023-11-30 14:41 ` [RFC 07/41] qdev: Introduce parent option in -device Zhao Liu
2023-11-30 14:41 ` [RFC 08/41] hw/core/topo: Introduce CPU topology device abstraction Zhao Liu
2023-11-30 14:41 ` [RFC 09/41] hw/core/topo: Support topology index for topology device Zhao Liu
2023-11-30 14:41 ` [RFC 10/41] hw/core/topo: Add virtual method to update topology info for parent Zhao Liu
2023-11-30 14:41 ` [RFC 11/41] hw/core/topo: Add virtual method to check topology child Zhao Liu
2023-11-30 14:41 ` [RFC 12/41] hw/core/topo: Add helpers to traverse the CPU topology tree Zhao Liu
2023-11-30 14:41 ` [RFC 13/41] hw/core/cpu: Convert CPU from general device to topology device Zhao Liu
2023-11-30 14:41 ` [RFC 14/41] PPC/ppc-core: Offload core-id to PPC specific core abstarction Zhao Liu
2023-11-30 14:41 ` [RFC 15/41] hw/cpu/core: Allow to configure plugged threads for cpu-core Zhao Liu
2023-11-30 14:41 ` [RFC 16/41] PPC/ppc-core: Limit plugged-threads and nr-threads to be equal Zhao Liu
2023-11-30 14:41 ` Zhao Liu [this message]
2023-11-30 14:41 ` [RFC 18/41] hw/cpu/cluster: Rename CPUClusterState to CPUCluster Zhao Liu
2023-11-30 14:41 ` [RFC 19/41] hw/cpu/cluster: Wrap TCG related ops and props into CONFIG_TCG Zhao Liu
2023-11-30 14:41 ` [RFC 20/41] hw/cpu/cluster: Descript cluster is not only used for TCG in comment Zhao Liu
2023-11-30 14:41 ` [RFC 21/41] hw/cpu/cluster: Allow cpu-cluster to be created by -device Zhao Liu
2023-11-30 14:41 ` [RFC 22/41] hw/cpu/cluster: Convert cpu-cluster from general device to topology device Zhao Liu
2023-11-30 14:41 ` [RFC 23/41] hw/cpu/die: Abstract cpu-die level as " Zhao Liu
2023-11-30 14:41 ` [RFC 24/41] hw/cpu/socket: Abstract cpu-socket " Zhao Liu
2023-11-30 14:41 ` [RFC 25/41] hw/cpu/book: Abstract cpu-book " Zhao Liu
2023-11-30 14:41 ` [RFC 26/41] hw/cpu/drawer: Abstract cpu-drawer " Zhao Liu
2023-11-30 14:41 ` [RFC 27/41] hw/core/slot: Introduce CPU slot as the root of CPU topology Zhao Liu
2023-11-30 14:41 ` [RFC 28/41] hw/core/slot: Maintain the core queue in CPU slot Zhao Liu
2023-11-30 14:41 ` [RFC 29/41] hw/core/slot: Statistics topology information " Zhao Liu
2023-11-30 14:41 ` [RFC 30/41] hw/core/slot: Check topology child to be added under " Zhao Liu
2023-11-30 14:41 ` [RFC 31/41] hw/machine: Plug cpu-slot into machine to maintain topology tree Zhao Liu
2023-11-30 14:41 ` [RFC 32/41] hw/machine: Build smp topology tree from -smp Zhao Liu
2023-11-30 14:41 ` [RFC 33/41] hw/machine: Validate smp topology tree without -smp Zhao Liu
2023-11-30 14:41 ` [RFC 34/41] hw/core/topo: Implement user-child to collect topology device from cli Zhao Liu
2023-11-30 14:41 ` [RFC 35/41] hw/i386: Make x86_cpu_new() private in x86.c Zhao Liu
2023-11-30 14:41 ` [RFC 36/41] hw/i386: Allow x86_cpu_new() to specify parent for new CPU Zhao Liu
2023-11-30 14:41 ` [RFC 37/41] hw/i386: Allow i386 to create new CPUs from QOM topology Zhao Liu
2023-11-30 14:42 ` [RFC 38/41] hw/i386: Wrap apic id and topology sub ids assigning as helpers Zhao Liu
2023-11-30 14:42 ` [RFC 39/41] hw/i386: Add the interface to search parent for QOM topology Zhao Liu
2023-11-30 14:42 ` [RFC 40/41] hw/i386: Support " Zhao Liu
2023-11-30 14:42 ` [RFC 41/41] hw/i386: Cleanup non-QOM topology support Zhao Liu
2023-12-11 13:36 ` [RFC 00/41] qom-topo: Abstract Everything about CPU Topology 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=20231130144203.2307629-18-zhao1.liu@linux.intel.com \
--to=zhao1.liu@linux.intel.com \
--cc=alex.bennee@linaro.org \
--cc=alistair@alistair23.me \
--cc=anthony.perard@citrix.com \
--cc=berrange@redhat.com \
--cc=bin.meng@windriver.com \
--cc=clg@kaod.org \
--cc=danielhb413@gmail.com \
--cc=david@gibson.dropbear.id.au \
--cc=edgar.iglesias@gmail.com \
--cc=eduardo@habkost.net \
--cc=fbarrat@linux.ibm.com \
--cc=harshpb@linux.ibm.com \
--cc=imammedo@redhat.com \
--cc=jasowang@redhat.com \
--cc=kraxel@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=liwei1518@gmail.com \
--cc=marcel.apfelbaum@gmail.com \
--cc=mst@redhat.com \
--cc=npiggin@gmail.com \
--cc=nsg@linux.ibm.com \
--cc=palmer@dabbelt.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=qemu-ppc@nongnu.org \
--cc=qemu-riscv@nongnu.org \
--cc=qemu-s390x@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=sstabellini@kernel.org \
--cc=thuth@redhat.com \
--cc=wangyanan55@huawei.com \
--cc=xen-devel@lists.xenproject.org \
--cc=yongwei.ma@intel.com \
--cc=zhao1.liu@intel.com \
--cc=zhenyu.z.wang@intel.com \
--cc=zhiwei_liu@linux.alibaba.com \
--cc=zhiyuan.lv@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).