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

perf stat: handle ENXIO error for perf_event_open

perf stat on PPC currently fails to run:

$ perf stat -- sleep 1
Error: open_counter returned with 6 (No such device or address). /bin/dmesg may provide additional information.

Fatal: Not all events could be opened.

The problem is that until 2.6.37 (behavior changed with commit b0a873e)
perf on PPC returns ENXIO when hw_perf_event_init() fails. With this
patch we get the expected behavior:

$ perf stat -v -- sleep 1
cycles event is not supported by the kernel.
stalled-cycles-frontend event is not supported by the kernel.
stalled-cycles-backend event is not supported by the kernel.
instructions event is not supported by the kernel.
branches event is not supported by the kernel.
branch-misses event is not supported by the kernel.

...

Signed-off-by: David Ahern <dsahern@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/1336490956-57145-1-git-send-email-dsahern@gmail.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

David Ahern and committed by
Arnaldo Carvalho de Melo
20d23aaa 09c0211c

+6 -1
+6 -1
tools/perf/builtin-stat.c
··· 488 488 489 489 list_for_each_entry(counter, &evsel_list->entries, node) { 490 490 if (create_perf_stat_counter(counter, first) < 0) { 491 + /* 492 + * PPC returns ENXIO for HW counters until 2.6.37 493 + * (behavior changed with commit b0a873e). 494 + */ 491 495 if (errno == EINVAL || errno == ENOSYS || 492 - errno == ENOENT || errno == EOPNOTSUPP) { 496 + errno == ENOENT || errno == EOPNOTSUPP || 497 + errno == ENXIO) { 493 498 if (verbose) 494 499 ui__warning("%s event is not supported by the kernel.\n", 495 500 event_name(counter));