blob: 5d17dc624cbe6f5b8fc1d9ad6f8e8cacd057b904 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
#!/bin/bash
# AMD IBS software filtering
cpu_family() {
grep -m1 '^cpu family[[:space:]]*:' /proc/cpuinfo \
| awk -F: '{gsub(/^[ \t]+/, "", $2); print $2}'
}
cpu_model() {
grep -m1 '^model[[:space:]]*:' /proc/cpuinfo \
| awk -F: '{gsub(/^[ \t]+/, "", $2); print $2}'
}
# IBS PMUs does not advertize privilege filtering capability. Rely
# on Family / Model check.
hw_priv_filter_supported() {
family=$(cpu_family)
model=$(cpu_model)
if (( family > 0x1a )) ||
{ (( family == 0x1a )) &&
{ { (( model >= 0x50 && model <= 0x5f )) ||
(( model >= 0x80 && model <= 0xaf )) ||
(( model >= 0xc0 && model <= 0xcf )); }; }; }; then
return 0 # True
else
return 1 # False
fi
}
ParanoidAndNotRoot() {
[ "$(id -u)" != 0 ] && [ "$(cat /proc/sys/kernel/perf_event_paranoid)" -gt $1 ]
}
echo "check availability of IBS swfilt"
# check if IBS PMU is available
if [ ! -d /sys/bus/event_source/devices/ibs_op ]; then
echo "[SKIP] IBS PMU does not exist"
exit 2
fi
# check if IBS PMU has swfilt format
if [ ! -f /sys/bus/event_source/devices/ibs_op/format/swfilt ]; then
echo "[SKIP] IBS PMU does not have swfilt"
exit 2
fi
echo "run perf record with modifier and swfilt"
err=0
# setting any modifiers should fail
if ! hw_priv_filter_supported; then
perf record -B -e ibs_op//u -o /dev/null true 2> /dev/null
if [ $? -eq 0 ]; then
echo "[FAIL] IBS PMU should not accept exclude_kernel"
exit 1
fi
fi
# setting it with swfilt should be fine
perf record -B -e ibs_op/swfilt/u -o /dev/null true
if [ $? -ne 0 ]; then
echo "[FAIL] IBS op PMU cannot handle swfilt for exclude_kernel"
exit 1
fi
if ! ParanoidAndNotRoot 1
then
# setting it with swfilt=1 should be fine
perf record -B -e ibs_op/swfilt=1/k -o /dev/null true
if [ $? -ne 0 ]; then
echo "[FAIL] IBS op PMU cannot handle swfilt for exclude_user"
exit 1
fi
else
echo "[SKIP] not root and perf_event_paranoid too high for exclude_user"
err=2
fi
# check ibs_fetch PMU as well
perf record -B -e ibs_fetch/swfilt/u -o /dev/null true
if [ $? -ne 0 ]; then
echo "[FAIL] IBS fetch PMU cannot handle swfilt for exclude_kernel"
exit 1
fi
# check system wide recording
if ! ParanoidAndNotRoot 0
then
perf record -aB --synth=no -e ibs_op/swfilt/k -o /dev/null true
if [ $? -ne 0 ]; then
echo "[FAIL] IBS op PMU cannot handle swfilt in system-wide mode"
exit 1
fi
else
echo "[SKIP] not root and perf_event_paranoid too high for system-wide/exclude_user"
err=2
fi
echo "check number of samples with swfilt"
kernel_sample=$(perf record -e ibs_op/swfilt/u -o- true | perf script -i- -F misc | grep -c ^K)
if [ ${kernel_sample} -ne 0 ]; then
echo "[FAIL] unexpected kernel samples: " ${kernel_sample}
exit 1
fi
if ! ParanoidAndNotRoot 1
then
user_sample=$(perf record -e ibs_fetch/swfilt/k -o- true | perf script -i- -F misc | grep -c ^U)
if [ ${user_sample} -ne 0 ]; then
echo "[FAIL] unexpected user samples: " ${user_sample}
exit 1
fi
else
echo "[SKIP] not root and perf_event_paranoid too high for exclude_user"
err=2
fi
exit $err
|