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

perf test shell lbr: Avoid failures with perf event paranoia

When not running as root and with higher perf event paranoia values
the perf record LBR tests could fail rather than skipping the
problematic tests.

Add the sensitivity to the test and confirm it passes with paranoia
values from -1 to 2.

Committer testing:

Testing with '$ perf test -vv lbr', i.e. as non root, and then comparing
the output shows the mentioned errors before this patch:

acme@x1:~$ grep -m1 "model name" /proc/cpuinfo
model name : 13th Gen Intel(R) Core(TM) i7-1365U
acme@x1:~$

Before:

132: perf record LBR tests : Skip

After:

132: perf record LBR tests : Ok

Fixes: 32559b99e0f59070 ("perf test: Add set of perf record LBR tests")
Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Chun-Tse Shao <ctshao@google.com>
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>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Ian Rogers and committed by
Arnaldo Carvalho de Melo
48314d20 98dbed7a

+20 -6
+20 -6
tools/perf/tests/shell/record_lbr.sh
··· 4 4 5 5 set -e 6 6 7 + ParanoidAndNotRoot() { 8 + [ "$(id -u)" != 0 ] && [ "$(cat /proc/sys/kernel/perf_event_paranoid)" -gt $1 ] 9 + } 10 + 7 11 if [ ! -f /sys/bus/event_source/devices/cpu/caps/branches ] && 8 12 [ ! -f /sys/bus/event_source/devices/cpu_core/caps/branches ] 9 13 then ··· 27 23 } 28 24 29 25 trap_cleanup() { 26 + echo "Unexpected signal in ${FUNCNAME[1]}" 30 27 cleanup 31 28 exit 1 32 29 } ··· 128 123 lbr_test "-j ind_jmp" "any indirect jump" 100 129 124 lbr_test "-j call" "direct calls" 2 130 125 lbr_test "-j ind_call,u" "any indirect user call" 100 131 - lbr_test "-a -b" "system wide any branch" 2 132 - lbr_test "-a -j any_call" "system wide any call" 2 126 + if ! ParanoidAndNotRoot 1 127 + then 128 + lbr_test "-a -b" "system wide any branch" 2 129 + lbr_test "-a -j any_call" "system wide any call" 2 130 + fi 133 131 134 132 # Parallel 135 133 parallel_lbr_test "-b" "parallel any branch" 100 & ··· 149 141 pid6=$! 150 142 parallel_lbr_test "-j ind_call,u" "parallel any indirect user call" 100 & 151 143 pid7=$! 152 - parallel_lbr_test "-a -b" "parallel system wide any branch" 100 & 153 - pid8=$! 154 - parallel_lbr_test "-a -j any_call" "parallel system wide any call" 100 & 155 - pid9=$! 144 + if ParanoidAndNotRoot 1 145 + then 146 + pid8= 147 + pid9= 148 + else 149 + parallel_lbr_test "-a -b" "parallel system wide any branch" 100 & 150 + pid8=$! 151 + parallel_lbr_test "-a -j any_call" "parallel system wide any call" 100 & 152 + pid9=$! 153 + fi 156 154 157 155 for pid in $pid1 $pid2 $pid3 $pid4 $pid5 $pid6 $pid7 $pid8 $pid9 158 156 do