From nobody Thu Nov 6 01:27:57 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1538748904806980.6465907151588; Fri, 5 Oct 2018 07:15:04 -0700 (PDT) Received: from localhost ([::1]:35384 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g8QsY-0002tP-5g for importer@patchew.org; Fri, 05 Oct 2018 10:14:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:32925) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g8QrH-0001qv-7j for qemu-devel@nongnu.org; Fri, 05 Oct 2018 10:13:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g8QrD-0005th-Nw for qemu-devel@nongnu.org; Fri, 05 Oct 2018 10:13:34 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47254) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g8Qr4-0005i4-If for qemu-devel@nongnu.org; Fri, 05 Oct 2018 10:13:25 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CA40830820DB for ; Fri, 5 Oct 2018 14:13:17 +0000 (UTC) Received: from thuth.com (dhcp-200-199.str.redhat.com [10.33.200.199]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2BA9D5D9C8; Fri, 5 Oct 2018 14:13:16 +0000 (UTC) From: Thomas Huth To: Paolo Bonzini Date: Fri, 5 Oct 2018 16:13:12 +0200 Message-Id: <1538748792-19444-1-git-send-email-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Fri, 05 Oct 2018 14:13:17 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH] accel: Improve selection of the default accelerator X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 --- 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, MachineSta= te *ms) return ret; } =20 -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) =20 accel =3D qemu_opt_get(qemu_get_machine_opts(), "accel"); if (accel =3D=3D NULL) { - /* Use the default "accelerator", tcg */ - accel =3D "tcg"; + /* Select the default accelerator */ + int pnlen =3D strlen(progname); + if (pnlen >=3D 3 && g_str_equal(&progname[pnlen - 3], "kvm")) { + /* If the program name ends with "kvm", we prefer KVM */ + accel =3D "kvm:tcg"; + } else { +#if defined(CONFIG_TCG) + accel =3D "tcg"; +#elif defined(CONFIG_KVM) + accel =3D "kvm"; +#else +#error "No default accelerator available" +#endif + } } =20 accel_list =3D 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 { =20 extern unsigned long tcg_tb_size; =20 -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); } =20 - configure_accelerator(current_machine); + configure_accelerator(current_machine, argv[0]); =20 if (!qtest_enabled() && machine_class->deprecation_reason) { error_report("Machine type '%s' is deprecated: %s", --=20 1.8.3.1