brintos

brintos / linux-shallow public Read only

0
0
Text · 2.1 KiB · 0c7d79a Raw
100 lines · bash
1#!/bin/sh2# perf stat metrics (shadow stat) test3# SPDX-License-Identifier: GPL-2.04 5set -e6 7THRESHOLD=0.0158 9# skip if system-wide mode is forbidden10perf stat -a true > /dev/null 2>&1 || exit 211 12# skip if on hybrid platform13perf stat -a -e cycles sleep 1 2>&1 | grep -e cpu_core && exit 214 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 rest20	do21		# skip not counted events22		if [ "$num" = "<not" ]; then23			continue24		fi25 26		# save cycles count27		if [ "$evt" = "cycles" ]; then28			cyc=$num29			continue30		fi31 32		# skip if no cycles33		if [ -z "$cyc" ]; then34			continue35		fi36 37		# use printf for rounding and a leading zero38		res=`echo $num $cyc | awk '{printf "%.2f", $1 / $2}'`39		if [ "$ipc" != "$res" ]; then40			# check the difference from the real result for FP imperfections41			diff=`echo $ipc $res $THRESHOLD | \42			awk '{x = ($1 - $2) < 0 ? ($2 - $1) : ($1 - $2); print (x > $3)}'`43 44			if [ $diff -eq 1 ]; then45				echo "IPC is different: $res != $ipc  ($num / $cyc)"46				exit 147			fi48 49			echo "Warning: Difference of IPC is under the threshold"50		fi51	done52}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 rest59	do60		# skip not counted events61		if [ "$num" = "<not" ]; then62			continue63		fi64 65		# save cycles count66		if [ "$evt" = "cycles" ]; then67			results="$results $cpu:$num"68			continue69		fi70 71		cyc=${results##* $cpu:}72		cyc=${cyc%% *}73 74		# skip if no cycles75		if [ -z "$cyc" ]; then76			continue77		fi78 79		# use printf for rounding and a leading zero80		res=`echo $num $cyc | awk '{printf "%.2f", $1 / $2}'`81		if [ "$ipc" != "$res" ]; then82			# check difference from the real result for FP imperfections83			diff=`echo $ipc $res $THRESHOLD | \84			awk '{x = ($1 - $2) < 0 ? ($2 - $1) : ($1 - $2); print (x > $3)}'`85 86			if [ $diff -eq 1 ]; then87				echo "IPC is different: $res != $ipc  ($num / $cyc)"88				exit 189			fi90 91			echo "Warning: Difference of IPC is under the threshold"92		fi93	done94}95 96test_global_aggr97test_no_aggr98 99exit 0100