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

perf test: Add kernel lock contention test

Add a new shell test to check if both normal 'perf lock record' +
contention and BPF (with -b) option are working.

Use 'perf bench sched messaging' as a workload since it creates some
contention for sending and receiving messages.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Acked-by: Adrian Hunter <adrian.hunter@intel.com>
Acked-by: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20220924004221.841024-3-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Namhyung Kim and committed by
Arnaldo Carvalho de Melo
ec685de2 6bbc4820

+73
+73
tools/perf/tests/shell/lock_contention.sh
··· 1 + #!/bin/sh 2 + # kernel lock contention analysis test 3 + # SPDX-License-Identifier: GPL-2.0 4 + 5 + set -e 6 + 7 + err=0 8 + perfdata=$(mktemp /tmp/__perf_test.perf.data.XXXXX) 9 + result=$(mktemp /tmp/__perf_test.result.XXXXX) 10 + 11 + cleanup() { 12 + rm -f ${perfdata} 13 + rm -f ${result} 14 + trap - exit term int 15 + } 16 + 17 + trap_cleanup() { 18 + cleanup 19 + exit ${err} 20 + } 21 + trap trap_cleanup exit term int 22 + 23 + check() { 24 + if [ `id -u` != 0 ]; then 25 + echo "[Skip] No root permission" 26 + err=2 27 + exit 28 + fi 29 + 30 + if ! perf list | grep -q lock:contention_begin; then 31 + echo "[Skip] No lock contention tracepoints" 32 + err=2 33 + exit 34 + fi 35 + } 36 + 37 + test_record() 38 + { 39 + echo "Testing perf lock record and perf lock contention" 40 + perf lock record -o ${perfdata} -- perf bench sched messaging > /dev/null 2>&1 41 + # the output goes to the stderr and we expect only 1 output (-E 1) 42 + perf lock contention -i ${perfdata} -E 1 -q 2> ${result} 43 + if [ $(cat "${result}" | wc -l) != "1" ]; then 44 + echo "[Fail] Recorded result count is not 1:" $(cat "${result}" | wc -l) 45 + err=1 46 + exit 47 + fi 48 + } 49 + 50 + test_bpf() 51 + { 52 + echo "Testing perf lock contention --use-bpf" 53 + 54 + if ! perf lock con -b true > /dev/null 2>&1 ; then 55 + echo "[Skip] No BPF support" 56 + exit 57 + fi 58 + 59 + # the perf lock contention output goes to the stderr 60 + perf lock con -a -b -E 1 -q -- perf bench sched messaging > /dev/null 2> ${result} 61 + if [ $(cat "${result}" | wc -l) != "1" ]; then 62 + echo "[Fail] BPF result count is not 1:" $(cat "${result}" | wc -l) 63 + err=1 64 + exit 65 + fi 66 + } 67 + 68 + check 69 + 70 + test_record 71 + test_bpf 72 + 73 + exit ${err}