Files
cubelinux-kernel/tools/perf/tests/shell/amd-ibs-swfilt.sh
T
Greg Kroah-Hartman 598cf27219 Linux 6.19.3
Link: https://lore.kernel.org/r/20260217200002.683975158@linuxfoundation.org
Tested-by: Florian Fainelli <florian.fainelli@broadcom.com>
Tested-by: Takeshi Ogasawara <takeshi.ogasawara@futuring-girl.com>
Tested-by: Peter Schneider <pschneider1968@googlemail.com>
Tested-by: Jon Hunter <jonathanh@nvidia.com>
Tested-by: Salvatore Bonaccorso <carnil@debian.org>
Tested-by: Brett A C Sheffield <bacs@librecast.net>
Tested-by: Mark Brown <broonie@kernel.org>
Tested-by: Luna Jernberg <droidbittin@gmail.com>
Tested-by: Ronald Warsow <rwarsow@gmx.de>
Tested-by: Justin M. Forbes <jforbes@fedoraproject.org>
Tested-by: Ron Economos <re@w6rz.net>
Tested-by: Miguel Ojeda <ojeda@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2026-02-19 16:33:27 +01:00

93 lines
2.4 KiB
Bash
Executable File

#!/bin/bash
# AMD IBS software filtering
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
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
# 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