Skip to contentSkip to conversation

accel: Improve selection of the default accelerator

PATCH In review Thomas Huth 7 participants 18 messages Oct 5, 2018 – Oct 10, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 accel: Improve selection of the default accelerator

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.

---
 accel/accel.c          | 18 +++++++++++++++---
 include/sysemu/accel.h |  2 +-
 vl.c                   |  2 +-
 3 files changed, 17 insertions(+), 5 deletions(-)
accel/accel.c +15 -3
index 966b2d8..9be195c 100644
@@ -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);
include/sysemu/accel.h +1 -1
index 637358f..285899e 100644
@@ -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) */
vl.c +1 -1
index 0388852..757246a 100644
@@ -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",
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 7 lines · On Fri, 5 Oct 2018 16:13:12 +0200 Thomas Huth <[email protected]> wrote:

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.

Heh, we haven't had that discussion for some time ;)

Quoted 22 lines
---
 accel/accel.c          | 18 +++++++++++++++---
 include/sysemu/accel.h |  2 +-
 vl.c                   |  2 +-
 3 files changed, 17 insertions(+), 5 deletions(-)
accel/accel.c +1 -1
index 966b2d8..9be195c 100644
@@ -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;

accel/accel.c void configure_accelerator(MachineState *ms) · line 86

Quoted 10 lines
accel/accel.c +5 -2
@@ -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";

Ends, or also starts?

(In general, that approach probably makes more sense than the current default.)

accel/accel.c void configure_accelerator(MachineState *ms) · line 93

Quoted 7 lines
accel/accel.c +7 -0
+        } else {
+#if defined(CONFIG_TCG)
+            accel = "tcg";
+#elif defined(CONFIG_KVM)
+            accel = "kvm";
+#else
+#error "No default accelerator available"

So, we can't configure a qemu with neither tcg nor kvm, but for example with hax or xen? (Is that possible today?)

accel/accel.c void configure_accelerator(MachineState *ms) · line 98

Quoted 5 lines
accel/accel.c +2 -0
+#endif
+        }
     }
 
     accel_list = g_strsplit(accel, ":", 0);

ISTR that we had a suggestion last time that we should provide qemu-kvm, qemu-tcg, etc. binaries...

#2 lore raw
Quoted 2 lines · Cornelia Huck

ISTR that we had a suggestion last time that we should provide qemu-kvm, qemu-tcg, etc. binaries...

That should shave off at least 0.1% from the length of the typical QEMU command line :-)

thanks
-- PMM

#3 lore raw
In reply to Cornelia Huck
Quoted 6 lines · Cornelia Huck
Quoted 4 lines

+ }

     }
 
     accel_list = g_strsplit(accel, ":", 0);

ISTR that we had a suggestion last time that we should provide qemu-kvm, qemu-tcg, etc. binaries...

Not qemu-tcg, as that would be qemu-system-*, but yes that was my suggestion. Compared to it, Thomas's patch provides almost the same benefit and has the big advantage of existing.

Paolo

#4 lore raw
In reply to Thomas Huth
Quoted 2 lines · Thomas Huth

When compiling with "--disable-tcg", we currently still use "tcg" as default accelerator. "kvm" should be used in this case instead.

This part is non-controversial and makes good sense.

Quoted 5 lines

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.

This part is much riskier and less clearly a good plan -- do we really want our behaviour to vary based on the name of the executable? Distros who want that sort of qemu-kvm wrapper generally are providing it already (the Ubuntu one is a 2-line shell script).

thanks
-- PMM

#5 lore raw
Quoted 5 lines · Peter Maydell
Quoted 2 lines · Thomas Huth

When compiling with "--disable-tcg", we currently still use "tcg" as default accelerator. "kvm" should be used in this case instead.

This part is non-controversial and makes good sense.

Though it probably should be extended to "whpx" and "hvf" (probably "xen" too if !CONFIG_KVM).

Quoted 11 lines
Quoted 5 lines

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.

This part is much riskier and less clearly a good plan -- do we really want our behaviour to vary based on the name of the executable? Distros who want that sort of qemu-kvm wrapper generally are providing it already (the Ubuntu one is a 2-line shell script).

I think it makes sense. At least RHEL has qemu-kvm but no qemu-system-x86_64, so it has a non-upstream patch to change the accelerator; for other distros there are two benefits:

1) now: they could switch to a symlink

