aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/tools/perf/tests/shell/stat+shadow_stat.sh
blob: 0c7d79a230eac2918c0a8a528c3a6824edea738d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/bin/sh
# perf stat metrics (shadow stat) test
# SPDX-License-Identifier: GPL-2.0

set -e

THRESHOLD=0.015

# skip if system-wide mode is forbidden
perf stat -a true > /dev/null 2>&1 || exit 2

# skip if on hybrid platform
perf stat -a -e cycles sleep 1 2>&1 | grep -e cpu_core && exit 2

test_global_aggr()
{
	perf stat -a --no-big-num -e cycles,instructions sleep 1  2>&1 | \
	grep -e cycles -e instructions | \
	while read num evt _ ipc rest
	do
		# skip not counted events
		if [ "$num" = "<not" ]; then
			continue
		fi

		# save cycles count
		if [ "$evt" = "cycles" ]; then
			cyc=$num
			continue
		fi

		# skip if no cycles
		if [ -z "$cyc" ]; then
			continue
		fi

		# use printf for rounding and a leading zero
		res=`echo $num $cyc | awk '{printf "%.2f", $1 / $2}'`
		if [ "$ipc" != "$res" ]; then
			# check the difference from the real result for FP imperfections
			diff=`echo $ipc $res $THRESHOLD | \
			awk '{x = ($1 - $2) < 0 ? ($2 - $1) : ($1 - $2); print (x > $3)}'`

			if [ $diff -eq 1 ]; then
				echo "IPC is different: $res != $ipc  ($num / $cyc)"
				exit 1
			fi

			echo "Warning: Difference of IPC is under the threshold"
		fi
	done
}

test_no_aggr()
{
	perf stat -a -A --no-big-num -e cycles,instructions sleep 1  2>&1 | \
	grep ^CPU | \
	while read cpu num evt _ ipc rest
	do
		# skip not counted events
		if [ "$num" = "<not" ]; then
			continue
		fi

		# save cycles count
		if [ "$evt" = "cycles" ]; then
			results="$results $cpu:$num"
			continue
		fi

		cyc=${results##* $cpu:}
		cyc=${cyc%% *}

		# skip if no cycles
		if [ -z "$cyc" ]; then
			continue
		fi

		# use printf for rounding and a leading zero
		res=`echo $num $cyc | awk '{printf "%.2f", $1 / $2}'`
		if [ "$ipc" != "$res" ]; then
			# check difference from the real result for FP imperfections
			diff=`echo $ipc $res $THRESHOLD | \
			awk '{x = ($1 - $2) < 0 ? ($2 - $1) : ($1 - $2); print (x > $3)}'`

			if [ $diff -eq 1 ]; then
				echo "IPC is different: $res != $ipc  ($num / $cyc)"
				exit 1
			fi

			echo "Warning: Difference of IPC is under the threshold"
		fi
	done
}

test_global_aggr
test_no_aggr

exit 0