Skip to content

Commit 60abedb

Browse files
Leo Yanacmel
authored andcommitted
perf test: Introduce script for data symbol testing
The test is designed with a data structure with 64-byte alignment, it has two fields "data1" and "data2", and other fields are reserved. Using the "perf mem" command, we can record and report memory samples for a self-contained workload with 1 second duration. If no samples are obtained for the data structure "buf1", it reports failure; and by checking the offset in structure "buf1", if the memory samples aren't for the "data1" and "data2" fields, it means wrong data symbol parsing and returns failure. Committer testing: [root@quaco ~]# grep -m1 "model name" /proc/cpuinfo model name : Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz [root@quaco ~]# [root@quaco ~]# perf test -v "data symbol" 104: Test data symbol : --- start --- test child forked, pid 192318 Compiling test program... Recording workload... [ perf record: Woken up 2 times to write data ] [ perf record: Captured and wrote 0.389 MB /tmp/__perf_test.perf.data.LIuQl (5570 samples) ] Cleaning up files... test child finished with 0 ---- end ---- Test data symbol: Ok [root@quaco ~]# Signed-off-by: Leo Yan <[email protected]> Tested-by: Arnaldo Carvalho de Melo <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Ravi Bangoria <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent fd643af commit 60abedb

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#!/bin/bash
2+
# Test data symbol
3+
4+
# SPDX-License-Identifier: GPL-2.0
5+
# Leo Yan <[email protected]>, 2022
6+
7+
skip_if_no_mem_event() {
8+
perf mem record -e list 2>&1 | egrep -q 'available' && return 0
9+
return 2
10+
}
11+
12+
skip_if_no_mem_event || exit 2
13+
14+
# skip if there's no compiler
15+
if ! [ -x "$(command -v cc)" ]; then
16+
echo "skip: no compiler, install gcc"
17+
exit 2
18+
fi
19+
20+
TEST_PROGRAM=$(mktemp /tmp/__perf_test.program.XXXXX)
21+
PERF_DATA=$(mktemp /tmp/__perf_test.perf.data.XXXXX)
22+
23+
check_result() {
24+
# The memory report format is as below:
25+
# 99.92% ... [.] buf1+0x38
26+
result=$(perf mem report -i ${PERF_DATA} -s symbol_daddr -q 2>&1 |
27+
awk '/buf1/ { print $4 }')
28+
29+
# Testing is failed if has no any sample for "buf1"
30+
[ -z "$result" ] && return 1
31+
32+
while IFS= read -r line; do
33+
# The "data1" and "data2" fields in structure "buf1" have
34+
# offset "0x0" and "0x38", returns failure if detect any
35+
# other offset value.
36+
if [ "$line" != "buf1+0x0" ] && [ "$line" != "buf1+0x38" ]; then
37+
return 1
38+
fi
39+
done <<< "$result"
40+
41+
return 0
42+
}
43+
44+
cleanup_files()
45+
{
46+
echo "Cleaning up files..."
47+
rm -f ${PERF_DATA}
48+
rm -f ${TEST_PROGRAM}
49+
}
50+
51+
trap cleanup_files exit term int
52+
53+
# compile test program
54+
echo "Compiling test program..."
55+
cat << EOF | cc -o ${TEST_PROGRAM} -x c -
56+
typedef struct _buf {
57+
char data1;
58+
char reserved[55];
59+
char data2;
60+
} buf __attribute__((aligned(64)));
61+
62+
static buf buf1;
63+
64+
int main(void) {
65+
for (;;) {
66+
buf1.data1++;
67+
buf1.data2 += buf1.data1;
68+
}
69+
return 0;
70+
}
71+
EOF
72+
73+
echo "Recording workload..."
74+
75+
# perf mem/c2c internally uses IBS PMU on AMD CPU which doesn't support
76+
# user/kernel filtering and per-process monitoring, spin program on
77+
# specific CPU and test in per-CPU mode.
78+
is_amd=$(egrep -c 'vendor_id.*AuthenticAMD' /proc/cpuinfo)
79+
if (($is_amd >= 1)); then
80+
perf mem record -o ${PERF_DATA} -C 0 -- taskset -c 0 $TEST_PROGRAM &
81+
else
82+
perf mem record --all-user -o ${PERF_DATA} -- $TEST_PROGRAM &
83+
fi
84+
85+
PERFPID=$!
86+
87+
sleep 1
88+
89+
kill $PERFPID
90+
wait $PERFPID
91+
92+
check_result
93+
exit $?

0 commit comments

Comments
 (0)