2) later: right now, "-accel kvm:tcg" works but we should instead switch that to "-accel kvm -accel tcg", and deprecate "-M accel=kvm:tcg" (which doesn't let you specify accelerator options).

I don't really like second guessing based on argv[0], because argv[0] can actually be spoofed by the exec-ing program. One idea could be to pick the "best" KVM-enabled emulator that we can build, and also install it as qemu-kvm with some magic to flip the default to kvm:tcg. But that can be done later; something like Thomas's patch is nice to have, and good enough.

Paolo

#6 lore raw
Quoted 9 lines · Paolo Bonzini
Quoted 5 lines · Peter Maydell
Quoted 2 lines · Thomas Huth

When compiling with "--disable-tcg", we currently still use "tcg" as default accelerator. "kvm" should be used in this case instead.

This part is non-controversial and makes good sense.

Though it probably should be extended to "whpx" and "hvf" (probably "xen" too if !CONFIG_KVM).

Sure, I was just unsure whether anybody has ever tried to compile with --disable-tcg and --disable-kvm and use one of those accelerators instead? Does it work?

Quoted 12 lines
Quoted 11 lines
Quoted 5 lines

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.

This part is much riskier and less clearly a good plan -- do we really want our behaviour to vary based on the name of the executable? Distros who want that sort of qemu-kvm wrapper generally are providing it already (the Ubuntu one is a 2-line shell script).

Quoted 5 lines

I think it makes sense. At least RHEL has qemu-kvm but no qemu-system-x86_64, so it has a non-upstream patch to change the accelerator; for other distros there are two benefits:

1) now: they could switch to a symlink

Right, I think it's a good idea to avoid wrapper scripts - there is less chance to get things wrong in this case.

Thomas

#7 lore raw
In reply to Peter Maydell
Quoted 5 lines · Peter Maydell
Quoted 2 lines · Thomas Huth

When compiling with "--disable-tcg", we currently still use "tcg" as default accelerator. "kvm" should be used in this case instead.

This part is non-controversial and makes good sense.

Agreed.

Quoted 11 lines
Quoted 5 lines

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.

This part is much riskier and less clearly a good plan -- do we really want our behaviour to vary based on the name of the executable? Distros who want that sort of qemu-kvm wrapper generally are providing it already (the Ubuntu one is a 2-line shell script).

I hate it when argv[0] affects behavior[*]. I hate shell wrappers less.

If a system provides just one qemu executable, and its default accelerator should be something other than tcg:kvm, then there's a use for making it compile-time configurable. Reading the default from /etc/ would also work. Not sure such a system exists.

[*] Go document the behavior with proper precision, and you might come to share the feeling.

#8 lore raw
Quoted 22 lines · Markus Armbruster
Quoted 5 lines · Peter Maydell
Quoted 2 lines · Thomas Huth

When compiling with "--disable-tcg", we currently still use "tcg" as default accelerator. "kvm" should be used in this case instead.

This part is non-controversial and makes good sense.

Agreed.

Quoted 11 lines
Quoted 5 lines

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.

This part is much riskier and less clearly a good plan -- do we really want our behaviour to vary based on the name of the executable? Distros who want that sort of qemu-kvm wrapper generally are providing it already (the Ubuntu one is a 2-line shell script).

Quoted 4 lines

I hate it when argv[0] affects behavior[*]. I hate shell wrappers less.

If a system provides just one qemu executable, and its default accelerator should be something other than tcg:kvm, then there's a use

Correction: "other than tcg". See configure_accelerator().

Remind me, why is "tcg" a good default?

Quoted 7 lines

for making it compile-time configurable. Reading the default from /etc/ would also work. Not sure such a system exists.

[*] Go document the behavior with proper precision, and you might come to share the feeling.

#9 lore raw
Quoted 24 lines · Markus Armbruster
Quoted 22 lines · Markus Armbruster
Quoted 5 lines · Peter Maydell
Quoted 2 lines · Thomas Huth

When compiling with "--disable-tcg", we currently still use "tcg" as default accelerator. "kvm" should be used in this case instead.

This part is non-controversial and makes good sense.

Agreed.

Quoted 11 lines
Quoted 5 lines

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.

This part is much riskier and less clearly a good plan -- do we really want our behaviour to vary based on the name of the executable? Distros who want that sort of qemu-kvm wrapper generally are providing it already (the Ubuntu one is a 2-line shell script).

Quoted 8 lines
Quoted 4 lines

I hate it when argv[0] affects behavior[*]. I hate shell wrappers less.

If a system provides just one qemu executable, and its default accelerator should be something other than tcg:kvm, then there's a use

Correction: "other than tcg". See configure_accelerator().

Remind me, why is "tcg" a good default?

"It's been always like this and we're keen on backward compatibility" ?

Thomas

#10 lore raw
In reply to Markus Armbruster
Quoted 24 lines · Markus Armbruster
Quoted 22 lines · Markus Armbruster
Quoted 5 lines · Peter Maydell
Quoted 2 lines · Thomas Huth

When compiling with "--disable-tcg", we currently still use "tcg" as default accelerator. "kvm" should be used in this case instead.

This part is non-controversial and makes good sense.

Agreed.

Quoted 11 lines
Quoted 5 lines

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.

