forked from intel/S0ixSelftestTool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paths0ix-selftest-tool.sh
executable file
·1420 lines (1287 loc) · 49.3 KB
/
s0ix-selftest-tool.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0-only
# This is a CPU Package C-state and S0ix failure selftest and debug script, it's
# designed for Linux OS running on Intel® Architecture-based client platforms.
# Aims to get the potential Package C-state or S0ix blocker clue in an easy way.
# Helps Linux users save the basic isolation effort to focus on the advanced debug
# or report a bug with the initial debug log attached.
# Copyright (c) 2021 Intel Corporation.
# Author: wendy.wang@intel.com
# Contributor: david.e.box@intel.com
PATH=$PATH:$HOME
DATE=$(date '+%Y%m%d-%H-%M')
DIR="$(pwd -P)"
TURBO_COLUMNS="CPU%c1,CPU%c6,CPU%c7,GFX%rc6,Pkg%pc2,Pkg%pc3,Pkg%pc6,Pkg%pc7,Pkg%pc8,Pkg%pc9,Pk%pc10,SYS%LPI"
DEEP="S0i2.0"
SHALLOW="c10"
PMC_CORE_SYSFS_PATH="/sys/kernel/debug/pmc_core"
PCIEPORT_D0=""
PCIEPORT_D3HOT=""
PCIEPORT_L0=""
ASPM_ENABLE=""
#Define which debug stage should go
DEBUG=""
touch "$PWD"/"$DATE"-s0ix-output.log
#Function to archive S0ix debug output
log_output() {
echo -e "${*}" | tee -a "$PWD"/"$DATE"-s0ix-output.log
}
#Define script must be run as root account
if [[ $EUID -ne 0 ]]; then
log_output "\nThis script must be run as root.\n" >&2
exit 0
fi
usage() {
cat <<EOF
Usage: ./${0##*/} [-s|h][-r on][-r off]
-r: Check PC10 residency during runtime with screen on or screen off
-s: Check S0ix residency during S2idle
-h: Display help
EOF
}
runtime=0
s2idle=0
#Promote the usage info when there is no option placed
if [[ $# -lt 1 ]]; then
usage && exit 1
fi
while getopts r:sh opt; do
case $opt in
r)
runtime=$OPTARG
;;
s)
s2idle=1
;;
h)
usage && exit 1
;;
*)
echo "Invalid option argument." && usage && exit 1
;;
esac
done
#Function to check whether slp_s0 is supported on the test platform
slp_s0_support() {
local lp=""
acpidump 1>/dev/null 2>&1 || {
log_output "The acpidump tool is needed to check whether low idle S0 \
\ncapability is enabled on the test platform, please install acpica-tools \
\nor check if the acpidump command execution failed.\n"
exit 0
}
acpidump -b 2>&1
iasl -d ./facp.dat 1>/dev/null 2>&1
sleep 2
lp=$(grep "Low Power S0 Idle" facp.dsl 2>&1 | awk '{print $(NF)}')
if [[ "$lp" -eq 1 ]]; then
log_output "\nLow Power S0 Idle is:$lp"
log_output "Your system supports low power S0 idle capability."
return 0
else
log_output "\nLow Power S0 Idle is:$lp"
log_output "Your system does not support low power S0 idle capability. \
\nIsolation suggestion: \
\nPlease check BIOS low power S0 idle capability setting.\n"
return 1
fi
}
#Judge whether intel_pmc_core sysfs debug files available
pmc_core_check() {
if [[ "$(ls -A $PMC_CORE_SYSFS_PATH)" ]]; then
log_output "\nThe pmc_core debug sysfs files are OK on your system."
return 0
else
log_output "\nThe pmc_core debug sysfs file is empty on your system."
log_output "Isolation suggestions: \
\nPlease check whether intel_pmc_core driver is loaded.\n"
return 1
fi
}
pci_d3_status_check() {
local duration=10
local d3_log=""
local pcieport_ds=""
local pci_tree=""
pci_tree=$(lspci -tvv)
#Prepare for the PCI Device D3 states check
echo -n "file pci-driver.c +p" >/sys/kernel/debug/dynamic_debug/control
echo N >/sys/module/printk/parameters/console_suspend
echo 1 >/sys/power/pm_debug_messages
dmesg -C
echo 0 >/sys/class/rtc/rtc0/wakealarm
echo +$duration >/sys/class/rtc/rtc0/wakealarm
"$DIR"/turbostat --quiet -o tc.out echo freeze 2>&1 >/sys/power/state
sleep 2
d3_log=$(dmesg | grep "PCI PM" 2>&1)
if [[ -n "$d3_log" ]]; then
log_output "\nChecking PCI Devices D3 States:\n$d3_log\n"
log_output "\nChecking PCI Devices tree diagram:\n$pci_tree\n"
fi
#Filter out the pcieport devices D states
pcieport_ds=$(echo "$d3_log" | grep -o "pcieport.*")
if [[ -n "$pcieport_ds" ]]; then
PCIEPORT_D0=$(echo "$pcieport_ds" | grep D0 |
awk -F " " '{print $2}' | sed 's/:$//')
PCIEPORT_D3HOT=$(echo "$pcieport_ds" | grep D3hot |
awk -F " " '{print $2}' | sed 's/:$//')
#Check the ASPM enable status for the D0 state pcieroot port
if [[ -n "$PCIEPORT_D0" ]]; then
ASPM_ENABLE=$(lspci -vvv -s"$PCIEPORT_D0" | grep "LnkCtl:" | grep Enabled)
log_output "The pcieport $PCIEPORT_D0 ASPM enable status:\n$ASPM_ENABLE\n"
fi
[[ -n "$PCIEPORT_D0" ]] && log_output "Pcieport is not in D3cold:\
\n\033[31m$PCIEPORT_D0\033[0m\n"
[[ -n "$PCIEPORT_D3HOT" ]] && log_output "Pcieport is not in D3cold: \
\n\033[31m$PCIEPORT_D3HOT\033[0m\n"
return 1
fi
return 0
}
#Function to automatically triage the potential deeper S0ix substate blockers
#through Intel_PMC_Core files: lpm_latch_mode and substate_requirements
#$1 is the archivable PC10 or shallower S0ix substate
#$2 is the deeper desired but not achieved S0ix substate
substate_triage() {
local col=""
local duration=15
local sub=""
local sta=""
local req=""
log_output "\n---Begin S0ix Substate Debug by substate_requirements---:\n"
#Before testing, need to clean the lpm_latch_mode setting
echo clear >"$PMC_CORE_SYSFS_PATH"/lpm_latch_mode 2>&1
log_output "Clear lpm_latch_mode is Done\n"
#Put $1 achieved PC10 or S0ix substate into lpm_latch_mode file
echo "$1" >"$PMC_CORE_SYSFS_PATH"/lpm_latch_mode 2>&1
log_output "Set $1 to lpm_latch_mode is Done\n"
log_output "Need to run once S2idle, please wait for 15 seconds...\n"
echo 0 >/sys/class/rtc/rtc0/wakealarm
echo +$duration >/sys/class/rtc/rtc0/wakealarm
"$DIR"/turbostat --quiet --show "$TURBO_COLUMNS" -o tc.out \
echo freeze 2>&1 >/sys/power/state
sleep 2
#Filter out the desired deeper S0ix substate column:col
eval "$(cat "$PMC_CORE_SYSFS_PATH"/substate_requirements | awk -F "|" '{
for(i=1;i<NF;i++)
{
$i = gensub(/^[ \t]*|[ \t]*$/,"","g",$i)
if($i == "'"$2"'")
printf("col=%d\n",i)
}
exit 0
}')" 2>&1
log_output "\nsubstate_requirements file shows:\n"
req="$(cat "$PMC_CORE_SYSFS_PATH"/substate_requirements | awk -F "|" \
'!/Int_Timer/ && !/LSX_Wake/ && !/VNN_REQ_STS/{print $1,$"'"${col}"'",$(NF-1)}')" 2>&1
log_output "$req"
#Filter out the IPs which are required but not show YES
sub="$(cat "$PMC_CORE_SYSFS_PATH"/substate_requirements | awk -F "|" \
'!/Int_Timer/ && !/LSX_Wake/ && !/VNN_REQ_STS/{print $1,$"'"${col}"'",$(NF-1)}' |
grep Required | awk '!/Yes/{print $0}')" 2>&1
if [[ -z "$sub" ]]; then
sta=$(cat "$PMC_CORE_SYSFS_PATH"/substate_status_registers)
log_output "\nDid not detect the potential blockers from substate_requirements, \
\nneed to check substate_status_registers file for the advanced debug.\n"
log_output "substate_status_registers:"
log_output "$sta"
return 0
else
log_output "\nBelow are the deeper S0ix substate required IPs did not show YES:\n"
log_output "\033[31m $sub \033[0m \n"
return 1
fi
}
#Function to check whether Intel graphics DMC FW load status on the test platform
dmc_check() {
local dmc_load=""
local dmc_log=""
dmc_load=$(grep "fw loaded" /sys/kernel/debug/dri/0/i915_dmc_info | head -n 1 |
awk '{print $3}')
dmc_log=$(dmesg | grep -i DMC 2>&1)
if [[ $dmc_load == yes ]]; then
log_output "\nYour system Intel graphics DMC FW loaded status is:$dmc_load
$dmc_log"
return 0
else
log_output "\n\033[31mYour system loaded Intel i915 DMC FW is not the latest \
version, \nor you did not install the DMC FW correctly: \n$dmc_log,
\nplease refer to \
https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git/tree/i915 \
\nto get the latest display DMC FW. \
\nor re-install the Firmware package or manually check DMC FW file from /lib/firmware/i915.
\nIf you are running with CentOS, try the command: \
#dracut -i /lib/firmware/i915 /lib/firmware/i915 --force and reboot.\n\033[0m"
return 1
fi
}
#Function to check runtime PC10 state when screen on
pc10_idle_on() {
local runtime_pkg10=""
local turbostat_runtime=""
local pc10_para="CPU%c1,CPU%c6,CPU%c7,GFX%rc6,Pkg%pc2,Pkg%pc3,Pkg%pc6,Pkg%pc7,Pkg%pc8,Pkg%pc9,Pk%pc10"
log_output "\nThe system will keep idle for 40 seconds then check runtime PC10 state:\n"
sleep 40
turbostat_runtime=$("$DIR"/turbostat --quiet --show "$pc10_para" sleep 30 2>&1)
runtime_pkg10=$(echo "$turbostat_runtime" | sed -n '/Pk\%pc10/{n;p}' |
awk '{print $11}')
log_output "\nThe CPU runtime PC10 residency when screen ON: $runtime_pkg10%\n"
log_output "\nTurbostat log: \n$turbostat_runtime\n"
#Judge whether turbostat tool supports the test platform
if [ -z "$runtime_pkg10" ]; then
log_output "\nYour system installed turbostat tool does not support this \
test platform. \
\nplease try to get the latest version turbostat tool.\n"
exit 0
fi
if [[ -n "$runtime_pkg10" ]] && [[ "$(echo "scale=2; $runtime_pkg10 > 90.00" |
bc)" -eq 1 ]]; then
log_output "\n\033[32mYour system achieved high runtime PC10 residency during screen ON: \
$runtime_pkg10%\033[0m\n"
return 0
elif
[[ -n "$runtime_pkg10" ]] &&
[[ "$(echo "scale=2; $runtime_pkg10 > 50.00" | bc)" -eq 1 ]] &&
[[ "$(echo "scale=2; $runtime_pkg10 < 90.00" | bc)" -eq 1 ]]
then
log_output "\nYour system achieved runtime PC10 during screen ON, \
\nbut the residency is not high enough: $runtime_pkg10%\n"
return 0
elif
[[ -n "$runtime_pkg10" ]] &&
[[ "$(echo "scale=2; $runtime_pkg10 > 0.00" | bc)" -eq 1 ]] &&
[[ "$(echo "scale=2; $runtime_pkg10 < 50.00" | bc)" -eq 1 ]]
then
log_output "\n\033[31mYour system achieved the runtime PC10 during screen ON, \
\nbut the residency is too low and need to do the further debugging: \
$runtime_pkg10%\033[0m\n"
return 1
fi
log_output "\n\033[31mYour system did not achieve the runtime PC10 state \
during screen ON\033[0m\n"
return 1
}
#Function to check runtime PC10 residency when screen OFF
pc10_idle_off() {
local pc10_para="CPU%c1,CPU%c6,CPU%c7,GFX%rc6,Pkg%pc2,Pkg%pc3,Pkg%pc6,Pkg%pc7,Pkg%pc8,Pkg%pc9,Pk%pc10"
log_output "\nThis script will turn off display using xset command, \
\nplease startx first, then run this script in xterminal.\n"
#Turn off display using xset command in GUI
xset +dpms 2>&1 || {
log_output "\033[31mPlease run this runtime PC10 check after startx\033[0m\n"
exit 0
}
log_output "\nWill turn off the display in 30 seconds timeout, then the \
\nturbostat tool will read the PC10 counter after 40 seconds idle...\n"
xset dpms 30
local runtime_pkg10=""
local turbostat_runtime=""
sleep 40
turbostat_runtime=$("$DIR"/turbostat --quiet --show "$pc10_para" sleep 35 2>&1)
runtime_pkg10=$(echo "$turbostat_runtime" | sed -n '/Pk\%pc10/{n;p}' |
awk '{print $11}')
log_output "The CPU runtime PC10 state when screen OFF: $runtime_pkg10%"
log_output "\nTurbostat log: \n$turbostat_runtime\n"
#Judge whether turbostat tool supports the test platform
if [[ -z "$runtime_pkg10" ]]; then
log_output "\nYour system installed turbostat tool does not support this
test platform. \
\nplease try to get the latest version turbostat tool.\n"
exit 0
fi
if [[ -n "$runtime_pkg10" ]] &&
[[ "$(echo "scale=2; $runtime_pkg10 > 90.00" | bc)" -eq 1 ]]; then
log_output "\n\033[32mYour system achieved the high runtime PC10 residency during \
screen OFF: $runtime_pkg10%\033[0m\n"
xset dpms force on && xset -dpms
return 0
elif
[[ -n "$runtime_pkg10" ]] &&
[[ "$(echo "scale=2; $runtime_pkg10 > 50.00" | bc)" -eq 1 ]] &&
[[ "$(echo "scale=2; $runtime_pkg10 < 90.00" | bc)" -eq 1 ]]
then
log_output "\nYour system achieved the runtime PC10 during screen OFF, \
\nbut the residency is not high enough: $runtime_pkg10%\n"
xset dpms force on && xset -dpms
return 0
elif
[[ -n "$runtime_pkg10" ]] &&
[[ "$(echo "scale=2; $runtime_pkg10 > 0.00" | bc)" -eq 1 ]] &&
[[ "$(echo "scale=2; $runtime_pkg10 < 50.00" | bc)" -eq 1 ]]
then
log_output "\n\033[31mYour system achieved the runtime PC10 state during Screen OFF, \
\nbut is the residency is too low and need to do the further debugging: \
$runtime_pkg10%\033[0m\n"
xset dpms force on && xset -dpms
return 1
fi
log_output "\n\033[31mYour system did not achieve the runtime PC10 state \
with screen OFF\033[0m\n"
xset dpms force on && xset -dpms
return 1
}
#Function to check which package c-state or S0ix state is available during S2idle
pkg_output() {
local rc6=""
local cc7=""
local pkg2=""
local pkg8=""
local pkg9=""
local pkg10=""
local slp_s0=""
local turbostat_after_s2idle=""
local duration=15
local sub_enable_flag=""
local sub_bf_enable=""
local sub_af_enable=""
local sub_num=""
local sub_bf=""
local sub_bf_res=""
local subarraybf=""
local resarraybf=""
local subarrayaf=""
local resarrayaf=""
local resdeltaarray=""
local s0ix_substate=""
local s0ix_substate_af=""
local sub_af=""
local sub_af_res=""
local shallower=""
local deeper=""
s0ix_substate="$(cat $PMC_CORE_SYSFS_PATH/substate_residencies)" 2>&1
sub_enable_flag="$(grep "Enabled" $PMC_CORE_SYSFS_PATH/substate_residencies)" 2>&1
if [[ -n "$s0ix_substate" ]] && [[ -z "$sub_enable_flag" ]]; then
sub_num="$(echo "$s0ix_substate" | wc -l)"
for ((i = 2; i <= sub_num; i++)); do
sub_bf="$(sed -n "$i, 1p" $PMC_CORE_SYSFS_PATH/substate_residencies |
awk '{print $1}')"
subarraybf[i]=$sub_bf
sub_bf_res="$(sed -n "$i,1p" $PMC_CORE_SYSFS_PATH/substate_residencies |
awk '{print $2}')"
resarraybf[i]=$sub_bf_res
done
#Print out the subarray and resarray contents
log_output "\nTest system supports S0ix.y substate"
log_output "\nS0ix substate before S2idle:\n" "${subarraybf[*]}"
log_output "\nS0ix substate residency before S2idle:\n" "${resarraybf[*]}"
elif
[[ -n "$s0ix_substate" ]] && [[ -n "$sub_enable_flag" ]]
then
sub_num="$(echo "$s0ix_substate" | grep -c "Enabled")"
for ((i = 1; i <= sub_num; i++)); do
sub_bf_enable="$(grep "Enabled" $PMC_CORE_SYSFS_PATH/substate_residencies)"
sub_bf="$(echo "$sub_bf_enable" | sed -n "$i,1p" | awk '{print $2}')"
subarraybf[i]=$sub_bf
sub_bf_res="$(echo "$sub_bf_enable" | sed -n "$i,1p" | awk '{print $3}')"
resarraybf[i]=$sub_bf_res
done
#Print out the subarray and resarray contents
log_output "\nTest system supports S0ix.y substate"
log_output "\nS0ix substate before S2idle:\n" "${subarraybf[*]}"
log_output "\nS0ix substate residency before S2idle:\n" "${resarraybf[*]}"
else
log_output "Test system does not support S0ix.y substate"
fi
echo 0 >/sys/class/rtc/rtc0/wakealarm
echo +$duration >/sys/class/rtc/rtc0/wakealarm
if turbostat_after_s2idle=$("$DIR"/turbostat --quiet --show "$TURBO_COLUMNS" \
echo freeze 2>&1 >/sys/power/state); then
log_output "\nTurbostat output: \n$turbostat_after_s2idle"
#Let system sleep 5 seconds in case some systems cannot finish S0ix substate
#and pkg cstate judgement before entering next S2idle cycle.
sleep 5
else
log_output "\n\033[31mThe system failed to place S2idle entry command by turbostat, \
\nplease check if the suspend is failed or turbostat tool version is old \
\ne.g. did you make turbostat tool executable or separately run S2idle command: \
\nrtcwake -m freeze -s 15\033[0m\n"
exit 0
fi
cc7=$(echo "$turbostat_after_s2idle" | sed -n '/CPU\%c7/{n;p}' |
awk '{print $3}')
log_output "\nCPU Core C7 residency after S2idle is: $cc7"
rc6=$(echo "$turbostat_after_s2idle" | sed -n '/GFX\%rc6/{n;p}' |
awk '{print $4}')
log_output "GFX RC6 residency after S2idle is: $rc6"
if [ -z "$rc6" ]; then
pkg2=$(echo "$turbostat_after_s2idle" | sed -n '/Pkg\%pc2/{n;p}' |
awk '{print $4}')
log_output "CPU Package C-state 2 residency after S2idle is: $pkg2"
pkg3=$(echo "$turbostat_after_s2idle" | sed -n '/Pkg\%pc3/{n;p}' |
awk '{print $5}')
log_output "CPU Package C-state 3 residency after S2idle is: $pkg3"
pkg8=$(echo "$turbostat_after_s2idle" | sed -n '/Pkg\%pc8/{n;p}' |
awk '{print $8}')
log_output "CPU Package C-state 8 residency after S2idle is: $pkg8"
pkg9=$(echo "$turbostat_after_s2idle" | sed -n '/Pkg\%pc9/{n;p}' |
awk '{print $9}')
log_output "CPU Package C-state 9 residency after S2idle is: $pkg9"
pkg10=$(echo "$turbostat_after_s2idle" | sed -n '/Pk\%pc10/{n;p}' |
awk '{print $10}')
log_output "CPU Package C-state 10 residency after S2idle is: $pkg10"
slp_s0=$(echo "$turbostat_after_s2idle" | sed -n '/SYS\%LPI/{n;p}' |
awk '{print $11}')
log_output "S0ix residency after S2idle is: $slp_s0"
else
pkg2=$(echo "$turbostat_after_s2idle" | sed -n '/Pkg\%pc2/{n;p}' |
awk '{print $5}')
log_output "CPU Package C-state 2 residency after S2idle is: $pkg2"
pkg3=$(echo "$turbostat_after_s2idle" | sed -n '/Pkg\%pc3/{n;p}' |
awk '{print $6}')
log_output "CPU Package C-state 3 residency after S2idle is: $pkg3"
pkg8=$(echo "$turbostat_after_s2idle" | sed -n '/Pkg\%pc8/{n;p}' |
awk '{print $9}')
log_output "CPU Package C-state 8 residency after S2idle is: $pkg8"
pkg9=$(echo "$turbostat_after_s2idle" | sed -n '/Pkg\%pc9/{n;p}' |
awk '{print $10}')
log_output "CPU Package C-state 9 residency after S2idle is: $pkg9"
pkg10=$(echo "$turbostat_after_s2idle" | sed -n '/Pk\%pc10/{n;p}' |
awk '{print $11}')
log_output "CPU Package C-state 10 residency after S2idle is: $pkg10"
slp_s0=$(echo "$turbostat_after_s2idle" | sed -n '/SYS\%LPI/{n;p}' |
awk '{print $12}')
log_output "S0ix residency after S2idle is: $slp_s0"
fi
s0ix_substate_af="$(cat $PMC_CORE_SYSFS_PATH/substate_residencies)" 2>&1
if [[ -z "$s0ix_substate_af" ]] &&
[[ "$(echo "scale=2; $slp_s0 > 0.00" | bc)" -eq 1 ]]; then
log_output "\n\033[32mCongratulations! Your system achieved S2idle S0ix \
residency: $slp_s0\033[0m\n"
exit 0
elif [[ -n "$s0ix_substate" ]] &&
[[ "$(echo "scale=2; $slp_s0 > 0.00" | bc)" -eq 1 ]] &&
[[ -z "$sub_enable_flag" ]]; then
OLD_IFS="$IFS"
IFS=$'\n'
sub_num="$(echo "$s0ix_substate_af" | wc -l)"
for ((j = 2; j <= sub_num; j++)); do
sub_af="$(sed -n "$j, 1p" "$PMC_CORE_SYSFS_PATH"/substate_residencies | awk '{print $1}')"
subarrayaf[j]=$sub_af
sub_af_res="$(sed -n "$j,1p" "$PMC_CORE_SYSFS_PATH"/substate_residencies | awk '{print $2}')"
resarrayaf[j]=$sub_af_res
done
IFS="$OLD_IFS"
#Print out the subarrayaf and resarrayaf
log_output "\nS0ix substate after S2idle:\n" "${subarrayaf[*]}"
log_output "\nS0ix substate residency after S2idle:\n" "${resarrayaf[*]}"
#Judge the substate residency delta
for ((k = 2; k <= sub_num; k++)); do
OLD_IFS="$IFS"
IFS=$'\n'
resdeltaarray[$k]=$((resarrayaf[k] - resarraybf[k]))
IFS="$OLD_IFS"
log_output "\nS0ix substates residency delta value:" \
"${subarrayaf[$k]}" "${resdeltaarray[$k]}"
done
#Scan resdeltaarray and judge which one has no-zero value
m=${#resdeltaarray[@]}
while [ $m -ge 2 ]; do
if [[ "${resdeltaarray[m]}" -gt "0" ]]; then
if [[ "$m" -eq "${#resdeltaarray[@]}" ]]; then
log_output "\n\033[32mCongratulations! Your system achieved the deepest \
S0ix substate!\033[0m \
\nHere is the S0ix substates status: \n$s0ix_substate_af\n"
exit 0
else
OLD_IFS="$IFS"
IFS=$'\n'
shallower=${subarrayaf[m]}
n=$((m + 1))
deeper=${subarrayaf[n]}
IFS="$OLD_IFS"
log_output "\n\033[31mYour system only get shallower S0ix substate \
residency:\033[0m" "\033[31m${subarrayaf[m]}\033[0m" "\033[31m${resarrayaf[m]}\033[0m"
log_output "\nNeed to debug why not deeper substate:" "$deeper"
if substate_triage "$shallower" "$deeper"; then
log_output "\n\033[31mPlease do the advanced debug based on above \
substate_status_registers info \nor report a bug with that attached.\033[0m\n"
log_output "\n---Debug PCIe root port device and link PM state---"
#Check PCI devices D states
pci_d3_status_check
#Check PCIe bridge link PM states
debug_pcie_bridge_lpm
judge_dstate_linkstate
else
log_output "\nPlease check the potential blockers\n"
fi
exit 0
fi
else
let m--
fi
done
exit 0
elif [[ -n "$s0ix_substate" ]] &&
[[ "$(echo "scale=2; $slp_s0 > 0.00" | bc)" -eq 1 ]] &&
[[ -n "$sub_enable_flag" ]]; then
OLD_IFS="$IFS"
IFS=$'\n'
sub_num="$(echo "$s0ix_substate_af" | grep -c "Enabled")"
for ((j = 1; j <= sub_num; j++)); do
sub_af_enable="$(grep "Enabled" $PMC_CORE_SYSFS_PATH/substate_residencies)"
sub_af="$(echo "$sub_af_enable" | sed -n "$j,1p" | awk '{print $2}')" subarrayaf[j]=$sub_af
sub_af_res="$(echo "$sub_af_enable" | sed -n "$j,1p" | awk '{print $3}')" resarrayaf[j]=$sub_af_res
done
IFS="$OLD_IFS"
#Print out subarrayaf and resarrayaf
log_output "\nS0ix substate after S2idle:\n" "${subarrayaf[*]}"
log_output "\nS0ix substate residency after S2idle:\n" "${resarrayaf[*]}"
#Judge the substate residency delta
for ((k = 1; k <= sub_num; k++)); do
OLD_IFS="$IFS"
IFS=$'\n'
resdeltaarray[$k]=$((resarrayaf[k] - resarraybf[k]))
IFS="$OLD_IFS"
log_output "\nS0ix substates residency delta value:" \
"${subarrayaf[$k]}" "${resdeltaarray[$k]}"
done
#Scan resdeltaarray and judge which one has no-zero value
m=${#resdeltaarray[@]}
while [ $m -ge 1 ]; do
if [[ "${resdeltaarray[m]}" -gt "0" ]]; then
if [[ "$m" -eq "${#resdeltaarray[@]}" ]]; then
log_output "\n\033[32mCongratulations! Your system achieved the \
deepest S0ix substate! \033[0m \
\nHere is the S0ix substates status: \n$s0ix_substate_af\n"
exit 0
else
OLD_IFS="$IFS"
IFS=$'\n'
shallower=${subarrayaf[m]}
n=$((m + 1))
deeper=${subarrayaf[n]}
IFS="$OLD_IFS"
log_output "\n\033[31mYour system only get shallower S0ix substate \
residency:\033[0m" "${subarrayaf[m]}" "${resarrayaf[m]}"
log_output "\nNeed to debug why not deeper substate:" "$deeper"
if [[ -z "$sub" ]]; then
sta=$(cat $PMC_CORE_SYSFS_PATH/substate_status_registers)
log_output "\nPlease check substate_status_registers file for the \
advanced debug:\n"
log_output "substate_status_registers:"
log_output "$sta\n"
fi
exit 0
fi
else
let m--
fi
done
exit 0
#Judge only PC10 residency is available when S0ix substate is supported
elif [[ -n "$s0ix_substate" ]] &&
[[ "$(echo "scale=2; $pkg10 > 0.00" | bc)" -eq 1 ]]; then
log_output "\n\033[31mYour system supports S0ix substates, but did not \
achieve the shallowest s0i2.0\033[0m
\nHere is the S0ix substates status: \n$s0ix_substate_af\n"
#Debug scenario 5: No any S0ix substate residency, only PC10 residency
DEBUG=5
elif [[ "$(echo "scale=2; $pkg10 > 0.00" | bc)" -eq 1 ]]; then
log_output "\nNeed to debug which IP blocked S0ix since PC10 is observed."
#Debug scenario 4: No S0ix residency, but has PC10 residency
DEBUG=4
elif [[ "$(echo "scale=2; $pkg9 > 0.00" | bc)" -eq 1 ]]; then
log_output "\nYour system achieved PC9 residency: $pkg9, \
but no PC10 residency:$pkg10,no S0ix residency: $slp_s0"
#Debug scenario 4: No PC10 residency, but has PC9 residency
DEBUG=4
elif [[ "$(echo "scale=2; $pkg8 > 0.00" | bc)" -eq 1 ]]; then
log_output "\nYour system achieved PC8 residency: $pkg8, \
but no PC10 residency:$pkg10,no S0ix residency: $slp_s0"
#Debug scenario 3: No PC10 residency, but has PC8 residency
DEBUG=3
elif [[ "$(echo "scale=2; $pkg3 > 0.00" | bc)" -eq 1 ]]; then
log_output "\nYour system achieved PC3 residency: $pkg3, \
but no PC8 residency during S2idle: $pkg8"
#Debug scenario 2: No PC8 residency, but has PC3 residency
DEBUG=2
elif [[ "$(echo "scale=2; $pkg2 > 0.00" | bc)" -eq 1 ]]; then
log_output "\nYour system achieved PC2 residency: $pkg2, \
but no PC8 residency during S2idle: $pkg8"
#Debug scenario 2: No PC8 residency, but has PC2 residency
DEBUG=2
else
#Debug scenario 0: No PC2 residency
log_output "\nYour system did not achieve PC2 state or PC2 residency is low: \
\n$pkg2"
DEBUG=1
fi
return 0
}
debug_no_pc2() {
local cc6=""
local rc6=""
local turbostat_after_s2idle=""
local duration=15
local pc2_para="CPU%c1,CPU%c6,CPU%c7,GFX%rc6,Pkg%pc2"
#Run powertop --auto-tune to double check PC2 status
if ! type powertop 1>/dev/null 2>&1; then
log_output "\033[31mPlease install powertop tool.\033[0m\n"
else
powertop --auto-tune 2>&1
fi
echo 0 >/sys/class/rtc/rtc0/wakealarm
echo +$duration >/sys/class/rtc/rtc0/wakealarm
if turbostat_after_s2idle=$("$DIR"/turbostat --quiet --show "$pc2_para" \
echo freeze 2>&1 >/sys/power/state); then
log_output "Turbostat output: \n$turbostat_after_s2idle"
sleep 5
else
log_output "\nThe system failed to place S2idle entry command, please re-try.\n"
exit 0
fi
cc6=$(echo "$turbostat_after_s2idle" | sed -n '/CPU\%c6/{n;p}' |
awk '{print $3}')
rc6=$(echo "$turbostat_after_s2idle" | sed -n '/GFX\%rc6/{n;p}' |
awk '{print $4}')
log_output "\nCPU Core c6:$cc6"
log_output "GFX rc6:$rc6"
#Check whether CPU Core C6 residency is available
if [[ "$(echo "scale=2; $cc6 > 0.00" | bc)" -eq 1 ]]; then
log_output "\nYour CPU Core C6 residency is available: $cc6"
else
log_output "\nYour CPU Core C6 residency is not available, \
need to check which CPU idle driver is in use:"
cat /sys/devices/system/cpu/cpuidle/current_driver
log_output "\nCheck what's the CPU idle driver status:"
grep . /sys/devices/system/cpu/cpu*/cpuidle/state*/* 2>&1
return 1
fi
#Check whether Intel graphics rc6 residency is available
if [[ "$(echo "scale=2; $rc6 > 0.00" | bc)" -eq 1 ]]; then
log_output "\nYour system Intel graphics RC6 residency is available, \
\nplease double confirm whether the latest Linux Kernel and the latest
BIOS are in use, \
\nsome hidden kernel or FW issues are beyond this script ability to isolate"
else
log_output "\nYour system did not get the GFX RC6 residency, it's a GFX problem, \
\nplease check any serious Intel i915 driver failure from dmesg log, if yes please
\nreport a bug, or the system is installed a third party of graphics device."
log_output "Check any Intel graphics i915 failure from dmesg log:"
dmesg | grep -i i915 | grep -iE "error|fail|BUG|HANG|WARNING" 2>&1
return 1
fi
return 0
}
#Function to check PCIe bridge Link Power Management state
debug_pcie_bridge_lpm() {
PCI_SYSFS="/sys/devices/pci0000:00"
PCI_BRIDGE_CLASS="0x060400"
devices=$(ls ${PCI_SYSFS})
bridge_devices=()
local link_substate_cap=""
local link_substate_ctl=""
local pci_tree=$(lspci -tvv)
# Get list of pci bridge devices
for dev in $devices; do
if [ -d "${PCI_SYSFS}"/"${dev}" ] &&
[ -f "${PCI_SYSFS}"/"${dev}"/config ]; then
class=$(cat "${PCI_SYSFS}"/"${dev}"/class)
if [[ "${class}" == "${PCI_BRIDGE_CLASS}" ]]; then
bridge_devices+=("${dev}")
fi
fi
done
link_state() {
local pciests1=$1
local byte1="$((16#${pciests1} >> 8))"
local ltsmstate="$((16#${pciests1} & 255))"
local l1msg="Link is in L1"
local policy=""
# Some bit manipulation to get Link Status
lnkstat=$(((byte1 >> 3) & 15))
case "${lnkstat}" in
0)
case "${ltsmstate}" in
[0-9] | 1[0-6])
l1msg="Link is in Detect"
;;
4[2-9])
l1msg="Link is in L2, LTSMSTATE=0"
;;
59 | 60 | 61)
l1msg="Link is Disabled"
;;
*)
l1msg="Link is not in Low Power State, LTSMSTATE=${ltsmstate}"
;;
esac
echo "${l1msg}"
;;
1)
echo "Link is Retraining"
;;
3)
case "${ltsmstate}" in
5[5-9] | 60)
l1msg="Link is in L1"
;;
61 | 62)
l1msg="Link is in L1.1"
;;
63 | 64)
l1msg="Link is in L1.2"
;;
*)
l1msg="Link is other L1 state, LTSMSTATE=${ltsmstate}"
;;
esac
echo "${l1msg}"
;;
4)
echo "Link is in L2"
;;
5)
echo "Link is in L3"
;;
[7-9] | 10)
echo "Link is in L0"
;;
*)
echo "Unknown link state ${lnkstat}"
;;
esac
}
#Let system sleep 20 seconds below, in case did not get correct PCIe bridge \
#Link state at beginning
sleep 20
#log_output "\nThe PCIe bridge link power management state is:"
echo "Available bridge device:" "${bridge_devices[@]}"
for dev in "${bridge_devices[@]}"; do
#Get lower 16 bits of PCIESTS1 register
pciests1=$(sudo xxd -ps -l2 -s 0x32a "${PCI_SYSFS}"/"${dev}"/config)
if [[ "$(link_state "${pciests1}")" == "Link is in L1.1" ]] ||
[[ "$(link_state "${pciests1}")" == "Link is in L1.2" ]] ||
[[ "$(link_state "${pciests1}")" == "Link is in Detect" ]] ||
[[ "$(link_state "${pciests1}")" == "Link is in Disabled" ]] ||
[[ "$(link_state "${pciests1}")" == "Link is in L2" ]] ||
[[ "$(link_state "${pciests1}")" == "Link is in L2, LTSMSTATE=0" ]] ||
[[ "$(link_state "${pciests1}")" == "Link is in L3" ]]; then
log_output "\n$dev $(link_state "${pciests1}")"
log_output "\nThe link power management state of PCIe bridge: $dev is OK."
else
PCIEPORT_L0="$dev"
log_output "\nThe PCIe bridge link power management state is:"
log_output "\033[31m$dev $(link_state "${pciests1}")\033[0m"
log_output "\nThe link power management state of PCIe bridge: \
\033[31m$dev\033[0m is not expected. \nwhich is expected to be L1.1 or L1.2, \
or user would run this script again.\n"
link_substate_cap=$(lspci -vvv -s"$dev" | grep L1SubCap)
link_substate_ctl=$(lspci -vvv -s"$dev" | grep L1SubCtl1)
log_output "\nThe L1SubCap of the failed $dev is:"
log_output "$link_substate_cap"
log_output "\nThe L1SubCtl1 of the failed $dev is:"
log_output "$link_substate_ctl\n"
log_output "\nChecking PCI Devices tree diagram:\n$pci_tree\n"
return 1
fi
done
#Check PCIE_ASPM default setting
policy=$(grep "\[.*\]" -o /sys/module/pcie_aspm/parameters/policy 2>&1)
if [[ "$policy" == "[default]" ]] ||
[[ "$policy" == "[powersupersave]" ]]; then
log_output "\nYour system default pcie_aspm policy setting is OK.\n"
else
log_output "\nYour system default PCIe_aspm policy setting is not proper, \
\nsuggest to set /sys/module/pcie_aspm/parameters/policy to default or \
powersupersave.\n"
return 1
fi
return 0
}
debug_no_pc8() {
local cc7=""
local rc6=""
local turbostat_after_s2idle=""
local duration=15
#Run powertop --auto-tune to make sure the devices runtime PM are enabled
if ! type powertop 1>/dev/null 2>&1; then
log_output "\033[31mPlease install powertop tool.\033[0m\n"
else
powertop --auto-tune 2>&1
fi
echo 0 >/sys/class/rtc/rtc0/wakealarm
echo +$duration >/sys/class/rtc/rtc0/wakealarm
if turbostat_after_s2idle=$("$DIR"/turbostat --quiet --show "$TURBO_COLUMNS" \
echo freeze 2>&1 >/sys/power/state); then
log_output "\nTurbostat output: \n\n$turbostat_after_s2idle"
sleep 5
else
log_output "\nThe system failed to place S2idle entry command, please re-try.\n"
exit 0
fi
cc7=$(echo "$turbostat_after_s2idle" | sed -n '/CPU\%c7/{n;p}' |
awk '{print $3}')
rc6=$(echo "$turbostat_after_s2idle" | sed -n '/GFX\%rc6/{n;p}' |
awk '{print $4}')
pkg8=$(echo "$turbostat_after_s2idle" | sed -n '/Pkg\%pc8/{n;p}' |
awk '{print $9}')
pkg10=$(echo "$turbostat_after_s2idle" | sed -n '/Pk\%pc10/{n;p}' |
awk '{print $11}')
slp_s0=$(echo "$turbostat_after_s2idle" | sed -n '/SYS\%LPI/{n;p}' |
awk '{print $12}')
#Check whether PC8,PC10 and S0ix is available after running powertop
if [[ "$(echo "scale=2; $slp_s0 > 0.00" | bc)" -eq 1 ]]; then
log_output "\nS0ix residency is achieved after powertop --auto-tune"
return 0
elif [[ "$(echo "scale=2; $pkg10 > 0.00" | bc)" -eq 1 ]]; then
log_output "\nPC10 residency achieved after powertop --auto-tune, \
but still no S0ix residency"
return 0
elif [[ "$(echo "scale=2; $pkg8 > 0.00" | bc)" -eq 1 ]]; then
log_output "\nPC8 residency achieved after powertop --auto-tune, \
but still no PC10 and S0ix"
return 0
fi
#Check whether CPU Core C7 residency is available
if [[ "$(echo "scale=2; $cc7 > 0.00" | bc)" -eq 1 ]]; then
log_output "\nYour CPU Core C7 residency is available: $cc7"
else
log_output "\nYour CPU Core C7 residency is not available, need to check \
which CPU idle driver is in use:"
cat /sys/devices/system/cpu/cpuidle/current_driver
log_output "\n\nCheck what's the CPU idle driver status:"
grep . /sys/devices/system/cpu/cpu*/cpuidle/state*/* 2>&1
return 1
fi
#Check whether Intel graphics RC6 residency is available and high enough for pc8
if [[ -z "$rc6" ]]; then
log_output "\n\033[31mPlease check if Intel graphic i915 driver is not loaded \
\nor Intel graphics controller has been disabled \
\nor the 3rd party graphics device is installed.\033[0m\n"
elif [[ "$(echo "scale=2; $rc6 > 50.00" | bc)" -eq 1 ]]; then
log_output "\nYour system Intel graphics RC6 residency is available:$rc6"
else
log_output "\nYour system graphics RC6 residency is low, need to double check \
the status after disabling gfx controller from BIOS setup \
\nor appending modprobe.blacklist=i915 kernel parameter to check any \
deeper Package C-state available,\nthen submit an i915 bug to Intel graphics team.\n"
return 1
fi
#Check whether PCIe Link PM is in L1 or L2, as L0 may block PC3
if [[ "$(echo "scale=2; $pkg8 < 1.00" | bc)" -eq 1 ]]; then
log_output "\nChecking PCIe Device D state and Bridge Link state:\n"
debug_pcie_bridge_lpm
pci_d3_status_check
fi
}
debug_no_dc9() {
local kbl_l=142
local kbl=158
local cml=165
local cml_l=166
local dc5_before=""
local dc5_after=""
local dc6_before=""
local dc6_after=""
local rc6_model_list=""
local model=""
local i=""
local turbostat_after_s2idle=""
local duration=15
local dmc_dir="/sys/kernel/debug/dri/0/i915_dmc_info"
if [ ! -f "$dmc_dir" ]; then
log_output "\nPlease check if the Intel graphics i915 driver is not loaded \
or the graphic controller has been disabled?"
return 0
fi
dc5_before=$(grep -i "DC3 -> DC5" $dmc_dir | awk '{print $(NF)}' 2>&1)
dc6_before=$(grep -i "DC5 -> DC6" $dmc_dir | awk '{print $(NF)}' 2>&1)
log_output "\nGFX DC5 before S2idle: $dc5_before"
log_output "GFX DC6 before S2idle: $dc6_before"
echo 0 >/sys/class/rtc/rtc0/wakealarm
echo +$duration >/sys/class/rtc/rtc0/wakealarm
if turbostat_after_s2idle=$("$DIR"/turbostat --quiet --show "$TURBO_COLUMNS" \
echo freeze 2>&1 >/sys/power/state); then
log_output "\nTurbostat output: \n\n$turbostat_after_s2idle"
sleep 5
else
log_output "\nThe system failed to place S2idle entry command, please re-try\n"
exit 0
fi
dc5_after=$(grep -i "DC3 -> DC5" $dmc_dir | awk '{print $(NF)}' 2>&1)
dc6_after=$(grep -i "DC5 -> DC6" $dmc_dir | awk '{print $(NF)}' 2>&1)
log_output "\nGFX DC5 after S2idle: $dc5_after"
log_output "GFX DC6 after S2idle: $dc6_after"
#Check DC6 state for Intel® Coffee lake, Whiskey lake, Comet lake platforms