360 lines · bash
1#!/bin/bash2# SPDX-License-Identifier: GPL-2.03 4# Testing and monitor the cpu desire performance, frequency, load,5# power consumption and throughput etc. when this script trigger6# gitsource test.7# 1) Download and tar gitsource codes.8# 2) Run gitsource benchmark on specific governors, ondemand or schedutil.9# 3) Run tbench benchmark comparative test on acpi-cpufreq kernel driver.10# 4) Get desire performance, frequency, load by perf.11# 5) Get power consumption and throughput by amd_pstate_trace.py.12# 6) Get run time by /usr/bin/time.13# 7) Analyse test results and save it in file selftest.gitsource.csv.14#8) Plot png images about time, energy and performance per watt for each test.15 16# protect against multiple inclusion17if [ $FILE_GITSOURCE ]; then18 return 019else20 FILE_GITSOURCE=DONE21fi22 23git_name="git-2.15.1"24git_tar="$git_name.tar.gz"25gitsource_url="https://github.com/git/git/archive/refs/tags/v2.15.1.tar.gz"26gitsource_governors=("ondemand" "schedutil")27 28# $1: governor, $2: round, $3: des-perf, $4: freq, $5: load, $6: time $7: energy, $8: PPW29store_csv_gitsource()30{31 echo "$1, $2, $3, $4, $5, $6, $7, $8" | tee -a $OUTFILE_GIT.csv > /dev/null 2>&132}33 34# clear some special lines35clear_csv_gitsource()36{37 if [ -f $OUTFILE_GIT.csv ]; then38 sed -i '/Comprison(%)/d' $OUTFILE_GIT.csv39 sed -i "/$(scaling_name)/d" $OUTFILE_GIT.csv40 fi41}42 43# find string $1 in file csv and get the number of lines44get_lines_csv_gitsource()45{46 if [ -f $OUTFILE_GIT.csv ]; then47 return `grep -c "$1" $OUTFILE_GIT.csv`48 else49 return 050 fi51}52 53pre_clear_gitsource()54{55 post_clear_gitsource56 rm -rf gitsource_*.png57 clear_csv_gitsource58}59 60post_clear_gitsource()61{62 rm -rf results/tracer-gitsource*63 rm -rf $OUTFILE_GIT*.log64 rm -rf $OUTFILE_GIT*.result65}66 67install_gitsource()68{69 if [ ! -d $SCRIPTDIR/$git_name ]; then70 pushd $(pwd) > /dev/null 2>&171 cd $SCRIPTDIR72 printf "Download gitsource, please wait a moment ...\n\n"73 wget -O $git_tar $gitsource_url > /dev/null 2>&174 75 printf "Tar gitsource ...\n\n"76 tar -xzf $git_tar77 popd > /dev/null 2>&178 fi79}80 81# $1: governor, $2: loop82run_gitsource()83{84 echo "Launching amd pstate tracer for $1 #$2 tracer_interval: $TRACER_INTERVAL"85 $TRACER -n tracer-gitsource-$1-$2 -i $TRACER_INTERVAL > /dev/null 2>&1 &86 87 printf "Make and test gitsource for $1 #$2 make_cpus: $MAKE_CPUS\n"88 BACKUP_DIR=$(pwd)89 pushd $BACKUP_DIR > /dev/null 2>&190 cd $SCRIPTDIR/$git_name91 $PERF stat -a --per-socket -I 1000 -e power/energy-pkg/ /usr/bin/time -o $BACKUP_DIR/$OUTFILE_GIT.time-gitsource-$1-$2.log make test -j$MAKE_CPUS > $BACKUP_DIR/$OUTFILE_GIT-perf-$1-$2.log 2>&192 popd > /dev/null 2>&193 94 for job in `jobs -p`95 do96 echo "Waiting for job id $job"97 wait $job98 done99}100 101# $1: governor, $2: loop102parse_gitsource()103{104 awk '{print $5}' results/tracer-gitsource-$1-$2/cpu.csv | sed -e '1d' | sed s/,// > $OUTFILE_GIT-des-perf-$1-$2.log105 avg_des_perf=$(awk 'BEGIN {i=0; sum=0};{i++; sum += $1};END {print sum/i}' $OUTFILE_GIT-des-perf-$1-$2.log)106 printf "Gitsource-$1-#$2 avg des perf: $avg_des_perf\n" | tee -a $OUTFILE_GIT.result107 108 awk '{print $7}' results/tracer-gitsource-$1-$2/cpu.csv | sed -e '1d' | sed s/,// > $OUTFILE_GIT-freq-$1-$2.log109 avg_freq=$(awk 'BEGIN {i=0; sum=0};{i++; sum += $1};END {print sum/i}' $OUTFILE_GIT-freq-$1-$2.log)110 printf "Gitsource-$1-#$2 avg freq: $avg_freq\n" | tee -a $OUTFILE_GIT.result111 112 awk '{print $11}' results/tracer-gitsource-$1-$2/cpu.csv | sed -e '1d' | sed s/,// > $OUTFILE_GIT-load-$1-$2.log113 avg_load=$(awk 'BEGIN {i=0; sum=0};{i++; sum += $1};END {print sum/i}' $OUTFILE_GIT-load-$1-$2.log)114 printf "Gitsource-$1-#$2 avg load: $avg_load\n" | tee -a $OUTFILE_GIT.result115 116 grep user $OUTFILE_GIT.time-gitsource-$1-$2.log | awk '{print $1}' | sed -e 's/user//' > $OUTFILE_GIT-time-$1-$2.log117 time_sum=$(awk 'BEGIN {sum=0};{sum += $1};END {print sum}' $OUTFILE_GIT-time-$1-$2.log)118 printf "Gitsource-$1-#$2 user time(s): $time_sum\n" | tee -a $OUTFILE_GIT.result119 120 grep Joules $OUTFILE_GIT-perf-$1-$2.log | awk '{print $4}' > $OUTFILE_GIT-energy-$1-$2.log121 en_sum=$(awk 'BEGIN {sum=0};{sum += $1};END {print sum}' $OUTFILE_GIT-energy-$1-$2.log)122 printf "Gitsource-$1-#$2 power consumption(J): $en_sum\n" | tee -a $OUTFILE_GIT.result123 124 # Permance is the number of run gitsource per second, denoted 1/t, where 1 is the number of run gitsource in t125 # seconds. It is well known that P=E/t, where P is power measured in watts(W), E is energy measured in joules(J),126 # and t is time measured in seconds(s). This means that performance per watt becomes127 # 1/t 1/t 1128 # ----- = ----- = ---129 # P E/t E130 # with unit given by 1 per joule.131 ppw=`echo "scale=9;1/$en_sum" | bc | awk '{printf "%.9f", $0}'`132 printf "Gitsource-$1-#$2 performance per watt(1/J): $ppw\n" | tee -a $OUTFILE_GIT.result133 printf "\n" | tee -a $OUTFILE_GIT.result134 135 driver_name=`echo $(scaling_name)`136 store_csv_gitsource "$driver_name-$1" $2 $avg_des_perf $avg_freq $avg_load $time_sum $en_sum $ppw137}138 139# $1: governor140loop_gitsource()141{142 printf "\nGitsource total test times is $LOOP_TIMES for $1\n\n"143 for i in `seq 1 $LOOP_TIMES`144 do145 run_gitsource $1 $i146 parse_gitsource $1 $i147 done148}149 150# $1: governor151gather_gitsource()152{153 printf "Gitsource test result for $1 (loops:$LOOP_TIMES)" | tee -a $OUTFILE_GIT.result154 printf "\n--------------------------------------------------\n" | tee -a $OUTFILE_GIT.result155 156 grep "Gitsource-$1-#" $OUTFILE_GIT.result | grep "avg des perf:" | awk '{print $NF}' > $OUTFILE_GIT-des-perf-$1.log157 avg_des_perf=$(awk 'BEGIN {sum=0};{sum += $1};END {print sum/'$LOOP_TIMES'}' $OUTFILE_GIT-des-perf-$1.log)158 printf "Gitsource-$1 avg des perf: $avg_des_perf\n" | tee -a $OUTFILE_GIT.result159 160 grep "Gitsource-$1-#" $OUTFILE_GIT.result | grep "avg freq:" | awk '{print $NF}' > $OUTFILE_GIT-freq-$1.log161 avg_freq=$(awk 'BEGIN {sum=0};{sum += $1};END {print sum/'$LOOP_TIMES'}' $OUTFILE_GIT-freq-$1.log)162 printf "Gitsource-$1 avg freq: $avg_freq\n" | tee -a $OUTFILE_GIT.result163 164 grep "Gitsource-$1-#" $OUTFILE_GIT.result | grep "avg load:" | awk '{print $NF}' > $OUTFILE_GIT-load-$1.log165 avg_load=$(awk 'BEGIN {sum=0};{sum += $1};END {print sum/'$LOOP_TIMES'}' $OUTFILE_GIT-load-$1.log)166 printf "Gitsource-$1 avg load: $avg_load\n" | tee -a $OUTFILE_GIT.result167 168 grep "Gitsource-$1-#" $OUTFILE_GIT.result | grep "user time(s):" | awk '{print $NF}' > $OUTFILE_GIT-time-$1.log169 time_sum=$(awk 'BEGIN {sum=0};{sum += $1};END {print sum}' $OUTFILE_GIT-time-$1.log)170 printf "Gitsource-$1 total user time(s): $time_sum\n" | tee -a $OUTFILE_GIT.result171 172 avg_time=$(awk 'BEGIN {sum=0};{sum += $1};END {print sum/'$LOOP_TIMES'}' $OUTFILE_GIT-time-$1.log)173 printf "Gitsource-$1 avg user times(s): $avg_time\n" | tee -a $OUTFILE_GIT.result174 175 grep "Gitsource-$1-#" $OUTFILE_GIT.result | grep "power consumption(J):" | awk '{print $NF}' > $OUTFILE_GIT-energy-$1.log176 en_sum=$(awk 'BEGIN {sum=0};{sum += $1};END {print sum}' $OUTFILE_GIT-energy-$1.log)177 printf "Gitsource-$1 total power consumption(J): $en_sum\n" | tee -a $OUTFILE_GIT.result178 179 avg_en=$(awk 'BEGIN {sum=0};{sum += $1};END {print sum/'$LOOP_TIMES'}' $OUTFILE_GIT-energy-$1.log)180 printf "Gitsource-$1 avg power consumption(J): $avg_en\n" | tee -a $OUTFILE_GIT.result181 182 # Permance is the number of run gitsource per second, denoted 1/t, where 1 is the number of run gitsource in t183 # seconds. It is well known that P=E/t, where P is power measured in watts(W), E is energy measured in joules(J),184 # and t is time measured in seconds(s). This means that performance per watt becomes185 # 1/t 1/t 1186 # ----- = ----- = ---187 # P E/t E188 # with unit given by 1 per joule.189 ppw=`echo "scale=9;1/$avg_en" | bc | awk '{printf "%.9f", $0}'`190 printf "Gitsource-$1 performance per watt(1/J): $ppw\n" | tee -a $OUTFILE_GIT.result191 printf "\n" | tee -a $OUTFILE_GIT.result192 193 driver_name=`echo $(scaling_name)`194 store_csv_gitsource "$driver_name-$1" "Average" $avg_des_perf $avg_freq $avg_load $avg_time $avg_en $ppw195}196 197# $1: base scaling_driver $2: base governor $3: comparison scaling_driver $4: comparison governor198__calc_comp_gitsource()199{200 base=`grep "$1-$2" $OUTFILE_GIT.csv | grep "Average"`201 comp=`grep "$3-$4" $OUTFILE_GIT.csv | grep "Average"`202 203 if [ -n "$base" -a -n "$comp" ]; then204 printf "\n==================================================\n" | tee -a $OUTFILE_GIT.result205 printf "Gitsource comparison $1-$2 VS $3-$4" | tee -a $OUTFILE_GIT.result206 printf "\n==================================================\n" | tee -a $OUTFILE_GIT.result207 208 # get the base values209 des_perf_base=`echo "$base" | awk '{print $3}' | sed s/,//`210 freq_base=`echo "$base" | awk '{print $4}' | sed s/,//`211 load_base=`echo "$base" | awk '{print $5}' | sed s/,//`212 time_base=`echo "$base" | awk '{print $6}' | sed s/,//`213 energy_base=`echo "$base" | awk '{print $7}' | sed s/,//`214 ppw_base=`echo "$base" | awk '{print $8}' | sed s/,//`215 216 # get the comparison values217 des_perf_comp=`echo "$comp" | awk '{print $3}' | sed s/,//`218 freq_comp=`echo "$comp" | awk '{print $4}' | sed s/,//`219 load_comp=`echo "$comp" | awk '{print $5}' | sed s/,//`220 time_comp=`echo "$comp" | awk '{print $6}' | sed s/,//`221 energy_comp=`echo "$comp" | awk '{print $7}' | sed s/,//`222 ppw_comp=`echo "$comp" | awk '{print $8}' | sed s/,//`223 224 # compare the base and comp values225 des_perf_drop=`echo "scale=4;($des_perf_comp-$des_perf_base)*100/$des_perf_base" | bc | awk '{printf "%.4f", $0}'`226 printf "Gitsource-$1 des perf base: $des_perf_base comprison: $des_perf_comp percent: $des_perf_drop\n" | tee -a $OUTFILE_GIT.result227 228 freq_drop=`echo "scale=4;($freq_comp-$freq_base)*100/$freq_base" | bc | awk '{printf "%.4f", $0}'`229 printf "Gitsource-$1 freq base: $freq_base comprison: $freq_comp percent: $freq_drop\n" | tee -a $OUTFILE_GIT.result230 231 load_drop=`echo "scale=4;($load_comp-$load_base)*100/$load_base" | bc | awk '{printf "%.4f", $0}'`232 printf "Gitsource-$1 load base: $load_base comprison: $load_comp percent: $load_drop\n" | tee -a $OUTFILE_GIT.result233 234 time_drop=`echo "scale=4;($time_comp-$time_base)*100/$time_base" | bc | awk '{printf "%.4f", $0}'`235 printf "Gitsource-$1 time base: $time_base comprison: $time_comp percent: $time_drop\n" | tee -a $OUTFILE_GIT.result236 237 energy_drop=`echo "scale=4;($energy_comp-$energy_base)*100/$energy_base" | bc | awk '{printf "%.4f", $0}'`238 printf "Gitsource-$1 energy base: $energy_base comprison: $energy_comp percent: $energy_drop\n" | tee -a $OUTFILE_GIT.result239 240 ppw_drop=`echo "scale=4;($ppw_comp-$ppw_base)*100/$ppw_base" | bc | awk '{printf "%.4f", $0}'`241 printf "Gitsource-$1 performance per watt base: $ppw_base comprison: $ppw_comp percent: $ppw_drop\n" | tee -a $OUTFILE_GIT.result242 printf "\n" | tee -a $OUTFILE_GIT.result243 244 store_csv_gitsource "$1-$2 VS $3-$4" "Comprison(%)" "$des_perf_drop" "$freq_drop" "$load_drop" "$time_drop" "$energy_drop" "$ppw_drop"245 fi246}247 248# calculate the comparison(%)249calc_comp_gitsource()250{251 # acpi-cpufreq-ondemand VS acpi-cpufreq-schedutil252 __calc_comp_gitsource ${all_scaling_names[0]} ${gitsource_governors[0]} ${all_scaling_names[0]} ${gitsource_governors[1]}253 254 # amd-pstate-ondemand VS amd-pstate-schedutil255 __calc_comp_gitsource ${all_scaling_names[1]} ${gitsource_governors[0]} ${all_scaling_names[1]} ${gitsource_governors[1]}256 257 # acpi-cpufreq-ondemand VS amd-pstate-ondemand258 __calc_comp_gitsource ${all_scaling_names[0]} ${gitsource_governors[0]} ${all_scaling_names[1]} ${gitsource_governors[0]}259 260 # acpi-cpufreq-schedutil VS amd-pstate-schedutil261 __calc_comp_gitsource ${all_scaling_names[0]} ${gitsource_governors[1]} ${all_scaling_names[1]} ${gitsource_governors[1]}262}263 264# $1: file_name, $2: title, $3: ylable, $4: column265plot_png_gitsource()266{267 # all_scaling_names[1] all_scaling_names[0] flag268 # amd-pstate acpi-cpufreq269 # N N 0270 # N Y 1271 # Y N 2272 # Y Y 3273 ret=`grep -c "${all_scaling_names[1]}" $OUTFILE_GIT.csv`274 if [ $ret -eq 0 ]; then275 ret=`grep -c "${all_scaling_names[0]}" $OUTFILE_GIT.csv`276 if [ $ret -eq 0 ]; then277 flag=0278 else279 flag=1280 fi281 else282 ret=`grep -c "${all_scaling_names[0]}" $OUTFILE_GIT.csv`283 if [ $ret -eq 0 ]; then284 flag=2285 else286 flag=3287 fi288 fi289 290 gnuplot << EOF291 set term png292 set output "$1"293 294 set title "$2"295 set xlabel "Test Cycles (round)"296 set ylabel "$3"297 298 set grid299 set style data histogram300 set style fill solid 0.5 border301 set boxwidth 0.8302 303 if ($flag == 1) {304 plot \305 "<(sed -n -e 's/,//g' -e '/${all_scaling_names[0]}-${gitsource_governors[0]}/p' $OUTFILE_GIT.csv)" using $4:xtic(2) title "${all_scaling_names[0]}-${gitsource_governors[0]}", \306 "<(sed -n -e 's/,//g' -e '/${all_scaling_names[0]}-${gitsource_governors[1]}/p' $OUTFILE_GIT.csv)" using $4:xtic(2) title "${all_scaling_names[0]}-${gitsource_governors[1]}"307 } else {308 if ($flag == 2) {309 plot \310 "<(sed -n -e 's/,//g' -e '/${all_scaling_names[1]}-${gitsource_governors[0]}/p' $OUTFILE_GIT.csv)" using $4:xtic(2) title "${all_scaling_names[1]}-${gitsource_governors[0]}", \311 "<(sed -n -e 's/,//g' -e '/${all_scaling_names[1]}-${gitsource_governors[1]}/p' $OUTFILE_GIT.csv)" using $4:xtic(2) title "${all_scaling_names[1]}-${gitsource_governors[1]}"312 } else {313 if ($flag == 3 ) {314 plot \315 "<(sed -n -e 's/,//g' -e '/${all_scaling_names[0]}-${gitsource_governors[0]}/p' $OUTFILE_GIT.csv)" using $4:xtic(2) title "${all_scaling_names[0]}-${gitsource_governors[0]}", \316 "<(sed -n -e 's/,//g' -e '/${all_scaling_names[0]}-${gitsource_governors[1]}/p' $OUTFILE_GIT.csv)" using $4:xtic(2) title "${all_scaling_names[0]}-${gitsource_governors[1]}", \317 "<(sed -n -e 's/,//g' -e '/${all_scaling_names[1]}-${gitsource_governors[0]}/p' $OUTFILE_GIT.csv)" using $4:xtic(2) title "${all_scaling_names[1]}-${gitsource_governors[0]}", \318 "<(sed -n -e 's/,//g' -e '/${all_scaling_names[1]}-${gitsource_governors[1]}/p' $OUTFILE_GIT.csv)" using $4:xtic(2) title "${all_scaling_names[1]}-${gitsource_governors[1]}"319 }320 }321 }322 quit323EOF324}325 326amd_pstate_gitsource()327{328 printf "\n---------------------------------------------\n"329 printf "*** Running gitsource ***"330 printf "\n---------------------------------------------\n"331 332 pre_clear_gitsource333 334 install_gitsource335 336 get_lines_csv_gitsource "Governor"337 if [ $? -eq 0 ]; then338 # add titles and unit for csv file339 store_csv_gitsource "Governor" "Round" "Des-perf" "Freq" "Load" "Time" "Energy" "Performance Per Watt"340 store_csv_gitsource "Unit" "" "" "GHz" "" "s" "J" "1/J"341 fi342 343 backup_governor344 for governor in ${gitsource_governors[*]} ; do345 printf "\nSpecified governor is $governor\n\n"346 switch_governor $governor347 loop_gitsource $governor348 gather_gitsource $governor349 done350 restore_governor351 352 plot_png_gitsource "gitsource_time.png" "Gitsource Benchmark Time" "Time (s)" 6353 plot_png_gitsource "gitsource_energy.png" "Gitsource Benchmark Energy" "Energy (J)" 7354 plot_png_gitsource "gitsource_ppw.png" "Gitsource Benchmark Performance Per Watt" "Performance Per Watt (1/J)" 8355 356 calc_comp_gitsource357 358 post_clear_gitsource359}360