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

perf test: Add more test cases for perf lock contention

Check callstack filter with two different aggregation mode.

$ sudo ./perf test -v contention
88: kernel lock contention analysis test :
--- start ---
test child forked, pid 83416
Testing perf lock record and perf lock contention
Testing perf lock contention --use-bpf
Testing perf lock record and perf lock contention at the same time
Testing perf lock contention --threads
Testing perf lock contention --lock-addr
Testing perf lock contention --type-filter (w/ spinlock)
Testing perf lock contention --lock-filter (w/ tasklist_lock)
Testing perf lock contention --callstack-filter (w/ unix_stream)
Testing perf lock contention --callstack-filter with task aggregation
test child finished with 0
---- end ----
kernel lock contention analysis test: Ok

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Hao Luo <haoluo@google.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Song Liu <song@kernel.org>
Cc: bpf@vger.kernel.org
Link: https://lore.kernel.org/r/20230202050455.2187592-5-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Namhyung Kim and committed by
Arnaldo Carvalho de Melo
79b7ca78 540f8b56

+62 -4
+62 -4
tools/perf/tests/shell/lock_contention.sh
··· 128 128 echo "Testing perf lock contention --type-filter (w/ spinlock)" 129 129 perf lock contention -i ${perfdata} -Y spinlock -q 2> ${result} 130 130 if [ $(grep -c -v spinlock "${result}") != "0" ]; then 131 - echo "[Fail] Recorded should not have non-spinlocks:" $(cat "${result}") 131 + echo "[Fail] Recorded result should not have non-spinlocks:" $(cat "${result}") 132 132 err=1 133 133 exit 134 134 fi ··· 139 139 140 140 perf lock con -a -b -Y spinlock -q -- perf bench sched messaging > /dev/null 2> ${result} 141 141 if [ $(grep -c -v spinlock "${result}") != "0" ]; then 142 - echo "[Fail] Recorded should not have non-spinlocks:" $(cat "${result}") 142 + echo "[Fail] BPF result should not have non-spinlocks:" $(cat "${result}") 143 143 err=1 144 144 exit 145 145 fi ··· 160 160 local type=$(head -1 "${result}" | awk '{ print $8 }' | sed -e 's/:.*//') 161 161 162 162 if [ $(grep -c -v "${type}" "${result}") != "0" ]; then 163 - echo "[Fail] Recorded should not have non-${type} locks:" $(cat "${result}") 163 + echo "[Fail] Recorded result should not have non-${type} locks:" $(cat "${result}") 164 164 err=1 165 165 exit 166 166 fi ··· 171 171 172 172 perf lock con -a -b -L tasklist_lock -q -- perf bench sched messaging > /dev/null 2> ${result} 173 173 if [ $(grep -c -v "${type}" "${result}") != "0" ]; then 174 - echo "[Fail] Recorded should not have non-${type} locks:" $(cat "${result}") 174 + echo "[Fail] BPF result should not have non-${type} locks:" $(cat "${result}") 175 + err=1 176 + exit 177 + fi 178 + } 179 + 180 + test_stack_filter() 181 + { 182 + echo "Testing perf lock contention --callstack-filter (w/ unix_stream)" 183 + perf lock contention -i ${perfdata} -v -q 2> ${result} 184 + if [ $(grep -c unix_stream "${result}") == "0" ]; then 185 + echo "[Skip] Could not find 'unix_stream'" 186 + return 187 + fi 188 + 189 + perf lock contention -i ${perfdata} -E 1 -S unix_stream -q 2> ${result} 190 + if [ $(cat "${result}" | wc -l) != "1" ]; then 191 + echo "[Fail] Recorded result should have a lock from unix_stream:" $(cat "${result}") 192 + err=1 193 + exit 194 + fi 195 + 196 + if ! perf lock con -b true > /dev/null 2>&1 ; then 197 + return 198 + fi 199 + 200 + perf lock con -a -b -S unix_stream -E 1 -q -- perf bench sched messaging > /dev/null 2> ${result} 201 + if [ $(cat "${result}" | wc -l) != "1" ]; then 202 + echo "[Fail] BPF result should have a lock from unix_stream:" $(cat "${result}") 203 + err=1 204 + exit 205 + fi 206 + } 207 + 208 + test_aggr_task_stack_filter() 209 + { 210 + echo "Testing perf lock contention --callstack-filter with task aggregation" 211 + perf lock contention -i ${perfdata} -v -q 2> ${result} 212 + if [ $(grep -c unix_stream "${result}") == "0" ]; then 213 + echo "[Skip] Could not find 'unix_stream'" 214 + return 215 + fi 216 + 217 + perf lock contention -i ${perfdata} -t -E 1 -S unix_stream -q 2> ${result} 218 + if [ $(cat "${result}" | wc -l) != "1" ]; then 219 + echo "[Fail] Recorded result should have a task from unix_stream:" $(cat "${result}") 220 + err=1 221 + exit 222 + fi 223 + 224 + if ! perf lock con -b true > /dev/null 2>&1 ; then 225 + return 226 + fi 227 + 228 + perf lock con -a -b -t -S unix_stream -E 1 -q -- perf bench sched messaging > /dev/null 2> ${result} 229 + if [ $(cat "${result}" | wc -l) != "1" ]; then 230 + echo "[Fail] BPF result should have a task from unix_stream:" $(cat "${result}") 175 231 err=1 176 232 exit 177 233 fi ··· 242 186 test_aggr_addr 243 187 test_type_filter 244 188 test_lock_filter 189 + test_stack_filter 190 + test_aggr_task_stack_filter 245 191 246 192 exit ${err}