Skip to content

Commit 45cd84b

Browse files
captain5050namhyung
authored andcommitted
perf tests: Add a DRM PMU test
The test opens any DRM devices so that the shell has fdinfo files containing the DRM data. The test then uses perf stat to make sure the events can be read. Signed-off-by: Ian Rogers <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Namhyung Kim <[email protected]>
1 parent 28917cb commit 45cd84b

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

tools/perf/tests/shell/drm_pmu.sh

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/bin/bash
2+
# DRM PMU
3+
# SPDX-License-Identifier: GPL-2.0
4+
5+
set -e
6+
7+
output=$(mktemp /tmp/perf.drm_pmu.XXXXXX.txt)
8+
9+
cleanup() {
10+
rm -f "${output}"
11+
12+
trap - EXIT TERM INT
13+
}
14+
15+
trap_cleanup() {
16+
echo "Unexpected signal in ${FUNCNAME[1]}"
17+
cleanup
18+
exit 1
19+
}
20+
trap trap_cleanup EXIT TERM INT
21+
22+
# Array to store file descriptors and device names
23+
declare -A device_fds
24+
25+
# Open all devices and store file descriptors. Opening the device will create a
26+
# /proc/$$/fdinfo file containing the DRM statistics.
27+
fd_count=3 # Start with file descriptor 3
28+
for device in /dev/dri/*
29+
do
30+
if [[ ! -c "$device" ]]
31+
then
32+
continue
33+
fi
34+
major=$(stat -c "%Hr" "$device")
35+
if [[ "$major" != 226 ]]
36+
then
37+
continue
38+
fi
39+
echo "Opening $device"
40+
eval "exec $fd_count<\"$device\""
41+
echo "fdinfo for: $device (FD: $fd_count)"
42+
cat "/proc/$$/fdinfo/$fd_count"
43+
echo
44+
device_fds["$device"]="$fd_count"
45+
fd_count=$((fd_count + 1))
46+
done
47+
48+
if [[ ${#device_fds[@]} -eq 0 ]]
49+
then
50+
echo "No DRM devices found [Skip]"
51+
cleanup
52+
exit 2
53+
fi
54+
55+
# For each DRM event
56+
err=0
57+
for p in $(perf list --raw-dump drm-)
58+
do
59+
echo -n "Testing perf stat of $p. "
60+
perf stat -e "$p" --pid=$$ true > "$output" 2>&1
61+
if ! grep -q "$p" "$output"
62+
then
63+
echo "Missing DRM event in: [Failed]"
64+
cat "$output"
65+
err=1
66+
else
67+
echo "[OK]"
68+
fi
69+
done
70+
71+
# Close all file descriptors
72+
for fd in "${device_fds[@]}"; do
73+
eval "exec $fd<&-"
74+
done
75+
76+
# Finished
77+
cleanup
78+
exit $err

0 commit comments

Comments
 (0)