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

perf offcpu: Update offcpu test for child process

Record off-cpu data with perf bench sched messaging workload and count
the number of offcpu-time events. Also update the test script not to
run next tests if failed already and revise the error messages.

$ sudo ./perf test offcpu -v
88: perf record offcpu profiling tests :
--- start ---
test child forked, pid 344780
Checking off-cpu privilege
Basic off-cpu test
Basic off-cpu test [Success]
Child task off-cpu test
Child task off-cpu test [Success]
test child finished with 0
---- end ----
perf record offcpu profiling tests: Ok

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Blake Jones <blakejones@google.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: Milian Wolff <milian.wolff@kdab.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Song Liu <songliubraving@fb.com>
Cc: bpf@vger.kernel.org
Link: https://lore.kernel.org/r/20220811185456.194721-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
ade1d030 d2347763

+50 -7
+50 -7
tools/perf/tests/shell/record_offcpu.sh
··· 19 19 } 20 20 trap trap_cleanup exit term int 21 21 22 - test_offcpu() { 23 - echo "Basic off-cpu test" 22 + test_offcpu_priv() { 23 + echo "Checking off-cpu privilege" 24 + 24 25 if [ `id -u` != 0 ] 25 26 then 26 - echo "Basic off-cpu test [Skipped permission]" 27 + echo "off-cpu test [Skipped permission]" 27 28 err=2 28 29 return 29 30 fi 30 - if perf record --off-cpu -o ${perfdata} --quiet true 2>&1 | grep BUILD_BPF_SKEL 31 + if perf record --off-cpu -o /dev/null --quiet true 2>&1 | grep BUILD_BPF_SKEL 31 32 then 32 - echo "Basic off-cpu test [Skipped missing BPF support]" 33 + echo "off-cpu test [Skipped missing BPF support]" 33 34 err=2 34 35 return 35 36 fi 37 + } 38 + 39 + test_offcpu_basic() { 40 + echo "Basic off-cpu test" 41 + 36 42 if ! perf record --off-cpu -e dummy -o ${perfdata} sleep 1 2> /dev/null 37 43 then 38 44 echo "Basic off-cpu test [Failed record]" ··· 47 41 fi 48 42 if ! perf evlist -i ${perfdata} | grep -q "offcpu-time" 49 43 then 50 - echo "Basic off-cpu test [Failed record]" 44 + echo "Basic off-cpu test [Failed no event]" 51 45 err=1 52 46 return 53 47 fi ··· 60 54 echo "Basic off-cpu test [Success]" 61 55 } 62 56 63 - test_offcpu 57 + test_offcpu_child() { 58 + echo "Child task off-cpu test" 59 + 60 + # perf bench sched messaging creates 400 processes 61 + if ! perf record --off-cpu -e dummy -o ${perfdata} -- \ 62 + perf bench sched messaging -g 10 > /dev/null 2&>1 63 + then 64 + echo "Child task off-cpu test [Failed record]" 65 + err=1 66 + return 67 + fi 68 + if ! perf evlist -i ${perfdata} | grep -q "offcpu-time" 69 + then 70 + echo "Child task off-cpu test [Failed no event]" 71 + err=1 72 + return 73 + fi 74 + # each process waits for read and write, so it should be more than 800 events 75 + if ! perf report -i ${perfdata} -s comm -q -n -t ';' --percent-limit=90 | \ 76 + awk -F ";" '{ if (NF > 3 && int($3) < 800) exit 1; }' 77 + then 78 + echo "Child task off-cpu test [Failed invalid output]" 79 + err=1 80 + return 81 + fi 82 + echo "Child task off-cpu test [Success]" 83 + } 84 + 85 + 86 + test_offcpu_priv 87 + 88 + if [ $err = 0 ]; then 89 + test_offcpu_basic 90 + fi 91 + 92 + if [ $err = 0 ]; then 93 + test_offcpu_child 94 + fi 64 95 65 96 cleanup 66 97 exit $err