Commit 8a92605d authored by Namhyung Kim's avatar Namhyung Kim Committed by Arnaldo Carvalho de Melo

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: default avatarNamhyung 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.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 3da35231
...@@ -115,14 +115,14 @@ static int bperf_load_program(struct evlist *evlist) ...@@ -115,14 +115,14 @@ static int bperf_load_program(struct evlist *evlist)
evsel->cgrp = NULL; evsel->cgrp = NULL;
/* open single copy of the events w/o cgroup */ /* open single copy of the events w/o cgroup */
err = evsel__open_per_cpu(evsel, evlist->core.all_cpus, -1); err = evsel__open_per_cpu(evsel, evsel->core.cpus, -1);
if (err) { if (err) {
pr_err("Failed to open first cgroup events\n"); pr_err("Failed to open first cgroup events\n");
goto out; goto out;
} }
map_fd = bpf_map__fd(skel->maps.events); map_fd = bpf_map__fd(skel->maps.events);
perf_cpu_map__for_each_cpu(cpu, j, evlist->core.all_cpus) { perf_cpu_map__for_each_cpu(cpu, j, evsel->core.cpus) {
int fd = FD(evsel, j); int fd = FD(evsel, j);
__u32 idx = evsel->core.idx * total_cpus + cpu.cpu; __u32 idx = evsel->core.idx * total_cpus + cpu.cpu;
...@@ -269,7 +269,7 @@ static int bperf_cgrp__read(struct evsel *evsel) ...@@ -269,7 +269,7 @@ static int bperf_cgrp__read(struct evsel *evsel)
goto out; goto out;
} }
perf_cpu_map__for_each_cpu(cpu, i, evlist->core.all_cpus) { perf_cpu_map__for_each_cpu(cpu, i, evsel->core.cpus) {
counts = perf_counts(evsel->counts, i, 0); counts = perf_counts(evsel->counts, i, 0);
counts->val = values[cpu.cpu].counter; counts->val = values[cpu.cpu].counter;
counts->ena = values[cpu.cpu].enabled; counts->ena = values[cpu.cpu].enabled;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment