Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf bpf: Rename 'cpu' to 'cpu_map_idx'

Synchronize the caller in evsel with the called function.

Shorten 3 lines of code in bperf_read by using
perf_cpu_map__for_each_cpu().

This code is frequently using variables named cpu as cpu map indices,
which doesn't matter as all CPUs are in the CPU map. It is strange in
some cases the cpumap is used at all.

Committer notes:

Found when building with BUILD_BPF_SKEL=1:

Remove unused 'num_cpu' variable in bperf__read().

Make 'j' an 'int' as it is used in perf_cpu_map__for_each_cpu() to compare against an 'int'

Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@arm.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
Cc: Mike Leach <mike.leach@linaro.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
Cc: Vineet Singh <vineet.singh@intel.com>
Cc: coresight@lists.linaro.org
Cc: linux-arm-kernel@lists.infradead.org
Cc: zhengjun.xing@intel.com
Link: https://lore.kernel.org/r/20220105061351.120843-45-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Ian Rogers and committed by
Arnaldo Carvalho de Melo
7263f349 91802e73

+11 -12
+9 -10
tools/perf/util/bpf_counter.c
··· 265 265 return 0; 266 266 } 267 267 268 - static int bpf_program_profiler__install_pe(struct evsel *evsel, int cpu, 268 + static int bpf_program_profiler__install_pe(struct evsel *evsel, int cpu_map_idx, 269 269 int fd) 270 270 { 271 271 struct bpf_prog_profiler_bpf *skel; ··· 277 277 assert(skel != NULL); 278 278 279 279 ret = bpf_map_update_elem(bpf_map__fd(skel->maps.events), 280 - &cpu, &fd, BPF_ANY); 280 + &cpu_map_idx, &fd, BPF_ANY); 281 281 if (ret) 282 282 return ret; 283 283 } ··· 566 566 return err; 567 567 } 568 568 569 - static int bperf__install_pe(struct evsel *evsel, int cpu, int fd) 569 + static int bperf__install_pe(struct evsel *evsel, int cpu_map_idx, int fd) 570 570 { 571 571 struct bperf_leader_bpf *skel = evsel->leader_skel; 572 572 573 573 return bpf_map_update_elem(bpf_map__fd(skel->maps.events), 574 - &cpu, &fd, BPF_ANY); 574 + &cpu_map_idx, &fd, BPF_ANY); 575 575 } 576 576 577 577 /* ··· 608 608 __u32 num_cpu_bpf = cpu__max_cpu(); 609 609 struct bpf_perf_event_value values[num_cpu_bpf]; 610 610 int reading_map_fd, err = 0; 611 - __u32 i, j, num_cpu; 611 + __u32 i; 612 + int j; 612 613 613 614 bperf_sync_counters(evsel); 614 615 reading_map_fd = bpf_map__fd(skel->maps.accum_readings); ··· 624 623 case BPERF_FILTER_GLOBAL: 625 624 assert(i == 0); 626 625 627 - num_cpu = all_cpu_map->nr; 628 - for (j = 0; j < num_cpu; j++) { 629 - cpu = all_cpu_map->map[j]; 626 + perf_cpu_map__for_each_cpu(cpu, j, all_cpu_map) { 630 627 perf_counts(evsel->counts, cpu, 0)->val = values[cpu].counter; 631 628 perf_counts(evsel->counts, cpu, 0)->ena = values[cpu].enabled; 632 629 perf_counts(evsel->counts, cpu, 0)->run = values[cpu].running; ··· 756 757 evsel->follower_skel == NULL; 757 758 } 758 759 759 - int bpf_counter__install_pe(struct evsel *evsel, int cpu, int fd) 760 + int bpf_counter__install_pe(struct evsel *evsel, int cpu_map_idx, int fd) 760 761 { 761 762 if (bpf_counter_skip(evsel)) 762 763 return 0; 763 - return evsel->bpf_counter_ops->install_pe(evsel, cpu, fd); 764 + return evsel->bpf_counter_ops->install_pe(evsel, cpu_map_idx, fd); 764 765 } 765 766 766 767 int bpf_counter__load(struct evsel *evsel, struct target *target)
+2 -2
tools/perf/util/bpf_counter.h
··· 16 16 typedef int (*bpf_counter_evsel_target_op)(struct evsel *evsel, 17 17 struct target *target); 18 18 typedef int (*bpf_counter_evsel_install_pe_op)(struct evsel *evsel, 19 - int cpu, 19 + int cpu_map_idx, 20 20 int fd); 21 21 22 22 struct bpf_counter_ops { ··· 40 40 int bpf_counter__disable(struct evsel *evsel); 41 41 int bpf_counter__read(struct evsel *evsel); 42 42 void bpf_counter__destroy(struct evsel *evsel); 43 - int bpf_counter__install_pe(struct evsel *evsel, int cpu, int fd); 43 + int bpf_counter__install_pe(struct evsel *evsel, int cpu_map_idx, int fd); 44 44 45 45 #else /* HAVE_BPF_SKEL */ 46 46