On 11/12/26 6:43 AM, Daniel P. Berrangé wrote:
On Fri, Nov 06, 2026 at 10:39:33AM +0800, Yonggang Luo wrote:
accel_cpu_register_type() creates the abstract parent
accel-<cpu type>. A subclass names that parent, and
type_initialize() aborts when the parent is missing. The old
type_init registered only target_cpu_type(), which is one name
in a multi-target process. Call the helper from the CPU type
init of each target that has an AccelCPU subclass.

ARM calls it because whpx-common.c parents accel-arm-cpu on
aarch64-softmmu. i386 calls it for TCG, KVM, HVF, NVMM, and
MSHV. i386-softmmu and x86_64-softmmu each pass their own
CPU_RESOLVING_TYPE, so WHPX on x86_64-softmmu finds
accel-x86_64-cpu. RISC-V calls it for TCG and KVM. PowerPC
calls it for KVM.

Other targets have no AccelCPU subclass. Machine init looks up
tcg-accel-<cpu type> or kvm-accel-<cpu type> and skips a missing
class, so those targets do not need the parent.

No extra tests is needed, as these QOM types already be
tested by the existing logic instantiating all QOM types.

Signed-off-by: Yonggang Luo <[email protected]>
---
  accel/accel-common.c      | 6 ++----
  include/accel/accel-cpu.h | 2 ++
  target/arm/cpu.c          | 2 ++
  target/i386/cpu.c         | 2 ++
  target/ppc/cpu_init.c     | 2 ++
  target/riscv/cpu.c        | 8 ++++++++
  6 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/accel/accel-common.c b/accel/accel-common.c
index 00a400243f..441d1b77fa 100644
--- a/accel/accel-common.c
+++ b/accel/accel-common.c
@@ -130,9 +130,9 @@ static const TypeInfo accel_types[] = {
DEFINE_TYPES(accel_types) -static void register_accel_target_type(void)
+void accel_cpu_register_type(const char *cpu_type)
  {
-    g_autofree char *name = g_strconcat("accel-", target_cpu_type(), NULL);
+    g_autofree char *name = g_strconcat("accel-", cpu_type, NULL);
      const TypeInfo accel_cpu_type = {
          .name = name,
          .parent = TYPE_OBJECT,
@@ -142,5 +142,3 @@ static void register_accel_target_type(void)
type_register_static(&accel_cpu_type);
  }

Is there a reason why we need to register this base class
repeatedly for each target ? This class is defined in target
independent code and the target specific behaviour is provided
by subclasses AFAICT, so I'm not seeing why we need to
duplicate the class per target.

I just proposed changing its name to "accel-cpu" so that
it is always available:

   https://lists.gnu.org/archive/html/qemu-devel/2026-11/msg02741.html

That seems to be the right move. I might have been confused in the beginning by thinking that a specific base class per target was needed to be able to override class pointers from AccelCPUClass.
After that, I didn't re-question the why and just assumed it was needed.

This predated the moment I understood that children class have their own copy of parent one, so can override base class behavior.

You're right, taking a fresh look, it does not seems to be necessary at all.

Thanks,
Pierrick

Reply via email to