Skip to contentSkip to conversation

Register accel-$cpu_type for all targets

PATCH Superseded Yonggang Luo 2 participants 9 messages Oct 28

Subsystems (2)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v2 cover Register accel-$cpu_type for all targets

A multi-target system binary links more than one target, so each one needs an accel-$cpu_type parent. accel-target.c is compiled once per target and calls accel_register_cpu_type() with that target's SysEmuTarget and CPU_RESOLVING_TYPE. A bool array keyed by SysEmuTarget records which arch already registered. Targets that share one CPU_RESOLVING_TYPE reuse the parent from the earlier arch.

linux-user still contains a single target and does not expose a target list in QOM, so it registers one accel-$cpu_type parent.

test-multi-target checks that each target's accel parent exists after QOM init.

This is an alternative to gating accelerator CPU types with is_available. The RISC-V TCG and KVM gates are reverted here as redundant.

Changes v1 -> v2:

- Drop the cached QOM target list. v1 walked that list in accel_system_register_types() and registered one accel-$cpu_type per distinct cpu_type
- Compile accel-target.c once per target and call accel_register_cpu_type() with that target's SysEmuTarget and CPU_RESOLVING_TYPE. Targets that share one CPU_RESOLVING_TYPE reuse the parent from the earlier arch
- Register the linux-user parent from that same per-target file. v1 kept a type_init in accel-user.c that called target_cpu_type()
- Revert the RISC-V TCG and KVM is_available gates, now that every linked target registers its parent

Yonggang Luo (3):
accel: register CPU parent for each target
Revert "target/riscv/kvm: restrict kvm-accel-riscv-cpu to riscv
targets"
Revert "target/riscv/tcg: restrict tcg-accel-riscv-cpu to riscv
targets"

 accel/accel-common.c           | 31 ++++++++++++++++++++++++++++---
 accel/accel-internal.h         |  2 ++
 accel/accel-target.c           | 21 +++++++++++++++++++++
 accel/meson.build              |  1 +
 target/riscv/kvm/kvm-cpu.c     |  2 --
 target/riscv/tcg/tcg-cpu.c     |  1 -
 tests/unit/test-multi-target.c | 22 ++++++++++++++++++++++
 7 files changed, 74 insertions(+), 6 deletions(-)
 create mode 100644 accel/accel-target.c
Signature · 1 line
2.55.0.windows.3
#1 lore raw

PATCH v2 1/3 accel: register CPU parent for each target

A multi-target binary registers one accel-$cpu_type parent per linked target. accel-target.c is compiled once per target and calls accel_register_cpu_type() with that target's target_arch and CPU_RESOLVING_TYPE. A bool array keyed by SysEmuTarget records which arch already registered. Targets that share one CPU_RESOLVING_TYPE reuse the parent from the earlier arch.

test-multi-target checks that each target's accel parent exists after QOM init.

---
 accel/accel-common.c           | 31 ++++++++++++++++++++++++++++---
 accel/accel-internal.h         |  2 ++
 accel/accel-target.c           | 21 +++++++++++++++++++++
 accel/meson.build              |  1 +
 tests/unit/test-multi-target.c | 22 ++++++++++++++++++++++
 5 files changed, 74 insertions(+), 3 deletions(-)
 create mode 100644 accel/accel-target.c
accel/accel-common.c +28 -3
index 00a400243f0..0d04b8c5749 100644
@@ -130,9 +130,9 @@ static const TypeInfo accel_types[] = {
 
 DEFINE_TYPES(accel_types)
 
-static void register_accel_target_type(void)
+static void register_accel_target_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,
@@ -143,4 +143,29 @@ static void register_accel_target_type(void)
     type_register_static(&accel_cpu_type);
 }
 
