From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_2 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A3621C33CA2 for ; Fri, 10 Jan 2020 10:09:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 806912072A for ; Fri, 10 Jan 2020 10:09:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727392AbgAJKJb convert rfc822-to-8bit (ORCPT ); Fri, 10 Jan 2020 05:09:31 -0500 Received: from 2.mo178.mail-out.ovh.net ([46.105.39.61]:47759 "EHLO 2.mo178.mail-out.ovh.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727352AbgAJKJb (ORCPT ); Fri, 10 Jan 2020 05:09:31 -0500 X-Greylist: delayed 602 seconds by postgrey-1.27 at vger.kernel.org; Fri, 10 Jan 2020 05:09:29 EST Received: from player688.ha.ovh.net (unknown [10.108.54.38]) by mo178.mail-out.ovh.net (Postfix) with ESMTP id B9A4A8A813 for ; Fri, 10 Jan 2020 10:51:20 +0100 (CET) Received: from kaod.org (lns-bzn-46-82-253-208-248.adsl.proxad.net [82.253.208.248]) (Authenticated sender: groug@kaod.org) by player688.ha.ovh.net (Postfix) with ESMTPSA id 56885DFACE0A; Fri, 10 Jan 2020 09:50:58 +0000 (UTC) Date: Fri, 10 Jan 2020 10:50:55 +0100 From: Greg Kurz To: Philippe =?UTF-8?B?TWF0aGlldS1EYXVkw6k=?= Cc: qemu-devel@nongnu.org, Peter Maydell , Eduardo Habkost , kvm@vger.kernel.org, Juan Quintela , qemu-ppc@nongnu.org, Marcelo Tosatti , "Dr. David Alan Gilbert" , qemu-arm@nongnu.org, Alistair Francis , Marcel Apfelbaum , Paolo Bonzini , David Gibson , Richard Henderson , Eric Blake Subject: Re: [PATCH 04/15] hw/ppc/spapr_rtas: Restrict variables scope to single switch case Message-ID: <20200110105055.3e72ddf4@bahia.lan> In-Reply-To: <9870f8ed-3fa0-1deb-860d-7481cb3db556@redhat.com> References: <20200109152133.23649-1-philmd@redhat.com> <20200109152133.23649-5-philmd@redhat.com> <20200109184349.1aefa074@bahia.lan> <9870f8ed-3fa0-1deb-860d-7481cb3db556@redhat.com> X-Mailer: Claws Mail 3.17.4 (GTK+ 2.24.32; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT X-Ovh-Tracer-Id: 5266959766281034019 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedufedrvdeifedgtdelucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecuhedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhepfffhvffukfgjfhfogggtgfesthhqredtredtjeenucfhrhhomhepifhrvghgucfmuhhriicuoehgrhhouhhgsehkrghougdrohhrgheqnecukfhppedtrddtrddtrddtpdekvddrvdehfedrvddtkedrvdegkeenucfrrghrrghmpehmohguvgepshhmthhpqdhouhhtpdhhvghlohepphhlrgihvghrieekkedrhhgrrdhovhhhrdhnvghtpdhinhgvtheptddrtddrtddrtddpmhgrihhlfhhrohhmpehgrhhouhhgsehkrghougdrohhrghdprhgtphhtthhopehkvhhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgnecuvehluhhsthgvrhfuihiivgeptd Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org On Fri, 10 Jan 2020 10:34:07 +0100 Philippe Mathieu-Daudé wrote: > On 1/9/20 6:43 PM, Greg Kurz wrote: > > On Thu, 9 Jan 2020 16:21:22 +0100 > > Philippe Mathieu-Daudé wrote: > > > >> We only access these variables in RTAS_SYSPARM_SPLPAR_CHARACTERISTICS > >> case, restrict their scope to avoid unnecessary initialization. > >> > > > > I guess a decent compiler can be smart enough detect that the initialization > > isn't needed outside of the RTAS_SYSPARM_SPLPAR_CHARACTERISTICS branch... > > Anyway, reducing scope isn't bad. The only hitch I could see is that some > > people do prefer to have all variables declared upfront, but there's a nested > > param_val variable already so I guess it's okay. > > I don't want to outsmart compilers :) > > The MACHINE() macro is not a simple cast, it does object introspection > with OBJECT_CHECK(), thus is not free. Since Sure, I understand the motivation in avoiding an unneeded call to calling object_dynamic_cast_assert(). > object_dynamic_cast_assert() argument is not const, I'm not sure the > compiler can remove the call. > Not remove the call, but delay it to the branch that uses it, ie. parameter == RTAS_SYSPARM_SPLPAR_CHARACTERISTICS. > Richard, Eric, do you know? > > >> Signed-off-by: Philippe Mathieu-Daudé > >> --- > >> hw/ppc/spapr_rtas.c | 4 ++-- > >> 1 file changed, 2 insertions(+), 2 deletions(-) > >> > >> diff --git a/hw/ppc/spapr_rtas.c b/hw/ppc/spapr_rtas.c > >> index 6f06e9d7fe..7237e5ebf2 100644 > >> --- a/hw/ppc/spapr_rtas.c > >> +++ b/hw/ppc/spapr_rtas.c > >> @@ -267,8 +267,6 @@ static void rtas_ibm_get_system_parameter(PowerPCCPU *cpu, > >> uint32_t nret, target_ulong rets) > >> { > >> PowerPCCPUClass *pcc = POWERPC_CPU_GET_CLASS(cpu); > >> - MachineState *ms = MACHINE(spapr); > >> - unsigned int max_cpus = ms->smp.max_cpus; > >> target_ulong parameter = rtas_ld(args, 0); > >> target_ulong buffer = rtas_ld(args, 1); > >> target_ulong length = rtas_ld(args, 2); > >> @@ -276,6 +274,8 @@ static void rtas_ibm_get_system_parameter(PowerPCCPU *cpu, > >> > >> switch (parameter) { > >> case RTAS_SYSPARM_SPLPAR_CHARACTERISTICS: { > >> + MachineState *ms = MACHINE(spapr); > >> + unsigned int max_cpus = ms->smp.max_cpus; > > > > The max_cpus variable used to be a global. Now that it got moved > > below ms->smp, I'm not sure it's worth keeping it IMHO. What about > > dropping it completely and do: > > > > char *param_val = g_strdup_printf("MaxEntCap=%d," > > "DesMem=%" PRIu64 "," > > "DesProcs=%d," > > "MaxPlatProcs=%d", > > ms->smp.max_cpus, > > current_machine->ram_size / MiB, > > ms->smp.cpus, > > ms->smp.max_cpus); > > OK, good idea. > > > And maybe insert an empty line between the declaration of param_val > > and the code for a better readability ? > > > >> char *param_val = g_strdup_printf("MaxEntCap=%d," > >> "DesMem=%" PRIu64 "," > >> "DesProcs=%d," > > >