From patchwork Thu Apr 25 17:56:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Habkost X-Patchwork-Id: 1091033 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44qlNH1VGPz9s3q for ; Fri, 26 Apr 2019 04:00:47 +1000 (AEST) Received: from localhost ([127.0.0.1]:33268 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hJifs-0002is-VE for incoming@patchwork.ozlabs.org; Thu, 25 Apr 2019 14:00:45 -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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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) MachineState *current_machine; -static MachineClass *find_machine(const char *name) +static MachineClass *find_machine(const char *name, GSList *machines) { - GSList *el, *machines = object_class_get_list(TYPE_MACHINE, false); + GSList *el; MachineClass *mc = NULL; for (el = machines; el; el = el->next) { @@ -1484,13 +1484,12 @@ static MachineClass *find_machine(const char *name) } } - g_slist_free(machines); return mc; } -static MachineClass *find_default_machine(void) +static MachineClass *find_default_machine(GSList *machines) { - GSList *el, *machines = object_class_get_list(TYPE_MACHINE, false); + GSList *el; MachineClass *mc = NULL; for (el = machines; el; el = el->next) { @@ -1502,7 +1501,6 @@ static MachineClass *find_default_machine(void) } } - g_slist_free(machines); return mc; } @@ -2585,16 +2583,15 @@ static gint machine_class_cmp(gconstpointer a, gconstpointer b) object_class_get_name(OBJECT_CLASS(mc1))); } - static MachineClass *machine_parse(const char *name) +static MachineClass *machine_parse(const char *name, GSList *machines) { MachineClass *mc = NULL; - GSList *el, *machines = object_class_get_list(TYPE_MACHINE, false); + GSList *el; if (name) { - mc = find_machine(name); + mc = 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, gconstpointer b) } } - g_slist_free(machines); exit(!name || !is_help_option(name)); } @@ -2706,7 +2702,8 @@ static const QEMUOption *lookup_opt(int argc, char **argv, static MachineClass *select_machine(void) { - MachineClass *machine_class = find_default_machine(); + GSList *machines = object_class_get_list(TYPE_MACHINE, false); + MachineClass *machine_class = find_default_machine(machines); const char *optarg; QemuOpts *opts; Location loc; @@ -2718,7 +2715,7 @@ static MachineClass *select_machine(void) optarg = qemu_opt_get(opts, "type"); if (optarg) { - machine_class = machine_parse(optarg); + machine_class = machine_parse(optarg, machines); } if (!machine_class) { @@ -2728,6 +2725,7 @@ static MachineClass *select_machine(void) } loc_pop(&loc); + g_slist_free(machines); return machine_class; }