-type_init(register_accel_target_type);
+void accel_register_cpu_type(SysEmuTarget arch, const char *cpu_type)
+{
+    static bool accel_cpu_registered[SYS_EMU_TARGET__MAX];
+    static const char *accel_cpu_types[SYS_EMU_TARGET__MAX];
+
+    if (accel_cpu_registered[arch]) {
+        return;
+    }
+
+    /*
+     * Keyed by target_arch. Targets that share CPU_RESOLVING_TYPE already
+     * have a parent from an earlier target_arch.
+     */
+    for (int i = 0; i < SYS_EMU_TARGET__MAX; i++) {
+        if (accel_cpu_registered[i] &&
+            g_str_equal(accel_cpu_types[i], cpu_type)) {
+            accel_cpu_registered[arch] = true;
+            accel_cpu_types[arch] = cpu_type;
+            return;
+        }
+    }
+
+    accel_cpu_registered[arch] = true;
+    accel_cpu_types[arch] = cpu_type;
+    register_accel_target_type(cpu_type);
+}
accel/accel-internal.h +2 -0
index d3a4422cbf7..736b07c5f08 100644
@@ -11,7 +11,9 @@
 #define ACCEL_INTERNAL_H
 
 #include "qemu/accel.h"
+#include "qapi/qapi-types-machine.h"
 
 void accel_init_ops_interfaces(AccelClass *ac);
+void accel_register_cpu_type(SysEmuTarget arch, const char *cpu_type);
 
 #endif /* ACCEL_SYSTEM_H */
