Skip to content

Commit 4f52ca1

Browse files
German Gomezacmel
authored andcommitted
perf test arm-spe: Check if perf-record hangs when recording workload with forks
Add shell test to check if perf-record hangs when recording an arm_spe event with forks. The test FAILS if the Kernel is not patched with Commit 961c391 ("perf: Always wake the parent event"). Unpatched Kernel: $ perf test -v 90 90: Check Arm SPE doesn't hang when there are forks --- start --- test child forked, pid 14232 Recording workload with fork Log lines = 90 /tmp/__perf_test.stderr.0Nu0U Log lines after 1 second = 90 /tmp/__perf_test.stderr.0Nu0U SPE hang test: FAIL test child finished with -1 ---- end ---- Check Arm SPE trace data in workload with forks: FAILED! Patched Kernel: $ perf test -v 90 90: Check Arm SPE doesn't hang when there are forks --- start --- test child forked, pid 2930 Compiling test program... Recording workload... Log lines = 478 /tmp/__perf_test.log.026AI Log lines after 1 second = 557 /tmp/__perf_test.log.026AI SPE hang test: PASS Cleaning up files... test child finished with 0 ---- end ---- Check Arm SPE trace data in workload with forks: Ok Reviewed-by: James Clark <[email protected]> Reviewed-by: Leo Yan <[email protected]> Signed-off-by: German Gomez <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Namhyung Kim <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 8db4308 commit 4f52ca1

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#!/bin/sh
2+
# Check Arm SPE doesn't hang when there are forks
3+
4+
# SPDX-License-Identifier: GPL-2.0
5+
# German Gomez <[email protected]>, 2022
6+
7+
skip_if_no_arm_spe_event() {
8+
perf list | egrep -q 'arm_spe_[0-9]+//' && return 0
9+
return 2
10+
}
11+
12+
skip_if_no_arm_spe_event || exit 2
13+
14+
# skip if there's no compiler
15+
if ! [ -x "$(command -v cc)" ]; then
16+
echo "failed: no compiler, install gcc"
17+
exit 2
18+
fi
19+
20+
TEST_PROGRAM_SOURCE=$(mktemp /tmp/__perf_test.program.XXXXX.c)
21+
TEST_PROGRAM=$(mktemp /tmp/__perf_test.program.XXXXX)
22+
PERF_DATA=$(mktemp /tmp/__perf_test.perf.data.XXXXX)
23+
PERF_RECORD_LOG=$(mktemp /tmp/__perf_test.log.XXXXX)
24+
25+
cleanup_files()
26+
{
27+
echo "Cleaning up files..."
28+
rm -f ${PERF_RECORD_LOG}
29+
rm -f ${PERF_DATA}
30+
rm -f ${TEST_PROGRAM_SOURCE}
31+
rm -f ${TEST_PROGRAM}
32+
}
33+
34+
trap cleanup_files exit term int
35+
36+
# compile test program
37+
cat << EOF > $TEST_PROGRAM_SOURCE
38+
#include <math.h>
39+
#include <stdio.h>
40+
#include <stdlib.h>
41+
#include <unistd.h>
42+
#include <sys/wait.h>
43+
44+
int workload() {
45+
while (1)
46+
sqrt(rand());
47+
return 0;
48+
}
49+
50+
int main() {
51+
switch (fork()) {
52+
case 0:
53+
return workload();
54+
case -1:
55+
return 1;
56+
default:
57+
wait(NULL);
58+
}
59+
return 0;
60+
}
61+
EOF
62+
63+
echo "Compiling test program..."
64+
CFLAGS="-lm"
65+
cc $TEST_PROGRAM_SOURCE $CFLAGS -o $TEST_PROGRAM || exit 1
66+
67+
echo "Recording workload..."
68+
perf record -o ${PERF_DATA} -e arm_spe/period=65536/ -vvv -- $TEST_PROGRAM > ${PERF_RECORD_LOG} 2>&1 &
69+
PERFPID=$!
70+
71+
# Check if perf hangs by checking the perf-record logs.
72+
sleep 1
73+
log0=$(wc -l $PERF_RECORD_LOG)
74+
echo Log lines = $log0
75+
sleep 1
76+
log1=$(wc -l $PERF_RECORD_LOG)
77+
echo Log lines after 1 second = $log1
78+
79+
kill $PERFPID
80+
wait $PERFPID
81+
# test program may leave an orphan process running the workload
82+
killall $(basename $TEST_PROGRAM)
83+
84+
if [ "$log0" = "$log1" ];
85+
then
86+
echo "SPE hang test: FAIL"
87+
exit 1
88+
else
89+
echo "SPE hang test: PASS"
90+
fi
91+
92+
exit 0

0 commit comments

Comments
 (0)