From: Damien Hedde <damien.hedde@greensocs.com>
To: qemu-devel@nongnu.org
Cc: "Damien Hedde" <damien.hedde@greensocs.com>,
"Peter Maydell" <peter.maydell@linaro.org>,
"Bin Meng" <bin.meng@windriver.com>,
qemu-riscv@nongnu.org,
"Alistair Francis" <alistair@alistair23.me>,
mark.burton@greensocs.com,
"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
"Yanan Wang" <wangyanan55@huawei.com>,
"Eduardo Habkost" <eduardo@habkost.net>,
qemu-arm@nongnu.org, "Palmer Dabbelt" <palmer@dabbelt.com>,
"Vijai Kumar K" <vijai@behindbytes.com>,
"Edgar E. Iglesias" <edgar.iglesias@gmail.com>,
"Alex Bennée" <alex.bennee@linaro.org>
Subject: [RFC PATCH 04/18] hw/cpu/cluster: make _cpu-cluster_ a subclass of _cpus_
Date: Wed, 30 Mar 2022 14:56:25 +0200 [thread overview]
Message-ID: <20220330125639.201937-5-damien.hedde@greensocs.com> (raw)
In-Reply-To: <20220330125639.201937-1-damien.hedde@greensocs.com>
Drop the cluster-id property as base class defines one.
cluster_id field is temporarily kept until gdbstub
is updated.
Signed-off-by: Damien Hedde <damien.hedde@greensocs.com>
---
include/hw/cpu/cluster.h | 17 ++++++++++--
hw/cpu/cluster.c | 58 +++++++++++++++++++++-------------------
2 files changed, 46 insertions(+), 29 deletions(-)
diff --git a/include/hw/cpu/cluster.h b/include/hw/cpu/cluster.h
index 09a2b86832..2125765f21 100644
--- a/include/hw/cpu/cluster.h
+++ b/include/hw/cpu/cluster.h
@@ -22,6 +22,7 @@
#include "hw/qdev-core.h"
#include "qom/object.h"
+#include "hw/cpu/cpus.h"
/*
* CPU Cluster type
@@ -55,7 +56,7 @@
*/
#define TYPE_CPU_CLUSTER "cpu-cluster"
-OBJECT_DECLARE_SIMPLE_TYPE(CPUClusterState, CPU_CLUSTER)
+OBJECT_DECLARE_TYPE(CPUClusterState, CPUClusterClass, CPU_CLUSTER)
/**
* CPUClusterState:
@@ -66,10 +67,22 @@ OBJECT_DECLARE_SIMPLE_TYPE(CPUClusterState, CPU_CLUSTER)
*/
struct CPUClusterState {
/*< private >*/
- DeviceState parent_obj;
+ CpusState parent_obj;
/*< public >*/
uint32_t cluster_id;
};
+/**
+ * CPUClusterClass:
+ * @parent_realize: to store base class realize method
+ */
+struct CPUClusterClass {
+ /*< private >*/
+ CpusClass parent_class;
+
+ /*< public >*/
+ DeviceRealize parent_realize;
+};
+
#endif
diff --git a/hw/cpu/cluster.c b/hw/cpu/cluster.c
index e444b7c29d..3daf897bd9 100644
--- a/hw/cpu/cluster.c
+++ b/hw/cpu/cluster.c
@@ -20,50 +20,39 @@
#include "qemu/osdep.h"
#include "hw/cpu/cluster.h"
+#include "hw/cpu/cpus.h"
#include "hw/qdev-properties.h"
#include "hw/core/cpu.h"
#include "qapi/error.h"
#include "qemu/module.h"
#include "qemu/cutils.h"
-static Property cpu_cluster_properties[] = {
- DEFINE_PROP_UINT32("cluster-id", CPUClusterState, cluster_id, 0),
- DEFINE_PROP_END_OF_LIST()
-};
-
-typedef struct CallbackData {
- CPUClusterState *cluster;
- int cpu_count;
-} CallbackData;
-
static int add_cpu_to_cluster(Object *obj, void *opaque)
{
- CallbackData *cbdata = opaque;
+ CpusState *base = CPUS(opaque);
CPUState *cpu = (CPUState *)object_dynamic_cast(obj, TYPE_CPU);
if (cpu) {
- cpu->cluster_index = cbdata->cluster->cluster_id;
- cbdata->cpu_count++;
+ cpu->cluster_index = base->cluster_index;
+ base->topology.cpus++;
}
return 0;
}
static void cpu_cluster_realize(DeviceState *dev, Error **errp)
{
- /* Iterate through all our CPU children and set their cluster_index */
+ CPUClusterClass *ccc = CPU_CLUSTER_GET_CLASS(dev);
CPUClusterState *cluster = CPU_CLUSTER(dev);
+ CpusState *base = CPUS(dev);
Object *cluster_obj = OBJECT(dev);
- CallbackData cbdata = {
- .cluster = cluster,
- .cpu_count = 0,
- };
- if (cluster->cluster_id >= MAX_CLUSTERS) {
- error_setg(errp, "cluster-id must be less than %d", MAX_CLUSTERS);
- return;
- }
+ /* This is a special legacy case */
+ assert(base->topology.cpus == 0);
+ assert(base->cpu_type == NULL);
+ assert(base->is_cluster);
- object_child_foreach_recursive(cluster_obj, add_cpu_to_cluster, &cbdata);
+ /* Iterate through all our CPU children and set their cluster_index */
+ object_child_foreach_recursive(cluster_obj, add_cpu_to_cluster, base);
/*
* A cluster with no CPUs is a bug in the board/SoC code that created it;
@@ -71,24 +60,39 @@ static void cpu_cluster_realize(DeviceState *dev, Error **errp)
* created the CPUs and parented them into the cluster object before
* realizing the cluster object.
*/
- assert(cbdata.cpu_count > 0);
+ assert(base->topology.cpus > 0);
+
+ /* realize base class (will set cluster field to true) */
+ ccc->parent_realize(dev, errp);
+
+ /*
+ * Temporarily copy the cluster id from the base class as
+ * gdbstub still uses our field.
+ */
+ cluster->cluster_id = base->cluster_index;
}
static void cpu_cluster_class_init(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
+ CPUClusterClass *ccc = CPU_CLUSTER_CLASS(klass);
+ CpusClass *cc = CPUS_CLASS(klass);
- device_class_set_props(dc, cpu_cluster_properties);
- dc->realize = cpu_cluster_realize;
+ device_class_set_parent_realize(dc, cpu_cluster_realize,
+ &ccc->parent_realize);
/* This is not directly for users, CPU children must be attached by code */
dc->user_creatable = false;
+
+ /* Cpus are created by external code */
+ cc->skip_cpus_creation = true;
}
static const TypeInfo cpu_cluster_type_info = {
.name = TYPE_CPU_CLUSTER,
- .parent = TYPE_DEVICE,
+ .parent = TYPE_CPUS,
.instance_size = sizeof(CPUClusterState),
+ .class_size = sizeof(CPUClusterClass),
.class_init = cpu_cluster_class_init,
};
--
2.35.1
next prev parent reply other threads:[~2022-03-30 13:06 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-30 12:56 [RFC PATCH 00/18] user-creatable cpu clusters Damien Hedde
2022-03-30 12:56 ` [RFC PATCH 01/18] define MAX_CLUSTERS in cpu.h instead of cluster.h Damien Hedde
2022-03-30 12:56 ` [RFC PATCH 02/18] hw/cpu/cpus: introduce _cpus_ device Damien Hedde
2022-04-16 17:52 ` Philippe Mathieu-Daudé
2022-04-19 9:11 ` Damien Hedde
2022-03-30 12:56 ` [RFC PATCH 03/18] hw/cpu/cpus: prepare to handle cpu clusters Damien Hedde
2022-03-30 12:56 ` Damien Hedde [this message]
2022-03-30 12:56 ` [RFC PATCH 05/18] gdbstub: deal with _cpus_ object instead of _cpu-cluster_ Damien Hedde
2022-03-30 12:56 ` [RFC PATCH 06/18] hw/cpu/cluster: remove cluster_id now that gdbstub is updated Damien Hedde
2022-03-30 12:56 ` [RFC PATCH 07/18] hw/cpu/cpus: add a common start-powered-off property Damien Hedde
2022-03-30 12:56 ` [RFC PATCH 08/18] hw/arm/arm_cpus: add arm_cpus device Damien Hedde
2022-04-16 18:01 ` Philippe Mathieu-Daudé
2022-03-30 12:56 ` [RFC PATCH 09/18] hw/arm/xlnx-zynqmp: convert cpu clusters to arm_cpus Damien Hedde
2022-04-16 18:06 ` Philippe Mathieu-Daudé
2022-03-30 12:56 ` [RFC PATCH 10/18] hw/riscv/riscv_hart: prepare transition to cpus Damien Hedde
2022-03-30 12:56 ` [RFC PATCH 11/18] hw/riscv: prepare riscv_hart " Damien Hedde
2022-03-30 12:56 ` [RFC PATCH 12/18] hw/riscv/virt: " Damien Hedde
2022-03-30 12:56 ` [RFC PATCH 13/18] hw/riscv/spike: " Damien Hedde
2022-03-30 12:56 ` [RFC PATCH 14/18] hw/riscv/riscv_hart: use cpus as base class Damien Hedde
2022-03-30 12:56 ` [RFC PATCH 15/18] hw/riscv/sifive_uµchip_pfsoc: apply riscv_hart_array update Damien Hedde
2022-03-30 12:56 ` [RFC PATCH 16/18] hw/riscv: update remaining machines due to " Damien Hedde
2022-03-30 12:56 ` [RFC PATCH 17/18] hw/riscv/riscv_hart: remove temporary features Damien Hedde
2022-03-30 12:56 ` [RFC PATCH 18/18] add myself as reviewer of the newly added _cpus_ Damien Hedde
2022-04-15 7:42 ` [RFC PATCH 00/18] user-creatable cpu clusters Damien Hedde
2022-04-21 15:51 ` Peter Maydell
2022-04-21 18:11 ` Damien Hedde
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=20220330125639.201937-5-damien.hedde@greensocs.com \
--to=damien.hedde@greensocs.com \
--cc=alex.bennee@linaro.org \
--cc=alistair@alistair23.me \
--cc=bin.meng@windriver.com \
--cc=edgar.iglesias@gmail.com \
--cc=eduardo@habkost.net \
--cc=f4bug@amsat.org \
--cc=mark.burton@greensocs.com \
--cc=palmer@dabbelt.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-riscv@nongnu.org \
--cc=vijai@behindbytes.com \
--cc=wangyanan55@huawei.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).