accel/accel-target.c new file +21 -0
new file mode 100644
index 00000000000..202238035d5
@@ -0,0 +1,21 @@
+/*
+ * Per-target accelerator CPU parent registration.
+ *
+ * Compiled once per target. Must not define a global symbol, so each
+ * copy can be linked into one binary.
+ *
+ * SPDX-License-Identifier: MIT
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/module.h"
+#include "accel/accel-cpu-target.h"
+#include "accel-internal.h"
+
+static void register_accel_target_type(void)
+{
+    accel_register_cpu_type(glue(SYS_EMU_TARGET_, TARGET_ARCH_VARIANT),
+                            CPU_RESOLVING_TYPE);
+}
+
+type_init(register_accel_target_type);
accel/meson.build +1 -0
index 1b5b37e3097..7da12b9741f 100644
@@ -1,4 +1,5 @@
 common_ss.add(files('accel-common.c'))
+specific_ss.add(files('accel-target.c'))
 system_ss.add(files('accel-system.c', 'accel-blocker.c', 'accel-qmp.c', 'accel-irq.c'))
 user_ss.add(files('accel-user.c'))
 
tests/unit/test-multi-target.c +22 -0
index c7559827a08..de75d6e9d35 100644
@@ -51,6 +51,24 @@ static void test_qom_types_are_unique(const void *data)
     object_class_get_list("", false);
 }
 
+static void test_accel_cpu_parent_per_target(const void *data)
+{
+    const TargetInfo *ti = data;
+    g_autofree char *name = NULL;
+
+    if (!g_test_subprocess()) {
+        g_test_trap_subprocess(NULL, 0, G_TEST_SUBPROCESS_INHERIT_STDERR);
+        g_test_trap_assert_passed();
+        return;
+    }
+
+    target_info_qom_set_target_info(ti);
+    module_call_init(MODULE_INIT_QOM);
+
+    name = g_strconcat("accel-", ti->cpu_type, NULL);
+    g_assert_nonnull(object_class_by_name(name));
+}
+
 int main(int argc, char **argv)
 {
     g_test_init(&argc, &argv, NULL);
@@ -64,7 +82,11 @@ int main(int argc, char **argv)
         g_autofree char *path =
             g_strdup_printf("/multi-targets/qom-types-are-unique/%s",
                             ti->target_name);
+        g_autofree char *accel_path =
+            g_strdup_printf("/multi-targets/accel-cpu-parent-per-target/%s",
+                            ti->target_name);
         g_test_add_data_func(path, ti, test_qom_types_are_unique);
+        g_test_add_data_func(accel_path, ti, test_accel_cpu_parent_per_target);
     }
 
     return g_test_run();
Signature · 1 line
2.55.0.windows.3
#2 lore raw

Re: [PATCH v2 1/3] accel: register CPU parent for each target

Quoted 57 lines · Yonggang Luo

A multi-target binary registers one accel-$cpu_type parent per linked target. accel-target.c is compiled once per target and calls accel_register_cpu_type() with that target's target_arch and CPU_RESOLVING_TYPE. A bool array keyed by SysEmuTarget records which arch already registered. Targets that share one CPU_RESOLVING_TYPE reuse the parent from the earlier arch.

test-multi-target checks that each target's accel parent exists after QOM init.

---
 accel/accel-common.c           | 31 ++++++++++++++++++++++++++++---
 accel/accel-internal.h         |  2 ++
 accel/accel-target.c           | 21 +++++++++++++++++++++
 accel/meson.build              |  1 +
 tests/unit/test-multi-target.c | 22 ++++++++++++++++++++++
 5 files changed, 74 insertions(+), 3 deletions(-)
 create mode 100644 accel/accel-target.c
accel/accel-common.c +18 -3
index 00a400243f0..0d04b8c5749 100644
@@ -130,9 +130,9 @@ static const TypeInfo accel_types[] = {
 
 DEFINE_TYPES(accel_types)
 
-static void register_accel_target_type(void)
+static void register_accel_target_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,
@@ -143,4 +143,29 @@ static void register_accel_target_type(void)
     type_register_static(&accel_cpu_type);
 }
 
-type_init(register_accel_target_type);
+void accel_register_cpu_type(SysEmuTarget arch, const char *cpu_type)
+{
+    static bool accel_cpu_registered[SYS_EMU_TARGET__MAX];
+    static const char *accel_cpu_types[SYS_EMU_TARGET__MAX];
+
+    if (accel_cpu_registered[arch]) {
+        return;
+    }
+
+    /*
+     * Keyed by target_arch. Targets that share CPU_RESOLVING_TYPE already
+     * have a parent from an earlier target_arch.
+     */
+    for (int i = 0; i < SYS_EMU_TARGET__MAX; i++) {
+        if (accel_cpu_registered[i] &&
+            g_str_equal(accel_cpu_types[i], cpu_type)) {

accel/accel-common.c static void register_accel_target_type(void) · line 171

Quoted 10 lines
accel/accel-common.c +10 -0
+            accel_cpu_registered[arch] = true;
+            accel_cpu_types[arch] = cpu_type;
+            return;
+        }
+    }
+
+    accel_cpu_registered[arch] = true;
+    accel_cpu_types[arch] = cpu_type;
+    register_accel_target_type(cpu_type);
+}

No need to do this, just move the whole type registration in accel-target.c and type will be present at runtime for all present targets.

Regards,
Pierrick

#3 lore raw

Re: [PATCH v2 1/3] accel: register CPU parent for each target

Quoted 64 lines · Pierrick Bouvier
Quoted 62 lines · Yonggang Luo

A multi-target binary registers one accel-$cpu_type parent per linked target. accel-target.c is compiled once per target and calls accel_register_cpu_type() with that target's target_arch and CPU_RESOLVING_TYPE. A bool array keyed by SysEmuTarget records which arch already registered. Targets that share one CPU_RESOLVING_TYPE reuse the parent from the earlier arch.

test-multi-target checks that each target's accel parent exists after QOM init.

---
 accel/accel-common.c           | 31 ++++++++++++++++++++++++++++---
 accel/accel-internal.h         |  2 ++
 accel/accel-target.c           | 21 +++++++++++++++++++++
 accel/meson.build              |  1 +
 tests/unit/test-multi-target.c | 22 ++++++++++++++++++++++
 5 files changed, 74 insertions(+), 3 deletions(-)
 create mode 100644 accel/accel-target.c
