Skip to content

Commit 3da3523

Browse files
namhyungacmel
authored andcommitted
perf stat: Fix cpu map index in bperf cgroup code
The previous cpu map introduced a bug in the bperf cgroup counter. This results in a failure when user gives a partial cpu map starting from non-zero. $ sudo ./perf stat -C 1-2 --bpf-counters --for-each-cgroup ^. sleep 1 libbpf: prog 'on_cgrp_switch': failed to create BPF link for perf_event FD 0: -9 (Bad file descriptor) Failed to attach cgroup program To get the FD of an evsel, it should use a map index not the CPU number. Fixes: 0255571 ("perf cpumap: Switch to using perf_cpu_map API") Signed-off-by: Namhyung Kim <namhyung@kernel.org> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: bpf@vger.kernel.org Cc: Ian Rogers <irogers@google.com> Cc: Ingo Molnar <mingo@kernel.org> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Song Liu <songliubraving@fb.com> Link: https://lore.kernel.org/r/20220916184132.1161506-3-namhyung@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 0d77326 commit 3da3523

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

tools/perf/util/bpf_counter_cgroup.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ static int bperf_load_program(struct evlist *evlist)
9595

9696
perf_cpu_map__for_each_cpu(cpu, i, evlist->core.all_cpus) {
9797
link = bpf_program__attach_perf_event(skel->progs.on_cgrp_switch,
98-
FD(cgrp_switch, cpu.cpu));
98+
FD(cgrp_switch, i));
9999
if (IS_ERR(link)) {
100100
pr_err("Failed to attach cgroup program\n");
101101
err = PTR_ERR(link);
@@ -123,7 +123,7 @@ static int bperf_load_program(struct evlist *evlist)
123123

124124
map_fd = bpf_map__fd(skel->maps.events);
125125
perf_cpu_map__for_each_cpu(cpu, j, evlist->core.all_cpus) {
126-
int fd = FD(evsel, cpu.cpu);
126+
int fd = FD(evsel, j);
127127
__u32 idx = evsel->core.idx * total_cpus + cpu.cpu;
128128

129129
err = bpf_map_update_elem(map_fd, &idx, &fd,

0 commit comments

Comments
 (0)