From nobody Thu Nov 13 03:15:52 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1576514605; cv=none; d=zohomail.com; s=zohoarc; b=itwxzRBjjFA+QqHHgxJ8xK1OnLCunlX6caX6YSezcjYU0vGmDGi+Nyk+rQ3hKzm7GQ0RzI8EVQUHW8EGl1n6GisHtM+ppHAC+rLzAfWKY5VtdKWthJO6tNOKocvYbnJKsuuvKUMCR5XMdYLUlLk6+XHIJ3puLiUgOljGKlC/snE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576514605; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=/Fn/zzlT03nOmdiYOhDzmLdgNJP3vAWSij9EwHSCsuo=; b=cOJkf/y8fQGq0UvpBna354caEFbpPnzqQPE3lXGcGumAd1tFNuGQWcHsw79Prab9TlC2o0wWgBLIEE0bactd+0WOnFUxJdf4MObhkinjmcu6TETQlAbdrcxRkHJQECokluoG7LspZ60/UE1A/cCGSpoyUH3nbtbFUf/O2epT/7E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 157651460548471.31220610975731; Mon, 16 Dec 2019 08:43:25 -0800 (PST) Received: from localhost ([::1]:56748 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1igtSq-0006Jo-16 for importer@patchew.org; Mon, 16 Dec 2019 11:43:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:56641) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1igtF4-0004v3-UG for qemu-devel@nongnu.org; Mon, 16 Dec 2019 11:29:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1igtF3-0007HZ-BL for qemu-devel@nongnu.org; Mon, 16 Dec 2019 11:29:06 -0500 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]:51968) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1igtF3-0007F3-3p for qemu-devel@nongnu.org; Mon, 16 Dec 2019 11:29:05 -0500 Received: by mail-wm1-x32f.google.com with SMTP id d73so7440962wmd.1 for ; Mon, 16 Dec 2019 08:29:05 -0800 (PST) Received: from 640k.lan ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id q68sm19962334wme.14.2019.12.16.08.29.02 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 16 Dec 2019 08:29:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/Fn/zzlT03nOmdiYOhDzmLdgNJP3vAWSij9EwHSCsuo=; b=naRdg8t1jrPnMawR0oslRcVD9W4oxD+k+EzyckXp2+BPC9qQTFvKwLvS6fwh9RDQid sovQfgGdgd2BHSBZ7c9ElMnDEfQiovwSSSESBQftIvU06e/qBOb7fIHgDjxGmHnw0lme 00YKwGpEXuPoV7IojlWMMa+GjtneynRVEQYEIwDvBS5TVqGoclmX08Bmp4MzQz7954Hd UGqHTha+dnt2r/EgCahEYZVyaiGXnq1PJMuUvedAJrSjajFVGeO1529a1rU+qpmju8J1 zepbc8U/XN4ltukEM7tpUZrHxnGrMIscjNCJ+kHKp8kVCOThjI8WZddo8G683SY2RHBB +hTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=/Fn/zzlT03nOmdiYOhDzmLdgNJP3vAWSij9EwHSCsuo=; b=ISu5SSZELqKKJz4WgnI/oOupuwCUviN0z/LQQNQI0Zeeo2M28RU6ifhhHj1FicKAqn vpcXKMl7AV/ocJ4TKMzmgzbATpnPKo0ojYhZ2vdmksAw3mKxg9cnue1zNV9L+vkVhnfL UpsDK4T2528V6AjdPkit6zqrwJ9kkXKigcOIVMLBtQivnBMdTasoztHlipRvvto8+xre pd/Ag+rkRlPJnw2SYiFym3+yP1eit7rY+S2vbPaGhxBB7VnASj7sJcrq7H5EYQzd36TN Th45IFkLVn4DW1qGoJfH7rrRUX2BpvarjeggWJbmHLfQLr3/ThAhakattzwbAGXiNxdr 6k+w== X-Gm-Message-State: APjAAAXJNm1wNG2gkezHiiDchyDqK9ytqUX51OoAndsoLtFdlazCxNt+ XF5bz0X3VoJB8t83m5I3MQ5qvmuh X-Google-Smtp-Source: APXvYqxB84VqkxAMEGgHstnt9oZEITxxkRbWT1TUKAccQ6rxHxtMRoSmCe0q/nbRb7jADwgLkFZLMw== X-Received: by 2002:a7b:c10f:: with SMTP id w15mr21464955wmi.69.1576513743262; Mon, 16 Dec 2019 08:29:03 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 16/62] vl: merge -accel processing into configure_accelerators Date: Mon, 16 Dec 2019 17:28:00 +0100 Message-Id: <1576513726-53700-17-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1576513726-53700-1-git-send-email-pbonzini@redhat.com> References: <1576513726-53700-1-git-send-email-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::32f X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) The next step is to move the parsing of "-machine accel=3D..." into vl.c, unifying it with the configure_accelerators() function that has just been introduced. This way, we will be able to desugar it into multiple "-accel" options, without polluting accel/accel.c. The CONFIG_TCG and CONFIG_KVM symbols are not available in vl.c, but we can use accel_find instead to find their value at runtime. Once we know that the binary has one of TCG or KVM, the default accelerator can be expressed simply as "tcg:kvm", because TCG never fails to initialize. Reviewed-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Paolo Bonzini --- accel/accel.c | 69 ++--------------------------------------------= ---- include/sysemu/accel.h | 4 ++- vl.c | 64 ++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 64 insertions(+), 73 deletions(-) diff --git a/accel/accel.c b/accel/accel.c index 5fa3171..60c3827 100644 --- a/accel/accel.c +++ b/accel/accel.c @@ -28,13 +28,7 @@ #include "hw/boards.h" #include "sysemu/arch_init.h" #include "sysemu/sysemu.h" -#include "sysemu/kvm.h" -#include "sysemu/qtest.h" -#include "hw/xen/xen.h" #include "qom/object.h" -#include "qemu/error-report.h" -#include "qemu/option.h" -#include "qapi/error.h" =20 static const TypeInfo accel_type =3D { .name =3D TYPE_ACCEL, @@ -44,7 +38,7 @@ static const TypeInfo accel_type =3D { }; =20 /* Lookup AccelClass from opt_name. Returns NULL if not found */ -static AccelClass *accel_find(const char *opt_name) +AccelClass *accel_find(const char *opt_name) { char *class_name =3D g_strdup_printf(ACCEL_CLASS_NAME("%s"), opt_name); AccelClass *ac =3D ACCEL_CLASS(object_class_by_name(class_name)); @@ -52,7 +46,7 @@ static AccelClass *accel_find(const char *opt_name) return ac; } =20 -static int accel_init_machine(AccelClass *acc, MachineState *ms) +int accel_init_machine(AccelClass *acc, MachineState *ms) { ObjectClass *oc =3D OBJECT_CLASS(acc); const char *cname =3D object_class_get_name(oc); @@ -71,65 +65,6 @@ static int accel_init_machine(AccelClass *acc, MachineSt= ate *ms) return ret; } =20 -void configure_accelerator(MachineState *ms, const char *progname) -{ - const char *accel; - char **accel_list, **tmp; - int ret; - bool accel_initialised =3D false; - bool init_failed =3D false; - AccelClass *acc =3D NULL; - - accel =3D qemu_opt_get(qemu_get_machine_opts(), "accel"); - if (accel =3D=3D NULL) { - /* 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_report("No accelerator selected and" - " no default accelerator available"); - exit(1); -#endif - } - } - - accel_list =3D g_strsplit(accel, ":", 0); - - for (tmp =3D accel_list; !accel_initialised && tmp && *tmp; tmp++) { - acc =3D accel_find(*tmp); - if (!acc) { - continue; - } - ret =3D accel_init_machine(acc, ms); - if (ret < 0) { - init_failed =3D true; - error_report("failed to initialize %s: %s", - acc->name, strerror(-ret)); - } else { - accel_initialised =3D true; - } - } - g_strfreev(accel_list); - - if (!accel_initialised) { - if (!init_failed) { - error_report("-machine accel=3D%s: No accelerator found", acce= l); - } - exit(1); - } - - if (init_failed) { - error_report("Back to %s accelerator", acc->name); - } -} - void accel_setup_post(MachineState *ms) { AccelState *accel =3D ms->accelerator; diff --git a/include/sysemu/accel.h b/include/sysemu/accel.h index 8eb60b8..90b6213 100644 --- a/include/sysemu/accel.h +++ b/include/sysemu/accel.h @@ -66,7 +66,9 @@ typedef struct AccelClass { =20 extern unsigned long tcg_tb_size; =20 -void configure_accelerator(MachineState *ms, const char *progname); +AccelClass *accel_find(const char *opt_name); +int accel_init_machine(AccelClass *acc, MachineState *ms); + /* Called just before os_setup_post (ie just before drop OS privs) */ void accel_setup_post(MachineState *ms); =20 diff --git a/vl.c b/vl.c index 6e454a0..14c78bc 100644 --- a/vl.c +++ b/vl.c @@ -2839,8 +2839,65 @@ static int do_configure_accelerator(void *opaque, Qe= muOpts *opts, Error **errp) return 0; } =20 -static void configure_accelerators(void) +static void configure_accelerators(const char *progname) { + const char *accel; + char **accel_list, **tmp; + int ret; + bool accel_initialised =3D false; + bool init_failed =3D false; + AccelClass *acc =3D NULL; + + qemu_opts_foreach(qemu_find_opts("icount"), + do_configure_icount, NULL, &error_fatal); + + accel =3D qemu_opt_get(qemu_get_machine_opts(), "accel"); + if (accel =3D=3D NULL) { + /* Select the default accelerator */ + if (!accel_find("tcg") && !accel_find("kvm")) { + error_report("No accelerator selected and" + " no default accelerator available"); + exit(1); + } else { + 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 { + accel =3D "tcg:kvm"; + } + } + } + + accel_list =3D g_strsplit(accel, ":", 0); + + for (tmp =3D accel_list; !accel_initialised && tmp && *tmp; tmp++) { + acc =3D accel_find(*tmp); + if (!acc) { + continue; + } + ret =3D accel_init_machine(acc, current_machine); + if (ret < 0) { + init_failed =3D true; + error_report("failed to initialize %s: %s", + acc->name, strerror(-ret)); + } else { + accel_initialised =3D true; + } + } + g_strfreev(accel_list); + + if (!accel_initialised) { + if (!init_failed) { + error_report("-machine accel=3D%s: No accelerator found", acce= l); + } + exit(1); + } + + if (init_failed) { + error_report("Back to %s accelerator", acc->name); + } + qemu_opts_foreach(qemu_find_opts("accel"), do_configure_accelerator, NULL, &error_fatal); =20 @@ -4167,9 +4224,7 @@ int main(int argc, char **argv, char **envp) * Note: uses machine properties such as kernel-irqchip, must run * after machine_set_property(). */ - qemu_opts_foreach(qemu_find_opts("icount"), - do_configure_icount, NULL, &error_fatal); - configure_accelerator(current_machine, argv[0]); + configure_accelerators(argv[0]); =20 /* * Beware, QOM objects created before this point miss global and @@ -4254,7 +4309,6 @@ int main(int argc, char **argv, char **envp) qemu_spice_init(); =20 cpu_ticks_init(); - configure_accelerators(); =20 if (default_net) { QemuOptsList *net =3D qemu_find_opts("net"); --=20 1.8.3.1