Skip to content

Commit 9e3567c

Browse files
committed
test: PC10 residency and resume time
Add option to run check-suspend-resume test with sleepgraph, to measure resume time. Updated test-socwatch to measure residency time. Signed-off-by: Emilia Kurdybelska <emiliax.kurdybelska@intel.com>
1 parent e13c1eb commit 9e3567c

File tree

3 files changed

+243
-59
lines changed

3 files changed

+243
-59
lines changed

test-case/check-suspend-resume.sh

Lines changed: 91 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ set -e
55
##
66
## Case Name: check suspend/resume status
77
## Preconditions:
8-
## N/A
8+
## - (if ran with --sleepgraph) Sleepgraph installed on dut
99
## Description:
1010
## Run the suspend/resume command to check device status
1111
## Case step:
@@ -26,27 +26,39 @@ source "$TOPDIR"/case-lib/lib.sh
2626
random_min=3 # wait time should >= 3 for other device wakeup from sleep
2727
random_max=20
2828

29-
OPT_NAME['l']='loop' OPT_DESC['l']='loop count'
30-
OPT_HAS_ARG['l']=1 OPT_VAL['l']=5
29+
OPT_NAME['l']='loop' OPT_DESC['l']='loop count'
30+
OPT_HAS_ARG['l']=1 OPT_VAL['l']=5
3131

32-
OPT_NAME['T']='type' OPT_DESC['T']="suspend/resume type from /sys/power/mem_sleep"
33-
OPT_HAS_ARG['T']=1 OPT_VAL['T']=""
32+
OPT_NAME['T']='type' OPT_DESC['T']="suspend/resume type from /sys/power/mem_sleep"
33+
OPT_HAS_ARG['T']=1 OPT_VAL['T']=""
3434

35-
OPT_NAME['S']='sleep' OPT_DESC['S']='suspend/resume command:rtcwake sleep duration'
36-
OPT_HAS_ARG['S']=1 OPT_VAL['S']=5
35+
OPT_NAME['S']='sleep' OPT_DESC['S']='suspend/resume command:rtcwake sleep duration'
36+
OPT_HAS_ARG['S']=1 OPT_VAL['S']=5
3737

38-
OPT_NAME['u']='unload-audio' OPT_DESC['u']='unload audio modules for the test'
39-
OPT_HAS_ARG['u']=0 OPT_VAL['u']=0
38+
OPT_NAME['u']='unload-audio' OPT_DESC['u']='unload audio modules for the test'
39+
OPT_HAS_ARG['u']=0 OPT_VAL['u']=0
4040

41-
OPT_NAME['w']='wait' OPT_DESC['w']='idle time after suspend/resume wakeup'
42-
OPT_HAS_ARG['w']=1 OPT_VAL['w']=5
41+
OPT_NAME['w']='wait' OPT_DESC['w']='idle time after suspend/resume wakeup'
42+
OPT_HAS_ARG['w']=1 OPT_VAL['w']=5
4343

44-
OPT_NAME['r']='random' OPT_DESC['r']="Randomly setup wait/sleep time, range is [$random_min-$random_max], this option will overwrite s & w option"
45-
OPT_HAS_ARG['r']=0 OPT_VAL['r']=0
44+
OPT_NAME['r']='random' OPT_DESC['r']="Randomly setup wait/sleep time, range is [$random_min-$random_max], this option will overwrite s & w option"
45+
OPT_HAS_ARG['r']=0 OPT_VAL['r']=0
4646

4747
# processid is set by check-suspend-resume-with-audio.sh for audio test case
48-
OPT_NAME['p']='processid' OPT_DESC['p']='Fail immediately if this process dies'
49-
OPT_HAS_ARG['p']=1 OPT_VAL['p']=''
48+
OPT_NAME['p']='processid' OPT_DESC['p']='Fail immediately if this process dies'
49+
OPT_HAS_ARG['p']=1 OPT_VAL['p']=''
50+
51+
OPT_NAME['s']='sleepgraph' OPT_DESC['s']='run with sleepgraph (http://github.com/intel/pm-graph.git)'
52+
OPT_HAS_ARG['s']=0 OPT_VAL['s']=0
53+
54+
OPT_NAME['c']='component-name' OPT_DESC['c']='component for which we check resume time'
55+
OPT_HAS_ARG['c']=1 OPT_VAL['c']=''
56+
57+
OPT_NAME['t']='resume-time' OPT_DESC['t']='resume time threshold'
58+
OPT_HAS_ARG['t']=1 OPT_VAL['t']=''
59+
60+
OPT_NAME['a']='acceptance-range' OPT_DESC['a']='acceptance range for thresholds'
61+
OPT_HAS_ARG['a']=1 OPT_VAL['a']=0.3
5062

