qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH RFC] accel: default to an actually available acceler


From: Cornelia Huck
Subject: [Qemu-devel] [PATCH RFC] accel: default to an actually available accelerator
Date: Wed, 6 Sep 2017 11:49:27 +0200

configure_accelerator() falls back to tcg if no accelerator has
been specified. Formerly, we could be sure that tcg is always
available; however, with --disable-tcg, this is not longer true,
and you are not able to start qemu without explicitly specifying
another accelerator on those builds.

Instead, choose an accelerator in the order tcg->kvm->xen->hax.

Signed-off-by: Cornelia Huck <address@hidden>
---

RFC mainly because this breaks iotest 186 in a different way on a
tcg-less x86_64 build: Before, it fails with "-machine accel=tcg: No
accelerator found"; afterwards, there seems to be a difference in
output due to different autogenerated devices. Not sure how to handle
that.

cc:ing some hopefully interested folks (-ENOMAINTAINER again).

---
 accel/accel.c              | 22 ++++++++++++++++++++--
 arch_init.c                | 17 +++++++++++++++++
 include/sysemu/arch_init.h |  2 ++
 qemu-options.hx            |  6 ++++--
 4 files changed, 43 insertions(+), 4 deletions(-)

diff --git a/accel/accel.c b/accel/accel.c
index 8ae40e1e13..26a3f32627 100644
--- a/accel/accel.c
+++ b/accel/accel.c
@@ -68,6 +68,25 @@ static int accel_init_machine(AccelClass *acc, MachineState 
*ms)
     return ret;
 }
 
+static const char *default_accelerator(void)
+{
+    if (tcg_available()) {
+        return "tcg";
+    }
+    if (kvm_available()) {
+        return "kvm";
+    }
+    if (xen_available()) {
+        return "xen";
+    }
+    if (hax_available()) {
+        return "hax";
+    }
+    /* configure makes sure we have at least one accelerator */
+    g_assert(false);
+    return "";
+}
+
 void configure_accelerator(MachineState *ms)
 {
     const char *accel, *p;
@@ -79,8 +98,7 @@ void configure_accelerator(MachineState *ms)
 
     accel = qemu_opt_get(qemu_get_machine_opts(), "accel");
     if (accel == NULL) {
-        /* Use the default "accelerator", tcg */
-        accel = "tcg";
+        accel = default_accelerator();
     }
 
     p = accel;
diff --git a/arch_init.c b/arch_init.c
index a0b8ed6167..1d84eca14d 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -103,6 +103,23 @@ int xen_available(void)
 #endif
 }
 
+int tcg_available(void)
+{
+#ifdef CONFIG_TCG
+    return 1;
+#else
+    return 0;
+#endif
+}
+
+int hax_available(void)
+{
+#ifdef CONFIG_HAX
+    return 1;
+#else
+    return 0;
+#endif
+}
 
 TargetInfo *qmp_query_target(Error **errp)
 {
diff --git a/include/sysemu/arch_init.h b/include/sysemu/arch_init.h
index 8751c468ed..43e515c233 100644
--- a/include/sysemu/arch_init.h
+++ b/include/sysemu/arch_init.h
@@ -30,6 +30,8 @@ extern const uint32_t arch_type;
 
 int kvm_available(void);
 int xen_available(void);
+int tcg_available(void);
+int hax_available(void);
 
 CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp);
 CpuModelExpansionInfo *arch_query_cpu_model_expansion(CpuModelExpansionType 
type,
diff --git a/qemu-options.hx b/qemu-options.hx
index 9f6e2adfff..386e6e945d 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -66,7 +66,8 @@ Supported machine properties are:
 @table @option
 @item address@hidden:@var{accels2}[:...]]
 This is used to enable an accelerator. Depending on the target architecture,
-kvm, xen, hax or tcg can be available. By default, tcg is used. If there is
+kvm, xen, hax or tcg can be available. By default, the first one available
+out of tcg, kvm, xen, hax (in that order) is used. If there is
 more than one accelerator specified, the next one is used if the previous one
 fails to initialize.
 @item kernel_irqchip=on|off
@@ -126,7 +127,8 @@ STEXI
 @item -accel @var{name}[,address@hidden,...]]
 @findex -accel
 This is used to enable an accelerator. Depending on the target architecture,
-kvm, xen, hax or tcg can be available. By default, tcg is used. If there is
+kvm, xen, hax or tcg can be available. By default, the first one available
+out of tcg, kvm, xen, hax (in that order) is used. If there is
 more than one accelerator specified, the next one is used if the previous one
 fails to initialize.
 @table @option
-- 
2.13.5




reply via email to

[Prev in Thread] Current Thread [Next in Thread]