Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf list pfm: Retry supported test with exclude_kernel

With paranoia set at 2 evsel__open will fail with EACCES for non-root
users. To avoid this stopping libpfm4 events from being printed, retry
with exclude_kernel enabled - copying the regular is_event_supported
test.

Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kang Minchul <tegongkang@gmail.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Link: https://lore.kernel.org/r/20230906234416.3472339-2-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Ian Rogers and committed by
Arnaldo Carvalho de Melo
6bd8c2ea 4f19fc18

+14 -1
+14 -1
tools/perf/util/pfm.c
··· 145 145 146 146 evsel->is_libpfm_event = true; 147 147 148 - if (evsel__open(evsel, cpus, threads) < 0) 148 + ret = evsel__open(evsel, cpus, threads); 149 + if (ret == -EACCES) { 150 + /* 151 + * This happens if the paranoid value 152 + * /proc/sys/kernel/perf_event_paranoid is set to 2 153 + * Re-run with exclude_kernel set; we don't do that 154 + * by default as some ARM machines do not support it. 155 + * 156 + */ 157 + evsel->core.attr.exclude_kernel = 1; 158 + ret = evsel__open(evsel, cpus, threads); 159 + 160 + } 161 + if (ret < 0) 149 162 result = false; 150 163 151 164 evsel__close(evsel);