This part is much riskier and less clearly a good plan -- do we really want our behaviour to vary based on the name of the executable? Distros who want that sort of qemu-kvm wrapper generally are providing it already (the Ubuntu one is a 2-line shell script).

Quoted 8 lines
Quoted 4 lines

I hate it when argv[0] affects behavior[*]. I hate shell wrappers less.

If a system provides just one qemu executable, and its default accelerator should be something other than tcg:kvm, then there's a use

Correction: "other than tcg". See configure_accelerator().

Remind me, why is "tcg" a good default?

Note that when libvirt is driving QEMU, the default is not used. Libvirt will always explicitly ask for either KVM or TCG. Libvirt reports whether each host supports TCG or KVM or both, and management applications will look at this and usually pick KVM, only use TCG if KVM isn't there.

IOW, most users of libvirt have effectively had the behaviour of '-accel kvm:tcg' for years. Only direct users of QEMU have suffered from '-accel tcg:kvm'.

The only time we've had trouble with this is with buggy nested virt implementations, which expose /dev/kvm but then crash & burn when it is used. I don't think that's an argument against prioritizing KVM though. Its an argument for not exposing broken nested virt to VMs.

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#11 lore raw
In reply to Markus Armbruster
Quoted 24 lines · On Tue, 09 Oct 2018 15:14:59 +0200 Markus Armbruster <[email protected]> wrote:
Quoted 22 lines · Markus Armbruster
Quoted 5 lines · Peter Maydell
Quoted 2 lines · Thomas Huth

When compiling with "--disable-tcg", we currently still use "tcg" as default accelerator. "kvm" should be used in this case instead.

This part is non-controversial and makes good sense.

Agreed.

Quoted 11 lines
Quoted 5 lines

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.

This part is much riskier and less clearly a good plan -- do we really want our behaviour to vary based on the name of the executable? Distros who want that sort of qemu-kvm wrapper generally are providing it already (the Ubuntu one is a 2-line shell script).

Quoted 8 lines
Quoted 4 lines

I hate it when argv[0] affects behavior[*]. I hate shell wrappers less.

If a system provides just one qemu executable, and its default accelerator should be something other than tcg:kvm, then there's a use

Correction: "other than tcg". See configure_accelerator().

Remind me, why is "tcg" a good default?

I'm not sure why a single accelerator (any of them) would be a good default. A list (tcg:kvm:<whatever>) sounds much saner, as it would continue to work even if some accelerators have been disabled (right?)

