From nobody Mon May 6 16:03:42 2024 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1504691466903185.2232164356475; Wed, 6 Sep 2017 02:51:06 -0700 (PDT) Received: from localhost ([::1]:35205 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dpWzB-0002Ir-QD for importer@patchew.org; Wed, 06 Sep 2017 05:51:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47841) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dpWxl-0001a3-Te for qemu-devel@nongnu.org; Wed, 06 Sep 2017 05:49:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dpWxi-0008Gt-R1 for qemu-devel@nongnu.org; Wed, 06 Sep 2017 05:49:37 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36248) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dpWxi-0008Gm-IB for qemu-devel@nongnu.org; Wed, 06 Sep 2017 05:49:34 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9055DC049D7F for ; Wed, 6 Sep 2017 09:49:33 +0000 (UTC) Received: from localhost (dhcp-192-215.str.redhat.com [10.33.192.215]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3B1CA19C9A; Wed, 6 Sep 2017 09:49:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 9055DC049D7F Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=cohuck@redhat.com From: Cornelia Huck To: qemu-devel@nongnu.org Date: Wed, 6 Sep 2017 11:49:27 +0200 Message-Id: <20170906094927.22376-1-cohuck@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 06 Sep 2017 09:49:33 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH RFC] accel: default to an actually available 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: lvivier@redhat.com, kwolf@redhat.com, thuth@redhat.com, Cornelia Huck , mreitz@redhat.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 --- RFC mainly because this breaks iotest 186 in a different way on a tcg-less x86_64 build: Before, it fails with "-machine accel=3Dtcg: 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, MachineSt= ate *ms) return ret; } =20 +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) =20 accel =3D qemu_opt_get(qemu_get_machine_opts(), "accel"); if (accel =3D=3D NULL) { - /* Use the default "accelerator", tcg */ - accel =3D "tcg"; + accel =3D default_accelerator(); } =20 p =3D 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 } =20 +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 +} =20 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; =20 int kvm_available(void); int xen_available(void); +int tcg_available(void); +int hax_available(void); =20 CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp); CpuModelExpansionInfo *arch_query_cpu_model_expansion(CpuModelExpansionTyp= e 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 accel=3D@var{accels1}[:@var{accels2}[:...]] This is used to enable an accelerator. Depending on the target architectur= e, -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=3Don|off @@ -126,7 +127,8 @@ STEXI @item -accel @var{name}[,prop=3D@var{value}[,...]] @findex -accel This is used to enable an accelerator. Depending on the target architectur= e, -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 --=20 2.13.5