5163
func_opt_parse_option "$@"
5264
func_lib_check_sudo
@@ -69,21 +81,28 @@ dlogi "Current suspend/resume type mode: $(cat /sys/power/mem_sleep)"
6981
loop_count=${OPT_VAL['l']}
7082
declare -a sleep_lst wait_lst
7183

72-
if [ ${OPT_VAL['r']} -eq 1 ]; then
84+
if [ "${OPT_VAL['r']}" -eq 1 ]; then
7385
# create random number list
74-
for i in $(seq 1 $loop_count)
86+
for i in $(seq 1 "$loop_count")
7587
do
76-
sleep_lst[$i]=$(func_lib_get_random $random_max $random_min)
77-
wait_lst[$i]=$(func_lib_get_random $random_max $random_min)
88+
sleep_lst[i]=$(func_lib_get_random $random_max $random_min)
89+
wait_lst[i]=$(func_lib_get_random $random_max $random_min)
7890
done
7991
else
80-
for i in $(seq 1 $loop_count)
92+
for i in $(seq 1 "$loop_count")
8193
do
82-
sleep_lst[$i]=${OPT_VAL['S']}
83-
wait_lst[$i]=${OPT_VAL['w']}
94+
sleep_lst[i]=${OPT_VAL['S']}
95+
wait_lst[i]=${OPT_VAL['w']}
8496
done
8597
fi
8698

