Now we need use the prepared target-list to register different accel-$cpu_type parent QOM type. So that multi-target won't error missing parent for different accel for different arch.
Also add a test for it in test-multi-target.c Signed-off-by: Yonggang Luo <[email protected]> --- accel/accel-common.c | 6 ++---- accel/accel-internal.h | 1 + accel/accel-system.c | 24 ++++++++++++++++++++++++ accel/accel-user.c | 7 +++++++ tests/unit/test-multi-target.c | 15 +++++++++++++++ 5 files changed, 49 insertions(+), 4 deletions(-) diff --git a/accel/accel-common.c b/accel/accel-common.c index 00a400243f0..0f4e202d8f8 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_register_cpu_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); diff --git a/accel/accel-internal.h b/accel/accel-internal.h index d3a4422cbf7..2b6f58526d3 100644 --- a/accel/accel-internal.h +++ b/accel/accel-internal.h @@ -13,5 +13,6 @@ #include "qemu/accel.h" void accel_init_ops_interfaces(AccelClass *ac); +void accel_register_cpu_type(const char *cpu_type); #endif /* ACCEL_SYSTEM_H */ diff --git a/accel/accel-system.c b/accel/accel-system.c index 1325b23864c..fdfa85179ee 100644 --- a/accel/accel-system.c +++ b/accel/accel-system.c @@ -25,6 +25,8 @@ #include "qemu/osdep.h" #include "qemu/accel.h" +#include "qemu/target-info-def.h" +#include "qemu/target-info-qom.h" #include "qom/compat-properties.h" #include "qapi/qapi-commands-accelerator.h" #include "monitor/monitor.h" @@ -32,6 +34,7 @@ #include "hw/core/boards.h" #include "hw/core/cpu.h" #include "accel/accel-ops.h" +#include "accel/accel-cpu.h" #include "accel/accel-cpu-ops.h" #include "system/cpus.h" #include "qemu/error-report.h" @@ -124,6 +127,27 @@ static const TypeInfo accel_ops_type_info = { static void accel_system_register_types(void) { + GSList *targets = target_info_qom_get_targets(); + const TargetInfo *ti, *prev_ti; + type_register_static(&accel_ops_type_info); + + for (GSList *l = targets; l; l = l->next) { + bool duplicate = false; + + ti = TARGET_INFO_CLASS(l->data)->target_info; + for (GSList *prev = targets; prev != l; prev = prev->next) { + prev_ti = TARGET_INFO_CLASS(prev->data)->target_info; + if (g_str_equal(prev_ti->cpu_type, ti->cpu_type)) { + duplicate = true; + break; + } + } + if (duplicate) { + continue; + } + + accel_register_cpu_type(ti->cpu_type); + } } type_init(accel_system_register_types); diff --git a/accel/accel-user.c b/accel/accel-user.c index 7d192306a65..85ede70e5bd 100644 --- a/accel/accel-user.c +++ b/accel/accel-user.c @@ -9,8 +9,15 @@ #include "qemu/osdep.h" #include "qemu/accel.h" +#include "qemu/target-info.h" #include "accel-internal.h" +static void register_accel_target_type(void) +{ + accel_register_cpu_type(target_cpu_type()); +} +type_init(register_accel_target_type); + void accel_init_ops_interfaces(AccelClass *ac) { /* nothing */ diff --git a/tests/unit/test-multi-target.c b/tests/unit/test-multi-target.c index c2922e0fed5..704e3297ef9 100644 --- a/tests/unit/test-multi-target.c +++ b/tests/unit/test-multi-target.c @@ -17,6 +17,7 @@ #include "qemu/base-arch-defs.h" #include "qemu/module.h" #include "qemu/target-info.h" +#include "qemu/target-info-def.h" #include "qemu/target-info-qom.h" #include "qom/object.h" @@ -70,6 +71,18 @@ static void test_machine_targets(void) } } +static void test_accel_cpu_parent_per_target(void) +{ + g_assert(targets); + + for (GSList *l = targets; l; l = l->next) { + const TargetInfo *ti = TARGET_INFO_CLASS(l->data)->target_info; + g_autofree char *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); @@ -86,5 +99,7 @@ int main(int argc, char **argv) test_qom_types_are_unique); g_test_add_func("/multi-targets/machine-targets", test_machine_targets); + g_test_add_func("/multi-targets/accel-cpu-parent-per-target", + test_accel_cpu_parent_per_target); return g_test_run(); } -- 2.55.0.windows.3