accel/accel-common.c +23 -3
index 00a400243f0..0d04b8c5749 100644
@@ -130,9 +130,9 @@ static const TypeInfo accel_types[] = {
 
 DEFINE_TYPES(accel_types)
 
-static void register_accel_target_type(void)
+static void register_accel_target_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,
@@ -143,4 +143,29 @@ static void register_accel_target_type(void)
     type_register_static(&accel_cpu_type);
 }
 
-type_init(register_accel_target_type);
+void accel_register_cpu_type(SysEmuTarget arch, const char *cpu_type)
+{
+    static bool accel_cpu_registered[SYS_EMU_TARGET__MAX];
+    static const char *accel_cpu_types[SYS_EMU_TARGET__MAX];
+
+    if (accel_cpu_registered[arch]) {
+        return;
+    }
+
+    /*
+     * Keyed by target_arch. Targets that share CPU_RESOLVING_TYPE already
+     * have a parent from an earlier target_arch.
+     */
+    for (int i = 0; i < SYS_EMU_TARGET__MAX; i++) {
+        if (accel_cpu_registered[i] &&
+            g_str_equal(accel_cpu_types[i], cpu_type)) {
+            accel_cpu_registered[arch] = true;
+            accel_cpu_types[arch] = cpu_type;
+            return;
+        }
+    }
Quoted 8 lines

accel/accel-common.c static void register_accel_target_type(void) · line 171

Quoted 5 lines
accel/accel-common.c +5 -0
+
+    accel_cpu_registered[arch] = true;
+    accel_cpu_types[arch] = cpu_type;
+    register_accel_target_type(cpu_type);
+}

No need to do this, just move the whole type registration in accel-target.c and type will be present at runtime for all present targets.

The issue is that CPU_RESOLVING_TYPE is not unique for each target_arch, you may not realize it.
for example:
arm/aarch64 sharing same

```
#define TYPE_ARM_CPU "arm-cpu"
#define CPU_RESOLVING_TYPE TYPE_ARM_CPU
```

And the same name can not be registered twice, that's why this accel_register_cpu_type should be
in a global shared place. We need accel_cpu_registered/accel_cpu_types for deduplication.

Quoted 3 lines

Regards,
Pierrick

Signature · 6 lines
         此致
礼
罗勇刚
Yours
    sincerely,
Yonggang Luo
#4 lore raw

Re: [PATCH v2 1/3] accel: register CPU parent for each target

Quoted 75 lines · Yonggang Luo
Quoted 64 lines · Pierrick Bouvier
Quoted 62 lines · Yonggang Luo

A multi-target binary registers one accel-$cpu_type parent per linked target. accel-target.c is compiled once per target and calls accel_register_cpu_type() with that target's target_arch and CPU_RESOLVING_TYPE. A bool array keyed by SysEmuTarget records which arch already registered. Targets that share one CPU_RESOLVING_TYPE reuse the parent from the earlier arch.

test-multi-target checks that each target's accel parent exists after QOM init.

---
 accel/accel-common.c           | 31 ++++++++++++++++++++++++++++---
 accel/accel-internal.h         |  2 ++
 accel/accel-target.c           | 21 +++++++++++++++++++++
 accel/meson.build              |  1 +
 tests/unit/test-multi-target.c | 22 ++++++++++++++++++++++
 5 files changed, 74 insertions(+), 3 deletions(-)
 create mode 100644 accel/accel-target.c
accel/accel-common.c +23 -3
index 00a400243f0..0d04b8c5749 100644
@@ -130,9 +130,9 @@ static const TypeInfo accel_types[] = {
 
 DEFINE_TYPES(accel_types)
 
-static void register_accel_target_type(void)
+static void register_accel_target_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,
@@ -143,4 +143,29 @@ static void register_accel_target_type(void)
     type_register_static(&accel_cpu_type);
 }
 
