Register accel-$cpu_type for all targets
v4 cover Register accel-$cpu_type for all targets
A multi-target system binary links more than one target. accel_cpu_register_type() creates the abstract parent accel-$cpu_type for each target that has an AccelCPU subclass. ARM, i386, RISC-V, and PowerPC call it. Other targets have no such subclass, and machine init skips a missing class.
test-multi-target checks the parent only for the CPU types that register it.
This is an alternative to gating accelerator CPU types with is_available. The RISC-V TCG and KVM gates are reverted here as redundant.
v3: https://lore.kernel.org/qemu-devel/[email protected]/
Changes v3 -> v4:
- Drop accel-cpu-target.c and the once-per-TARGET_BASE_ARCH build. Register the parent with accel_cpu_register_type() only where an AccelCPU subclass exists
- Call it from ARM, i386, RISC-V, and PowerPC. v3 registered a parent for every linked target
- Check those parents from test_qom_types_are_unique(). v3 expected one for every target in the test
Yonggang Luo (3):
accel: register CPU parent only for AccelCPU subclasses 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 | 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 ++++++++ target/riscv/kvm/kvm-cpu.c | 2 -- target/riscv/tcg/tcg-cpu.c | 1 - tests/unit/test-multi-target.c | 25 +++++++++++++++++++++++++ 9 files changed, 43 insertions(+), 7 deletions(-)
Signature · 1 line
2.55.0.windows.3
PATCH v4 1/3 accel: register CPU parent only for AccelCPU subclasses
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. test-multi-target checks the parent only for the CPU types that register it.
--- 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 ++++++++ tests/unit/test-multi-target.c | 25 +++++++++++++++++++++++++ 7 files changed, 43 insertions(+), 4 deletions(-)
accel/accel-common.c +2 -4
@@ -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); } - -type_init (register_accel_target_type);
include/accel/accel-cpu.h +2 -0
@@ -20,4 +20,6 @@ typedef struct AccelCPUClass { bool (*cpu_target_realize)(CPUState *cpu, Error **errp); } AccelCPUClass; +void accel_cpu_register_type (const char *cpu_type); +#endif /* ACCEL_CPU_H */
target/arm/cpu.c +2 -0
@@ -28,6 +28,7 @@#include "qemu/module.h" #include "qapi/error.h" #include "cpu.h" +#include "accel/accel-cpu.h" #ifdef CONFIG_TCG #include "exec/translation-block.h" #include "accel/tcg/cpu-ops.h"
@@ -2753,6 +2754,7 @@ static const TypeInfo arm_cpu_type_info = {static void arm_cpu_register_types (void ) { +accel_cpu_register_type (CPU_RESOLVING_TYPE );type_register_static (&arm_cpu_type_info); }
target/i386/cpu.c +2 -0
@@ -23,6 +23,7 @@#include "qemu/qemu-print.h" #include "qemu/hw-version.h" #include "cpu.h" +#include "accel/accel-cpu.h" #include "tcg/helper-tcg.h" #include "exec/translation-block.h" #include "system/hvf.h"
@@ -11093,6 +11094,7 @@ static void x86_cpu_register_types(void) {int i; +accel_cpu_register_type (CPU_RESOLVING_TYPE );type_register_static (&x86_cpu_type_info);for (i =0 ; i <ARRAY_SIZE (builtin_x86_defs); i++) {x86_register_cpudef_types (&builtin_x86_defs[i]);
target/ppc/cpu_init.c +2 -0
@@ -43,6 +43,7 @@#include "exec/page-protection.h" #include "exec/watchpoint.h" #include "helper_regs.h" +#include "accel/accel-cpu.h" #include "internal.h" #include "spr_common.h" #include "power8-pmu.h"
@@ -7589,6 +7590,7 @@ static const TypeInfo ppc_vhyp_type_info = {static void ppc_cpu_register_types (void ) { +accel_cpu_register_type (CPU_RESOLVING_TYPE );type_register_static (&ppc_cpu_type_info);#ifndef CONFIG_USER_ONLY type_register_static (&ppc_vhyp_type_info);
target/riscv/cpu.c +8 -0
@@ -25,6 +25,7 @@#include "qemu/guest-random.h" #include "qemu/atomic.h" #include "cpu.h" +#include "accel/accel-cpu.h" #include "cpu_vendorid.h" #include "target/riscv/tcg/csr.h" #include "internals.h"
@@ -3931,3 +3932,10 @@ static const TypeInfo riscv_cpu_type_infos[] = { };DEFINE_TYPES (riscv_cpu_type_infos) + +static void riscv_accel_cpu_register_type(void) +{ +accel_cpu_register_type (CPU_RESOLVING_TYPE ); +} + +type_init (riscv_accel_cpu_register_type)
tests/unit/test-multi-target.c +25 -0
@@ -30,6 +30,28 @@/* stub for system/main.c */ int (*qemu_main)(void ); +static void test_accel_cpu_parent (const TargetInfo *ti) +{ +static const char *const needed[] = { +"arm-cpu" , +"i386-cpu" , +"powerpc-cpu" , +"powerpc64-cpu" , +"riscv-cpu" , +"x86_64-cpu" , + }; +size_t i; + g_autofree char *name = NULL; + +for (i =0 ; i <ARRAY_SIZE (needed); i++) { +if (g_str_equal (ti->cpu_type, needed[i])) { + name =g_strconcat ("accel-" , ti->cpu_type,NULL ); +g_assert_nonnull (object_class_by_name (name)); +return ; + } + } +} +static void test_qom_types_are_unique (const void *data) {const TargetInfo *ti = data;
@@ -49,6 +71,9 @@ static void test_qom_types_are_unique(const void *data)module_call_init (MODULE_INIT_QOM );/* trigger type_initialize for all types */ object_class_get_list ("" , false); + +/* Accel parent lookup depends on the QOM types above being unique. */ +test_accel_cpu_parent (ti); }int main (int argc,char **argv)
Signature · 1 line
2.55.0.windows.3
Re: [PATCH v4 1/3] accel: register CPU parent only for AccelCPU subclasses
Quoted 137 lines · Yonggang Luo
accel_cpu_register_type()creates the abstract parent accel-<cpu type>. A subclass names that parent, andtype_initialize()aborts when the parent is missing. The oldtype_initregistered onlytarget_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.cparents 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 ownCPU_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. test-multi-target checks the parent only for the CPU types that register it.
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 ++++++++ tests/unit/test-multi-target.c | 25 +++++++++++++++++++++++++ 7 files changed, 43 insertions(+), 4 deletions(-)accel/accel-common.c +2
-4@@ -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); } - -type_init (register_accel_target_type);include/accel/accel-cpu.h +2
-0@@ -20,4 +20,6 @@ typedef struct AccelCPUClass { bool (*cpu_target_realize)(CPUState *cpu, Error **errp); } AccelCPUClass; +void accel_cpu_register_type (const char *cpu_type); +#endif /* ACCEL_CPU_H */ target/arm/cpu.c +2
-0@@ -28,6 +28,7 @@#include "qemu/module.h" #include "qapi/error.h" #include "cpu.h" +#include "accel/accel-cpu.h" #ifdef CONFIG_TCG #include "exec/translation-block.h" #include "accel/tcg/cpu-ops.h" @@ -2753,6 +2754,7 @@ static const TypeInfo arm_cpu_type_info = {static void arm_cpu_register_types (void ) { +accel_cpu_register_type (CPU_RESOLVING_TYPE );type_register_static (&arm_cpu_type_info); }target/i386/cpu.c +2
-0@@ -23,6 +23,7 @@#include "qemu/qemu-print.h" #include "qemu/hw-version.h" #include "cpu.h" +#include "accel/accel-cpu.h" #include "tcg/helper-tcg.h" #include "exec/translation-block.h" #include "system/hvf.h" @@ -11093,6 +11094,7 @@ static void x86_cpu_register_types(void) {int i; +accel_cpu_register_type (CPU_RESOLVING_TYPE );type_register_static (&x86_cpu_type_info);for (i =0 ; i <ARRAY_SIZE (builtin_x86_defs); i++) {x86_register_cpudef_types (&builtin_x86_defs[i]);target/ppc/cpu_init.c +2
-0@@ -43,6 +43,7 @@#include "exec/page-protection.h" #include "exec/watchpoint.h" #include "helper_regs.h" +#include "accel/accel-cpu.h" #include "internal.h" #include "spr_common.h" #include "power8-pmu.h" @@ -7589,6 +7590,7 @@ static const TypeInfo ppc_vhyp_type_info = {static void ppc_cpu_register_types (void ) { +accel_cpu_register_type (CPU_RESOLVING_TYPE );type_register_static (&ppc_cpu_type_info);#ifndef CONFIG_USER_ONLY type_register_static (&ppc_vhyp_type_info);target/riscv/cpu.c +1
-0@@ -25,6 +25,7 @@#include "qemu/guest-random.h" #include "qemu/atomic.h" #include "cpu.h" +#include "accel/accel-cpu.h" #include "cpu_vendorid.h" #include "target/riscv/tcg/csr.h" #include "internals.h"
target/riscv/cpu.c static const TypeInfo riscv_cpu_type_infos[] = { · line 3940
Quoted 9 lines
target/riscv/cpu.c +6
-0@@ -3931,3 +3932,10 @@ static const TypeInfo riscv_cpu_type_infos[] = { };DEFINE_TYPES (riscv_cpu_type_infos) + +static void riscv_accel_cpu_register_type(void) +{ +accel_cpu_register_type (CPU_RESOLVING_TYPE ); +} +
This looks good to me.
Quoted 35 lines
target/riscv/cpu.c +1
-0+type_init (riscv_accel_cpu_register_type)tests/unit/test-multi-target.c +22
-0@@ -30,6 +30,28 @@/* stub for system/main.c */ int (*qemu_main)(void ); +static void test_accel_cpu_parent (const TargetInfo *ti) +{ +static const char *const needed[] = { +"arm-cpu" , +"i386-cpu" , +"powerpc-cpu" , +"powerpc64-cpu" , +"riscv-cpu" , +"x86_64-cpu" , + }; +size_t i; + g_autofree char *name = NULL; + +for (i =0 ; i <ARRAY_SIZE (needed); i++) { +if (g_str_equal (ti->cpu_type, needed[i])) { + name =g_strconcat ("accel-" , ti->cpu_type,NULL ); +g_assert_nonnull (object_class_by_name (name)); +return ; + } + } +} +static void test_qom_types_are_unique (const void *data) {const TargetInfo *ti = data;
tests/unit/test-multi-target.c static void test_qom_types_are_unique(const void *data) · line 79
Quoted 9 lines
tests/unit/test-multi-target.c +3
-0@@ -49,6 +71,9 @@ static void test_qom_types_are_unique(const void *data)module_call_init (MODULE_INIT_QOM );/* trigger type_initialize for all types */ object_class_get_list ("" , false); + +/* Accel parent lookup depends on the QOM types above being unique. */ +test_accel_cpu_parent (ti); }int main (int argc,char **argv)
This is not needed. When those targets will be added, it will already be tested by the existing logic instantiating all QOM types. That's fine to not cover that for i386/ppc until they are not part of multi target.
Thanks,
Pierrick
Re: [PATCH v4 1/3] accel: register CPU parent only for AccelCPU subclasses
Quoted 194 lines · Pierrick Bouvier
Quoted 137 lines · Yonggang Luo
accel_cpu_register_type()creates the abstract parent accel-<cpu type>. A subclass names that parent, andtype_initialize()aborts when the parent is missing. The oldtype_initregistered onlytarget_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.cparents 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 ownCPU_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. test-multi-target checks the parent only for the CPU types that register it.
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 ++++++++ tests/unit/test-multi-target.c | 25 +++++++++++++++++++++++++ 7 files changed, 43 insertions(+), 4 deletions(-)accel/accel-common.c +2
-4@@ -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); } - -type_init (register_accel_target_type);include/accel/accel-cpu.h +2
-0@@ -20,4 +20,6 @@ typedef struct AccelCPUClass { bool (*cpu_target_realize)(CPUState *cpu, Error **errp); } AccelCPUClass; +void accel_cpu_register_type (const char *cpu_type); +#endif /* ACCEL_CPU_H */ target/arm/cpu.c +2
-0@@ -28,6 +28,7 @@#include "qemu/module.h" #include "qapi/error.h" #include "cpu.h" +#include "accel/accel-cpu.h" #ifdef CONFIG_TCG #include "exec/translation-block.h" #include "accel/tcg/cpu-ops.h" @@ -2753,6 +2754,7 @@ static const TypeInfo arm_cpu_type_info = {static void arm_cpu_register_types (void ) { +accel_cpu_register_type (CPU_RESOLVING_TYPE );type_register_static (&arm_cpu_type_info); }target/i386/cpu.c +2
-0@@ -23,6 +23,7 @@#include "qemu/qemu-print.h" #include "qemu/hw-version.h" #include "cpu.h" +#include "accel/accel-cpu.h" #include "tcg/helper-tcg.h" #include "exec/translation-block.h" #include "system/hvf.h" @@ -11093,6 +11094,7 @@ static void x86_cpu_register_types(void) {int i; +accel_cpu_register_type (CPU_RESOLVING_TYPE );type_register_static (&x86_cpu_type_info);for (i =0 ; i <ARRAY_SIZE (builtin_x86_defs); i++) {x86_register_cpudef_types (&builtin_x86_defs[i]);target/ppc/cpu_init.c +2
-0@@ -43,6 +43,7 @@#include "exec/page-protection.h" #include "exec/watchpoint.h" #include "helper_regs.h" +#include "accel/accel-cpu.h" #include "internal.h" #include "spr_common.h" #include "power8-pmu.h" @@ -7589,6 +7590,7 @@ static const TypeInfo ppc_vhyp_type_info = {static void ppc_cpu_register_types (void ) { +accel_cpu_register_type (CPU_RESOLVING_TYPE );type_register_static (&ppc_cpu_type_info);#ifndef CONFIG_USER_ONLY type_register_static (&ppc_vhyp_type_info);target/riscv/cpu.c +1
-0@@ -25,6 +25,7 @@#include "qemu/guest-random.h" #include "qemu/atomic.h" #include "cpu.h" +#include "accel/accel-cpu.h" #include "cpu_vendorid.h" #include "target/riscv/tcg/csr.h" #include "internals.h" target/riscv/cpu.c static const TypeInfo riscv_cpu_type_infos[] = { · line 3940
Quoted 9 lines
target/riscv/cpu.c +6
-0@@ -3931,3 +3932,10 @@ static const TypeInfo riscv_cpu_type_infos[] = { };DEFINE_TYPES (riscv_cpu_type_infos) + +static void riscv_accel_cpu_register_type(void) +{ +accel_cpu_register_type (CPU_RESOLVING_TYPE ); +} +This looks good to me.
Quoted 43 lines
target/riscv/cpu.c +1
-0+type_init (riscv_accel_cpu_register_type)tests/unit/test-multi-target.c +25
-0@@ -30,6 +30,28 @@/* stub for system/main.c */ int (*qemu_main)(void ); +static void test_accel_cpu_parent (const TargetInfo *ti) +{ +static const char *const needed[] = { +"arm-cpu" , +"i386-cpu" , +"powerpc-cpu" , +"powerpc64-cpu" , +"riscv-cpu" , +"x86_64-cpu" , + }; +size_t i; + g_autofree char *name = NULL; + +for (i =0 ; i <ARRAY_SIZE (needed); i++) { +if (g_str_equal (ti->cpu_type, needed[i])) { + name =g_strconcat ("accel-" , ti->cpu_type,NULL ); +g_assert_nonnull (object_class_by_name (name)); +return ; + } + } +} +static void test_qom_types_are_unique (const void *data) {const TargetInfo *ti = data;@@ -49,6 +71,9 @@ static void test_qom_types_are_unique(const void *data)module_call_init (MODULE_INIT_QOM );/* trigger type_initialize for all types */ object_class_get_list ("" , false); + +/* Accel parent lookup depends on the QOM types above being unique. */ +test_accel_cpu_parent (ti); }
Quoted 6 lines
tests/unit/test-multi-target.c static void test_qom_types_are_unique(const void *data) · line 79
Quoted 1 line
tests/unit/test-multi-target.c +0
-0int main (int argc,char **argv)This is not needed. When those targets will be added, it will already be tested by the existing logic instantiating all QOM types. That's fine to not cover that for i386/ppc until they are not part of multi target.
So we have no need to add tests for it, I'll drop it in the new version?
Quoted 3 lines
Thanks,
Pierrick
Signature · 6 lines
此致
礼
罗勇刚
Yours
sincerely,
Yonggang LuoRe: [PATCH v4 1/3] accel: register CPU parent only for AccelCPU subclasses
Quoted 196 lines · Yonggang Luo
Quoted 194 lines · Pierrick Bouvier
Quoted 137 lines · Yonggang Luo
accel_cpu_register_type()creates the abstract parent accel-<cpu type>. A subclass names that parent, andtype_initialize()aborts when the parent is missing. The oldtype_initregistered onlytarget_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.cparents 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 ownCPU_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. test-multi-target checks the parent only for the CPU types that register it.
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 ++++++++ tests/unit/test-multi-target.c | 25 +++++++++++++++++++++++++ 7 files changed, 43 insertions(+), 4 deletions(-)accel/accel-common.c +2
-4@@ -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); } - -type_init (register_accel_target_type);include/accel/accel-cpu.h +2
-0@@ -20,4 +20,6 @@ typedef struct AccelCPUClass { bool (*cpu_target_realize)(CPUState *cpu, Error **errp); } AccelCPUClass; +void accel_cpu_register_type (const char *cpu_type); +#endif /* ACCEL_CPU_H */ target/arm/cpu.c +2
-0@@ -28,6 +28,7 @@#include "qemu/module.h" #include "qapi/error.h" #include "cpu.h" +#include "accel/accel-cpu.h" #ifdef CONFIG_TCG #include "exec/translation-block.h" #include "accel/tcg/cpu-ops.h" @@ -2753,6 +2754,7 @@ static const TypeInfo arm_cpu_type_info = {static void arm_cpu_register_types (void ) { +accel_cpu_register_type (CPU_RESOLVING_TYPE );type_register_static (&arm_cpu_type_info); }target/i386/cpu.c +2
-0@@ -23,6 +23,7 @@#include "qemu/qemu-print.h" #include "qemu/hw-version.h" #include "cpu.h" +#include "accel/accel-cpu.h" #include "tcg/helper-tcg.h" #include "exec/translation-block.h" #include "system/hvf.h" @@ -11093,6 +11094,7 @@ static void x86_cpu_register_types(void) {int i; +accel_cpu_register_type (CPU_RESOLVING_TYPE );type_register_static (&x86_cpu_type_info);for (i =0 ; i <ARRAY_SIZE (builtin_x86_defs); i++) {x86_register_cpudef_types (&builtin_x86_defs[i]);target/ppc/cpu_init.c +2
-0@@ -43,6 +43,7 @@#include "exec/page-protection.h" #include "exec/watchpoint.h" #include "helper_regs.h" +#include "accel/accel-cpu.h" #include "internal.h" #include "spr_common.h" #include "power8-pmu.h" @@ -7589,6 +7590,7 @@ static const TypeInfo ppc_vhyp_type_info = {static void ppc_cpu_register_types (void ) { +accel_cpu_register_type (CPU_RESOLVING_TYPE );type_register_static (&ppc_cpu_type_info);#ifndef CONFIG_USER_ONLY type_register_static (&ppc_vhyp_type_info);target/riscv/cpu.c +1
-0@@ -25,6 +25,7 @@#include "qemu/guest-random.h" #include "qemu/atomic.h" #include "cpu.h" +#include "accel/accel-cpu.h" #include "cpu_vendorid.h" #include "target/riscv/tcg/csr.h" #include "internals.h" target/riscv/cpu.c static const TypeInfo riscv_cpu_type_infos[] = { · line 3940
Quoted 9 lines
target/riscv/cpu.c +6
-0@@ -3931,3 +3932,10 @@ static const TypeInfo riscv_cpu_type_infos[] = { };DEFINE_TYPES (riscv_cpu_type_infos) + +static void riscv_accel_cpu_register_type(void) +{ +accel_cpu_register_type (CPU_RESOLVING_TYPE ); +} +This looks good to me.
Quoted 43 lines
target/riscv/cpu.c +1
-0+type_init (riscv_accel_cpu_register_type)tests/unit/test-multi-target.c +25
-0@@ -30,6 +30,28 @@/* stub for system/main.c */ int (*qemu_main)(void ); +static void test_accel_cpu_parent (const TargetInfo *ti) +{ +static const char *const needed[] = { +"arm-cpu" , +"i386-cpu" , +"powerpc-cpu" , +"powerpc64-cpu" , +"riscv-cpu" , +"x86_64-cpu" , + }; +size_t i; + g_autofree char *name = NULL; + +for (i =0 ; i <ARRAY_SIZE (needed); i++) { +if (g_str_equal (ti->cpu_type, needed[i])) { + name =g_strconcat ("accel-" , ti->cpu_type,NULL ); +g_assert_nonnull (object_class_by_name (name)); +return ; + } + } +} +static void test_qom_types_are_unique (const void *data) {const TargetInfo *ti = data;@@ -49,6 +71,9 @@ static void test_qom_types_are_unique(const void *data)module_call_init (MODULE_INIT_QOM );/* trigger type_initialize for all types */ object_class_get_list ("" , false); + +/* Accel parent lookup depends on the QOM types above being unique. */ +test_accel_cpu_parent (ti); }
Quoted 9 lines
Quoted 6 lines
tests/unit/test-multi-target.c static void test_qom_types_are_unique(const void *data) · line 79
Quoted 1 line
tests/unit/test-multi-target.c +0
-0int main (int argc,char **argv)This is not needed. When those targets will be added, it will already be tested by the existing logic instantiating all QOM types. That's fine to not cover that for i386/ppc until they are not part of multi target.
So we have no need to add tests for it, I'll drop it in the new version?
Yes
Quoted 7 lines
Quoted 4 lines
Thanks,
Pierrick
PATCH v4 2/3 Revert "target/riscv/kvm: restrict kvm-accel-riscv-cpu to riscv targets"
In reply to Yonggang LuoThis 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
@@ -27,7 +27,6 @@#include "qapi/qapi-builtin-type-infos.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"
@@ -2241,7 +2240,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
Re: [PATCH v4 2/3] Revert "target/riscv/kvm: restrict kvm-accel-riscv-cpu to riscv targets"
Quoted 9 lines · Yonggang Luo
This is redundant now as all accel-$cpu_type parent is already registered.
This reverts commit
2d3e6b4003d5380c245ce8ffac4b8866f6d10a33.Signed-off-by Yonggang Luo <[email protected]>--- target/riscv/kvm/kvm-cpu.c | 2 -- 1 file changed, 2 deletions(-)
PATCH v4 3/3 Revert "target/riscv/tcg: restrict tcg-accel-riscv-cpu to riscv targets"
In reply to Yonggang LuoThis 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
@@ -1755,7 +1755,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
Re: [PATCH v4 3/3] Revert "target/riscv/tcg: restrict tcg-accel-riscv-cpu to riscv targets"
Quoted 9 lines · Yonggang Luo
This is redundant now as all accel-$cpu_type parent is already registered.
This reverts commit
ec65e16fd2ba012d57b1bbfcfcd04c31c4111924.Signed-off-by Yonggang Luo <[email protected]>--- target/riscv/tcg/tcg-cpu.c | 1 - 1 file changed, 1 deletion(-)