amd-ibs-swfilt.sh 2.4 KB

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