Skip to content

Commit 2d656b0

Browse files
namhyungacmel
authored andcommitted
perf stat: Fix handling of unsupported cgroup events when using BPF counters
When --for-each-cgroup option is used, it fails when any of events is not supported and exits immediately. This is not how 'perf stat' handles unsupported events. Let's ignore the failure and proceed with others so that the output is similar to when BPF counters are not used: Before: $ sudo ./perf stat -a --bpf-counters -e L1-icache-loads,L1-dcache-loads --for-each-cgroup system.slice,user.slice sleep 1 Failed to open first cgroup events $ After it shows output similat to when --bpf-counters isn't specified: $ sudo ./perf stat -a --bpf-counters -e L1-icache-loads,L1-dcache-loads --for-each-cgroup system.slice,user.slice sleep 1 Performance counter stats for 'system wide': <not supported> L1-icache-loads system.slice 29,892,418 L1-dcache-loads system.slice <not supported> L1-icache-loads user.slice 52,497,220 L1-dcache-loads user.slice $ Fixes: 944138f ("perf stat: Enable BPF counter with --for-each-cgroup") Signed-off-by: Namhyung Kim <[email protected]> Tested-by: Arnaldo Carvalho de Melo <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Ian Rogers <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Song Liu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent fb710dd commit 2d656b0

File tree

1 file changed

+3
-11
lines changed

1 file changed

+3
-11
lines changed

tools/perf/util/bpf_counter_cgroup.c

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -116,27 +116,19 @@ static int bperf_load_program(struct evlist *evlist)
116116

117117
/* open single copy of the events w/o cgroup */
118118
err = evsel__open_per_cpu(evsel, evsel->core.cpus, -1);
119-
if (err) {
120-
pr_err("Failed to open first cgroup events\n");
121-
goto out;
122-
}
119+
if (err == 0)
120+
evsel->supported = true;
123121

124122
map_fd = bpf_map__fd(skel->maps.events);
125123
perf_cpu_map__for_each_cpu(cpu, j, evsel->core.cpus) {
126124
int fd = FD(evsel, j);
127125
__u32 idx = evsel->core.idx * total_cpus + cpu.cpu;
128126

129-
err = bpf_map_update_elem(map_fd, &idx, &fd,
130-
BPF_ANY);
131-
if (err < 0) {
132-
pr_err("Failed to update perf_event fd\n");
133-
goto out;
134-
}
127+
bpf_map_update_elem(map_fd, &idx, &fd, BPF_ANY);
135128
}
136129

137130
evsel->cgrp = leader_cgrp;
138131
}
139-
evsel->supported = true;
140132

141133
if (evsel->cgrp == cgrp)
142134
continue;

0 commit comments

Comments
 (0)