-type_init(register_accel_target_type);
+void accel_register_cpu_type(SysEmuTarget arch, const char *cpu_type)
+{
+    static bool accel_cpu_registered[SYS_EMU_TARGET__MAX];
+    static const char *accel_cpu_types[SYS_EMU_TARGET__MAX];
+
+    if (accel_cpu_registered[arch]) {
+        return;
+    }
+
+    /*
+     * Keyed by target_arch. Targets that share CPU_RESOLVING_TYPE already
+     * have a parent from an earlier target_arch.
+     */
+    for (int i = 0; i < SYS_EMU_TARGET__MAX; i++) {
+        if (accel_cpu_registered[i] &&
+            g_str_equal(accel_cpu_types[i], cpu_type)) {
+            accel_cpu_registered[arch] = true;
+            accel_cpu_types[arch] = cpu_type;
+            return;
+        }
+    }
Quoted 8 lines

accel/accel-common.c static void register_accel_target_type(void) · line 171

Quoted 5 lines
accel/accel-common.c +5 -0
+
+    accel_cpu_registered[arch] = true;
+    accel_cpu_types[arch] = cpu_type;
+    register_accel_target_type(cpu_type);
+}

No need to do this, just move the whole type registration in accel-target.c and type will be present at runtime for all present targets.

Quoted 9 lines

The issue is that CPU_RESOLVING_TYPE is not unique for each target_arch, you may not realize it.
for example:
arm/aarch64 sharing same

```
#define TYPE_ARM_CPU "arm-cpu"
#define CPU_RESOLVING_TYPE TYPE_ARM_CPU
```

Oh right. In this case, the accel-target has to be added once per base architecture (in each target/*/).

Quoted 11 lines

And the same name can not be registered twice, that's why this accel_register_cpu_type should be
in a global shared place. We need accel_cpu_registered/accel_cpu_types for deduplication.

Quoted 3 lines

Regards,
Pierrick

#5 lore raw

Re: [PATCH v2 1/3] accel: register CPU parent for each target

Quoted 87 lines · Pierrick Bouvier
Quoted 75 lines · Yonggang Luo
Quoted 64 lines · Pierrick Bouvier
Quoted 62 lines · Yonggang Luo

A multi-target binary registers one accel-$cpu_type parent per linked target. accel-target.c is compiled once per target and calls accel_register_cpu_type() with that target's target_arch and CPU_RESOLVING_TYPE. A bool array keyed by SysEmuTarget records which arch already registered. Targets that share one CPU_RESOLVING_TYPE reuse the parent from the earlier arch.

test-multi-target checks that each target's accel parent exists after QOM init.

---
 accel/accel-common.c           | 31 ++++++++++++++++++++++++++++---
 accel/accel-internal.h         |  2 ++
 accel/accel-target.c           | 21 +++++++++++++++++++++
 accel/meson.build              |  1 +
 tests/unit/test-multi-target.c | 22 ++++++++++++++++++++++
 5 files changed, 74 insertions(+), 3 deletions(-)
 create mode 100644 accel/accel-target.c
accel/accel-common.c +23 -3
index 00a400243f0..0d04b8c5749 100644
@@ -130,9 +130,9 @@ static const TypeInfo accel_types[] = {
 
 DEFINE_TYPES(accel_types)
 
-static void register_accel_target_type(void)
+static void register_accel_target_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,
@@ -143,4 +143,29 @@ static void register_accel_target_type(void)
     type_register_static(&accel_cpu_type);
 }
 
-type_init(register_accel_target_type);
+void accel_register_cpu_type(SysEmuTarget arch, const char *cpu_type)
+{
+    static bool accel_cpu_registered[SYS_EMU_TARGET__MAX];
+    static const char *accel_cpu_types[SYS_EMU_TARGET__MAX];
+
+    if (accel_cpu_registered[arch]) {
+        return;
+    }
+
+    /*
+     * Keyed by target_arch. Targets that share CPU_RESOLVING_TYPE already
+     * have a parent from an earlier target_arch.
+     */
+    for (int i = 0; i < SYS_EMU_TARGET__MAX; i++) {
+        if (accel_cpu_registered[i] &&
+            g_str_equal(accel_cpu_types[i], cpu_type)) {
+            accel_cpu_registered[arch] = true;
+            accel_cpu_types[arch] = cpu_type;
+            return;
+        }
+    }
Quoted 8 lines

accel/accel-common.c static void register_accel_target_type(void) · line 171

Quoted 5 lines
accel/accel-common.c +5 -0
+
+    accel_cpu_registered[arch] = true;
+    accel_cpu_types[arch] = cpu_type;
+    register_accel_target_type(cpu_type);
+}

