The TYPE_ACCEL_CPU QOM type name currently expands to a dynamic
string based on the target CPU resolving type name. So we have
a hierarchy that looks like:

   object
     +- accel-{x86_64,ppc64,riscv64,...}-cpu
         +- kvm-accel-x86_64-cpu
         +- tcg-accel-x86_64-cpu
         +- mshv-accel-x86_64-cpu
         +- tcg-accel-riscv-cpu

where the middle class changes its name at runtime, so if leaf
CPU classes from different targets are linked together, their
immediate parent will be missing unless the selected target
matches.

The TYPE_ACCEL_CPU class is an abstract base class that does
not inherantly have target specific logic. It is expected to
be subclassed with children from different targets, and only
those childrenneed to have names derived from the CPU resolving
type name to ensure unique QOM naming.

IOW, TYPE_ACCEL_CPU can be given a fixed name while keeping
the same hierarchy structure:

   object
     +- accel-cpu
         +- kvm-accel-x86_64-cpu
         +- tcg-accel-x86_64-cpu
         +- mshv-accel-x86_64-cpu
         +- tcg-accel-riscv-cpu

Signed-off-by: Daniel P. Berrangé <[email protected]>
---
 accel/accel-common.c             | 3 +--
 include/accel/accel-cpu-target.h | 3 +--
 include/accel/accel-cpu.h        | 2 ++
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/accel/accel-common.c b/accel/accel-common.c
index 00a400243f0..05b1c44e1ed 100644
--- a/accel/accel-common.c
+++ b/accel/accel-common.c
@@ -132,9 +132,8 @@ DEFINE_TYPES(accel_types)
 
 static void register_accel_target_type(void)
 {
-    g_autofree char *name = g_strconcat("accel-", target_cpu_type(), NULL);
     const TypeInfo accel_cpu_type = {
-        .name = name,
+        .name = TYPE_ACCEL_CPU,
         .parent = TYPE_OBJECT,
         .abstract = true,
         .class_size = sizeof(AccelCPUClass),
diff --git a/include/accel/accel-cpu-target.h b/include/accel/accel-cpu-target.h
index 6feb344e29b..cf33ebd79fc 100644
--- a/include/accel/accel-cpu-target.h
+++ b/include/accel/accel-cpu-target.h
@@ -24,8 +24,7 @@
 #include "accel/accel-cpu.h"
 #include "cpu.h"
 
-#define TYPE_ACCEL_CPU "accel-" CPU_RESOLVING_TYPE
-#define ACCEL_CPU_NAME(name) (name "-" TYPE_ACCEL_CPU)
+#define ACCEL_CPU_NAME(name) (name "-accel-" CPU_RESOLVING_TYPE)
 DECLARE_CLASS_CHECKERS(AccelCPUClass, ACCEL_CPU, TYPE_ACCEL_CPU)
 
 #endif /* ACCEL_CPU_H */
diff --git a/include/accel/accel-cpu.h b/include/accel/accel-cpu.h
index 9e7eede7c3c..809b7d21fd3 100644
--- a/include/accel/accel-cpu.h
+++ b/include/accel/accel-cpu.h
@@ -20,4 +20,6 @@ typedef struct AccelCPUClass {
     bool (*cpu_target_realize)(CPUState *cpu, Error **errp);
 } AccelCPUClass;
 
+#define TYPE_ACCEL_CPU "accel-cpu"
+
 #endif /* ACCEL_CPU_H */
-- 
2.56.1


Reply via email to