(And I'd prefer kvm to be first in that list; anything that relies on tcg being used should specify it explicitly... a normal user will likely always want the fast variant.)

Quoted 3 lines
Quoted 3 lines

for making it compile-time configurable. Reading the default from /etc/ would also work. Not sure such a system exists.

Or making it overrideable like that.

Quoted 6 lines
Quoted 5 lines

[*] Go document the behavior with proper precision, and you might come to share the feeling.

#12 lore raw
Quoted 7 lines · Cornelia Huck

I'm not sure why a single accelerator (any of them) would be a good default. A list (tcg:kvm:<whatever>) sounds much saner, as it would continue to work even if some accelerators have been disabled (right?)

(And I'd prefer kvm to be first in that list; anything that relies on tcg being used should specify it explicitly... a normal user will likely always want the fast variant.)

tcg should be the default for binaries without KVM compiled in, of course... But as Thomas points out, the reason for our current default is the usual "because we tend not to change things that would break existing working command lines".

thanks
-- PMM

#13 lore raw
Quoted 5 lines · Peter Maydell
Quoted 4 lines · Cornelia Huck

I'm not sure why a single accelerator (any of them) would be a good default. A list (tcg:kvm:<whatever>) sounds much saner, as it would continue to work even if some accelerators have been disabled (right?)

Quoted 8 lines
Quoted 3 lines

(And I'd prefer kvm to be first in that list; anything that relies on tcg being used should specify it explicitly... a normal user will likely always want the fast variant.)

tcg should be the default for binaries without KVM compiled in, of course... But as Thomas points out, the reason for our current default is the usual "because we tend not to change things that would break existing working command lines".

Putting KVM first shouldn't break existing working command lines in general.

If user doesn't have KVM it won't have any impact as it'll still fallback to TCG. If user does have KVM, their VMs will be faster.

It could conceivably break if

- TCG had some different behaviour to KVM that
the guest relied upon (we should fix such differences)
- KVM kmod was buggy (eg broken nested virt, again should be something we fix)
- If the guest OS relied on things being slow (that's already fragile)

IMHO we should assume that TCG & KVM are functionally equivalent and non-broken, and thus changing default accelerator should not be considered an incompatible change.

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#14 lore raw
Quoted 10 lines · Daniel P. Berrangé
Quoted 9 lines · Peter Maydell
Quoted 7 lines · Cornelia Huck

I'm not sure why a single accelerator (any of them) would be a good default. A list (tcg:kvm:<whatever>) sounds much saner, as it would continue to work even if some accelerators have been disabled (right?)

(And I'd prefer kvm to be first in that list; anything that relies on tcg being used should specify it explicitly... a normal user will likely always want the fast variant.)

Quoted 7 lines
Quoted 4 lines

tcg should be the default for binaries without KVM compiled in, of course... But as Thomas points out, the reason for our current default is the usual "because we tend not to change things that would break existing working command lines".

Putting KVM first shouldn't break existing working command lines in general.

There are ARM QEMU command lines which will fail with KVM and work with TCG (eg ones which use -cpu something-other-than-host or which ask for a GICv3 when the host has only a GICv2). These are basically cases where KVM can't provide features that TCG can. I imagine other archs like power have similar.

thanks
-- PMM

#15 lore raw
Quoted 16 lines · On Tue, 9 Oct 2018 15:34:22 +0100 Peter Maydell <[email protected]>…
Quoted 15 lines · Daniel P. Berrangé
Quoted 13 lines · Peter Maydell
Quoted 7 lines · Cornelia Huck

I'm not sure why a single accelerator (any of them) would be a good default. A list (tcg:kvm:<whatever>) sounds much saner, as it would continue to work even if some accelerators have been disabled (right?)

(And I'd prefer kvm to be first in that list; anything that relies on tcg being used should specify it explicitly... a normal user will likely always want the fast variant.)

tcg should be the default for binaries without KVM compiled in, of course... But as Thomas points out, the reason for our current default is the usual "because we tend not to change things that would break existing working command lines".

Quoted 8 lines
Quoted 2 lines

Putting KVM first shouldn't break existing working command lines in general.

There are ARM QEMU command lines which will fail with KVM and work with TCG (eg ones which use -cpu something-other-than-host or which ask for a GICv3 when the host has only a GICv2). These are basically cases where KVM can't provide features that TCG can. I imagine other archs like power have similar.

Well, on s390x there are (newer) cpu models that we don't support with tcg but that work fine with kvm on a new-enough host... so I'm not sure whether we can assume that any given accelerator supports the same set of cpu models.

It feels like we're doomed whatever we decide to do :/

#16 lore raw
In reply to Daniel P. Berrangé
Quoted 8 lines · Daniel P. Berrangé
Quoted 8 lines
Quoted 4 lines

(And I'd prefer kvm to be first in that list; anything that relies on tcg being used should specify it explicitly... a normal user will likely always want the fast variant.)

tcg should be the default for binaries without KVM compiled in, of course... But as Thomas points out, the reason for our current default is the usual "because we tend not to change things that would break existing working command lines".

... and because we rely on people that want KVM using almost always the distro qemu-kvm.

Quoted 10 lines

Putting KVM first shouldn't break existing working command lines in general.

If user doesn't have KVM it won't have any impact as it'll still fallback to TCG. If user does have KVM, their VMs will be faster.

It could conceivably break if

- TCG had some different behaviour to KVM that the guest relied upon (we should fix such differences)

TCG can emulate stuff that doesn't exist in the host processor (e.g. MPX, PKRU, and on older processors SMEP/SMAP though those should be ubiquitous). There are (or were) CI systems for the kernel that were using it that way.

Paolo

Quoted 8 lines

- KVM kmod was buggy (eg broken nested virt, again should be something we fix)
- If the guest OS relied on things being slow (that's already fragile)

IMHO we should assume that TCG & KVM are functionally equivalent and non-broken, and thus changing default accelerator should not be considered an incompatible change.

#17 lore raw
In reply to Thomas Huth
Quoted 32 lines · Thomas Huth

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.

---
 accel/accel.c          | 18 +++++++++++++++---
 include/sysemu/accel.h |  2 +-
 vl.c                   |  2 +-
 3 files changed, 17 insertions(+), 5 deletions(-)
accel/accel.c +1 -1
index 966b2d8..9be195c 100644
@@ -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) {

accel/accel.c void configure_accelerator(MachineState *ms) · line 89

Quoted 10 lines
accel/accel.c +8 -2
-        /* 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";

OK until here.

accel/accel.c void configure_accelerator(MachineState *ms) · line 91

Quoted 2 lines
accel/accel.c +2 -0
+#elif defined(CONFIG_KVM)
+            accel = "kvm";

I'm not sure "kvm" here is necessary.

Quoted 34 lines
accel/accel.c +4 -0
+#else
+#error "No default accelerator available"
+#endif
+        }
     }
 
     accel_list = g_strsplit(accel, ":", 0);
include/sysemu/accel.h +1 -1
index 637358f..285899e 100644
@@ -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) */
vl.c +1 -1
index 0388852..757246a 100644
@@ -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",