From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6F77BAA; Tue, 12 Dec 2023 07:12:03 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 7F51E143D; Tue, 12 Dec 2023 07:12:49 -0800 (PST) Received: from [192.168.1.3] (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id BEE2D3F738; Tue, 12 Dec 2023 07:11:57 -0800 (PST) Message-ID: Date: Tue, 12 Dec 2023 15:11:53 +0000 Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: [PATCH v1 10/14] perf top: Avoid repeated function calls Content-Language: en-US To: Ian Rogers References: <20231129060211.1890454-1-irogers@google.com> <20231129060211.1890454-11-irogers@google.com> Cc: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Adrian Hunter , Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , Thomas Gleixner , Darren Hart , Davidlohr Bueso , =?UTF-8?Q?Andr=c3=a9_Almeida?= , Kan Liang , K Prateek Nayak , Sean Christopherson , Paolo Bonzini , Kajol Jain , Athira Rajeev , Andrew Jones , Alexandre Ghiti , Atish Patra , "Steinar H. Gunderson" , Yang Jihong , Yang Li , Changbin Du , Sandipan Das , Ravi Bangoria , Paran Lee , Nick Desaulniers , Huacai Chen , Yanteng Si , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, bpf@vger.kernel.org From: James Clark In-Reply-To: <20231129060211.1890454-11-irogers@google.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 29/11/2023 06:02, Ian Rogers wrote: > Add a local variable to avoid repeated calls to perf_cpu_map__nr. > > Signed-off-by: Ian Rogers Reviewed-by: James Clark > --- > tools/perf/util/top.c | 9 ++++----- > 1 file changed, 4 insertions(+), 5 deletions(-) > > diff --git a/tools/perf/util/top.c b/tools/perf/util/top.c > index be7157de0451..4db3d1bd686c 100644 > --- a/tools/perf/util/top.c > +++ b/tools/perf/util/top.c > @@ -28,6 +28,7 @@ size_t perf_top__header_snprintf(struct perf_top *top, char *bf, size_t size) > struct record_opts *opts = &top->record_opts; > struct target *target = &opts->target; > size_t ret = 0; > + int nr_cpus; > > if (top->samples) { > samples_per_sec = top->samples / top->delay_secs; > @@ -93,19 +94,17 @@ size_t perf_top__header_snprintf(struct perf_top *top, char *bf, size_t size) > else > ret += SNPRINTF(bf + ret, size - ret, " (all"); > > + nr_cpus = perf_cpu_map__nr(top->evlist->core.user_requested_cpus); > if (target->cpu_list) > ret += SNPRINTF(bf + ret, size - ret, ", CPU%s: %s)", > - perf_cpu_map__nr(top->evlist->core.user_requested_cpus) > 1 > - ? "s" : "", > + nr_cpus > 1 ? "s" : "", > target->cpu_list); > else { > if (target->tid) > ret += SNPRINTF(bf + ret, size - ret, ")"); > else > ret += SNPRINTF(bf + ret, size - ret, ", %d CPU%s)", > - perf_cpu_map__nr(top->evlist->core.user_requested_cpus), > - perf_cpu_map__nr(top->evlist->core.user_requested_cpus) > 1 > - ? "s" : ""); > + nr_cpus, nr_cpus > 1 ? "s" : ""); > } > > perf_top__reset_sample_counters(top);