Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests: amd-pstate: Trigger tbench benchmark and test cpus

Add tbench.sh trigger the tbench testing and monitor the cpu desire
performance, frequency, load, power consumption and throughput etc.

Signed-off-by: Meng Li <li.meng@amd.com>
Acked-by: Huang Rui <ray.huang@amd.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

authored by

Meng Li and committed by
Shuah Khan
ba2d788a e5df3268

+583 -11
+9 -1
tools/testing/selftests/amd-pstate/Makefile
··· 4 4 # No binaries, but make sure arg-less "make" doesn't trigger "run_tests" 5 5 all: 6 6 7 + uname_M := $(shell uname -m 2>/dev/null || echo not) 8 + ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/x86/ -e s/x86_64/x86/) 9 + 10 + ifeq (x86,$(ARCH)) 11 + TEST_GEN_FILES += ../../../power/x86/amd_pstate_tracer/amd_pstate_trace.py 12 + TEST_GEN_FILES += ../../../power/x86/intel_pstate_tracer/intel_pstate_tracer.py 13 + endif 14 + 7 15 TEST_PROGS := run.sh 8 - TEST_FILES := basic.sh 16 + TEST_FILES := basic.sh tbench.sh 9 17 10 18 include ../lib.mk
+235 -10
tools/testing/selftests/amd-pstate/run.sh
··· 9 9 fi 10 10 11 11 source basic.sh 12 + source tbench.sh 12 13 13 14 # amd-pstate-ut only run on x86/x86_64 AMD systems. 14 15 ARCH=$(uname -m 2>/dev/null | sed -e 's/i.86/x86/' -e 's/x86_64/x86/') 15 16 VENDOR=$(cat /proc/cpuinfo | grep -m 1 'vendor_id' | awk '{print $NF}') 16 17 18 + msg="Skip all tests:" 17 19 FUNC=all 18 20 OUTFILE=selftest 21 + OUTFILE_TBENCH="$OUTFILE.tbench" 22 + 23 + SYSFS= 24 + CPUROOT= 25 + CPUFREQROOT= 26 + MAKE_CPUS= 27 + 28 + TIME_LIMIT=100 29 + PROCESS_NUM=128 30 + LOOP_TIMES=3 31 + TRACER_INTERVAL=10 32 + CURRENT_TEST=amd-pstate 33 + COMPARATIVE_TEST= 19 34 20 35 # Kselftest framework requirement - SKIP code is 4. 21 36 ksft_skip=4 37 + all_scaling_names=("acpi-cpufreq" "amd-pstate") 38 + 39 + # Get current cpufreq scaling driver name 40 + scaling_name() 41 + { 42 + if [ "$COMPARATIVE_TEST" = "" ]; then 43 + echo "$CURRENT_TEST" 44 + else 45 + echo "$COMPARATIVE_TEST" 46 + fi 47 + } 48 + 49 + # Counts CPUs with cpufreq directories 50 + count_cpus() 51 + { 52 + count=0; 53 + 54 + for cpu in `ls $CPUROOT | grep "cpu[0-9].*"`; do 55 + if [ -d $CPUROOT/$cpu/cpufreq ]; then 56 + let count=count+1; 57 + fi 58 + done 59 + 60 + echo $count; 61 + } 62 + 63 + # $1: policy 64 + find_current_governor() 65 + { 66 + cat $CPUFREQROOT/$1/scaling_governor 67 + } 68 + 69 + backup_governor() 70 + { 71 + policies=$(ls $CPUFREQROOT| grep "policy[0-9].*") 72 + for policy in $policies; do 73 + cur_gov=$(find_current_governor $policy) 74 + echo "$policy $cur_gov" >> $OUTFILE.backup_governor.log 75 + done 76 + 77 + printf "Governor $cur_gov backup done.\n" 78 + } 79 + 80 + restore_governor() 81 + { 82 + i=0; 83 + 84 + policies=$(awk '{print $1}' $OUTFILE.backup_governor.log) 85 + for policy in $policies; do 86 + let i++; 87 + governor=$(sed -n ''$i'p' $OUTFILE.backup_governor.log | awk '{print $2}') 88 + 89 + # switch governor 90 + echo $governor > $CPUFREQROOT/$policy/scaling_governor 91 + done 92 + 93 + printf "Governor restored to $governor.\n" 94 + } 95 + 96 + # $1: governor 97 + switch_governor() 98 + { 99 + policies=$(ls $CPUFREQROOT| grep "policy[0-9].*") 100 + for policy in $policies; do 101 + filepath=$CPUFREQROOT/$policy/scaling_available_governors 102 + 103 + # Exit if cpu isn't managed by cpufreq core 104 + if [ ! -f $filepath ]; then 105 + return; 106 + fi 107 + 108 + echo $1 > $CPUFREQROOT/$policy/scaling_governor 109 + done 110 + 111 + printf "Switched governor to $1.\n" 112 + } 22 113 23 114 # All amd-pstate tests 24 115 amd_pstate_all() ··· 118 27 printf "***** Running AMD P-state Sanity Tests *****\n" 119 28 printf "=============================================\n\n" 120 29 30 + count=$(count_cpus) 31 + if [ $count = 0 ]; then 32 + printf "No cpu is managed by cpufreq core, exiting\n" 33 + exit; 34 + else 35 + printf "AMD P-state manages: $count CPUs\n" 36 + fi 37 + 121 38 # unit test for amd-pstate kernel driver 122 39 amd_pstate_basic 40 + 41 + # tbench 42 + amd_pstate_tbench 123 43 } 124 44 125 45 help() ··· 139 37 [-h <help>] 140 38 [-o <output-file-for-dump>] 141 39 [-c <all: All testing, 142 - basic: Basic testing.>] 40 + basic: Basic testing, 41 + tbench: Tbench testing.>] 42 + [-t <tbench time limit>] 43 + [-p <tbench process number>] 44 + [-l <loop times for tbench>] 45 + [-i <amd tracer interval>] 46 + [-m <comparative test: acpi-cpufreq>] 143 47 \n" 144 48 exit 2 145 49 } 146 50 147 51 parse_arguments() 148 52 { 149 - while getopts ho:c: arg 53 + while getopts ho:c:t:p:l:i:m: arg 150 54 do 151 55 case $arg in 152 56 h) # --help 153 57 help 154 58 ;; 155 59 156 - c) # --func_type (Function to perform: basic (default: all)) 60 + c) # --func_type (Function to perform: basic, tbench (default: all)) 157 61 FUNC=$OPTARG 158 62 ;; 159 63 ··· 167 59 OUTFILE=$OPTARG 168 60 ;; 169 61 62 + t) # --tbench-time-limit 63 + TIME_LIMIT=$OPTARG 64 + ;; 65 + 66 + p) # --tbench-process-number 67 + PROCESS_NUM=$OPTARG 68 + ;; 69 + 70 + l) # --tbench-loop-times 71 + LOOP_TIMES=$OPTARG 72 + ;; 73 + 74 + i) # --amd-tracer-interval 75 + TRACER_INTERVAL=$OPTARG 76 + ;; 77 + 78 + m) # --comparative-test 79 + COMPARATIVE_TEST=$OPTARG 80 + ;; 81 + 170 82 *) 171 83 help 172 84 ;; 173 85 esac 174 86 done 87 + } 88 + 89 + command_perf() 90 + { 91 + if ! command -v perf > /dev/null; then 92 + echo $msg please install perf. >&2 93 + exit $ksft_skip 94 + fi 95 + } 96 + 97 + command_tbench() 98 + { 99 + if ! command -v tbench > /dev/null; then 100 + if apt policy dbench > /dev/null 2>&1; then 101 + echo $msg apt install dbench >&2 102 + exit $ksft_skip 103 + elif yum list available | grep dbench > /dev/null 2>&1; then 104 + echo $msg yum install dbench >&2 105 + exit $ksft_skip 106 + fi 107 + fi 108 + 109 + if ! command -v tbench > /dev/null; then 110 + echo $msg please install tbench. >&2 111 + exit $ksft_skip 112 + fi 175 113 } 176 114 177 115 prerequisite() ··· 234 80 fi 235 81 236 82 scaling_driver=$(cat /sys/devices/system/cpu/cpufreq/policy0/scaling_driver) 237 - if [ "$scaling_driver" != "amd-pstate" ]; then 238 - echo "$0 # Skipped: Test can only run on amd-pstate driver." 239 - echo "$0 # Please set X86_AMD_PSTATE enabled." 240 - echo "$0 # Current cpufreq scaling drvier is $scaling_driver." 241 - exit $ksft_skip 83 + if [ "$COMPARATIVE_TEST" = "" ]; then 84 + if [ "$scaling_driver" != "$CURRENT_TEST" ]; then 85 + echo "$0 # Skipped: Test can only run on $CURRENT_TEST driver or run comparative test." 86 + echo "$0 # Please set X86_AMD_PSTATE enabled or run comparative test." 87 + echo "$0 # Current cpufreq scaling drvier is $scaling_driver." 88 + exit $ksft_skip 89 + fi 90 + else 91 + case "$FUNC" in 92 + "tbench") 93 + if [ "$scaling_driver" != "$COMPARATIVE_TEST" ]; then 94 + echo "$0 # Skipped: Comparison test can only run on $COMPARATIVE_TEST driver." 95 + echo "$0 # Current cpufreq scaling drvier is $scaling_driver." 96 + exit $ksft_skip 97 + fi 98 + ;; 99 + 100 + *) 101 + echo "$0 # Skipped: Comparison test are only for tbench." 102 + echo "$0 # Current comparative test is for $FUNC." 103 + exit $ksft_skip 104 + ;; 105 + esac 242 106 fi 243 107 244 - msg="Skip all tests:" 245 108 if [ ! -w /dev ]; then 246 109 echo $msg please run this as root >&2 247 110 exit $ksft_skip 111 + fi 112 + 113 + case "$FUNC" in 114 + "all") 115 + command_perf 116 + command_tbench 117 + ;; 118 + 119 + "tbench") 120 + command_perf 121 + command_tbench 122 + ;; 123 + esac 124 + 125 + SYSFS=`mount -t sysfs | head -1 | awk '{ print $3 }'` 126 + 127 + if [ ! -d "$SYSFS" ]; then 128 + echo $msg sysfs is not mounted >&2 129 + exit 2 130 + fi 131 + 132 + CPUROOT=$SYSFS/devices/system/cpu 133 + CPUFREQROOT="$CPUROOT/cpufreq" 134 + 135 + if ! ls $CPUROOT/cpu* > /dev/null 2>&1; then 136 + echo $msg cpus not available in sysfs >&2 137 + exit 2 138 + fi 139 + 140 + if ! ls $CPUROOT/cpufreq > /dev/null 2>&1; then 141 + echo $msg cpufreq directory not available in sysfs >&2 142 + exit 2 248 143 fi 249 144 } 250 145 251 146 do_test() 252 147 { 148 + # Check if CPUs are managed by cpufreq or not 149 + count=$(count_cpus) 150 + MAKE_CPUS=$((count*2)) 151 + 152 + if [ $count = 0 ]; then 153 + echo "No cpu is managed by cpufreq core, exiting" 154 + exit 2; 155 + fi 156 + 253 157 case "$FUNC" in 254 158 "all") 255 159 amd_pstate_all ··· 315 103 316 104 "basic") 317 105 amd_pstate_basic 106 + ;; 107 + 108 + "tbench") 109 + amd_pstate_tbench 318 110 ;; 319 111 320 112 *) ··· 333 117 { 334 118 case "$FUNC" in 335 119 "all") 336 - rm -rf $OUTFILE* 120 + rm -rf $OUTFILE.log 121 + rm -rf $OUTFILE.backup_governor.log 122 + rm -rf *.png 123 + ;; 124 + 125 + "tbench") 126 + rm -rf $OUTFILE.log 127 + rm -rf $OUTFILE.backup_governor.log 128 + rm -rf tbench_*.png 337 129 ;; 338 130 339 131 *) ··· 352 128 post_clear_dumps() 353 129 { 354 130 rm -rf $OUTFILE.log 131 + rm -rf $OUTFILE.backup_governor.log 355 132 } 356 133 357 134 # Parse arguments
+339
tools/testing/selftests/amd-pstate/tbench.sh
··· 1 + #!/bin/sh 2 + # SPDX-License-Identifier: GPL-2.0 3 + 4 + # Testing and monitor the cpu desire performance, frequency, load, 5 + # power consumption and throughput etc.when this script trigger tbench 6 + # test cases. 7 + # 1) Run tbench benchmark on specific governors, ondemand or schedutil. 8 + # 2) Run tbench benchmark comparative test on acpi-cpufreq kernel driver. 9 + # 3) Get desire performance, frequency, load by perf. 10 + # 4) Get power consumption and throughput by amd_pstate_trace.py. 11 + # 5) Analyse test results and save it in file selftest.tbench.csv. 12 + # 6) Plot png images about performance, energy and performance per watt for each test. 13 + 14 + # protect against multiple inclusion 15 + if [ $FILE_TBENCH ]; then 16 + return 0 17 + else 18 + FILE_TBENCH=DONE 19 + fi 20 + 21 + tbench_governors=("ondemand" "schedutil") 22 + 23 + # $1: governor, $2: round, $3: des-perf, $4: freq, $5: load, $6: performance, $7: energy, $8: performance per watt 24 + store_csv_tbench() 25 + { 26 + echo "$1, $2, $3, $4, $5, $6, $7, $8" | tee -a $OUTFILE_TBENCH.csv > /dev/null 2>&1 27 + } 28 + 29 + # clear some special lines 30 + clear_csv_tbench() 31 + { 32 + if [ -f $OUTFILE_TBENCH.csv ]; then 33 + sed -i '/Comprison(%)/d' $OUTFILE_TBENCH.csv 34 + sed -i "/$(scaling_name)/d" $OUTFILE_TBENCH.csv 35 + fi 36 + } 37 + 38 + # find string $1 in file csv and get the number of lines 39 + get_lines_csv_tbench() 40 + { 41 + if [ -f $OUTFILE_TBENCH.csv ]; then 42 + return `grep -c "$1" $OUTFILE_TBENCH.csv` 43 + else 44 + return 0 45 + fi 46 + } 47 + 48 + pre_clear_tbench() 49 + { 50 + post_clear_tbench 51 + rm -rf tbench_*.png 52 + clear_csv_tbench 53 + } 54 + 55 + post_clear_tbench() 56 + { 57 + rm -rf results/tracer-tbench* 58 + rm -rf $OUTFILE_TBENCH*.log 59 + rm -rf $OUTFILE_TBENCH*.result 60 + 61 + } 62 + 63 + # $1: governor, $2: loop 64 + run_tbench() 65 + { 66 + echo "Launching amd pstate tracer for $1 #$2 tracer_interval: $TRACER_INTERVAL" 67 + ./amd_pstate_trace.py -n tracer-tbench-$1-$2 -i $TRACER_INTERVAL > /dev/null 2>&1 & 68 + 69 + printf "Test tbench for $1 #$2 time_limit: $TIME_LIMIT procs_num: $PROCESS_NUM\n" 70 + tbench_srv > /dev/null 2>&1 & 71 + perf stat -a --per-socket -I 1000 -e power/energy-pkg/ tbench -t $TIME_LIMIT $PROCESS_NUM > $OUTFILE_TBENCH-perf-$1-$2.log 2>&1 72 + 73 + pid=`pidof tbench_srv` 74 + kill $pid 75 + 76 + for job in `jobs -p` 77 + do 78 + echo "Waiting for job id $job" 79 + wait $job 80 + done 81 + } 82 + 83 + # $1: governor, $2: loop 84 + parse_tbench() 85 + { 86 + awk '{print $5}' results/tracer-tbench-$1-$2/cpu.csv | sed -e '1d' | sed s/,// > $OUTFILE_TBENCH-des-perf-$1-$2.log 87 + avg_des_perf=$(awk 'BEGIN {i=0; sum=0};{i++; sum += $1};END {print sum/i}' $OUTFILE_TBENCH-des-perf-$1-$2.log) 88 + printf "Tbench-$1-#$2 avg des perf: $avg_des_perf\n" | tee -a $OUTFILE_TBENCH.result 89 + 90 + awk '{print $7}' results/tracer-tbench-$1-$2/cpu.csv | sed -e '1d' | sed s/,// > $OUTFILE_TBENCH-freq-$1-$2.log 91 + avg_freq=$(awk 'BEGIN {i=0; sum=0};{i++; sum += $1};END {print sum/i}' $OUTFILE_TBENCH-freq-$1-$2.log) 92 + printf "Tbench-$1-#$2 avg freq: $avg_freq\n" | tee -a $OUTFILE_TBENCH.result 93 + 94 + awk '{print $11}' results/tracer-tbench-$1-$2/cpu.csv | sed -e '1d' | sed s/,// > $OUTFILE_TBENCH-load-$1-$2.log 95 + avg_load=$(awk 'BEGIN {i=0; sum=0};{i++; sum += $1};END {print sum/i}' $OUTFILE_TBENCH-load-$1-$2.log) 96 + printf "Tbench-$1-#$2 avg load: $avg_load\n" | tee -a $OUTFILE_TBENCH.result 97 + 98 + grep Throughput $OUTFILE_TBENCH-perf-$1-$2.log | awk '{print $2}' > $OUTFILE_TBENCH-throughput-$1-$2.log 99 + tp_sum=$(awk 'BEGIN {sum=0};{sum += $1};END {print sum}' $OUTFILE_TBENCH-throughput-$1-$2.log) 100 + printf "Tbench-$1-#$2 throughput(MB/s): $tp_sum\n" | tee -a $OUTFILE_TBENCH.result 101 + 102 + grep Joules $OUTFILE_TBENCH-perf-$1-$2.log | awk '{print $4}' > $OUTFILE_TBENCH-energy-$1-$2.log 103 + en_sum=$(awk 'BEGIN {sum=0};{sum += $1};END {print sum}' $OUTFILE_TBENCH-energy-$1-$2.log) 104 + printf "Tbench-$1-#$2 power consumption(J): $en_sum\n" | tee -a $OUTFILE_TBENCH.result 105 + 106 + # Permance is throughput per second, denoted T/t, where T is throught rendered in t seconds. 107 + # It is well known that P=E/t, where P is power measured in watts(W), E is energy measured in joules(J), 108 + # and t is time measured in seconds(s). This means that performance per watt becomes 109 + # T/t T/t T 110 + # --- = --- = --- 111 + # P E/t E 112 + # with unit given by MB per joule. 113 + ppw=`echo "scale=4;($TIME_LIMIT-1)*$tp_sum/$en_sum" | bc | awk '{printf "%.4f", $0}'` 114 + printf "Tbench-$1-#$2 performance per watt(MB/J): $ppw\n" | tee -a $OUTFILE_TBENCH.result 115 + printf "\n" | tee -a $OUTFILE_TBENCH.result 116 + 117 + driver_name=`echo $(scaling_name)` 118 + store_csv_tbench "$driver_name-$1" $2 $avg_des_perf $avg_freq $avg_load $tp_sum $en_sum $ppw 119 + } 120 + 121 + # $1: governor 122 + loop_tbench() 123 + { 124 + printf "\nTbench total test times is $LOOP_TIMES for $1\n\n" 125 + for i in `seq 1 $LOOP_TIMES` 126 + do 127 + run_tbench $1 $i 128 + parse_tbench $1 $i 129 + done 130 + } 131 + 132 + # $1: governor 133 + gather_tbench() 134 + { 135 + printf "Tbench test result for $1 (loops:$LOOP_TIMES)" | tee -a $OUTFILE_TBENCH.result 136 + printf "\n--------------------------------------------------\n" | tee -a $OUTFILE_TBENCH.result 137 + 138 + grep "Tbench-$1-#" $OUTFILE_TBENCH.result | grep "avg des perf:" | awk '{print $NF}' > $OUTFILE_TBENCH-des-perf-$1.log 139 + avg_des_perf=$(awk 'BEGIN {sum=0};{sum += $1};END {print sum/'$LOOP_TIMES'}' $OUTFILE_TBENCH-des-perf-$1.log) 140 + printf "Tbench-$1 avg des perf: $avg_des_perf\n" | tee -a $OUTFILE_TBENCH.result 141 + 142 + grep "Tbench-$1-#" $OUTFILE_TBENCH.result | grep "avg freq:" | awk '{print $NF}' > $OUTFILE_TBENCH-freq-$1.log 143 + avg_freq=$(awk 'BEGIN {sum=0};{sum += $1};END {print sum/'$LOOP_TIMES'}' $OUTFILE_TBENCH-freq-$1.log) 144 + printf "Tbench-$1 avg freq: $avg_freq\n" | tee -a $OUTFILE_TBENCH.result 145 + 146 + grep "Tbench-$1-#" $OUTFILE_TBENCH.result | grep "avg load:" | awk '{print $NF}' > $OUTFILE_TBENCH-load-$1.log 147 + avg_load=$(awk 'BEGIN {sum=0};{sum += $1};END {print sum/'$LOOP_TIMES'}' $OUTFILE_TBENCH-load-$1.log) 148 + printf "Tbench-$1 avg load: $avg_load\n" | tee -a $OUTFILE_TBENCH.result 149 + 150 + grep "Tbench-$1-#" $OUTFILE_TBENCH.result | grep "throughput(MB/s):" | awk '{print $NF}' > $OUTFILE_TBENCH-throughput-$1.log 151 + tp_sum=$(awk 'BEGIN {sum=0};{sum += $1};END {print sum}' $OUTFILE_TBENCH-throughput-$1.log) 152 + printf "Tbench-$1 total throughput(MB/s): $tp_sum\n" | tee -a $OUTFILE_TBENCH.result 153 + 154 + avg_tp=$(awk 'BEGIN {sum=0};{sum += $1};END {print sum/'$LOOP_TIMES'}' $OUTFILE_TBENCH-throughput-$1.log) 155 + printf "Tbench-$1 avg throughput(MB/s): $avg_tp\n" | tee -a $OUTFILE_TBENCH.result 156 + 157 + grep "Tbench-$1-#" $OUTFILE_TBENCH.result | grep "power consumption(J):" | awk '{print $NF}' > $OUTFILE_TBENCH-energy-$1.log 158 + en_sum=$(awk 'BEGIN {sum=0};{sum += $1};END {print sum}' $OUTFILE_TBENCH-energy-$1.log) 159 + printf "Tbench-$1 total power consumption(J): $en_sum\n" | tee -a $OUTFILE_TBENCH.result 160 + 161 + avg_en=$(awk 'BEGIN {sum=0};{sum += $1};END {print sum/'$LOOP_TIMES'}' $OUTFILE_TBENCH-energy-$1.log) 162 + printf "Tbench-$1 avg power consumption(J): $avg_en\n" | tee -a $OUTFILE_TBENCH.result 163 + 164 + # Permance is throughput per second, denoted T/t, where T is throught rendered in t seconds. 165 + # It is well known that P=E/t, where P is power measured in watts(W), E is energy measured in joules(J), 166 + # and t is time measured in seconds(s). This means that performance per watt becomes 167 + # T/t T/t T 168 + # --- = --- = --- 169 + # P E/t E 170 + # with unit given by MB per joule. 171 + ppw=`echo "scale=4;($TIME_LIMIT-1)*$avg_tp/$avg_en" | bc | awk '{printf "%.4f", $0}'` 172 + printf "Tbench-$1 performance per watt(MB/J): $ppw\n" | tee -a $OUTFILE_TBENCH.result 173 + printf "\n" | tee -a $OUTFILE_TBENCH.result 174 + 175 + driver_name=`echo $(scaling_name)` 176 + store_csv_tbench "$driver_name-$1" "Average" $avg_des_perf $avg_freq $avg_load $avg_tp $avg_en $ppw 177 + } 178 + 179 + # $1: base scaling_driver $2: base governor $3: comparative scaling_driver $4: comparative governor 180 + __calc_comp_tbench() 181 + { 182 + base=`grep "$1-$2" $OUTFILE_TBENCH.csv | grep "Average"` 183 + comp=`grep "$3-$4" $OUTFILE_TBENCH.csv | grep "Average"` 184 + 185 + if [ -n "$base" -a -n "$comp" ]; then 186 + printf "\n==================================================\n" | tee -a $OUTFILE_TBENCH.result 187 + printf "Tbench comparison $1-$2 VS $3-$4" | tee -a $OUTFILE_TBENCH.result 188 + printf "\n==================================================\n" | tee -a $OUTFILE_TBENCH.result 189 + 190 + # get the base values 191 + des_perf_base=`echo "$base" | awk '{print $3}' | sed s/,//` 192 + freq_base=`echo "$base" | awk '{print $4}' | sed s/,//` 193 + load_base=`echo "$base" | awk '{print $5}' | sed s/,//` 194 + perf_base=`echo "$base" | awk '{print $6}' | sed s/,//` 195 + energy_base=`echo "$base" | awk '{print $7}' | sed s/,//` 196 + ppw_base=`echo "$base" | awk '{print $8}' | sed s/,//` 197 + 198 + # get the comparative values 199 + des_perf_comp=`echo "$comp" | awk '{print $3}' | sed s/,//` 200 + freq_comp=`echo "$comp" | awk '{print $4}' | sed s/,//` 201 + load_comp=`echo "$comp" | awk '{print $5}' | sed s/,//` 202 + perf_comp=`echo "$comp" | awk '{print $6}' | sed s/,//` 203 + energy_comp=`echo "$comp" | awk '{print $7}' | sed s/,//` 204 + ppw_comp=`echo "$comp" | awk '{print $8}' | sed s/,//` 205 + 206 + # compare the base and comp values 207 + des_perf_drop=`echo "scale=4;($des_perf_comp-$des_perf_base)*100/$des_perf_base" | bc | awk '{printf "%.4f", $0}'` 208 + printf "Tbench-$1 des perf base: $des_perf_base comprison: $des_perf_comp percent: $des_perf_drop\n" | tee -a $OUTFILE_TBENCH.result 209 + 210 + freq_drop=`echo "scale=4;($freq_comp-$freq_base)*100/$freq_base" | bc | awk '{printf "%.4f", $0}'` 211 + printf "Tbench-$1 freq base: $freq_base comprison: $freq_comp percent: $freq_drop\n" | tee -a $OUTFILE_TBENCH.result 212 + 213 + load_drop=`echo "scale=4;($load_comp-$load_base)*100/$load_base" | bc | awk '{printf "%.4f", $0}'` 214 + printf "Tbench-$1 load base: $load_base comprison: $load_comp percent: $load_drop\n" | tee -a $OUTFILE_TBENCH.result 215 + 216 + perf_drop=`echo "scale=4;($perf_comp-$perf_base)*100/$perf_base" | bc | awk '{printf "%.4f", $0}'` 217 + printf "Tbench-$1 perf base: $perf_base comprison: $perf_comp percent: $perf_drop\n" | tee -a $OUTFILE_TBENCH.result 218 + 219 + energy_drop=`echo "scale=4;($energy_comp-$energy_base)*100/$energy_base" | bc | awk '{printf "%.4f", $0}'` 220 + printf "Tbench-$1 energy base: $energy_base comprison: $energy_comp percent: $energy_drop\n" | tee -a $OUTFILE_TBENCH.result 221 + 222 + ppw_drop=`echo "scale=4;($ppw_comp-$ppw_base)*100/$ppw_base" | bc | awk '{printf "%.4f", $0}'` 223 + printf "Tbench-$1 performance per watt base: $ppw_base comprison: $ppw_comp percent: $ppw_drop\n" | tee -a $OUTFILE_TBENCH.result 224 + printf "\n" | tee -a $OUTFILE_TBENCH.result 225 + 226 + store_csv_tbench "$1-$2 VS $3-$4" "Comprison(%)" "$des_perf_drop" "$freq_drop" "$load_drop" "$perf_drop" "$energy_drop" "$ppw_drop" 227 + fi 228 + } 229 + 230 + # calculate the comparison(%) 231 + calc_comp_tbench() 232 + { 233 + # acpi-cpufreq-ondemand VS acpi-cpufreq-schedutil 234 + __calc_comp_tbench ${all_scaling_names[0]} ${tbench_governors[0]} ${all_scaling_names[0]} ${tbench_governors[1]} 235 + 236 + # amd-pstate-ondemand VS amd-pstate-schedutil 237 + __calc_comp_tbench ${all_scaling_names[1]} ${tbench_governors[0]} ${all_scaling_names[1]} ${tbench_governors[1]} 238 + 239 + # acpi-cpufreq-ondemand VS amd-pstate-ondemand 240 + __calc_comp_tbench ${all_scaling_names[0]} ${tbench_governors[0]} ${all_scaling_names[1]} ${tbench_governors[0]} 241 + 242 + # acpi-cpufreq-schedutil VS amd-pstate-schedutil 243 + __calc_comp_tbench ${all_scaling_names[0]} ${tbench_governors[1]} ${all_scaling_names[1]} ${tbench_governors[1]} 244 + } 245 + 246 + # $1: file_name, $2: title, $3: ylable, $4: column 247 + plot_png_tbench() 248 + { 249 + # all_scaling_names[1] all_scaling_names[0] flag 250 + # amd-pstate acpi-cpufreq 251 + # N N 0 252 + # N Y 1 253 + # Y N 2 254 + # Y Y 3 255 + ret=`grep -c "${all_scaling_names[1]}" $OUTFILE_TBENCH.csv` 256 + if [ $ret -eq 0 ]; then 257 + ret=`grep -c "${all_scaling_names[0]}" $OUTFILE_TBENCH.csv` 258 + if [ $ret -eq 0 ]; then 259 + flag=0 260 + else 261 + flag=1 262 + fi 263 + else 264 + ret=`grep -c "${all_scaling_names[0]}" $OUTFILE_TBENCH.csv` 265 + if [ $ret -eq 0 ]; then 266 + flag=2 267 + else 268 + flag=3 269 + fi 270 + fi 271 + 272 + gnuplot << EOF 273 + set term png 274 + set output "$1" 275 + 276 + set title "$2" 277 + set xlabel "Test Cycles (round)" 278 + set ylabel "$3" 279 + 280 + set grid 281 + set style data histogram 282 + set style fill solid 0.5 border 283 + set boxwidth 0.8 284 + 285 + if ($flag == 1) { 286 + plot \ 287 + "<(sed -n -e 's/,//g' -e '/${all_scaling_names[0]}-${tbench_governors[0]}/p' $OUTFILE_TBENCH.csv)" using $4:xtic(2) title "${all_scaling_names[0]}-${tbench_governors[0]}", \ 288 + "<(sed -n -e 's/,//g' -e '/${all_scaling_names[0]}-${tbench_governors[1]}/p' $OUTFILE_TBENCH.csv)" using $4:xtic(2) title "${all_scaling_names[0]}-${tbench_governors[1]}" 289 + } else { 290 + if ($flag == 2) { 291 + plot \ 292 + "<(sed -n -e 's/,//g' -e '/${all_scaling_names[1]}-${tbench_governors[0]}/p' $OUTFILE_TBENCH.csv)" using $4:xtic(2) title "${all_scaling_names[1]}-${tbench_governors[0]}", \ 293 + "<(sed -n -e 's/,//g' -e '/${all_scaling_names[1]}-${tbench_governors[1]}/p' $OUTFILE_TBENCH.csv)" using $4:xtic(2) title "${all_scaling_names[1]}-${tbench_governors[1]}" 294 + } else { 295 + if ($flag == 3 ) { 296 + plot \ 297 + "<(sed -n -e 's/,//g' -e '/${all_scaling_names[0]}-${tbench_governors[0]}/p' $OUTFILE_TBENCH.csv)" using $4:xtic(2) title "${all_scaling_names[0]}-${tbench_governors[0]}", \ 298 + "<(sed -n -e 's/,//g' -e '/${all_scaling_names[0]}-${tbench_governors[1]}/p' $OUTFILE_TBENCH.csv)" using $4:xtic(2) title "${all_scaling_names[0]}-${tbench_governors[1]}", \ 299 + "<(sed -n -e 's/,//g' -e '/${all_scaling_names[1]}-${tbench_governors[0]}/p' $OUTFILE_TBENCH.csv)" using $4:xtic(2) title "${all_scaling_names[1]}-${tbench_governors[0]}", \ 300 + "<(sed -n -e 's/,//g' -e '/${all_scaling_names[1]}-${tbench_governors[1]}/p' $OUTFILE_TBENCH.csv)" using $4:xtic(2) title "${all_scaling_names[1]}-${tbench_governors[1]}" 301 + } 302 + } 303 + } 304 + quit 305 + EOF 306 + } 307 + 308 + amd_pstate_tbench() 309 + { 310 + printf "\n---------------------------------------------\n" 311 + printf "*** Running tbench ***" 312 + printf "\n---------------------------------------------\n" 313 + 314 + pre_clear_tbench 315 + 316 + get_lines_csv_tbench "Governor" 317 + if [ $? -eq 0 ]; then 318 + # add titles and unit for csv file 319 + store_csv_tbench "Governor" "Round" "Des-perf" "Freq" "Load" "Performance" "Energy" "Performance Per Watt" 320 + store_csv_tbench "Unit" "" "" "GHz" "" "MB/s" "J" "MB/J" 321 + fi 322 + 323 + backup_governor 324 + for governor in ${tbench_governors[*]} ; do 325 + printf "\nSpecified governor is $governor\n\n" 326 + switch_governor $governor 327 + loop_tbench $governor 328 + gather_tbench $governor 329 + done 330 + restore_governor 331 + 332 + plot_png_tbench "tbench_perfromance.png" "Tbench Benchmark Performance" "Performance" 6 333 + plot_png_tbench "tbench_energy.png" "Tbench Benchmark Energy" "Energy (J)" 7 334 + plot_png_tbench "tbench_ppw.png" "Tbench Benchmark Performance Per Watt" "Performance Per Watt (MB/J)" 8 335 + 336 + calc_comp_tbench 337 + 338 + post_clear_tbench 339 + }