stat+shadow_stat.sh 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #!/bin/bash
  2. # perf stat metrics (shadow stat) test
  3. # SPDX-License-Identifier: GPL-2.0
  4. set -e
  5. THRESHOLD=0.015
  6. # skip if system-wide mode is forbidden
  7. perf stat -a true > /dev/null 2>&1 || exit 2
  8. # skip if on hybrid platform
  9. perf stat -a -e cycles sleep 1 2>&1 | grep -e cpu_core && exit 2
  10. test_global_aggr()
  11. {
  12. perf stat -a --no-big-num -M insn_per_cycle sleep 1 2>&1 | \
  13. grep -e cycles -e instructions | \
  14. while read num evt _ ipc rest
  15. do
  16. # skip not counted events
  17. if [ "$num" = "<not" ]; then
  18. continue
  19. fi
  20. # save cycles count
  21. if [ "$evt" = "cycles" ]; then
  22. cyc=$num
  23. continue
  24. fi
  25. # skip if no cycles
  26. if [ -z "$cyc" ]; then
  27. continue
  28. fi
  29. # use printf for rounding and a leading zero
  30. res=`echo $num $cyc | awk '{printf "%.2f", $1 / $2}'`
  31. if [ "$ipc" != "$res" ]; then
  32. # check the difference from the real result for FP imperfections
  33. diff=`echo $ipc $res $THRESHOLD | \
  34. awk '{x = ($1 - $2) < 0 ? ($2 - $1) : ($1 - $2); print (x > $3)}'`
  35. if [ $diff -eq 1 ]; then
  36. echo "IPC is different: $res != $ipc ($num / $cyc)"
  37. exit 1
  38. fi
  39. echo "Warning: Difference of IPC is under the threshold"
  40. fi
  41. done
  42. }
  43. test_no_aggr()
  44. {
  45. perf stat -a -A --no-big-num -M insn_per_cycle sleep 1 2>&1 | \
  46. grep ^CPU | \
  47. while read cpu num evt _ ipc rest
  48. do
  49. # skip not counted events
  50. if [ "$num" = "<not" ]; then
  51. continue
  52. fi
  53. # save cycles count
  54. if [ "$evt" = "cycles" ]; then
  55. results="$results $cpu:$num"
  56. continue
  57. fi
  58. cyc=${results##* $cpu:}
  59. cyc=${cyc%% *}
  60. # skip if no cycles
  61. if [ -z "$cyc" ]; then
  62. continue
  63. fi
  64. # use printf for rounding and a leading zero
  65. res=`echo $num $cyc | awk '{printf "%.2f", $1 / $2}'`
  66. if [ "$ipc" != "$res" ]; then
  67. # check difference from the real result for FP imperfections
  68. diff=`echo $ipc $res $THRESHOLD | \
  69. awk '{x = ($1 - $2) < 0 ? ($2 - $1) : ($1 - $2); print (x > $3)}'`
  70. if [ $diff -eq 1 ]; then
  71. echo "IPC is different: $res != $ipc ($num / $cyc)"
  72. exit 1
  73. fi
  74. echo "Warning: Difference of IPC is under the threshold"
  75. fi
  76. done
  77. }
  78. test_global_aggr
  79. test_no_aggr
  80. exit 0