99+
if [ "${OPT_VAL['s']}" -eq 1 ]; then
100+
if ! command -v sleepgraph >/dev/null 2>&1; then
101+
echo "Sleepgraph is not installed! Exiting..."
102+
exit 1
103+
fi
104+
fi
105+
87106
save_initial_stats()
88107
{
89108
printf '\n\n'
@@ -142,8 +161,9 @@ main()
142161
sleep 1
143162

144163
local keep_modules=true already_unloaded=false
164+
sleepgraph_failures=0
145165

146-
if [ ${OPT_VAL['u']} = 1 ]; then
166+
if [ "${OPT_VAL['u']}" = 1 ]; then
147167
keep_modules=false
148168
fi
149169

@@ -159,7 +179,7 @@ main()
159179
expected_wakeup_count=$(cat /sys/power/wakeup_count)
160180
expected_stats_success=$(cat /sys/power/suspend_stats/success)
161181
save_initial_stats
162-
for i in $(seq 1 $loop_count)
182+
for i in $(seq 1 "$loop_count")
163183
do
164184
sleep_once "$i"
165185
done
@@ -168,6 +188,51 @@ main()
168188
die "Failed to reload audio drivers"
169189
sof-kernel-log-check.sh "$KERNEL_CHECKPOINT" ||
170190
die "Found kernel error after reloading audio drivers"
191+
192+
if [ $sleepgraph_failures -eq 0 ]; then
193+
dlogi "FINAL TEST RESULT: All time measurements within the thresholds."
194+
else
195+
die "FINAL TEST RESULT: Some time measurements not within the thresholds!"
196+
fi
197+
}
198+
199+
analyze_sleepgraph_results()
200+
{
201+
dlogi "Analyzing sleepgraph results"
202+
results_file=$(find suspend-*/*.html)
203+
cp "$results_file" "$LOG_ROOT/"
204+
205+
thresholds=$( jq -n \
206+
--arg component_name "${OPT_VAL['c']}" \
207+
--arg resume_time "${OPT_VAL['t']}" \
208+
'{$component_name:{"resume":$resume_time}}')
209+
210+
thresholds_acceptance_range="${OPT_VAL['a']}"
211+
212+
dlogi "Analyzing $results_file file..."
213+
if python3 "$SCRIPT_HOME"/tools/analyze-sleepgraph-results.py "$results_file" "$thresholds" "$thresholds_acceptance_range"; then
214+
dlogi "All times measurements within the thresholds"
215+
else
216+
dlogw "Time measurements not within the thresholds!"
217+
sleepgraph_failures=$((sleepgraph_failures+1))
218+
fi
219+
}
220+
221+
run_rtcwake()
222+
{
223+
if [ "${OPT_VAL['s']}" -eq 1 ]; then
224+
# remove any files from previous sleepgraph runs
225+
rm -rf suspend-*
226+
227+
dlogc "Run the command: sleepgraph -rtcwake ${sleep_lst[$i]} -m freeze"
228+
sudo sleepgraph -rtcwake "${sleep_lst[$i]}" -m freeze ||
229+
dump_and_die "rtcwake returned $?"
230+
analyze_sleepgraph_results
231+
else
232+
dlogc "Run the command: rtcwake -m mem -s ${sleep_lst[$i]}"
233+
sudo rtcwake -m mem -s "${sleep_lst[$i]}" ||
234+
dump_and_die "rtcwake returned $?"
235+
fi
171236
}
172237

173238
sleep_once()
@@ -179,11 +244,9 @@ sleep_once()
179244
setup_kernel_check_point
180245
expected_wakeup_count=$((expected_wakeup_count+1))
181246
expected_stats_success=$((expected_stats_success+1))
182-
dlogc "Run the command: rtcwake -m mem -s ${sleep_lst[$i]}"
183-
sudo rtcwake -m mem -s "${sleep_lst[$i]}" ||
184-
dump_and_die "rtcwake returned $?"
247+
run_rtcwake
185248
dlogc "sleep for ${wait_lst[$i]}"
186-
sleep ${wait_lst[$i]}
249+
sleep "${wait_lst[$i]}"
187250
dlogi "Check for the kernel log status"
188251
# check kernel log for each iteration to catch issues
189252
sof-kernel-log-check.sh "$KERNEL_CHECKPOINT" || dump_and_die "Caught error in kernel log"
Lines changed: 78 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,7 @@ OPT_NAME['u']='unload-audio' OPT_DESC['u']='unload audio modules for the test'
3838
OPT_HAS_ARG['u']=0 OPT_VAL['u']=0
3939

4040
: "${SOCWATCH_PATH:=$HOME/socwatch}"
41-
SOCWATCH_VERSION=$("$SOCWATCH_PATH"/socwatch --version |grep Version)
42-
43-
# reference cmd: sudo ./socwatch -t 20 -s 5 -f cpu-cstate -f pkg-pwr -o fredtest5
44-
#SOCWATCH_CMD="./socwatch"
45-
SOCWATCH_FEATURE_PARAMS=( -f cpu-cstate -f pkg-pwr )
41+
SOCWATCH_VERSION=$(sudo "$SOCWATCH_PATH"/socwatch --version | grep Version)
4642

4743
func_opt_parse_option "$@"
4844
func_lib_check_sudo
@@ -54,7 +50,29 @@ start_test
5450

5551
check_socwatch_module_loaded()
5652
{
57-
lsmod | grep -q socwatch || dlogi "socwatch is not loaded"
53+
lsmod | grep -q socwatch || die "socwatch is not loaded"
54+
}
55+
56+
check_for_PC10_state()
57+
{
58+
pc10_count=$(awk '/Package C-State Summary: Entry Counts/{f=1; next} f && /PC10/{print $3; exit}' "$socwatch_output".csv)
59+
if [ -z "$pc10_count" ]; then
60+
die "PC10 State not achieved"
61+
fi
62+
dlogi "Entered into PC10 State $pc10_count times"
63+
64+
pc10_per=$(awk '/Package C-State Summary: Residency/{f=1; next} f && /PC10/{print $3; exit}' "$socwatch_output".csv)
65+
pc10_time=$(awk '/Package C-State Summary: Residency/{f=1; next} f && /PC10/{print $5; exit}' "$socwatch_output".csv)
66+
dlogi "Spent $pc10_time ms ($pc10_per %) in PC10 State"
67+
68+
json_str=$( jq -n \
69+
--arg id "$i" \
70+
--arg cnt "$pc10_count" \
71+
--arg time "$pc10_time" \
72+
--arg per "$pc10_per" \
73+
'{$id: {pc10_entires_count: $cnt, time_ms: $time, time_percentage: $per}}' )
74+
75+
results=$(jq --slurp 'add' <(echo "$results") <(echo "$json_str"))
5876
}
5977

6078
socwatch_test_once()
@@ -63,35 +81,29 @@ socwatch_test_once()
6381
dlogi "===== Loop($i/$loop_count) ====="
6482
dlogi "SoCWatch version: ${SOCWATCH_VERSION}"
6583

84+
socwatch_output="$LOG_ROOT/socwatch-results/socwatch_output_$i"
85+
6686
# set up checkpoint for each iteration
6787
setup_kernel_check_point
6888

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-
7389
( set -x
74-
sudo "$SOCWATCH_PATH"/socwatch -t "$duration" -s "$wait_time" "${SOCWATCH_FEATURE_PARAMS[@]}" -o "$SOCWATCH_PATH/sofsocwatch-$i" ) ||
90+
sudo "$SOCWATCH_PATH"/socwatch -m -f sys -f cpu -f cpu-hw -f pcie -f hw-cpu-cstate \
91+
-f pcd-slps0 -f tcss-state -f tcss -f pcie-lpm -n 200 -t "$duration" -s "$wait_time" \
92+
-r json -o "$socwatch_output" ) ||
7593
die "socwatch returned $?"
7694

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"/
95+
# analyze SoCWatch results
96+
check_for_PC10_state
8397

84-
dlogi "Check for the kernel log status"
8598
# check kernel log for each iteration to catch issues
99+
dlogi "Check for the kernel log status"
86100
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
90101
}
91102

92-
main()
103+
unload_modules()
93104
{
94-
local keep_modules=true already_unloaded=false
105+
keep_modules=true
106+
already_unloaded=false
95107

96108
[ -d "$SOCWATCH_PATH" ] ||
97109
die "SOCWATCH not found in SOCWATCH_PATH=$SOCWATCH_PATH"
@@ -106,22 +118,57 @@ main()
106118
dlogw 'modules already unloaded, ignoring option -u!'
107119
}
108120

109-
$already_unloaded || $keep_modules || "$TOPDIR"/tools/kmod/sof_remove.sh ||
121+
if ! [ $already_unloaded ] || [ $keep_modules ]; then
122+
"$TOPDIR"/tools/kmod/sof_remove.sh ||
110123
die "Failed to unload audio drivers"
124+
fi
125+
}
126+
127+
load_modules()
128+
{
129+
if ! [ $already_unloaded ] || [ $keep_modules ]; then
130+
"$TOPDIR"/tools/kmod/sof_insert.sh ||
131+
die "Failed to reload audio drivers"
132+
fi
133+
134+
sof-kernel-log-check.sh "$KERNEL_CHECKPOINT" ||
135+
die "Found kernel error after reloading audio drivers"
136+
}
137+
138+
run_socwatch_tests()
139+
{
140+
# load socwatch module, if the module is loaded, go ahead with the testing
141+
sudo bash "$SOCWATCH_PATH"/drivers/insmod-socwatch || true
142+
check_socwatch_module_loaded || die "socwatch module not loaded"
143+
144+
# Create a dir for all socwatch reports
145+
mkdir "$LOG_ROOT/socwatch-results"
146+
pc10_results_file="$LOG_ROOT/socwatch-results/pc10_results.json"
147+
touch "$pc10_results_file"
111148

112-
# socwatch test from here
113149
for i in $(seq 1 "$loop_count")
114150
do
115151
socwatch_test_once "$i"
116152
done
153+
echo "$results" > "$pc10_results_file"
154+
dlogi "****** PC10 STATE RESULTS: ******"
155+
dlogi "$results"
156+
dlogi "*********************************"
117157

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"
158+
# zip all SoCWatch reports
159+
cd "$LOG_ROOT"
160+
tar -zcvf socwatch-results.tar.gz socwatch-results/
161+
rm -rf "$LOG_ROOT/socwatch-results/"
122162

123-
# DON"T delete socwatch directory after test, delete before new test
124-
# rm -rf $SOCWATCH_PATH
163+
# unload socwatch module
164+
sudo bash "$SOCWATCH_PATH"/drivers/rmmod-socwatch
165+
}
166+
167+
main()
168+
{
169+
unload_modules
170+
run_socwatch_tests
171+
load_modules
125172
}
126173

127174
main "$@"

0 commit comments

Comments
 (0)