diff options
author | Ian Rogers <irogers@google.com> | 2025-08-25 14:12:03 -0700 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2025-09-12 15:51:43 -0300 |
commit | 9eac5612da1c91027fb842d42cdf228d8c93e350 (patch) | |
tree | 92ab57e74ef9d0a6f0187babd8f02d99adb1fc91 | |
parent | 7970e206e18f0d9c2c5e36d2dbdfb0d52902aa9d (diff) |
perf stat: Don't skip failing group events
Pass errno to stat_handle_error() rather than reading errno after it has
potentially been clobbered.
Move "skippable" handling first as a skippable event (from the perf stat
default list) should always just be skipped.
Remove logic to skip rather than fail events in a group when they
aren't the group leader.
The original logic was added in commit cb5ef60067c1 ("perf stat: Error
out unsupported group leader immediately") due to error handling and
opening being together and an assertion being raised.
Not failing this case causes broken groups to not report values,
particularly for topdown events.
Closes: https://lore.kernel.org/lkml/20250822082233.1850417-1-dapeng1.mi@linux.intel.com/
Reported-by: Dapeng Mi <dapeng1.mi@linux.intel.com>
Reviewed-by: Dapeng Mi <dapeng1.mi@linux.intel.com>
Signed-off-by: Ian Rogers <irogers@google.com>
Tested-by: Dapeng Mi <dapeng1.mi@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Howard Chu <howardchu95@gmail.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@linaro.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Falcon <thomas.falcon@intel.com>
Cc: Yoshihiro Furudera <fj5100bi@fujitsu.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r-- | tools/perf/builtin-stat.c | 48 |
1 files changed, 21 insertions, 27 deletions
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 2c38dd98f6ca..ab567919b89a 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -613,33 +613,40 @@ enum counter_recovery { COUNTER_FATAL, }; -static enum counter_recovery stat_handle_error(struct evsel *counter) +static enum counter_recovery stat_handle_error(struct evsel *counter, int err) { char msg[BUFSIZ]; + + if (counter->skippable) { + if (verbose > 0) { + ui__warning("skipping event %s that kernel failed to open .\n", + evsel__name(counter)); + } + counter->supported = false; + counter->errored = true; + return COUNTER_SKIP; + } + /* * PPC returns ENXIO for HW counters until 2.6.37 * (behavior changed with commit b0a873e). */ - if (errno == EINVAL || errno == ENOSYS || - errno == ENOENT || errno == ENXIO) { - if (verbose > 0) + if (err == EINVAL || err == ENOSYS || err == ENOENT || err == ENXIO) { + if (verbose > 0) { ui__warning("%s event is not supported by the kernel.\n", evsel__name(counter)); + } counter->supported = false; /* * errored is a sticky flag that means one of the counter's * cpu event had a problem and needs to be reexamined. */ counter->errored = true; - - if ((evsel__leader(counter) != counter) || - !(counter->core.leader->nr_members > 1)) - return COUNTER_SKIP; - } else if (evsel__fallback(counter, &target, errno, msg, sizeof(msg))) { + } else if (evsel__fallback(counter, &target, err, msg, sizeof(msg))) { if (verbose > 0) ui__warning("%s\n", msg); return COUNTER_RETRY; - } else if (target__has_per_thread(&target) && errno != EOPNOTSUPP && + } else if (target__has_per_thread(&target) && err != EOPNOTSUPP && evsel_list->core.threads && evsel_list->core.threads->err_thread != -1) { /* @@ -651,29 +658,16 @@ static enum counter_recovery stat_handle_error(struct evsel *counter) evsel_list->core.threads->err_thread = -1; return COUNTER_RETRY; } - } else if (counter->skippable) { - if (verbose > 0) - ui__warning("skipping event %s that kernel failed to open .\n", - evsel__name(counter)); - counter->supported = false; - counter->errored = true; - return COUNTER_SKIP; - } - - if (errno == EOPNOTSUPP) { + } else if (err == EOPNOTSUPP) { if (verbose > 0) { ui__warning("%s event is not supported by the kernel.\n", evsel__name(counter)); } counter->supported = false; counter->errored = true; - - if ((evsel__leader(counter) != counter) || - !(counter->core.leader->nr_members > 1)) - return COUNTER_SKIP; } - evsel__open_strerror(counter, &target, errno, msg, sizeof(msg)); + evsel__open_strerror(counter, &target, err, msg, sizeof(msg)); ui__error("%s\n", msg); if (child_pid != -1) @@ -761,7 +755,7 @@ try_again: continue; } - switch (stat_handle_error(counter)) { + switch (stat_handle_error(counter, errno)) { case COUNTER_FATAL: err = -1; goto err_out; @@ -803,7 +797,7 @@ try_again_reset: if (create_perf_stat_counter(counter, &stat_config, &target, evlist_cpu_itr.cpu_map_idx) < 0) { - switch (stat_handle_error(counter)) { + switch (stat_handle_error(counter, errno)) { case COUNTER_FATAL: err = -1; goto err_out; |