All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] accel: Improve selection of the default accelerator
@ 2018-10-05 14:13 Thomas Huth
  2018-10-05 14:22 ` Peter Maydell
                   ` (2 more replies)
  0 siblings, 3 replies; 18+ messages in thread
From: Thomas Huth @ 2018-10-05 14:13 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: qemu-devel

When compiling with "--disable-tcg", we currently still use "tcg"
as default accelerator. "kvm" should be used in this case instead.
Also, some downstream distros provide QEMU binaries which have "kvm"
in their names (e.g. "qemu-kvm" on RHEL or "kvm" on Ubuntu) that use
KVM by default - and some users might want to do something similar
with upstream binaries, too. Accomodate them by using "kvm:tcg" as
default when we detect such a binary name.

Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 accel/accel.c          | 18 +++++++++++++++---
 include/sysemu/accel.h |  2 +-
 vl.c                   |  2 +-
 3 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/accel/accel.c b/accel/accel.c
index 966b2d8..9be195c 100644
--- a/accel/accel.c
+++ b/accel/accel.c
@@ -68,7 +68,7 @@ static int accel_init_machine(AccelClass *acc, MachineState *ms)
     return ret;
 }
 
-void configure_accelerator(MachineState *ms)
+void configure_accelerator(MachineState *ms, const char *progname)
 {
     const char *accel;
     char **accel_list, **tmp;
@@ -79,8 +79,20 @@ void configure_accelerator(MachineState *ms)
 
     accel = qemu_opt_get(qemu_get_machine_opts(), "accel");
     if (accel == NULL) {
-        /* Use the default "accelerator", tcg */
-        accel = "tcg";
+        /* Select the default accelerator */
+        int pnlen = strlen(progname);
+        if (pnlen >= 3 && g_str_equal(&progname[pnlen - 3], "kvm")) {
+            /* If the program name ends with "kvm", we prefer KVM */
+            accel = "kvm:tcg";
+        } else {
+#if defined(CONFIG_TCG)
+            accel = "tcg";
+#elif defined(CONFIG_KVM)
+            accel = "kvm";
+#else
+#error "No default accelerator available"
+#endif
+        }
     }
 
     accel_list = g_strsplit(accel, ":", 0);
diff --git a/include/sysemu/accel.h b/include/sysemu/accel.h
index 637358f..285899e 100644
--- a/include/sysemu/accel.h
+++ b/include/sysemu/accel.h
@@ -66,7 +66,7 @@ typedef struct AccelClass {
 
 extern unsigned long tcg_tb_size;
 
-void configure_accelerator(MachineState *ms);
+void configure_accelerator(MachineState *ms, const char *progname);
 /* Register accelerator specific global properties */
 void accel_register_compat_props(AccelState *accel);
 /* Called just before os_setup_post (ie just before drop OS privs) */
diff --git a/vl.c b/vl.c
index 0388852..757246a 100644
--- a/vl.c
+++ b/vl.c
@@ -4220,7 +4220,7 @@ int main(int argc, char **argv, char **envp)
         exit(1);
     }
 
-    configure_accelerator(current_machine);
+    configure_accelerator(current_machine, argv[0]);
 
     if (!qtest_enabled() && machine_class->deprecation_reason) {
         error_report("Machine type '%s' is deprecated: %s",
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2018-10-10  8:02 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-05 14:13 [Qemu-devel] [PATCH] accel: Improve selection of the default accelerator Thomas Huth
2018-10-05 14:22 ` Peter Maydell
2018-10-05 21:12   ` Paolo Bonzini
2018-10-10  8:02     ` Thomas Huth
2018-10-09  9:05   ` Markus Armbruster
2018-10-09 13:14     ` Markus Armbruster
2018-10-09 13:23       ` Thomas Huth
2018-10-09 13:41       ` Daniel P. Berrangé
2018-10-09 13:43       ` Cornelia Huck
2018-10-09 13:58         ` Peter Maydell
2018-10-09 14:23           ` Daniel P. Berrangé
2018-10-09 14:34             ` Peter Maydell
2018-10-09 15:06               ` Cornelia Huck
2018-10-09 15:35             ` Paolo Bonzini
2018-10-05 14:30 ` Cornelia Huck
2018-10-05 14:40   ` Peter Maydell
2018-10-05 21:13   ` Paolo Bonzini
2018-10-05 14:39 ` Philippe Mathieu-Daudé

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.