Skip to content

Commit 7263f34

Browse files
captain5050acmel
authored andcommitted
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>
1 parent 91802e7 commit 7263f34

2 files changed

Lines changed: 11 additions & 12 deletions

File tree

tools/perf/util/bpf_counter.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ static int bpf_program_profiler__read(struct evsel *evsel)
265265
return 0;
266266
}
267267

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,
269269
int fd)
270270
{
271271
struct bpf_prog_profiler_bpf *skel;
@@ -277,7 +277,7 @@ static int bpf_program_profiler__install_pe(struct evsel *evsel, int cpu,
277277
assert(skel != NULL);
278278

279279
ret = bpf_map_update_elem(bpf_map__fd(skel->maps.events),
280-
&cpu, &fd, BPF_ANY);
280+
&cpu_map_idx, &fd, BPF_ANY);
281281
if (ret)
282282
return ret;
283283
}
@@ -566,12 +566,12 @@ static int bperf__load(struct evsel *evsel, struct target *target)
566566
return err;
567567
}
568568

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)
570570
{
571571
struct bperf_leader_bpf *skel = evsel->leader_skel;
572572

573573
return bpf_map_update_elem(bpf_map__fd(skel->maps.events),
574-
&cpu, &fd, BPF_ANY);
574+
&cpu_map_idx, &fd, BPF_ANY);
575575
}
576576

577577
/*
@@ -608,7 +608,8 @@ static int bperf__read(struct evsel *evsel)
608608
__u32 num_cpu_bpf = cpu__max_cpu();
609609
struct bpf_perf_event_value values[num_cpu_bpf];
610610
int reading_map_fd, err = 0;
611-
__u32 i, j, num_cpu;
611+
__u32 i;
612+
int j;
612613

613614
bperf_sync_counters(evsel);
614615
reading_map_fd = bpf_map__fd(skel->maps.accum_readings);
@@ -623,9 +624,7 @@ static int bperf__read(struct evsel *evsel)
623624
case BPERF_FILTER_GLOBAL:
624625
assert(i == 0);
625626

626-
num_cpu = all_cpu_map->nr;
627-
for (j = 0; j < num_cpu; j++) {
628-
cpu = all_cpu_map->map[j];
627+
perf_cpu_map__for_each_cpu(cpu, j, all_cpu_map) {
629628
perf_counts(evsel->counts, cpu, 0)->val = values[cpu].counter;
630629
perf_counts(evsel->counts, cpu, 0)->ena = values[cpu].enabled;
631630
perf_counts(evsel->counts, cpu, 0)->run = values[cpu].running;
@@ -757,11 +756,11 @@ static inline bool bpf_counter_skip(struct evsel *evsel)
757756
evsel->follower_skel == NULL;
758757
}
759758

760-
int bpf_counter__install_pe(struct evsel *evsel, int cpu, int fd)
759+
int bpf_counter__install_pe(struct evsel *evsel, int cpu_map_idx, int fd)
761760
{
762761
if (bpf_counter_skip(evsel))
763762
return 0;
764-
return evsel->bpf_counter_ops->install_pe(evsel, cpu, fd);
763+
return evsel->bpf_counter_ops->install_pe(evsel, cpu_map_idx, fd);
765764
}
766765

767766
int bpf_counter__load(struct evsel *evsel, struct target *target)

tools/perf/util/bpf_counter.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ typedef int (*bpf_counter_evsel_op)(struct evsel *evsel);
1616
typedef int (*bpf_counter_evsel_target_op)(struct evsel *evsel,
1717
struct target *target);
1818
typedef int (*bpf_counter_evsel_install_pe_op)(struct evsel *evsel,
19-
int cpu,
19+
int cpu_map_idx,
2020
int fd);
2121

2222
struct bpf_counter_ops {
@@ -40,7 +40,7 @@ int bpf_counter__enable(struct evsel *evsel);
4040
int bpf_counter__disable(struct evsel *evsel);
4141
int bpf_counter__read(struct evsel *evsel);
4242
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);
4444

4545
#else /* HAVE_BPF_SKEL */
4646

0 commit comments

Comments
 (0)