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 5A79DB8; Tue, 12 Dec 2023 03:25:19 -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 5C35E143D; Tue, 12 Dec 2023 03:26:05 -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 24F483F762; Tue, 12 Dec 2023 03:25:14 -0800 (PST) Message-ID: Date: Tue, 12 Dec 2023 11:25:14 +0000 Precedence: bulk X-Mailing-List: linux-perf-users@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 13/14] perf cpumap: Use perf_cpu_map__for_each_cpu when possible Content-Language: en-US To: Ian Rogers References: <20231129060211.1890454-1-irogers@google.com> <20231129060211.1890454-14-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-14-irogers@google.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 29/11/2023 06:02, Ian Rogers wrote: > Rather than manually iterating the CPU map, use > perf_cpu_map__for_each_cpu. When possible tidy local variables. > > Signed-off-by: Ian Rogers > --- > tools/perf/arch/arm64/util/header.c | 10 ++-- > tools/perf/tests/bitmap.c | 13 +++--- > tools/perf/tests/topology.c | 46 +++++++++---------- > tools/perf/util/bpf_kwork.c | 16 ++++--- > tools/perf/util/bpf_kwork_top.c | 12 ++--- > tools/perf/util/cpumap.c | 12 ++--- > .../scripting-engines/trace-event-python.c | 12 +++-- > tools/perf/util/session.c | 5 +- > tools/perf/util/svghelper.c | 20 ++++---- > 9 files changed, 72 insertions(+), 74 deletions(-) > [...] > diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c > index 860e1837ba96..8ef0e5ac03c2 100644 > --- a/tools/perf/util/scripting-engines/trace-event-python.c > +++ b/tools/perf/util/scripting-engines/trace-event-python.c > @@ -1693,13 +1693,15 @@ static void python_process_stat(struct perf_stat_config *config, > { > struct perf_thread_map *threads = counter->core.threads; > struct perf_cpu_map *cpus = counter->core.cpus; > - int cpu, thread; > > - for (thread = 0; thread < perf_thread_map__nr(threads); thread++) { > - for (cpu = 0; cpu < perf_cpu_map__nr(cpus); cpu++) { > - process_stat(counter, perf_cpu_map__cpu(cpus, cpu), > + for (int thread = 0; thread < perf_thread_map__nr(threads); thread++) { > + int idx; > + struct perf_cpu cpu; > + > + perf_cpu_map__for_each_cpu(cpu, idx, cpus) { > + process_stat(counter, cpu, > perf_thread_map__pid(threads, thread), tstamp, > - perf_counts(counter->counts, cpu, thread)); > + perf_counts(counter->counts, idx, thread)); I thought changing cpu to idx was fixing a bug, but it was actually just hard to read before where cpu was actually idx and not cpu, so this cleanup is pretty good. Reviewed-by: James Clark