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 <irogers@xxxxxxxxxx> > --- > 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 <james.clark@xxxxxxx>