| 1 | |
| 2 | |
| 3 | |
| 4 |
|
| 5 | set -e
|
| 6 |
|
| 7 | THRESHOLD=0.015
|
| 8 |
|
| 9 | |
| 10 | perf stat -a true > /dev/null 2>&1 || exit 2
|
| 11 |
|
| 12 | |
| 13 | perf stat -a -e cycles sleep 1 2>&1 | grep -e cpu_core && exit 2
|
| 14 |
|
| 15 | test_global_aggr()
|
| 16 | {
|
| 17 | perf stat -a --no-big-num -M insn_per_cycle sleep 1 2>&1 | \
|
| 18 | grep -e cycles -e instructions | \
|
| 19 | while read num evt _ ipc rest
|
| 20 | do
|
| 21 | |
| 22 | if [ "$num" = "<not" ]; then
|
| 23 | continue
|
| 24 | fi
|
| 25 |
|
| 26 | |
| 27 | if [ "$evt" = "cycles" ]; then
|
| 28 | cyc=$num
|
| 29 | continue
|
| 30 | fi
|
| 31 |
|
| 32 | |
| 33 | if [ -z "$cyc" ]; then
|
| 34 | continue
|
| 35 | fi
|
| 36 |
|
| 37 | |
| 38 | res=`echo $num $cyc | awk '{printf "%.2f", $1 / $2}'`
|
| 39 | if [ "$ipc" != "$res" ]; then
|
| 40 | |
| 41 | diff=`echo $ipc $res $THRESHOLD | \
|
| 42 | awk '{x = ($1 - $2) < 0 ? ($2 - $1) : ($1 - $2); print (x > $3)}'`
|
| 43 |
|
| 44 | if [ $diff -eq 1 ]; then
|
| 45 | echo "IPC is different: $res != $ipc ($num / $cyc)"
|
| 46 | exit 1
|
| 47 | fi
|
| 48 |
|
| 49 | echo "Warning: Difference of IPC is under the threshold"
|
| 50 | fi
|
| 51 | done
|
| 52 | }
|
| 53 |
|
| 54 | test_no_aggr()
|
| 55 | {
|
| 56 | perf stat -a -A --no-big-num -M insn_per_cycle sleep 1 2>&1 | \
|
| 57 | grep ^CPU | \
|
| 58 | while read cpu num evt _ ipc rest
|
| 59 | do
|
| 60 | |
| 61 | if [ "$num" = "<not" ]; then
|
| 62 | continue
|
| 63 | fi
|
| 64 |
|
| 65 | |
| 66 | if [ "$evt" = "cycles" ]; then
|
| 67 | results="$results $cpu:$num"
|
| 68 | continue
|
| 69 | fi
|
| 70 |
|
| 71 | cyc=${results##* $cpu:}
|
| 72 | cyc=${cyc%% *}
|
| 73 |
|
| 74 | |
| 75 | if [ -z "$cyc" ]; then
|
| 76 | continue
|
| 77 | fi
|
| 78 |
|
| 79 | |
| 80 | res=`echo $num $cyc | awk '{printf "%.2f", $1 / $2}'`
|
| 81 | if [ "$ipc" != "$res" ]; then
|
| 82 | |
| 83 | diff=`echo $ipc $res $THRESHOLD | \
|
| 84 | awk '{x = ($1 - $2) < 0 ? ($2 - $1) : ($1 - $2); print (x > $3)}'`
|
| 85 |
|
| 86 | if [ $diff -eq 1 ]; then
|
| 87 | echo "IPC is different: $res != $ipc ($num / $cyc)"
|
| 88 | exit 1
|
| 89 | fi
|
| 90 |
|
| 91 | echo "Warning: Difference of IPC is under the threshold"
|
| 92 | fi
|
| 93 | done
|
| 94 | }
|
| 95 |
|
| 96 | test_global_aggr
|
| 97 | test_no_aggr
|
| 98 |
|
| 99 | exit 0
|