11#! /bin/bash
22# AMD IBS software filtering
33
4+ ParanoidAndNotRoot () {
5+ [ " $( id -u) " != 0 ] && [ " $( cat /proc/sys/kernel/perf_event_paranoid) " -gt $1 ]
6+ }
7+
48echo " check availability of IBS swfilt"
59
610# check if IBS PMU is available
@@ -16,6 +20,7 @@ if [ ! -f /sys/bus/event_source/devices/ibs_op/format/swfilt ]; then
1620fi
1721
1822echo " run perf record with modifier and swfilt"
23+ err=0
1924
2025# setting any modifiers should fail
2126perf record -B -e ibs_op//u -o /dev/null true 2> /dev/null
@@ -31,11 +36,17 @@ if [ $? -ne 0 ]; then
3136 exit 1
3237fi
3338
34- # setting it with swfilt=1 should be fine
35- perf record -B -e ibs_op/swfilt=1/k -o /dev/null true
36- if [ $? -ne 0 ]; then
37- echo " [FAIL] IBS op PMU cannot handle swfilt for exclude_user"
38- exit 1
39+ if ! ParanoidAndNotRoot 1
40+ then
41+ # setting it with swfilt=1 should be fine
42+ perf record -B -e ibs_op/swfilt=1/k -o /dev/null true
43+ if [ $? -ne 0 ]; then
44+ echo " [FAIL] IBS op PMU cannot handle swfilt for exclude_user"
45+ exit 1
46+ fi
47+ else
48+ echo " [SKIP] not root and perf_event_paranoid too high for exclude_user"
49+ err=2
3950fi
4051
4152# check ibs_fetch PMU as well
@@ -46,10 +57,16 @@ if [ $? -ne 0 ]; then
4657fi
4758
4859# check system wide recording
49- perf record -aB --synth=no -e ibs_op/swfilt/k -o /dev/null true
50- if [ $? -ne 0 ]; then
51- echo " [FAIL] IBS op PMU cannot handle swfilt in system-wide mode"
52- exit 1
60+ if ! ParanoidAndNotRoot 0
61+ then
62+ perf record -aB --synth=no -e ibs_op/swfilt/k -o /dev/null true
63+ if [ $? -ne 0 ]; then
64+ echo " [FAIL] IBS op PMU cannot handle swfilt in system-wide mode"
65+ exit 1
66+ fi
67+ else
68+ echo " [SKIP] not root and perf_event_paranoid too high for system-wide/exclude_user"
69+ err=2
5370fi
5471
5572echo " check number of samples with swfilt"
@@ -60,8 +77,16 @@ if [ ${kernel_sample} -ne 0 ]; then
6077 exit 1
6178fi
6279
63- user_sample=$( perf record -e ibs_fetch/swfilt/k -o- true | perf script -i- -F misc | grep -c ^U)
64- if [ ${user_sample} -ne 0 ]; then
65- echo " [FAIL] unexpected user samples: " ${user_sample}
66- exit 1
80+ if ! ParanoidAndNotRoot 1
81+ then
82+ user_sample=$( perf record -e ibs_fetch/swfilt/k -o- true | perf script -i- -F misc | grep -c ^U)
83+ if [ ${user_sample} -ne 0 ]; then
84+ echo " [FAIL] unexpected user samples: " ${user_sample}
85+ exit 1
86+ fi
87+ else
88+ echo " [SKIP] not root and perf_event_paranoid too high for exclude_user"
89+ err=2
6790fi
91+
92+ exit $err
0 commit comments