Loading...
Note: File does not exist in v5.4.
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