1#!/bin/bash 2# AMD IBS software filtering 3 4ParanoidAndNotRoot() { 5 [ "$(id -u)" != 0 ] && [ "$(cat /proc/sys/kernel/perf_event_paranoid)" -gt $1 ] 6} 7 8echo "check availability of IBS swfilt" 9 10# check if IBS PMU is available 11if [ ! -d /sys/bus/event_source/devices/ibs_op ]; then 12 echo "[SKIP] IBS PMU does not exist" 13 exit 2 14fi 15 16# check if IBS PMU has swfilt format 17if [ ! -f /sys/bus/event_source/devices/ibs_op/format/swfilt ]; then 18 echo "[SKIP] IBS PMU does not have swfilt" 19 exit 2 20fi 21 22echo "run perf record with modifier and swfilt" 23err=0 24 25# setting any modifiers should fail 26perf record -B -e ibs_op//u -o /dev/null true 2> /dev/null 27if [ $? -eq 0 ]; then 28 echo "[FAIL] IBS PMU should not accept exclude_kernel" 29 exit 1 30fi 31 32# setting it with swfilt should be fine 33perf record -B -e ibs_op/swfilt/u -o /dev/null true 34if [ $? -ne 0 ]; then 35 echo "[FAIL] IBS op PMU cannot handle swfilt for exclude_kernel" 36 exit 1 37fi 38 39if ! ParanoidAndNotRoot 1 40then 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 47else 48 echo "[SKIP] not root and perf_event_paranoid too high for exclude_user" 49 err=2 50fi 51 52# check ibs_fetch PMU as well 53perf record -B -e ibs_fetch/swfilt/u -o /dev/null true 54if [ $? -ne 0 ]; then 55 echo "[FAIL] IBS fetch PMU cannot handle swfilt for exclude_kernel" 56 exit 1 57fi 58 59# check system wide recording 60if ! ParanoidAndNotRoot 0 61then 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 67else 68 echo "[SKIP] not root and perf_event_paranoid too high for system-wide/exclude_user" 69 err=2 70fi 71 72echo "check number of samples with swfilt" 73 74kernel_sample=$(perf record -e ibs_op/swfilt/u -o- true | perf script -i- -F misc | grep -c ^K) 75if [ ${kernel_sample} -ne 0 ]; then 76 echo "[FAIL] unexpected kernel samples: " ${kernel_sample} 77 exit 1 78fi 79 80if ! ParanoidAndNotRoot 1 81then 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 87else 88 echo "[SKIP] not root and perf_event_paranoid too high for exclude_user" 89 err=2 90fi 91 92exit $err 93