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

perf stat: Stop repeating when ref_perf_stat() returns -1

Exit when run_perf_stat() returns an error to avoid continuously
repeating the same error message. It's not expected that COUNTER_FATAL
or internal errors are recoverable so there's no point in retrying.

This fixes the following flood of error messages for permission issues,
for example when perf_event_paranoid==3:
perf stat -r 1044 -- false

Error:
Access to performance monitoring and observability operations is limited.
...
Error:
Access to performance monitoring and observability operations is limited.
...
(repeating for 1044 times).

Signed-off-by: Levi Yun <yeoreum.yun@arm.com>
Reviewed-by: James Clark <james.clark@linaro.org>
Cc: nd@arm.com
Cc: howardchu95@gmail.com
Link: https://lore.kernel.org/r/20240925132022.2650180-3-yeoreum.yun@arm.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>

authored by

Levi Yun and committed by
Namhyung Kim
b77f8c36 e880a70f

+12 -1
+12 -1
tools/perf/builtin-stat.c
··· 968 968 return err; 969 969 } 970 970 971 + /* 972 + * Returns -1 for fatal errors which signifies to not continue 973 + * when in repeat mode. 974 + * 975 + * Returns < -1 error codes when stat record is used. These 976 + * result in the stat information being displayed, but writing 977 + * to the file fails and is non fatal. 978 + */ 971 979 static int run_perf_stat(int argc, const char **argv, int run_idx) 972 980 { 973 981 int ret; ··· 2907 2899 evlist__reset_prev_raw_counts(evsel_list); 2908 2900 2909 2901 status = run_perf_stat(argc, argv, run_idx); 2910 - if (forever && status != -1 && !interval) { 2902 + if (status == -1) 2903 + break; 2904 + 2905 + if (forever && !interval) { 2911 2906 print_counters(NULL, argc, argv); 2912 2907 perf_stat__reset_stats(); 2913 2908 }