Skip to content

Commit 8a92605

Browse files
namhyungacmel
authored andcommitted
perf stat: Use evsel->core.cpus to iterate cpus in BPF cgroup counters
If it mixes core and uncore events, each evsel would have different cpu map. But it assumed they are same with evlist's all_cpus and accessed by the same index. This resulted in a crash like below. $ perf stat -a --bpf-counters --for-each_cgroup ^. -e cycles,imc/cas_count_read/ sleep 1 Segmentation fault While it's not recommended to use uncore events for cgroup aggregation, it should not crash. Signed-off-by: Namhyung Kim <namhyung@kernel.org> Cc: Adrian Hunter <adrian.hunter@intel.com> 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> Cc: bpf@vger.kernel.org Link: https://lore.kernel.org/r/20220916184132.1161506-4-namhyung@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 3da3523 commit 8a92605

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

tools/perf/util/bpf_counter_cgroup.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,14 @@ static int bperf_load_program(struct evlist *evlist)
115115
evsel->cgrp = NULL;
116116

117117
/* open single copy of the events w/o cgroup */
118-
err = evsel__open_per_cpu(evsel, evlist->core.all_cpus, -1);
118+
err = evsel__open_per_cpu(evsel, evsel->core.cpus, -1);
119119
if (err) {
120120
pr_err("Failed to open first cgroup events\n");
121121
goto out;
122122
}
123123

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

@@ -269,7 +269,7 @@ static int bperf_cgrp__read(struct evsel *evsel)
269269
goto out;
270270
}
271271

272-
perf_cpu_map__for_each_cpu(cpu, i, evlist->core.all_cpus) {
272+
perf_cpu_map__for_each_cpu(cpu, i, evsel->core.cpus) {
273273
counts = perf_counts(evsel->counts, i, 0);
274274
counts->val = values[cpu.cpu].counter;
275275
counts->ena = values[cpu.cpu].enabled;

0 commit comments

Comments
 (0)