No need to do this, just move the whole type registration in accel-target.c and type will be present at runtime for all present targets.

Quoted 9 lines

The issue is that CPU_RESOLVING_TYPE is not unique for each target_arch, you may not realize it.
for example:
arm/aarch64 sharing same

```
#define TYPE_ARM_CPU "arm-cpu"
#define CPU_RESOLVING_TYPE TYPE_ARM_CPU
```
Quoted 2 lines

Oh right. In this case, the accel-target has to be added once per base architecture (in each target/*/).

So you mean call register_accel_target_type at each target/$base/cpu.c? too much duplicated code scattered.

Quoted 13 lines
Quoted 12 lines

And the same name can not be registered twice, that's why this accel_register_cpu_type should be
in a global shared place. We need accel_cpu_registered/accel_cpu_types for deduplication.

Quoted 3 lines

Regards,
Pierrick

Signature · 6 lines
         此致
礼
罗勇刚
Yours
    sincerely,
Yonggang Luo
#6 lore raw

Re: [PATCH v2 1/3] accel: register CPU parent for each target

Quoted 89 lines · Yonggang Luo
Quoted 87 lines · Pierrick Bouvier
Quoted 84 lines · Yonggang Luo
Quoted 64 lines · Pierrick Bouvier
Quoted 62 lines · Yonggang Luo

A multi-target binary registers one accel-$cpu_type parent per linked target. accel-target.c is compiled once per target and calls accel_register_cpu_type() with that target's target_arch and CPU_RESOLVING_TYPE. A bool array keyed by SysEmuTarget records which arch already registered. Targets that share one CPU_RESOLVING_TYPE reuse the parent from the earlier arch.

test-multi-target checks that each target's accel parent exists after QOM init.

---
 accel/accel-common.c           | 31 ++++++++++++++++++++++++++++---
 accel/accel-internal.h         |  2 ++
 accel/accel-target.c           | 21 +++++++++++++++++++++
 accel/meson.build              |  1 +
 tests/unit/test-multi-target.c | 22 ++++++++++++++++++++++
 5 files changed, 74 insertions(+), 3 deletions(-)
 create mode 100644 accel/accel-target.c
accel/accel-common.c +23 -3
index 00a400243f0..0d04b8c5749 100644
@@ -130,9 +130,9 @@ static const TypeInfo accel_types[] = {
 
 DEFINE_TYPES(accel_types)
 
-static void register_accel_target_type(void)
+static void register_accel_target_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,
@@ -143,4 +143,29 @@ static void register_accel_target_type(void)
     type_register_static(&accel_cpu_type);
 }
 
-type_init(register_accel_target_type);
+void accel_register_cpu_type(SysEmuTarget arch, const char *cpu_type)
+{
+    static bool accel_cpu_registered[SYS_EMU_TARGET__MAX];
+    static const char *accel_cpu_types[SYS_EMU_TARGET__MAX];
+
+    if (accel_cpu_registered[arch]) {
+        return;
+    }
+
+    /*
+     * Keyed by target_arch. Targets that share CPU_RESOLVING_TYPE already
+     * have a parent from an earlier target_arch.
+     */
+    for (int i = 0; i < SYS_EMU_TARGET__MAX; i++) {
+        if (accel_cpu_registered[i] &&
+            g_str_equal(accel_cpu_types[i], cpu_type)) {
+            accel_cpu_registered[arch] = true;
+            accel_cpu_types[arch] = cpu_type;
+            return;
+        }
+    }
Quoted 8 lines

accel/accel-common.c static void register_accel_target_type(void) · line 171

Quoted 5 lines
accel/accel-common.c +5 -0
+
+    accel_cpu_registered[arch] = true;
+    accel_cpu_types[arch] = cpu_type;
+    register_accel_target_type(cpu_type);
+}

