xref: /openbmc/linux/tools/testing/selftests/amd-pstate/tbench.sh (revision 7ae9fb1b7ecbb5d85d07857943f677fd1a559b18)
1*ba2d788aSMeng Li#!/bin/sh
2*ba2d788aSMeng Li# SPDX-License-Identifier: GPL-2.0
3*ba2d788aSMeng Li
4*ba2d788aSMeng Li# Testing and monitor the cpu desire performance, frequency, load,
5*ba2d788aSMeng Li# power consumption and throughput etc.when this script trigger tbench
6*ba2d788aSMeng Li# test cases.
7*ba2d788aSMeng Li# 1) Run tbench benchmark on specific governors, ondemand or schedutil.
8*ba2d788aSMeng Li# 2) Run tbench benchmark comparative test on acpi-cpufreq kernel driver.
9*ba2d788aSMeng Li# 3) Get desire performance, frequency, load by perf.
10*ba2d788aSMeng Li# 4) Get power consumption and throughput by amd_pstate_trace.py.
11*ba2d788aSMeng Li# 5) Analyse test results and save it in file selftest.tbench.csv.
12*ba2d788aSMeng Li# 6) Plot png images about performance, energy and performance per watt for each test.
13*ba2d788aSMeng Li
14*ba2d788aSMeng Li# protect against multiple inclusion
15*ba2d788aSMeng Liif [ $FILE_TBENCH ]; then
16*ba2d788aSMeng Li	return 0
17*ba2d788aSMeng Lielse
18*ba2d788aSMeng Li	FILE_TBENCH=DONE
19*ba2d788aSMeng Lifi
20*ba2d788aSMeng Li
21*ba2d788aSMeng Litbench_governors=("ondemand" "schedutil")
22*ba2d788aSMeng Li
23*ba2d788aSMeng Li# $1: governor, $2: round, $3: des-perf, $4: freq, $5: load, $6: performance, $7: energy, $8: performance per watt
24*ba2d788aSMeng Listore_csv_tbench()
25*ba2d788aSMeng Li{
26*ba2d788aSMeng Li	echo "$1, $2, $3, $4, $5, $6, $7, $8" | tee -a $OUTFILE_TBENCH.csv > /dev/null 2>&1
27*ba2d788aSMeng Li}
28*ba2d788aSMeng Li
29*ba2d788aSMeng Li# clear some special lines
30*ba2d788aSMeng Liclear_csv_tbench()
31*ba2d788aSMeng Li{
32*ba2d788aSMeng Li	if [ -f $OUTFILE_TBENCH.csv ]; then
33*ba2d788aSMeng Li		sed -i '/Comprison(%)/d' $OUTFILE_TBENCH.csv
34*ba2d788aSMeng Li		sed -i "/$(scaling_name)/d" $OUTFILE_TBENCH.csv
35*ba2d788aSMeng Li	fi
36*ba2d788aSMeng Li}
37*ba2d788aSMeng Li
38*ba2d788aSMeng Li# find string $1 in file csv and get the number of lines
39*ba2d788aSMeng Liget_lines_csv_tbench()
40*ba2d788aSMeng Li{
41*ba2d788aSMeng Li	if [ -f $OUTFILE_TBENCH.csv ]; then
42*ba2d788aSMeng Li		return `grep -c "$1" $OUTFILE_TBENCH.csv`
43*ba2d788aSMeng Li	else
44*ba2d788aSMeng Li		return 0
45*ba2d788aSMeng Li	fi
46*ba2d788aSMeng Li}
47*ba2d788aSMeng Li
48*ba2d788aSMeng Lipre_clear_tbench()
49*ba2d788aSMeng Li{
50*ba2d788aSMeng Li	post_clear_tbench
51*ba2d788aSMeng Li	rm -rf tbench_*.png
52*ba2d788aSMeng Li	clear_csv_tbench
53*ba2d788aSMeng Li}
54*ba2d788aSMeng Li
55*ba2d788aSMeng Lipost_clear_tbench()
56*ba2d788aSMeng Li{
57*ba2d788aSMeng Li	rm -rf results/tracer-tbench*
58*ba2d788aSMeng Li	rm -rf $OUTFILE_TBENCH*.log
59*ba2d788aSMeng Li	rm -rf $OUTFILE_TBENCH*.result
60*ba2d788aSMeng Li
61*ba2d788aSMeng Li}
62*ba2d788aSMeng Li
63*ba2d788aSMeng Li# $1: governor, $2: loop
64*ba2d788aSMeng Lirun_tbench()
65*ba2d788aSMeng Li{
66*ba2d788aSMeng Li	echo "Launching amd pstate tracer for $1 #$2 tracer_interval: $TRACER_INTERVAL"
67*ba2d788aSMeng Li	./amd_pstate_trace.py -n tracer-tbench-$1-$2 -i $TRACER_INTERVAL > /dev/null 2>&1 &
68*ba2d788aSMeng Li
69*ba2d788aSMeng Li	printf "Test tbench for $1 #$2 time_limit: $TIME_LIMIT procs_num: $PROCESS_NUM\n"
70*ba2d788aSMeng Li	tbench_srv > /dev/null 2>&1 &
71*ba2d788aSMeng Li	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*ba2d788aSMeng Li
73*ba2d788aSMeng Li	pid=`pidof tbench_srv`
74*ba2d788aSMeng Li	kill $pid
75*ba2d788aSMeng Li
76*ba2d788aSMeng Li	for job in `jobs -p`
77*ba2d788aSMeng Li	do
78*ba2d788aSMeng Li		echo "Waiting for job id $job"
79*ba2d788aSMeng Li		wait $job
80*ba2d788aSMeng Li	done
81*ba2d788aSMeng Li}
82*ba2d788aSMeng Li
83*ba2d788aSMeng Li# $1: governor, $2: loop
84*ba2d788aSMeng Liparse_tbench()
85*ba2d788aSMeng Li{
86*ba2d788aSMeng Li	awk '{print $5}' results/tracer-tbench-$1-$2/cpu.csv | sed -e '1d' | sed s/,// > $OUTFILE_TBENCH-des-perf-$1-$2.log
87*ba2d788aSMeng Li	avg_des_perf=$(awk 'BEGIN {i=0; sum=0};{i++; sum += $1};END {print sum/i}' $OUTFILE_TBENCH-des-perf-$1-$2.log)
88*ba2d788aSMeng Li	printf "Tbench-$1-#$2 avg des perf: $avg_des_perf\n" | tee -a $OUTFILE_TBENCH.result
89*ba2d788aSMeng Li
90*ba2d788aSMeng Li	awk '{print $7}' results/tracer-tbench-$1-$2/cpu.csv | sed -e '1d' | sed s/,// > $OUTFILE_TBENCH-freq-$1-$2.log
91*ba2d788aSMeng Li	avg_freq=$(awk 'BEGIN {i=0; sum=0};{i++; sum += $1};END {print sum/i}' $OUTFILE_TBENCH-freq-$1-$2.log)
92*ba2d788aSMeng Li	printf "Tbench-$1-#$2 avg freq: $avg_freq\n" | tee -a $OUTFILE_TBENCH.result
93*ba2d788aSMeng Li
94*ba2d788aSMeng Li	awk '{print $11}' results/tracer-tbench-$1-$2/cpu.csv | sed -e '1d' | sed s/,// > $OUTFILE_TBENCH-load-$1-$2.log
95*ba2d788aSMeng Li	avg_load=$(awk 'BEGIN {i=0; sum=0};{i++; sum += $1};END {print sum/i}' $OUTFILE_TBENCH-load-$1-$2.log)
96*ba2d788aSMeng Li	printf "Tbench-$1-#$2 avg load: $avg_load\n" | tee -a $OUTFILE_TBENCH.result
97*ba2d788aSMeng Li
98*ba2d788aSMeng Li	grep Throughput $OUTFILE_TBENCH-perf-$1-$2.log | awk '{print $2}' > $OUTFILE_TBENCH-throughput-$1-$2.log
99*ba2d788aSMeng Li	tp_sum=$(awk 'BEGIN {sum=0};{sum += $1};END {print sum}' $OUTFILE_TBENCH-throughput-$1-$2.log)
100*ba2d788aSMeng Li	printf "Tbench-$1-#$2 throughput(MB/s): $tp_sum\n" | tee -a $OUTFILE_TBENCH.result
101*ba2d788aSMeng Li
102*ba2d788aSMeng Li	grep Joules $OUTFILE_TBENCH-perf-$1-$2.log | awk '{print $4}' > $OUTFILE_TBENCH-energy-$1-$2.log
103*ba2d788aSMeng Li	en_sum=$(awk 'BEGIN {sum=0};{sum += $1};END {print sum}' $OUTFILE_TBENCH-energy-$1-$2.log)
104*ba2d788aSMeng Li	printf "Tbench-$1-#$2 power consumption(J): $en_sum\n" | tee -a $OUTFILE_TBENCH.result
105*ba2d788aSMeng Li
106*ba2d788aSMeng Li	# Permance is throughput per second, denoted T/t, where T is throught rendered in t seconds.
107*ba2d788aSMeng Li	# It is well known that P=E/t, where P is power measured in watts(W), E is energy measured in joules(J),
108*ba2d788aSMeng Li	# and t is time measured in seconds(s). This means that performance per watt becomes
109*ba2d788aSMeng Li	#       T/t   T/t    T
110*ba2d788aSMeng Li	#       --- = --- = ---
111*ba2d788aSMeng Li	#        P    E/t    E
112*ba2d788aSMeng Li	# with unit given by MB per joule.
113*ba2d788aSMeng Li	ppw=`echo "scale=4;($TIME_LIMIT-1)*$tp_sum/$en_sum" | bc | awk '{printf "%.4f", $0}'`
114*ba2d788aSMeng Li	printf "Tbench-$1-#$2 performance per watt(MB/J): $ppw\n" | tee -a $OUTFILE_TBENCH.result
115*ba2d788aSMeng Li	printf "\n" | tee -a $OUTFILE_TBENCH.result
116*ba2d788aSMeng Li
117*ba2d788aSMeng Li	driver_name=`echo $(scaling_name)`
118*ba2d788aSMeng Li	store_csv_tbench "$driver_name-$1" $2 $avg_des_perf $avg_freq $avg_load $tp_sum $en_sum $ppw
119*ba2d788aSMeng Li}
120*ba2d788aSMeng Li
121*ba2d788aSMeng Li# $1: governor
122*ba2d788aSMeng Liloop_tbench()
123*ba2d788aSMeng Li{
124*ba2d788aSMeng Li	printf "\nTbench total test times is $LOOP_TIMES for $1\n\n"
125*ba2d788aSMeng Li	for i in `seq 1 $LOOP_TIMES`
126*ba2d788aSMeng Li	do
127*ba2d788aSMeng Li		run_tbench $1 $i
128*ba2d788aSMeng Li		parse_tbench $1 $i
129*ba2d788aSMeng Li	done
130*ba2d788aSMeng Li}
131*ba2d788aSMeng Li
132*ba2d788aSMeng Li# $1: governor
133*ba2d788aSMeng Ligather_tbench()
134*ba2d788aSMeng Li{
135*ba2d788aSMeng Li	printf "Tbench test result for $1 (loops:$LOOP_TIMES)" | tee -a $OUTFILE_TBENCH.result
136*ba2d788aSMeng Li	printf "\n--------------------------------------------------\n" | tee -a $OUTFILE_TBENCH.result
137*ba2d788aSMeng Li
138*ba2d788aSMeng Li	grep "Tbench-$1-#" $OUTFILE_TBENCH.result | grep "avg des perf:" | awk '{print $NF}' > $OUTFILE_TBENCH-des-perf-$1.log
139*ba2d788aSMeng Li	avg_des_perf=$(awk 'BEGIN {sum=0};{sum += $1};END {print sum/'$LOOP_TIMES'}' $OUTFILE_TBENCH-des-perf-$1.log)
140*ba2d788aSMeng Li	printf "Tbench-$1 avg des perf: $avg_des_perf\n" | tee -a $OUTFILE_TBENCH.result
141*ba2d788aSMeng Li
142*ba2d788aSMeng Li	grep "Tbench-$1-#" $OUTFILE_TBENCH.result | grep "avg freq:" | awk '{print $NF}' > $OUTFILE_TBENCH-freq-$1.log
143*ba2d788aSMeng Li	avg_freq=$(awk 'BEGIN {sum=0};{sum += $1};END {print sum/'$LOOP_TIMES'}' $OUTFILE_TBENCH-freq-$1.log)
144*ba2d788aSMeng Li	printf "Tbench-$1 avg freq: $avg_freq\n" | tee -a $OUTFILE_TBENCH.result
145*ba2d788aSMeng Li
146*ba2d788aSMeng Li	grep "Tbench-$1-#" $OUTFILE_TBENCH.result | grep "avg load:" | awk '{print $NF}' > $OUTFILE_TBENCH-load-$1.log
147*ba2d788aSMeng Li	avg_load=$(awk 'BEGIN {sum=0};{sum += $1};END {print sum/'$LOOP_TIMES'}' $OUTFILE_TBENCH-load-$1.log)
148*ba2d788aSMeng Li	printf "Tbench-$1 avg load: $avg_load\n" | tee -a $OUTFILE_TBENCH.result
149*ba2d788aSMeng Li
150*ba2d788aSMeng Li	grep "Tbench-$1-#" $OUTFILE_TBENCH.result | grep "throughput(MB/s):" | awk '{print $NF}' > $OUTFILE_TBENCH-throughput-$1.log
151*ba2d788aSMeng Li	tp_sum=$(awk 'BEGIN {sum=0};{sum += $1};END {print sum}' $OUTFILE_TBENCH-throughput-$1.log)
152*ba2d788aSMeng Li	printf "Tbench-$1 total throughput(MB/s): $tp_sum\n" | tee -a $OUTFILE_TBENCH.result
153*ba2d788aSMeng Li
154*ba2d788aSMeng Li	avg_tp=$(awk 'BEGIN {sum=0};{sum += $1};END {print sum/'$LOOP_TIMES'}' $OUTFILE_TBENCH-throughput-$1.log)
155*ba2d788aSMeng Li	printf "Tbench-$1 avg throughput(MB/s): $avg_tp\n" | tee -a $OUTFILE_TBENCH.result
156*ba2d788aSMeng Li
157*ba2d788aSMeng Li	grep "Tbench-$1-#" $OUTFILE_TBENCH.result | grep "power consumption(J):" | awk '{print $NF}' > $OUTFILE_TBENCH-energy-$1.log
158*ba2d788aSMeng Li	en_sum=$(awk 'BEGIN {sum=0};{sum += $1};END {print sum}' $OUTFILE_TBENCH-energy-$1.log)
159*ba2d788aSMeng Li	printf "Tbench-$1 total power consumption(J): $en_sum\n" | tee -a $OUTFILE_TBENCH.result
160*ba2d788aSMeng Li
161*ba2d788aSMeng Li	avg_en=$(awk 'BEGIN {sum=0};{sum += $1};END {print sum/'$LOOP_TIMES'}' $OUTFILE_TBENCH-energy-$1.log)
162*ba2d788aSMeng Li	printf "Tbench-$1 avg power consumption(J): $avg_en\n" | tee -a $OUTFILE_TBENCH.result
163*ba2d788aSMeng Li
164*ba2d788aSMeng Li	# Permance is throughput per second, denoted T/t, where T is throught rendered in t seconds.
165*ba2d788aSMeng Li	# It is well known that P=E/t, where P is power measured in watts(W), E is energy measured in joules(J),
166*ba2d788aSMeng Li	# and t is time measured in seconds(s). This means that performance per watt becomes
167*ba2d788aSMeng Li	#       T/t   T/t    T
168*ba2d788aSMeng Li	#       --- = --- = ---
169*ba2d788aSMeng Li	#        P    E/t    E
170*ba2d788aSMeng Li	# with unit given by MB per joule.
171*ba2d788aSMeng Li	ppw=`echo "scale=4;($TIME_LIMIT-1)*$avg_tp/$avg_en" | bc | awk '{printf "%.4f", $0}'`
172*ba2d788aSMeng Li	printf "Tbench-$1 performance per watt(MB/J): $ppw\n" | tee -a $OUTFILE_TBENCH.result
173*ba2d788aSMeng Li	printf "\n" | tee -a $OUTFILE_TBENCH.result
174*ba2d788aSMeng Li
175*ba2d788aSMeng Li	driver_name=`echo $(scaling_name)`
176*ba2d788aSMeng Li	store_csv_tbench "$driver_name-$1" "Average" $avg_des_perf $avg_freq $avg_load $avg_tp $avg_en $ppw
177*ba2d788aSMeng Li}
178*ba2d788aSMeng Li
179*ba2d788aSMeng Li# $1: base scaling_driver $2: base governor $3: comparative scaling_driver $4: comparative governor
180*ba2d788aSMeng Li__calc_comp_tbench()
181*ba2d788aSMeng Li{
182*ba2d788aSMeng Li	base=`grep "$1-$2" $OUTFILE_TBENCH.csv | grep "Average"`
183*ba2d788aSMeng Li	comp=`grep "$3-$4" $OUTFILE_TBENCH.csv | grep "Average"`
184*ba2d788aSMeng Li
185*ba2d788aSMeng Li	if [ -n "$base" -a -n "$comp" ]; then
186*ba2d788aSMeng Li		printf "\n==================================================\n" | tee -a $OUTFILE_TBENCH.result
187*ba2d788aSMeng Li		printf "Tbench comparison $1-$2 VS $3-$4" | tee -a $OUTFILE_TBENCH.result
188*ba2d788aSMeng Li		printf "\n==================================================\n" | tee -a $OUTFILE_TBENCH.result
189*ba2d788aSMeng Li
190*ba2d788aSMeng Li		# get the base values
191*ba2d788aSMeng Li		des_perf_base=`echo "$base" | awk '{print $3}' | sed s/,//`
192*ba2d788aSMeng Li		freq_base=`echo "$base" | awk '{print $4}' | sed s/,//`
193*ba2d788aSMeng Li		load_base=`echo "$base" | awk '{print $5}' | sed s/,//`
194*ba2d788aSMeng Li		perf_base=`echo "$base" | awk '{print $6}' | sed s/,//`
195*ba2d788aSMeng Li		energy_base=`echo "$base" | awk '{print $7}' | sed s/,//`
196*ba2d788aSMeng Li		ppw_base=`echo "$base" | awk '{print $8}' | sed s/,//`
197*ba2d788aSMeng Li
198*ba2d788aSMeng Li		# get the comparative values
199*ba2d788aSMeng Li		des_perf_comp=`echo "$comp" | awk '{print $3}' | sed s/,//`
200*ba2d788aSMeng Li		freq_comp=`echo "$comp" | awk '{print $4}' | sed s/,//`
201*ba2d788aSMeng Li		load_comp=`echo "$comp" | awk '{print $5}' | sed s/,//`
202*ba2d788aSMeng Li		perf_comp=`echo "$comp" | awk '{print $6}' | sed s/,//`
203*ba2d788aSMeng Li		energy_comp=`echo "$comp" | awk '{print $7}' | sed s/,//`
204*ba2d788aSMeng Li		ppw_comp=`echo "$comp" | awk '{print $8}' | sed s/,//`
205*ba2d788aSMeng Li
206*ba2d788aSMeng Li		# compare the base and comp values
207*ba2d788aSMeng Li		des_perf_drop=`echo "scale=4;($des_perf_comp-$des_perf_base)*100/$des_perf_base" | bc | awk '{printf "%.4f", $0}'`
208*ba2d788aSMeng Li		printf "Tbench-$1 des perf base: $des_perf_base comprison: $des_perf_comp percent: $des_perf_drop\n" | tee -a $OUTFILE_TBENCH.result
209*ba2d788aSMeng Li
210*ba2d788aSMeng Li		freq_drop=`echo "scale=4;($freq_comp-$freq_base)*100/$freq_base" | bc | awk '{printf "%.4f", $0}'`
211*ba2d788aSMeng Li		printf "Tbench-$1 freq base: $freq_base comprison: $freq_comp percent: $freq_drop\n" | tee -a $OUTFILE_TBENCH.result
212*ba2d788aSMeng Li
213*ba2d788aSMeng Li		load_drop=`echo "scale=4;($load_comp-$load_base)*100/$load_base" | bc | awk '{printf "%.4f", $0}'`
214*ba2d788aSMeng Li		printf "Tbench-$1 load base: $load_base comprison: $load_comp percent: $load_drop\n" | tee -a $OUTFILE_TBENCH.result
215*ba2d788aSMeng Li
216*ba2d788aSMeng Li		perf_drop=`echo "scale=4;($perf_comp-$perf_base)*100/$perf_base" | bc | awk '{printf "%.4f", $0}'`
217*ba2d788aSMeng Li		printf "Tbench-$1 perf base: $perf_base comprison: $perf_comp percent: $perf_drop\n" | tee -a $OUTFILE_TBENCH.result
218*ba2d788aSMeng Li
219*ba2d788aSMeng Li		energy_drop=`echo "scale=4;($energy_comp-$energy_base)*100/$energy_base" | bc | awk '{printf "%.4f", $0}'`
220*ba2d788aSMeng Li		printf "Tbench-$1 energy base: $energy_base comprison: $energy_comp percent: $energy_drop\n" | tee -a $OUTFILE_TBENCH.result
221*ba2d788aSMeng Li
222*ba2d788aSMeng Li		ppw_drop=`echo "scale=4;($ppw_comp-$ppw_base)*100/$ppw_base" | bc | awk '{printf "%.4f", $0}'`
223*ba2d788aSMeng Li		printf "Tbench-$1 performance per watt base: $ppw_base comprison: $ppw_comp percent: $ppw_drop\n" | tee -a $OUTFILE_TBENCH.result
224*ba2d788aSMeng Li		printf "\n" | tee -a $OUTFILE_TBENCH.result
225*ba2d788aSMeng Li
226*ba2d788aSMeng Li		store_csv_tbench "$1-$2 VS $3-$4" "Comprison(%)" "$des_perf_drop" "$freq_drop" "$load_drop" "$perf_drop" "$energy_drop" "$ppw_drop"
227*ba2d788aSMeng Li	fi
228*ba2d788aSMeng Li}
229*ba2d788aSMeng Li
230*ba2d788aSMeng Li# calculate the comparison(%)
231*ba2d788aSMeng Licalc_comp_tbench()
232*ba2d788aSMeng Li{
233*ba2d788aSMeng Li	# acpi-cpufreq-ondemand VS acpi-cpufreq-schedutil
234*ba2d788aSMeng Li	__calc_comp_tbench ${all_scaling_names[0]} ${tbench_governors[0]} ${all_scaling_names[0]} ${tbench_governors[1]}
235*ba2d788aSMeng Li
236*ba2d788aSMeng Li	# amd-pstate-ondemand VS amd-pstate-schedutil
237*ba2d788aSMeng Li	__calc_comp_tbench ${all_scaling_names[1]} ${tbench_governors[0]} ${all_scaling_names[1]} ${tbench_governors[1]}
238*ba2d788aSMeng Li
239*ba2d788aSMeng Li	# acpi-cpufreq-ondemand VS amd-pstate-ondemand
240*ba2d788aSMeng Li	__calc_comp_tbench ${all_scaling_names[0]} ${tbench_governors[0]} ${all_scaling_names[1]} ${tbench_governors[0]}
241*ba2d788aSMeng Li
242*ba2d788aSMeng Li	# acpi-cpufreq-schedutil VS amd-pstate-schedutil
243*ba2d788aSMeng Li	__calc_comp_tbench ${all_scaling_names[0]} ${tbench_governors[1]} ${all_scaling_names[1]} ${tbench_governors[1]}
244*ba2d788aSMeng Li}
245*ba2d788aSMeng Li
246*ba2d788aSMeng Li# $1: file_name, $2: title, $3: ylable, $4: column
247*ba2d788aSMeng Liplot_png_tbench()
248*ba2d788aSMeng Li{
249*ba2d788aSMeng Li	# all_scaling_names[1] all_scaling_names[0] flag
250*ba2d788aSMeng Li	#    amd-pstate           acpi-cpufreq
251*ba2d788aSMeng Li	#         N                   N             0
252*ba2d788aSMeng Li	#         N                   Y             1
253*ba2d788aSMeng Li	#         Y                   N             2
254*ba2d788aSMeng Li	#         Y                   Y             3
255*ba2d788aSMeng Li	ret=`grep -c "${all_scaling_names[1]}" $OUTFILE_TBENCH.csv`
256*ba2d788aSMeng Li	if [ $ret -eq 0 ]; then
257*ba2d788aSMeng Li		ret=`grep -c "${all_scaling_names[0]}" $OUTFILE_TBENCH.csv`
258*ba2d788aSMeng Li		if [ $ret -eq 0 ]; then
259*ba2d788aSMeng Li			flag=0
260*ba2d788aSMeng Li		else
261*ba2d788aSMeng Li			flag=1
262*ba2d788aSMeng Li		fi
263*ba2d788aSMeng Li	else
264*ba2d788aSMeng Li		ret=`grep -c "${all_scaling_names[0]}" $OUTFILE_TBENCH.csv`
265*ba2d788aSMeng Li		if [ $ret -eq 0 ]; then
266*ba2d788aSMeng Li			flag=2
267*ba2d788aSMeng Li		else
268*ba2d788aSMeng Li			flag=3
269*ba2d788aSMeng Li		fi
270*ba2d788aSMeng Li	fi
271*ba2d788aSMeng Li
272*ba2d788aSMeng Li	gnuplot << EOF
273*ba2d788aSMeng Li		set term png
274*ba2d788aSMeng Li		set output "$1"
275*ba2d788aSMeng Li
276*ba2d788aSMeng Li		set title "$2"
277*ba2d788aSMeng Li		set xlabel "Test Cycles (round)"
278*ba2d788aSMeng Li		set ylabel "$3"
279*ba2d788aSMeng Li
280*ba2d788aSMeng Li		set grid
281*ba2d788aSMeng Li		set style data histogram
282*ba2d788aSMeng Li		set style fill solid 0.5 border
283*ba2d788aSMeng Li		set boxwidth 0.8
284*ba2d788aSMeng Li
285*ba2d788aSMeng Li		if ($flag == 1) {
286*ba2d788aSMeng Li			plot \
287*ba2d788aSMeng Li			"<(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*ba2d788aSMeng Li			"<(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*ba2d788aSMeng Li		} else {
290*ba2d788aSMeng Li			if ($flag == 2) {
291*ba2d788aSMeng Li				plot \
292*ba2d788aSMeng Li				"<(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*ba2d788aSMeng Li				"<(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*ba2d788aSMeng Li			} else {
295*ba2d788aSMeng Li				if ($flag == 3 ) {
296*ba2d788aSMeng Li					plot \
297*ba2d788aSMeng Li					"<(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*ba2d788aSMeng Li					"<(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*ba2d788aSMeng Li					"<(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*ba2d788aSMeng Li					"<(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*ba2d788aSMeng Li				}
302*ba2d788aSMeng Li			}
303*ba2d788aSMeng Li		}
304*ba2d788aSMeng Li		quit
305*ba2d788aSMeng LiEOF
306*ba2d788aSMeng Li}
307*ba2d788aSMeng Li
308*ba2d788aSMeng Liamd_pstate_tbench()
309*ba2d788aSMeng Li{
310*ba2d788aSMeng Li	printf "\n---------------------------------------------\n"
311*ba2d788aSMeng Li	printf "*** Running tbench                        ***"
312*ba2d788aSMeng Li	printf "\n---------------------------------------------\n"
313*ba2d788aSMeng Li
314*ba2d788aSMeng Li	pre_clear_tbench
315*ba2d788aSMeng Li
316*ba2d788aSMeng Li	get_lines_csv_tbench "Governor"
317*ba2d788aSMeng Li	if [ $? -eq 0 ]; then
318*ba2d788aSMeng Li		# add titles and unit for csv file
319*ba2d788aSMeng Li		store_csv_tbench "Governor" "Round" "Des-perf" "Freq" "Load" "Performance" "Energy" "Performance Per Watt"
320*ba2d788aSMeng Li		store_csv_tbench "Unit" "" "" "GHz" "" "MB/s" "J" "MB/J"
321*ba2d788aSMeng Li	fi
322*ba2d788aSMeng Li
323*ba2d788aSMeng Li	backup_governor
324*ba2d788aSMeng Li	for governor in ${tbench_governors[*]} ; do
325*ba2d788aSMeng Li		printf "\nSpecified governor is $governor\n\n"
326*ba2d788aSMeng Li		switch_governor $governor
327*ba2d788aSMeng Li		loop_tbench $governor
328*ba2d788aSMeng Li		gather_tbench $governor
329*ba2d788aSMeng Li	done
330*ba2d788aSMeng Li	restore_governor
331*ba2d788aSMeng Li
332*ba2d788aSMeng Li	plot_png_tbench "tbench_perfromance.png" "Tbench Benchmark Performance" "Performance" 6
333*ba2d788aSMeng Li	plot_png_tbench "tbench_energy.png" "Tbench Benchmark Energy" "Energy (J)" 7
334*ba2d788aSMeng Li	plot_png_tbench "tbench_ppw.png" "Tbench Benchmark Performance Per Watt" "Performance Per Watt (MB/J)" 8
335*ba2d788aSMeng Li
336*ba2d788aSMeng Li	calc_comp_tbench
337*ba2d788aSMeng Li
338*ba2d788aSMeng Li	post_clear_tbench
339*ba2d788aSMeng Li}
340