Split configure_accelerators into a first function (still named configure_accelerators) that loops and chooses the first accelerator for which preinit succeeds, and a second function create_accelerator which calls machine_init on the chosen accelerator.
configure_accelerators can be called without knowing any machine properties. create_accelerator cannot be called until the machine properties are defined. For now call them at the same place, so no functional change. Signed-off-by: Steve Sistare <steven.sist...@oracle.com> --- accel/accel-system.c | 6 ------ system/vl.c | 27 +++++++++++++++++++++------ 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/accel/accel-system.c b/accel/accel-system.c index fef6625..f6c947d 100644 --- a/accel/accel-system.c +++ b/accel/accel-system.c @@ -36,14 +36,8 @@ int accel_init_machine(AccelState *accel, MachineState *ms) int ret; ms->accelerator = accel; *(acc->allowed) = true; - ret = acc->preinit(accel); - if (ret < 0) { - goto fail; - } - ret = acc->init_machine(ms); if (ret < 0) { -fail: ms->accelerator = NULL; *(acc->allowed) = false; object_unref(OBJECT(accel)); diff --git a/system/vl.c b/system/vl.c index 8b345dd..b94a6b9 100644 --- a/system/vl.c +++ b/system/vl.c @@ -182,6 +182,7 @@ static const char *log_file; static bool list_data_dirs; static const char *qtest_chrdev; static const char *qtest_log; +static AccelState *accel; static int has_defaults = 1; static int default_audio = 1; @@ -2337,7 +2338,7 @@ static int do_configure_accelerator(void *opaque, QemuOpts *opts, Error **errp) accel, &error_fatal); - ret = accel_init_machine(accel, current_machine); + ret = ac->preinit ? ac->preinit(accel) : 0; if (ret < 0) { if (!qtest_with_kvm || ret != -ENOENT) { error_report("failed to initialize %s: %s", acc, strerror(-ret)); @@ -2353,13 +2354,10 @@ bad: return 0; } -static void configure_accelerators(const char *progname) +static AccelState *configure_accelerators(const char *progname) { AccelSearch acs = {0}; - qemu_opts_foreach(qemu_find_opts("icount"), - do_configure_icount, NULL, &error_fatal); - if (QTAILQ_EMPTY(&qemu_accel_opts.head)) { char **accel_list, **tmp; @@ -2418,6 +2416,22 @@ static void configure_accelerators(const char *progname) if (acs.init_failed && !qtest_chrdev) { error_report("falling back to %s", ACCEL_GET_CLASS(acs.accel)->name); } + return acs.accel; +} + +static void create_accelerator(AccelState *accel) +{ + int ret; + + qemu_opts_foreach(qemu_find_opts("icount"), + do_configure_icount, NULL, &error_fatal); + + ret = accel_init_machine(accel, current_machine); + if (ret < 0) { + error_report("failed to initialize %s: %s", + ACCEL_GET_CLASS(accel)->name, strerror(-ret)); + exit(1); + } if (icount_enabled() && !tcg_enabled()) { error_report("-icount is not allowed with hardware virtualization"); @@ -3731,7 +3745,8 @@ void qemu_init(int argc, char **argv) * Note: uses machine properties such as kernel-irqchip, must run * after qemu_apply_machine_options. */ - configure_accelerators(argv[0]); + accel = configure_accelerators(argv[0]); + create_accelerator(accel); phase_advance(PHASE_ACCEL_CREATED); /* -- 1.8.3.1