@@ -38,7 +38,7 @@ OPT_NAME['u']='unload-audio' OPT_DESC['u']='unload audio modules for the test'
3838OPT_HAS_ARG[' u' ]=0 OPT_VAL[' u' ]=0
3939
4040: " ${SOCWATCH_PATH:= $HOME / socwatch} "
41- SOCWATCH_VERSION=$( " $SOCWATCH_PATH " /socwatch --version | grep Version)
41+ SOCWATCH_VERSION=$( sudo " $SOCWATCH_PATH " /socwatch --version | grep Version)
4242
4343# reference cmd: sudo ./socwatch -t 20 -s 5 -f cpu-cstate -f pkg-pwr -o fredtest5
4444# SOCWATCH_CMD="./socwatch"
@@ -57,41 +57,57 @@ check_socwatch_module_loaded()
5757 lsmod | grep -q socwatch || dlogi " socwatch is not loaded"
5858}
5959
60+ check_for_PC10_state ()
61+ {
62+ pc10_count=$( awk ' /Package C-State Summary: Entry Counts/{f=1; next} f && /PC10/{print $3; exit}' $socwatch_output .csv)
63+ if [ -z " $pc10_count " ]; then
64+ die " PC10 State not achieved"
65+ fi
66+ dlogi " Entered into PC10 State $pc10_count times"
67+
68+ pc10_per=$( awk ' /Package C-State Summary: Residency/{f=1; next} f && /PC10/{print $3; exit}' $socwatch_output .csv)
69+ pc10_time=$( awk ' /Package C-State Summary: Residency/{f=1; next} f && /PC10/{print $5; exit}' $socwatch_output .csv)
70+ dlogi " Spent $pc10_time ms ($pc10_per %) in PC10 State"
71+
72+ json_str=$( jq -n \
73+ --arg id " $i " \
74+ --arg cnt " $pc10_count " \
75+ --arg time " $pc10_time " \
76+ --arg per " $pc10_per " \
77+ ' {$id: {pc10_entires_count: $cnt, time_ms: $time, time_percentage: $per}}' )
78+
79+ results=$( jq --slurp ' add' <( echo " $results " ) <( echo " $json_str " ) )
80+ }
81+
6082socwatch_test_once ()
6183{
6284 local i=" $1 "
6385 dlogi " ===== Loop($i /$loop_count ) ====="
6486 dlogi " SoCWatch version: ${SOCWATCH_VERSION} "
6587
88+ socwatch_output=" $LOG_ROOT /socwatch-results/socwatch_output_$i "
89+
6690 # set up checkpoint for each iteration
6791 setup_kernel_check_point
6892
69- # load socwatch module, if the module is loaded, go ahead with the testing (-q)
70- sudo " $SOCWATCH_PATH " /drivers/insmod-socwatch -q || true
71- check_socwatch_module_loaded || die " socwatch module not loaded"
72-
7393 ( set -x
74- sudo " $SOCWATCH_PATH " /socwatch -t " $duration " -s " $wait_time " " ${SOCWATCH_FEATURE_PARAMS[@]} " -o " $SOCWATCH_PATH /sofsocwatch-$i " ) ||
94+ sudo " $SOCWATCH_PATH " /socwatch -m -f sys -f cpu -f cpu-hw -f pcie -f hw-cpu-cstate \
95+ -f pcd-slps0 -f tcss-state -f tcss -f pcie-lpm -n 200 -t " $duration " -s " $wait_time " \
96+ -r json -o " $socwatch_output " ) ||
7597 die " socwatch returned $? "
7698
77- # filter output and copy to log directory
78- grep " Package C-State Summary: Residency" -B 8 -A 11 " $SOCWATCH_PATH /sofsocwatch-$i .csv" | tee " $SOCWATCH_PATH /socwatch-$i .txt"
79- grep " Package Power Summary: Average Rate" -B 6 -A 4 " $SOCWATCH_PATH /sofsocwatch-$i .csv" | tee -a " $SOCWATCH_PATH /socwatch-$i .txt"
80- # zip original csv report
81- gzip " $SOCWATCH_PATH /sofsocwatch-$i .csv"
82- mv " $SOCWATCH_PATH /socwatch-$i .txt" " $SOCWATCH_PATH /sofsocwatch-$i .csv.gz" " $LOG_ROOT " /
99+ # analyze SoCWatch results
100+ check_for_PC10_state
83101
84- dlogi " Check for the kernel log status"
85102 # check kernel log for each iteration to catch issues
103+ dlogi " Check for the kernel log status"
86104 sof-kernel-log-check.sh " $KERNEL_CHECKPOINT " || die " Caught error in kernel log"
87-
88- # unload socwatch module
89- sudo " $SOCWATCH_PATH " /drivers/rmmod-socwatch || true
90105}
91106
92- main ()
107+ unload_modules ()
93108{
94- local keep_modules=true already_unloaded=false
109+ keep_modules=true
110+ already_unloaded=false
95111
96112 [ -d " $SOCWATCH_PATH " ] ||
97113 die " SOCWATCH not found in SOCWATCH_PATH=$SOCWATCH_PATH "
@@ -108,20 +124,44 @@ main()
108124
109125 $already_unloaded || $keep_modules || " $TOPDIR " /tools/kmod/sof_remove.sh ||
110126 die " Failed to unload audio drivers"
127+ }
128+
129+ load_modules ()
130+ {
131+ $already_unloaded || $keep_modules || " $TOPDIR " /tools/kmod/sof_insert.sh ||
132+ die " Failed to reload audio drivers"
133+ sof-kernel-log-check.sh " $KERNEL_CHECKPOINT " ||
134+ die " Found kernel error after reloading audio drivers"
135+ }
136+
137+ run_socwatch_tests ()
138+ {
139+ # load socwatch module, if the module is loaded, go ahead with the testing
140+ sudo " $SOCWATCH_PATH " /drivers/insmod-socwatch || true
141+ check_socwatch_module_loaded || die " socwatch module not loaded"
142+
143+ mkdir " $LOG_ROOT /socwatch-results"
144+ pc10_results_file=" $LOG_ROOT /socwatch-results/pc10_results.json"
145+ touch " $pc10_results_file "
111146
112- # socwatch test from here
113147 for i in $( seq 1 " $loop_count " )
114148 do
115149 socwatch_test_once " $i "
116150 done
151+ echo " $results " > " $pc10_results_file "
117152
118- $already_unloaded || $keep_modules || " $TOPDIR " /tools/kmod/sof_insert.sh ||
119- die " Failed to reload audio drivers"
120- sof-kernel-log-check.sh " $KERNEL_CHECKPOINT " ||
121- die " Found kernel error after reloading audio drivers"
153+ # zip all SoCWatch reports
154+ tar -zcvf " $LOG_ROOT /socwatch-results.tar.gz" " $LOG_ROOT /socwatch-results/"
122155
123- # DON"T delete socwatch directory after test, delete before new test
124- # rm -rf $SOCWATCH_PATH
156+ # unload socwatch module
157+ sudo " $SOCWATCH_PATH " /drivers/rmmod-socwatch
158+ }
159+
160+ main ()
161+ {
162+ unload_modules
163+ run_socwatch_tests
164+ load_modules
125165}
126166
127167main " $@ "
0 commit comments