Back to home page

OSCL-LXR

 
 

    


0001 #!/bin/sh
0002 # perf stat metrics (shadow stat) test
0003 # SPDX-License-Identifier: GPL-2.0
0004 
0005 set -e
0006 
0007 # skip if system-wide mode is forbidden
0008 perf stat -a true > /dev/null 2>&1 || exit 2
0009 
0010 # skip if on hybrid platform
0011 perf stat -a -e cycles sleep 1 2>&1 | grep -e cpu_core && exit 2
0012 
0013 test_global_aggr()
0014 {
0015         perf stat -a --no-big-num -e cycles,instructions sleep 1  2>&1 | \
0016         grep -e cycles -e instructions | \
0017         while read num evt hash ipc rest
0018         do
0019                 # skip not counted events
0020                 if [ "$num" = "<not" ]; then
0021                         continue
0022                 fi
0023 
0024                 # save cycles count
0025                 if [ "$evt" = "cycles" ]; then
0026                         cyc=$num
0027                         continue
0028                 fi
0029 
0030                 # skip if no cycles
0031                 if [ -z "$cyc" ]; then
0032                         continue
0033                 fi
0034 
0035                 # use printf for rounding and a leading zero
0036                 res=`printf "%.2f" $(echo "scale=6; $num / $cyc" | bc -q)`
0037                 if [ "$ipc" != "$res" ]; then
0038                         echo "IPC is different: $res != $ipc  ($num / $cyc)"
0039                         exit 1
0040                 fi
0041         done
0042 }
0043 
0044 test_no_aggr()
0045 {
0046         perf stat -a -A --no-big-num -e cycles,instructions sleep 1  2>&1 | \
0047         grep ^CPU | \
0048         while read cpu num evt hash ipc rest
0049         do
0050                 # skip not counted events
0051                 if [ "$num" = "<not" ]; then
0052                         continue
0053                 fi
0054 
0055                 # save cycles count
0056                 if [ "$evt" = "cycles" ]; then
0057                         results="$results $cpu:$num"
0058                         continue
0059                 fi
0060 
0061                 cyc=${results##* $cpu:}
0062                 cyc=${cyc%% *}
0063 
0064                 # skip if no cycles
0065                 if [ -z "$cyc" ]; then
0066                         continue
0067                 fi
0068 
0069                 # use printf for rounding and a leading zero
0070                 res=`printf "%.2f" $(echo "scale=6; $num / $cyc" | bc -q)`
0071                 if [ "$ipc" != "$res" ]; then
0072                         echo "IPC is different for $cpu: $res != $ipc  ($num / $cyc)"
0073                         exit 1
0074                 fi
0075         done
0076 }
0077 
0078 test_global_aggr
0079 test_no_aggr
0080 
0081 exit 0