No need to do this, just move the whole type registration in accel-target.c and type will be present at runtime for all present targets.

The issue is that CPU_RESOLVING_TYPE is not unique for each target_arch, you may not realize it.
for example:
arm/aarch64 sharing same

```
#define TYPE_ARM_CPU "arm-cpu"
#define CPU_RESOLVING_TYPE TYPE_ARM_CPU
```
Quoted 6 lines
Quoted 2 lines

Oh right. In this case, the accel-target has to be added once per base architecture (in each target/*/).

So you mean call register_accel_target_type at each target/$base/cpu.c? too much duplicated code scattered.

You may need a new file as cpu.c will run for each variant.

Quoted 15 lines
Quoted 13 lines
Quoted 12 lines

And the same name can not be registered twice, that's why this accel_register_cpu_type should be
in a global shared place. We need accel_cpu_registered/accel_cpu_types for deduplication.

Quoted 3 lines

Regards,
Pierrick

#7 lore raw

PATCH v2 2/3 Revert "target/riscv/kvm: restrict kvm-accel-riscv-cpu to riscv targets"

In reply to Yonggang Luo

This is redundant now as all accel-$cpu_type parent is already registered.

This reverts commit 2d3e6b4003d5380c245ce8ffac4b8866f6d10a33.

---
 target/riscv/kvm/kvm-cpu.c | 2 --
 1 file changed, 2 deletions(-)
target/riscv/kvm/kvm-cpu.c +0 -2
index 5a82a63b822..c085b22b23e 100644
@@ -26,7 +26,6 @@
 #include "qapi/error.h"
 #include "qemu/error-report.h"
 #include "qemu/main-loop.h"
-#include "qemu/target-info.h"
 #include "qapi/visitor.h"
 #include "system/system.h"
 #include "system/kvm.h"
@@ -2236,7 +2235,6 @@ static const TypeInfo kvm_cpu_accel_type_info = {
 
     .parent = TYPE_ACCEL_CPU,
     .class_init = kvm_cpu_accel_class_init,
-    .is_available = target_base_riscv,
     .abstract = true,
 };
 static void kvm_cpu_accel_register_types(void)
Signature · 1 line
2.55.0.windows.3
#8 lore raw

PATCH v2 3/3 Revert "target/riscv/tcg: restrict tcg-accel-riscv-cpu to riscv targets"

In reply to Yonggang Luo

This is redundant now as all accel-$cpu_type parent is already registered.

This reverts commit ec65e16fd2ba012d57b1bbfcfcd04c31c4111924.

---
 target/riscv/tcg/tcg-cpu.c | 1 -
 1 file changed, 1 deletion(-)
target/riscv/tcg/tcg-cpu.c +0 -1
index 2a7796c382e..1369b7c4ded 100644
@@ -1754,7 +1754,6 @@ static const TypeInfo riscv_tcg_cpu_accel_type_info = {
 
     .parent = TYPE_ACCEL_CPU,
     .class_init = riscv_tcg_cpu_accel_class_init,
-    .is_available = target_base_riscv,
     .abstract = true,
 };
 
Signature · 1 line
2.55.0.windows.3