From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: qemu-devel@nongnu.org
Cc: "Richard Henderson" <richard.henderson@linaro.org>,
"Dapeng Mi" <dapeng1.mi@intel.com>,
"Sean Christopherson" <seanjc@google.com>,
"Bin Meng" <bin.meng@windriver.com>,
"Zhuocheng Ding" <zhuocheng.ding@intel.com>,
"Alex Bennée" <alex.bennee@linaro.org>,
"Zhenyu Wang" <zhenyu.z.wang@intel.com>,
qemu-riscv@nongnu.org,
"Alistair Francis" <alistair.francis@wdc.com>,
"Zhao Liu" <zhao1.liu@intel.com>,
"Edgar E. Iglesias" <edgar.iglesias@gmail.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Marcel Apfelbaum" <marcel.apfelbaum@gmail.com>,
"Robert Hoo" <robert.hu@linux.intel.com>,
"Yanan Wang" <wangyanan55@huawei.com>,
qemu-arm@nongnu.org, "Peter Maydell" <peter.maydell@linaro.org>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>,
"Palmer Dabbelt" <palmer@dabbelt.com>,
"Like Xu" <like.xu.linux@gmail.com>,
"Alistair Francis" <alistair@alistair23.me>,
"Zhao Liu" <zhao1.liu@linux.intel.com>,
"Eduardo Habkost" <eduardo@habkost.net>
Subject: [PATCH 3/5] hw/cpu/cluster: Restrict CPU cluster to a particular CPU type
Date: Thu, 16 Feb 2023 15:23:36 +0100 [thread overview]
Message-ID: <20230216142338.82982-4-philmd@linaro.org> (raw)
In-Reply-To: <20230216142338.82982-1-philmd@linaro.org>
CPU cluster id is used by TCG accelerator to "group" CPUs
sharing the same ISA features, so TranslationBlock can be
shared between the cluster (see commit f7b78602fd "accel/tcg:
Add cluster number to TCG TB hash"). This mean we shouldn't
mix different kind of CPUs into the same cluster.
Enforce that by adding a 'cpu-type' property. The cluster's
realize() method will check all children are of that 'cpu-type'
class.
If the property is not set, the first CPU added to a cluster
sets its CPU type, and only that type fo CPU can be added.
Example of error:
qemu-system-aarch64: cluster /machine/soc/rpu-cluster can only accept cortex-r5f-arm-cpu CPUs (got cortex-a9-arm-cpu)
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
hw/cpu/cluster.c | 19 ++++++++++++++++---
include/hw/cpu/cluster.h | 1 +
2 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/hw/cpu/cluster.c b/hw/cpu/cluster.c
index b0cdf7d931..0d06944824 100644
--- a/hw/cpu/cluster.c
+++ b/hw/cpu/cluster.c
@@ -28,6 +28,7 @@
static Property cpu_cluster_properties[] = {
DEFINE_PROP_UINT32("cluster-id", CPUClusterState, cluster_id, 0),
+ DEFINE_PROP_STRING("cpu-type", CPUClusterState, cpu_type),
DEFINE_PROP_END_OF_LIST()
};
@@ -41,11 +42,17 @@ static bool add_cpu_to_cluster(Object *obj, void *opaque, Error **errp)
CallbackData *cbdata = opaque;
CPUState *cpu;
- cpu = (CPUState *)object_dynamic_cast(obj, TYPE_CPU);
+ if (cbdata->cluster->cpu_type == NULL) {
+ /* If no 'cpu-type' property set, enforce it with the first CPU added */
+ assert(object_dynamic_cast(obj, TYPE_CPU) != NULL);
+ cbdata->cluster->cpu_type = g_strdup(object_get_typename(obj));
+ }
+
+ cpu = (CPUState *)object_dynamic_cast(obj, cbdata->cluster->cpu_type);
if (!cpu) {
- error_setg(errp, "cluster %s can only accept CPU types (got %s)",
+ error_setg(errp, "cluster %s can only accept %s CPUs (got %s)",
object_get_canonical_path(OBJECT(cbdata->cluster)),
- object_get_typename(obj));
+ cbdata->cluster->cpu_type, object_get_typename(obj));
return false;
}
@@ -69,6 +76,12 @@ static void cpu_cluster_realize(DeviceState *dev, Error **errp)
error_setg(errp, "cluster-id must be less than %d", MAX_CLUSTERS);
return;
}
+ if (cluster->cpu_type) {
+ if (object_class_is_abstract(object_class_by_name(cluster->cpu_type))) {
+ error_setg(errp, "cpu-type must be a concrete class");
+ return;
+ }
+ }
if (!object_child_foreach(cluster_obj, add_cpu_to_cluster, &cbdata, errp)) {
return;
diff --git a/include/hw/cpu/cluster.h b/include/hw/cpu/cluster.h
index 53fbf36af5..c9792d6f05 100644
--- a/include/hw/cpu/cluster.h
+++ b/include/hw/cpu/cluster.h
@@ -76,6 +76,7 @@ struct CPUClusterState {
/*< public >*/
uint32_t cluster_id;
+ char *cpu_type;
};
#endif
--
2.38.1
next prev parent reply other threads:[~2023-02-16 14:25 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-16 14:23 [PATCH 0/5] hw/cpu/cluster: Restrict CPU cluster to a particular CPU type Philippe Mathieu-Daudé
2023-02-16 14:23 ` [PATCH 1/5] hw/cpu: Extend CPUState::cluster_index documentation Philippe Mathieu-Daudé
2023-02-21 17:47 ` Peter Maydell
2023-02-16 14:23 ` [PATCH 2/5] hw/cpu/cluster: Only add CPU objects to CPU cluster Philippe Mathieu-Daudé
2023-02-21 17:56 ` Peter Maydell
2023-02-16 14:23 ` Philippe Mathieu-Daudé [this message]
2023-02-21 17:59 ` [PATCH 3/5] hw/cpu/cluster: Restrict CPU cluster to a particular CPU type Peter Maydell
2023-02-16 14:23 ` [PATCH 4/5] hw/arm: Restrict CPU clusters to the expected type Philippe Mathieu-Daudé
2023-02-16 14:23 ` [PATCH 5/5] hw/riscv: " Philippe Mathieu-Daudé
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=20230216142338.82982-4-philmd@linaro.org \
--to=philmd@linaro.org \
--cc=alex.bennee@linaro.org \
--cc=alistair.francis@wdc.com \
--cc=alistair@alistair23.me \
--cc=bin.meng@windriver.com \
--cc=dapeng1.mi@intel.com \
--cc=edgar.iglesias@gmail.com \
--cc=eduardo@habkost.net \
--cc=like.xu.linux@gmail.com \
--cc=marcel.apfelbaum@gmail.com \
--cc=palmer@dabbelt.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-riscv@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=robert.hu@linux.intel.com \
--cc=seanjc@google.com \
--cc=wangyanan55@huawei.com \
--cc=zhao1.liu@intel.com \
--cc=zhao1.liu@linux.intel.com \
--cc=zhenyu.z.wang@intel.com \
--cc=zhuocheng.ding@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).