From nobody Mon Feb 9 07:23:19 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; spf=pass (zoho.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=1556215314; cv=none; d=zoho.com; s=zohoarc; b=fMUtcmKM4bAf+6rygZstcQNMBclbdfZQwl4twUR+7XzSHNJG0C3Sv+Qjj9IFSXIAZA9RdCgoCjq31GlCJ51bZURgH0EElget85ZfRsJeVfV8Nfsmv/0IiK9TIHpTKKyAueLT96RvidMdrqL7f9lPMCDjlHMa5jr7phQjktlkIHM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1556215314; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=8L/OklnQZSlQF19QYmsODGfsvh/qjasDgEuM/VUBFoI=; b=P45eDx37Kse+haFiAEJGDBlS5pQtq/oqRFv9VOd93DkDsClbQpVTfT1BoDP8dYry+dO0ackU3ReF95eVa6MwxXhH3DpO8e9yluc6RQu3I41ZoU9Dv+Lsd0evGvOT//O/fdOrFBNZ1E0aSVemT9qoHeXawrf0r74FMJkSW/qU2Cs= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.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 1556215314037147.2503963052203; Thu, 25 Apr 2019 11:01:54 -0700 (PDT) Received: from localhost ([127.0.0.1]:33317 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hJigw-000434-2T for importer@patchew.org; Thu, 25 Apr 2019 14:01:50 -0400 Received: from eggs.gnu.org ([209.51.188.92]:41381) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hJicP-0000HQ-VF for qemu-devel@nongnu.org; Thu, 25 Apr 2019 13:57:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hJicO-0004wo-Tm for qemu-devel@nongnu.org; Thu, 25 Apr 2019 13:57:09 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39666) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hJicO-0004wA-L1 for qemu-devel@nongnu.org; Thu, 25 Apr 2019 13:57:08 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DFAF136887; Thu, 25 Apr 2019 17:57:07 +0000 (UTC) Received: from localhost (ovpn-116-9.gru2.redhat.com [10.97.116.9]) by smtp.corp.redhat.com (Postfix) with ESMTP id 720A760C70; Thu, 25 Apr 2019 17:57:07 +0000 (UTC) From: Eduardo Habkost To: Peter Maydell , qemu-devel@nongnu.org, Marcel Apfelbaum Date: Thu, 25 Apr 2019 14:56:51 -0300 Message-Id: <20190425175659.24876-4-ehabkost@redhat.com> In-Reply-To: <20190425175659.24876-1-ehabkost@redhat.com> References: <20190425175659.24876-1-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 25 Apr 2019 17:57:07 +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] [PULL 03/11] vl.c: allocate TYPE_MACHINE list once during bootup 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: Wei Yang Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Wei Yang Now all the functions used to select machine is local and the call flow looks like below: select_machine() find_default_machine() machine_parse() find_machine() All these related function will need a GSList for TYPE_MACHINE. Currently we allocate this list each time we use it, while this is not necessary to do so because we don't need to modify this. This patch make the TYPE_MACHINE list allocation in select_machine and pass this to its child for use. Signed-off-by: Wei Yang Reviewed-by: Markus Armbruster Message-Id: <20190405064121.23662-3-richardw.yang@linux.intel.com> Signed-off-by: Eduardo Habkost --- vl.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/vl.c b/vl.c index c237c9a0ac..fb8c8eda2a 100644 --- a/vl.c +++ b/vl.c @@ -1465,9 +1465,9 @@ static int usb_parse(const char *cmdline) =20 MachineState *current_machine; =20 -static MachineClass *find_machine(const char *name) +static MachineClass *find_machine(const char *name, GSList *machines) { - GSList *el, *machines =3D object_class_get_list(TYPE_MACHINE, false); + GSList *el; MachineClass *mc =3D NULL; =20 for (el =3D machines; el; el =3D el->next) { @@ -1484,13 +1484,12 @@ static MachineClass *find_machine(const char *name) } } =20 - g_slist_free(machines); return mc; } =20 -static MachineClass *find_default_machine(void) +static MachineClass *find_default_machine(GSList *machines) { - GSList *el, *machines =3D object_class_get_list(TYPE_MACHINE, false); + GSList *el; MachineClass *mc =3D NULL; =20 for (el =3D machines; el; el =3D el->next) { @@ -1502,7 +1501,6 @@ static MachineClass *find_default_machine(void) } } =20 - g_slist_free(machines); return mc; } =20 @@ -2585,16 +2583,15 @@ static gint machine_class_cmp(gconstpointer a, gcon= stpointer b) object_class_get_name(OBJECT_CLASS(mc1))); } =20 - static MachineClass *machine_parse(const char *name) +static MachineClass *machine_parse(const char *name, GSList *machines) { MachineClass *mc =3D NULL; - GSList *el, *machines =3D object_class_get_list(TYPE_MACHINE, false); + GSList *el; =20 if (name) { - mc =3D find_machine(name); + mc =3D find_machine(name, machines); } if (mc) { - g_slist_free(machines); return mc; } if (name && !is_help_option(name)) { @@ -2614,7 +2611,6 @@ static gint machine_class_cmp(gconstpointer a, gconst= pointer b) } } =20 - g_slist_free(machines); exit(!name || !is_help_option(name)); } =20 @@ -2706,7 +2702,8 @@ static const QEMUOption *lookup_opt(int argc, char **= argv, =20 static MachineClass *select_machine(void) { - MachineClass *machine_class =3D find_default_machine(); + GSList *machines =3D object_class_get_list(TYPE_MACHINE, false); + MachineClass *machine_class =3D find_default_machine(machines); const char *optarg; QemuOpts *opts; Location loc; @@ -2718,7 +2715,7 @@ static MachineClass *select_machine(void) =20 optarg =3D qemu_opt_get(opts, "type"); if (optarg) { - machine_class =3D machine_parse(optarg); + machine_class =3D machine_parse(optarg, machines); } =20 if (!machine_class) { @@ -2728,6 +2725,7 @@ static MachineClass *select_machine(void) } =20 loc_pop(&loc); + g_slist_free(machines); return machine_class; } =20 --=20 2.18.0.rc1.1.g3f1ff2140