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