├── .gitignore ├── turbostat ├── shell.nix ├── SECURITY.md ├── README.md ├── LICENSE └── s0ix-selftest-tool.sh /.gitignore: -------------------------------------------------------------------------------- 1 | *.dsl 2 | *.dat 3 | *.log 4 | -------------------------------------------------------------------------------- /turbostat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intel/S0ixSelftestTool/HEAD/turbostat -------------------------------------------------------------------------------- /shell.nix: -------------------------------------------------------------------------------- 1 | { pkgs ? import {} }: 2 | pkgs.mkShell { 3 | nativeBuildInputs = [ 4 | pkgs.acpica-tools 5 | pkgs.linuxPackages.turbostat 6 | pkgs.xxd 7 | pkgs.powertop 8 | pkgs.gawk 9 | pkgs.bc 10 | ]; 11 | } 12 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | Intel is committed to rapidly addressing security vulnerabilities affecting our customers and providing clear guidance on the solution, impact, severity and mitigation. 3 | 4 | ## Reporting a Vulnerability 5 | Please report any security vulnerabilities in this project utilizing the guidelines [here](https://www.intel.com/content/www/us/en/security-center/vulnerability-handling-guidelines.html). 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Release Notes for S0ix Selftest Tool 2 | 3 | Thanks for using S0ix Selftest Tool. This tool is designed for Linux OS, it can 4 | be used to do the initial debugging for the S2idle path CPU Package C-state and 5 | S0ix failures for Intel® Client platforms, it also supports the basic runtime PC10 6 | status check. 7 | 8 | When linux users' system fails to enter PC10 or S0ix via S2idle, they can use this 9 | script to get the initial debugging infomation or potenial blockers before reporting 10 | the bugs in the Bugzilla. This script will archive the debugging process logs, 11 | which will be helpful for the future advanced debugging. 12 | 13 | This tool's design follows the basic debugging process introduced in the 14 | documents below: 15 | https://web.archive.org/web/20230614200816/https://01.org/blogs/qwang59/2018/how-achieve-s0ix-states-linux 16 | https://web.archive.org/web/20230614200306/https://01.org/blogs/qwang59/2020/linux-s0ix-troubleshooting 17 | 18 | How to use this tool? 19 | 20 | To check S2idle Path Package C-state or S0ix, using 21 | `./s0ix-selftest-tool.sh -s` 22 | Usually the users only need to wait for less than 3 minutes to get the debugging 23 | results or messages. 24 | 25 | To check runtime PC10 with screen on, using 26 | `./s0ix-selftest-tool.sh -r on` 27 | 28 | To check runtime PC10 with screen off, using 29 | `./s0ix-selftest-tool.sh -r off` 30 | 31 | Additional Notes: 32 | 1. The users need to run this tool as root account 33 | 34 | 2. If the users see "awk: line 10: function gensub never defined" message during 35 | running the script, please install gawk 36 | 37 | 3. If the users see "sudo: xxd: command not found" message during running the script, 38 | please try to install a vim-common package 39 | 40 | 4. There are two binaries that will be used in this tool: turbostat and powertop 41 | 42 | 5. The acpidump tool(can be accessed by installing acpica-tools) is needed for using this tool 43 | 44 | 6. Before using this tool please disable secure boot option from BIOS setup, 45 | which may cause Operation permission issues 46 | 47 | 7. If the users' system fails to enter S2idle, then this tool will not help. All 48 | the s0ix debugging is based on S2idle entry and exit working normally, if there is 49 | any driver or fw issue that blocks the S2idle functionality itself, please fix that first. 50 | 51 | 8. If the users have a good idea to improve this script, you are very welcome to send 52 | us the patches, thanks! 53 | 54 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | , 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | -------------------------------------------------------------------------------- /s0ix-selftest-tool.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # SPDX-License-Identifier: GPL-2.0-only 4 | # This is a CPU Package C-state and S0ix failure selftest and debug script, it's 5 | # designed for Linux OS running on Intel® Architecture-based client platforms. 6 | # Aims to get the potential Package C-state or S0ix blocker clue in an easy way. 7 | # Helps Linux users save the basic isolation effort to focus on the advanced debug 8 | # or report a bug with the initial debug log attached. 9 | 10 | # Copyright (c) 2021 Intel Corporation. 11 | # Author: wendy.wang@intel.com 12 | # Contributor: david.e.box@intel.com 13 | 14 | PATH=$PATH:$HOME 15 | DATE=$(date '+%Y%m%d-%H-%M') 16 | DIR="$(pwd -P)" 17 | TURBO_COLUMNS="CPU%c1,CPU%c6,CPU%c7,Pkg%pc2,Pkg%pc3,Pkg%pc6,Pkg%pc8,Pk%pc10,SYS%LPI" 18 | DEEP="S0i2.0" 19 | SHALLOW="c10" 20 | PMC_CORE_SYSFS_PATH="/sys/kernel/debug/pmc_core" 21 | PCIEPORT_D0="" 22 | PCIEPORT_D3HOT="" 23 | PCIEPORT_L0="" 24 | ASPM_ENABLE="" 25 | KERNEL_VER="$(uname -a)" 26 | #Define which debug stage should go 27 | DEBUG="" 28 | touch "$PWD"/"$DATE"-s0ix-output.log 29 | 30 | #Function to archive S0ix debug output 31 | log_output() { 32 | echo -e "${*}" | tee -a "$PWD"/"$DATE"-s0ix-output.log 33 | } 34 | 35 | # Function to return the index of a column name in turbo columns 36 | get_column_index(){ 37 | local columns="$1" 38 | local target="$2" 39 | IFS=',' read -ra column_array <<< "$columns" 40 | 41 | for i in "${!column_array[@]}"; do 42 | if [[ "${column_array[i]}" == "$target" ]]; then 43 | echo $((i + 1)) # Return 1-based index 44 | return 45 | fi 46 | done 47 | 48 | # Return -1 if the column name is not found 49 | echo "-1" 50 | } 51 | 52 | #Define script must be run as root account 53 | if [[ $EUID -ne 0 ]]; then 54 | log_output "\nThis script must be run as root.\n" >&2 55 | exit 0 56 | fi 57 | 58 | usage() { 59 | cat </dev/null 2>&1 || { 97 | log_output "The acpidump tool is needed to check whether low idle S0 \ 98 | \ncapability is enabled on the test platform, please install acpica-tools \ 99 | \nor check if the acpidump command execution failed.\n" 100 | exit 0 101 | } 102 | acpidump -b 2>&1 103 | iasl -d ./facp.dat 1>/dev/null 2>&1 104 | sleep 2 105 | lp=$(grep "Low Power S0 Idle" facp.dsl 2>&1 | awk '{print $(NF)}') 106 | 107 | if [[ "$lp" -eq 1 ]]; then 108 | log_output "\nLow Power S0 Idle is:$lp" 109 | log_output "Your system supports low power S0 idle capability." 110 | return 0 111 | else 112 | log_output "\nLow Power S0 Idle is:$lp" 113 | log_output "Your system does not support low power S0 idle capability. \ 114 | \nIsolation suggestion: \ 115 | \nPlease check BIOS low power S0 idle capability setting.\n" 116 | return 1 117 | fi 118 | } 119 | 120 | #Judge whether intel_pmc_core sysfs debug files available 121 | pmc_core_check() { 122 | if [[ "$(ls -A $PMC_CORE_SYSFS_PATH)" ]]; then 123 | log_output "\nThe pmc_core debug sysfs files are OK on your system." 124 | return 0 125 | else 126 | log_output "\nThe pmc_core debug sysfs file is empty on your system." 127 | log_output "Isolation suggestions: \ 128 | \nPlease check whether intel_pmc_core driver is loaded.\n" 129 | return 1 130 | fi 131 | } 132 | 133 | pci_d3_status_check() { 134 | local duration=10 135 | local d3_log="" 136 | local pcieport_ds="" 137 | local pci_tree="" 138 | pci_tree=$(lspci -tvv) 139 | #Prepare for the PCI Device D3 states check 140 | echo -n "file pci-driver.c +p" >/sys/kernel/debug/dynamic_debug/control 141 | echo N >/sys/module/printk/parameters/console_suspend 142 | echo 1 >/sys/power/pm_debug_messages 143 | dmesg -C 144 | 145 | echo 0 >/sys/class/rtc/rtc0/wakealarm 146 | echo +$duration >/sys/class/rtc/rtc0/wakealarm 147 | 148 | "$DIR"/turbostat --quiet -o tc.out echo freeze 2>&1 >/sys/power/state 149 | sleep 2 150 | d3_log=$(dmesg | grep "PCI PM" 2>&1) 151 | 152 | if [[ -n "$d3_log" ]]; then 153 | log_output "\nChecking PCI Devices D3 States:\n$d3_log\n" 154 | log_output "\nChecking PCI Devices tree diagram:\n$pci_tree\n" 155 | fi 156 | #Filter out the pcieport devices D states 157 | pcieport_ds=$(echo "$d3_log" | grep -o "pcieport.*") 158 | if [[ -n "$pcieport_ds" ]]; then 159 | PCIEPORT_D0=$(echo "$pcieport_ds" | grep D0 | 160 | awk -F " " '{print $2}' | sed 's/:$//') 161 | PCIEPORT_D3HOT=$(echo "$pcieport_ds" | grep D3hot | 162 | awk -F " " '{print $2}' | sed 's/:$//') 163 | #Check the ASPM enable status for the D0 state pcieroot port 164 | if [[ -n "$PCIEPORT_D0" ]]; then 165 | for PCIEPORT in $PCIEPORT_D0; do 166 | ASPM_ENABLE=$(lspci -vvv -s"$PCIEPORT" | grep "LnkCtl:" | grep Enabled) 167 | log_output "The pcieport $PCIEPORT ASPM enable status:\n$ASPM_ENABLE\n" 168 | 169 | log_output "Pcieport is not in D3cold:\ 170 | \n\033[31m$PCIEPORT\033[0m\n" 171 | done 172 | fi 173 | [[ -n "$PCIEPORT_D3HOT" ]] && log_output "Pcieport is not in D3cold: \ 174 | \n\033[31m$PCIEPORT_D3HOT\033[0m\n" 175 | return 1 176 | fi 177 | return 0 178 | } 179 | 180 | #Function to automatically triage the potential deeper S0ix substate blockers 181 | #through Intel_PMC_Core files: lpm_latch_mode and substate_requirements 182 | #$1 is the archivable PC10 or shallower S0ix substate 183 | #$2 is the deeper desired but not achieved S0ix substate 184 | substate_triage() { 185 | local col="" 186 | local duration=15 187 | local sub="" 188 | local sta="" 189 | local req="" 190 | 191 | log_output "\n---Begin S0ix Substate Debug by substate_requirements---:\n" 192 | #Before testing, need to clean the lpm_latch_mode setting 193 | echo clear >"$PMC_CORE_SYSFS_PATH"/lpm_latch_mode 2>&1 194 | log_output "Clear lpm_latch_mode is Done\n" 195 | #Put $1 achieved PC10 or S0ix substate into lpm_latch_mode file 196 | echo "$1" >"$PMC_CORE_SYSFS_PATH"/lpm_latch_mode 2>&1 197 | log_output "Set $1 to lpm_latch_mode is Done\n" 198 | 199 | log_output "Need to run once S2idle, please wait for 15 seconds...\n" 200 | echo 0 >/sys/class/rtc/rtc0/wakealarm 201 | echo +$duration >/sys/class/rtc/rtc0/wakealarm 202 | 203 | "$DIR"/turbostat --quiet --show "$TURBO_COLUMNS" -o tc.out \ 204 | echo freeze 2>&1 >/sys/power/state 205 | sleep 2 206 | #Filter out the desired deeper S0ix substate column:col 207 | eval "$(cat "$PMC_CORE_SYSFS_PATH"/substate_requirements | awk -F "|" '{ 208 | for(i=1;i&1 216 | 217 | log_output "\nsubstate_requirements file shows:\n" 218 | req="$(cat "$PMC_CORE_SYSFS_PATH"/substate_requirements | awk -F "|" \ 219 | '!/Int_Timer/ && !/LSX_Wake/ && !/VNN_REQ_STS/{print $1,$"'"${col}"'",$(NF-1)}')" 2>&1 220 | log_output "$req" 221 | 222 | #Filter out the IPs which are required but not show YES 223 | sub="$(cat "$PMC_CORE_SYSFS_PATH"/substate_requirements | awk -F "|" \ 224 | '!/Int_Timer/ && !/LSX_Wake/ && !/VNN_REQ_STS/{print $1,$"'"${col}"'",$(NF-1)}' | 225 | grep Required | awk '!/Yes/{print $0}')" 2>&1 226 | if [[ -z "$sub" ]]; then 227 | sta=$(cat "$PMC_CORE_SYSFS_PATH"/substate_status_registers) 228 | log_output "\nDid not detect the potential blockers from substate_requirements, \ 229 | \nneed to check substate_status_registers file for the advanced debug.\n" 230 | log_output "substate_status_registers:" 231 | log_output "$sta" 232 | return 0 233 | else 234 | log_output "\nBelow are the deeper S0ix substate required IPs did not show YES:\n" 235 | log_output "\033[31m $sub \033[0m \n" 236 | return 1 237 | fi 238 | } 239 | 240 | #Function to check whether Intel graphics DMC FW load status on the test platform 241 | dmc_check() { 242 | local dmc_load="" 243 | local dmc_log="" 244 | 245 | dmc_load=$(grep "fw loaded" /sys/kernel/debug/dri/0/i915_dmc_info | head -n 1 | 246 | awk '{print $3}') 247 | dmc_log=$(dmesg | grep -i DMC 2>&1) 248 | 249 | if [[ -n "$dmc_load" ]] && [[ $dmc_load == yes ]]; then 250 | log_output "\nYour system Intel graphics DMC FW loaded status is:$dmc_load\n" 251 | else 252 | log_output "\nDid not get i915 dmc info from sysfs.\n" 253 | if [[ -n "$dmc_log" ]]; then 254 | log_output "$dmc_log\n" 255 | return 0 256 | else 257 | log_output "\n\033[31mYour system loaded Intel i915 DMC FW is not the latest \ 258 | version, \nor you did not install the DMC FW correctly: \n$dmc_log, 259 | \nplease refer to \ 260 | https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git/tree/i915 \ 261 | \nto get the latest display DMC FW. \ 262 | \nor re-install the Firmware package or manually check DMC FW file from /lib/firmware/i915. 263 | \nIf you are running with CentOS, try the command: \ 264 | #dracut -i /lib/firmware/i915 /lib/firmware/i915 --force and reboot.\n\033[0m" 265 | return 1 266 | fi 267 | fi 268 | } 269 | 270 | #Function to check runtime PC10 state when screen on 271 | pc10_idle_on() { 272 | local runtime_pkg8="" 273 | local runtime_pkg10="" 274 | local turbostat_runtime="" 275 | local dmc_dir="/sys/kernel/debug/dri/0/i915_dmc_info" 276 | local pc10_para=$(echo "$TURBO_COLUMNS" | sed 's/,[^,]*$//') 277 | local dc5_before="" 278 | local dc5_after="" 279 | local dc6_before="" 280 | local dc6_after="" 281 | 282 | dc5_before=$(grep -i "DC3 -> DC5" $dmc_dir | awk '{print $NF}' 2>&1) 283 | dc6_before=$(grep -i "DC5 -> DC6" $dmc_dir | awk '{print $NF}' 2>&1) 284 | log_output "\nThe system will keep idle for 40 seconds then check runtime PC10 state:\n" 285 | sleep 40 286 | dc5_after=$(grep -i "DC3 -> DC5" $dmc_dir | awk '{print $NF}' 2>&1) 287 | dc6_after=$(grep -i "DC5 -> DC6" $dmc_dir | awk '{print $NF}' 2>&1) 288 | dmc_info=$(cat /sys/kernel/debug/dri/0/i915_dmc_info) 289 | dc5_count_delta=$(echo "$dc5_after-$dc5_before" | bc) 290 | dc6_count_delta=$(echo "$dc6_after-$dc6_before" | bc) 291 | turbostat_runtime=$("$DIR"/turbostat --quiet --show "$pc10_para" sleep 30 2>&1) 292 | runtime_pkg8=$(echo "$turbostat_runtime" | sed -n '3p' | 293 | awk -v idx=$(get_column_index "$pc10_para" "Pkg%pc8") '{print $idx}') 294 | runtime_pkg10=$(echo "$turbostat_runtime" | sed -n '3p' | 295 | awk -v idx=$(get_column_index "$pc10_para" "Pk%pc10") '{print $idx}') 296 | log_output "\nThe CPU runtime PC10 residency when screen ON: $runtime_pkg10%" 297 | log_output "The CPU runtime PC8 residency when screen ON: $runtime_pkg8%\n" 298 | log_output "\nTurbostat log: \n$turbostat_runtime\n" 299 | 300 | #Judge whether turbostat tool supports the test platform 301 | if [ -z "$runtime_pkg10" ]; then 302 | log_output "\nYour system installed turbostat tool does not support this \ 303 | test platform. \ 304 | \nplease try to get the latest version turbostat tool.\n" 305 | exit 0 306 | fi 307 | 308 | if [[ -n "$runtime_pkg10" ]] && [[ "$(echo "scale=2; $runtime_pkg10 > 90.00" | 309 | bc)" -eq 1 ]]; then 310 | log_output "\n\033[32mYour system achieved high runtime PC10 residency during screen ON: \ 311 | $runtime_pkg10%\033[0m\n" 312 | return 0 313 | 314 | elif 315 | [[ -n "$runtime_pkg10" ]] && 316 | [[ "$(echo "scale=2; $runtime_pkg10 > 50.00" | bc)" -eq 1 ]] && 317 | [[ "$(echo "scale=2; $runtime_pkg10 < 90.00" | bc)" -eq 1 ]] 318 | then 319 | log_output "\nYour system achieved runtime PC10 during screen ON, \ 320 | \nbut the residency is not high enough: $runtime_pkg10%\n" 321 | return 0 322 | 323 | elif 324 | [[ -n "$runtime_pkg10" ]] && 325 | [[ "$(echo "scale=2; $runtime_pkg10 > 0.00" | bc)" -eq 1 ]] && 326 | [[ "$(echo "scale=2; $runtime_pkg10 < 50.00" | bc)" -eq 1 ]] 327 | then 328 | log_output "\n\033[31mYour system achieved the runtime PC10 during screen ON, \ 329 | \nbut the residency is too low and need to do the further debugging: \ 330 | $runtime_pkg10%\033[0m 331 | \n\nPotential Isolation Check: \ 332 | \nDisplay DC5 count delta is $dc5_count_delta in 40 seconds idle, \ 333 | \nwhich stands for display behavior. \ 334 | \nDisplay DC6 count delta is $dc6_count_delta in 40 seconds idle, \ 335 | \nwhich includes other peripheral besides display.\ 336 | \n/sys/kernel/debug/dri/0/i915_dmc_info shows:\n" 337 | log_output "$dmc_info" 338 | return 0 339 | 340 | elif 341 | [[ -n "$runtime_pkg8" ]] && 342 | [[ "$(echo "scale=2; $runtime_pkg8 > 1.00" | bc)" -eq 1 ]] 343 | then 344 | log_output "\n\033[32mYour system did not achieve the runtime PC10 during screen ON, \ 345 | \nbut the runtime PC8 residency is available:$runtime_pkg8%\033[0m\n" 346 | return 0 347 | fi 348 | 349 | log_output "\n\033[31mYour system did not achieve the runtime PC10 state \ 350 | during screen ON\033[0m\n" 351 | return 1 352 | } 353 | 354 | #Function to check runtime PC10 residency when screen OFF 355 | pc10_idle_off() { 356 | local pc10_para=$(echo "$TURBO_COLUMNS" | sed 's/,[^,]*$//') 357 | log_output "\nThis script will turn off display using xset command, \ 358 | \nplease startx first, then run this script in xterminal.\n" 359 | #Turn off display using xset command in GUI 360 | xset +dpms 2>&1 || { 361 | log_output "\033[31mPlease run this runtime PC10 check after startx\033[0m\n" 362 | exit 0 363 | } 364 | log_output "\nWill turn off the display in 30 seconds timeout, then the \ 365 | \nturbostat tool will read the PC10 counter after 40 seconds idle...\n" 366 | xset dpms 30 367 | 368 | local runtime_pkg8="" 369 | local runtime_pkg10="" 370 | local turbostat_runtime="" 371 | sleep 40 372 | turbostat_runtime=$("$DIR"/turbostat --quiet --show "$pc10_para" sleep 35 2>&1) 373 | runtime_pkg8=$(echo "$turbostat_runtime" | sed -n '3p' | 374 | awk -v idx=$(get_column_index "$pc10_para" "Pkg%pc8") '{print $idx}') 375 | runtime_pkg10=$(echo "$turbostat_runtime" | sed -n '3p' | 376 | awk -v idx=$(get_column_index "$pc10_para" "Pk%pc10") '{print $idx}') 377 | log_output "The CPU runtime PC10 state when screen OFF: $runtime_pkg10%" 378 | log_output "The CPU runtime PC8 residency when screen OFF: $runtime_pkg8%\n" 379 | log_output "\nTurbostat log: \n$turbostat_runtime\n" 380 | 381 | #Judge whether turbostat tool supports the test platform 382 | if [[ -z "$runtime_pkg10" ]]; then 383 | log_output "\nYour system installed turbostat tool does not support this 384 | test platform. \ 385 | \nplease try to get the latest version turbostat tool.\n" 386 | exit 0 387 | fi 388 | 389 | if [[ -n "$runtime_pkg10" ]] && 390 | [[ "$(echo "scale=2; $runtime_pkg10 > 90.00" | bc)" -eq 1 ]]; then 391 | log_output "\n\033[32mYour system achieved the high runtime PC10 residency during \ 392 | screen OFF: $runtime_pkg10%\033[0m\n" 393 | xset dpms force on && xset -dpms 394 | return 0 395 | 396 | elif 397 | [[ -n "$runtime_pkg10" ]] && 398 | [[ "$(echo "scale=2; $runtime_pkg10 > 50.00" | bc)" -eq 1 ]] && 399 | [[ "$(echo "scale=2; $runtime_pkg10 < 90.00" | bc)" -eq 1 ]] 400 | then 401 | log_output "\nYour system achieved the runtime PC10 during screen OFF, \ 402 | \nbut the residency is not high enough: $runtime_pkg10%\n" 403 | xset dpms force on && xset -dpms 404 | return 0 405 | 406 | elif 407 | [[ -n "$runtime_pkg10" ]] && 408 | [[ "$(echo "scale=2; $runtime_pkg10 > 0.00" | bc)" -eq 1 ]] && 409 | [[ "$(echo "scale=2; $runtime_pkg10 < 50.00" | bc)" -eq 1 ]] 410 | then 411 | log_output "\n\033[31mYour system achieved the runtime PC10 state during Screen OFF, \ 412 | \nbut the residency is too low and need to do the further debugging: \ 413 | $runtime_pkg10%\033[0m\n" 414 | xset dpms force on && xset -dpms 415 | return 0 416 | 417 | elif 418 | [[ -n "$runtime_pkg8" ]] && 419 | [[ "$(echo "scale=2; $runtime_pkg8 > 1.00" | bc)" -eq 1 ]] 420 | then 421 | log_output "\n\033[32mYour system did not achieve the runtime PC10 during screen OFF, \ 422 | \nbut the runtime PC8 residency is available:$runtime_pkg8%\033[0m\n" 423 | xset dpms force on && xset -dpms 424 | return 0 425 | fi 426 | 427 | log_output "\n\033[31mYour system did not achieve the runtime PC10 state \ 428 | with screen OFF\033[0m\n" 429 | xset dpms force on && xset -dpms 430 | return 1 431 | } 432 | 433 | #Function to check which package c-state or S0ix state is available during S2idle 434 | pkg_output() { 435 | local rc6="" 436 | local cc7="" 437 | local pkg2="" 438 | local pkg6="" 439 | local pkg8="" 440 | local pkg10="" 441 | local slp_s0="" 442 | local turbostat_after_s2idle="" 443 | local duration=15 444 | local sub_enable_flag="" 445 | local sub_bf_enable="" 446 | local sub_af_enable="" 447 | local sub_num="" 448 | local sub_bf="" 449 | local sub_bf_res="" 450 | local subarraybf="" 451 | local resarraybf="" 452 | local subarrayaf="" 453 | local resarrayaf="" 454 | local resdeltaarray="" 455 | local s0ix_substate="" 456 | local s0ix_substate_af="" 457 | local sub_af="" 458 | local sub_af_res="" 459 | local shallower="" 460 | local deeper="" 461 | 462 | s0ix_substate="$(cat $PMC_CORE_SYSFS_PATH/substate_residencies)" 2>&1 463 | sub_enable_flag="$(grep "Enabled" $PMC_CORE_SYSFS_PATH/substate_residencies)" 2>&1 464 | if [[ -n "$s0ix_substate" ]] && [[ -z "$sub_enable_flag" ]]; then 465 | sub_num="$(echo "$s0ix_substate" | wc -l)" 466 | for ((i = 2; i <= sub_num; i++)); do 467 | sub_bf="$(sed -n "$i, 1p" $PMC_CORE_SYSFS_PATH/substate_residencies | 468 | awk '{print $1}')" 469 | subarraybf[i]=$sub_bf 470 | sub_bf_res="$(sed -n "$i,1p" $PMC_CORE_SYSFS_PATH/substate_residencies | 471 | awk '{print $2}')" 472 | resarraybf[i]=$sub_bf_res 473 | done 474 | #Print out the subarray and resarray contents 475 | log_output "\nTest system supports S0ix.y substate" 476 | log_output "\nS0ix substate before S2idle:\n" "${subarraybf[*]}" 477 | log_output "\nS0ix substate residency before S2idle:\n" "${resarraybf[*]}" 478 | elif 479 | [[ -n "$s0ix_substate" ]] && [[ -n "$sub_enable_flag" ]] 480 | then 481 | sub_num="$(echo "$s0ix_substate" | grep -c "Enabled")" 482 | for ((i = 1; i <= sub_num; i++)); do 483 | sub_bf_enable="$(grep "Enabled" $PMC_CORE_SYSFS_PATH/substate_residencies)" 484 | sub_bf="$(echo "$sub_bf_enable" | sed -n "$i,1p" | awk '{print $2}')" 485 | subarraybf[i]=$sub_bf 486 | sub_bf_res="$(echo "$sub_bf_enable" | sed -n "$i,1p" | awk '{print $3}')" 487 | resarraybf[i]=$sub_bf_res 488 | done 489 | #Print out the subarray and resarray contents 490 | log_output "\nTest system supports S0ix.y substate" 491 | log_output "\nS0ix substate before S2idle:\n" "${subarraybf[*]}" 492 | log_output "\nS0ix substate residency before S2idle:\n" "${resarraybf[*]}" 493 | else 494 | log_output "Test system does not support S0ix.y substate" 495 | fi 496 | 497 | echo 0 >/sys/class/rtc/rtc0/wakealarm 498 | echo +$duration >/sys/class/rtc/rtc0/wakealarm 499 | 500 | if turbostat_after_s2idle=$("$DIR"/turbostat --quiet --show "$TURBO_COLUMNS" \ 501 | echo freeze 2>&1 >/sys/power/state); then 502 | log_output "\nTurbostat output: \n$turbostat_after_s2idle" 503 | #Let system sleep 5 seconds in case some systems cannot finish S0ix substate 504 | #and pkg cstate judgement before entering next S2idle cycle. 505 | sleep 5 506 | else 507 | log_output "\n\033[31mThe system failed to place S2idle entry command by turbostat, \ 508 | \nplease check if the suspend is failed or turbostat tool version is old \ 509 | \ne.g. did you make turbostat tool executable or separately run S2idle command: \ 510 | \nrtcwake -m freeze -s 15\033[0m\n" 511 | exit 0 512 | fi 513 | 514 | TURBO_RESULT_COLUMNS=$(echo "$turbostat_after_s2idle" | sed -n '2p' | sed 's/\t/,/g') 515 | cc7=$(echo "$turbostat_after_s2idle" | sed -n '3p' | 516 | awk -v idx=$(get_column_index "$TURBO_RESULT_COLUMNS" "CPU%c7") '{print $idx}') 517 | log_output "\nCPU Core C7 residency after S2idle is: $cc7" 518 | 519 | for i in 2 3 6 8; do 520 | column_idx=$(get_column_index "$TURBO_RESULT_COLUMNS" "Pkg%pc$i") 521 | if [ ${column_idx} -eq -1 ]; then 522 | log_output "\033[31mThe system does not support the Pkg%pc$i.\033[0m" 523 | else 524 | pkg=$(echo "$turbostat_after_s2idle" | sed -n '3p' | 525 | awk -v idx=$column_idx '{print $idx}') 526 | log_output "CPU Package C-state $i residency after S2idle is: $pkg" 527 | eval "pkg$i=\$pkg" 528 | fi 529 | done 530 | 531 | pkg10=$(echo "$turbostat_after_s2idle" | sed -n '3p' | 532 | awk -v idx=$(get_column_index "$TURBO_RESULT_COLUMNS" "Pk%pc10") '{print $idx}') 533 | log_output "CPU Package C-state 10 residency after S2idle is: $pkg10" 534 | 535 | slp_s0=$(echo "$turbostat_after_s2idle" | sed -n '3p' | 536 | awk -v idx=$(get_column_index "$TURBO_RESULT_COLUMNS" "SYS%LPI") '{print $idx}') 537 | log_output "S0ix residency after S2idle is: $slp_s0" 538 | 539 | s0ix_substate_af="$(cat $PMC_CORE_SYSFS_PATH/substate_residencies)" 2>&1 540 | if [[ -z "$s0ix_substate_af" ]] && 541 | [[ "$(echo "scale=2; $slp_s0 > 0.00" | bc)" -eq 1 ]]; then 542 | log_output "\n\033[32mCongratulations! Your system achieved S2idle S0ix \ 543 | residency: $slp_s0\033[0m\n" 544 | exit 0 545 | 546 | elif [[ -n "$s0ix_substate" ]] && 547 | [[ "$(echo "scale=2; $slp_s0 > 0.00" | bc)" -eq 1 ]] && 548 | [[ -z "$sub_enable_flag" ]]; then 549 | OLD_IFS="$IFS" 550 | IFS=$'\n' 551 | sub_num="$(echo "$s0ix_substate_af" | wc -l)" 552 | for ((j = 2; j <= sub_num; j++)); do 553 | sub_af="$(sed -n "$j, 1p" "$PMC_CORE_SYSFS_PATH"/substate_residencies | awk '{print $1}')" 554 | subarrayaf[j]=$sub_af 555 | sub_af_res="$(sed -n "$j,1p" "$PMC_CORE_SYSFS_PATH"/substate_residencies | awk '{print $2}')" 556 | resarrayaf[j]=$sub_af_res 557 | done 558 | IFS="$OLD_IFS" 559 | #Print out the subarrayaf and resarrayaf 560 | log_output "\nS0ix substate after S2idle:\n" "${subarrayaf[*]}" 561 | log_output "\nS0ix substate residency after S2idle:\n" "${resarrayaf[*]}" 562 | #Judge the substate residency delta 563 | for ((k = 2; k <= sub_num; k++)); do 564 | OLD_IFS="$IFS" 565 | IFS=$'\n' 566 | resdeltaarray[$k]=$((resarrayaf[k] - resarraybf[k])) 567 | IFS="$OLD_IFS" 568 | log_output "\nS0ix substates residency delta value:" \ 569 | "${subarrayaf[$k]}" "${resdeltaarray[$k]}" 570 | done 571 | #Scan resdeltaarray and judge which one has no-zero value 572 | m=${#resdeltaarray[@]} 573 | while [ $m -ge 2 ]; do 574 | if [[ "${resdeltaarray[m]}" -gt "0" ]]; then 575 | if [[ "$m" -eq "${#resdeltaarray[@]}" ]]; then 576 | log_output "\n\033[32mCongratulations! Your system achieved the deepest \ 577 | S0ix substate!\033[0m \ 578 | \nHere is the S0ix substates status: \n$s0ix_substate_af\n" 579 | exit 0 580 | else 581 | OLD_IFS="$IFS" 582 | IFS=$'\n' 583 | shallower=${subarrayaf[m]} 584 | n=$((m + 1)) 585 | deeper=${subarrayaf[n]} 586 | IFS="$OLD_IFS" 587 | log_output "\n\033[31mYour system only get shallower S0ix substate \ 588 | residency:\033[0m" "\033[31m${subarrayaf[m]}\033[0m" "\033[31m${resarrayaf[m]}\033[0m" 589 | log_output "\nNeed to debug why not deeper substate:" "$deeper" 590 | if substate_triage "$shallower" "$deeper"; then 591 | log_output "\n\033[31mPlease do the advanced debug based on above \ 592 | substate_status_registers info \nor report a bug with that attached.\033[0m\n" 593 | log_output "\n---Debug PCIe root port device and link PM state---" 594 | #Check PCI devices D states 595 | pci_d3_status_check 596 | #Check PCIe bridge link PM states 597 | debug_pcie_bridge_lpm 598 | judge_dstate_linkstate 599 | else 600 | log_output "\nPlease check the potential blockers\n" 601 | fi 602 | exit 0 603 | fi 604 | else 605 | let m-- 606 | fi 607 | done 608 | exit 0 609 | elif [[ -n "$s0ix_substate" ]] && 610 | [[ "$(echo "scale=2; $slp_s0 > 0.00" | bc)" -eq 1 ]] && 611 | [[ -n "$sub_enable_flag" ]]; then 612 | OLD_IFS="$IFS" 613 | IFS=$'\n' 614 | sub_num="$(echo "$s0ix_substate_af" | grep -c "Enabled")" 615 | for ((j = 1; j <= sub_num; j++)); do 616 | sub_af_enable="$(grep "Enabled" $PMC_CORE_SYSFS_PATH/substate_residencies)" 617 | sub_af="$(echo "$sub_af_enable" | sed -n "$j,1p" | awk '{print $2}')" subarrayaf[j]=$sub_af 618 | sub_af_res="$(echo "$sub_af_enable" | sed -n "$j,1p" | awk '{print $3}')" resarrayaf[j]=$sub_af_res 619 | done 620 | IFS="$OLD_IFS" 621 | #Print out subarrayaf and resarrayaf 622 | log_output "\nS0ix substate after S2idle:\n" "${subarrayaf[*]}" 623 | log_output "\nS0ix substate residency after S2idle:\n" "${resarrayaf[*]}" 624 | #Judge the substate residency delta 625 | for ((k = 1; k <= sub_num; k++)); do 626 | OLD_IFS="$IFS" 627 | IFS=$'\n' 628 | resdeltaarray[$k]=$((resarrayaf[k] - resarraybf[k])) 629 | IFS="$OLD_IFS" 630 | log_output "\nS0ix substates residency delta value:" \ 631 | "${subarrayaf[$k]}" "${resdeltaarray[$k]}" 632 | done 633 | #Scan resdeltaarray and judge which one has no-zero value 634 | m=${#resdeltaarray[@]} 635 | while [ $m -ge 1 ]; do 636 | if [[ "${resdeltaarray[m]}" -gt "0" ]]; then 637 | if [[ "$m" -eq "${#resdeltaarray[@]}" ]]; then 638 | log_output "\n\033[32mCongratulations! Your system achieved the \ 639 | deepest S0ix substate! \033[0m \ 640 | \nHere is the S0ix substates status: \n$s0ix_substate_af\n" 641 | exit 0 642 | else 643 | OLD_IFS="$IFS" 644 | IFS=$'\n' 645 | shallower=${subarrayaf[m]} 646 | n=$((m + 1)) 647 | deeper=${subarrayaf[n]} 648 | IFS="$OLD_IFS" 649 | log_output "\n\033[31mYour system only get shallower S0ix substate \ 650 | residency:\033[0m" "${subarrayaf[m]}" "${resarrayaf[m]}" 651 | log_output "\nNeed to debug why not deeper substate:" "$deeper" 652 | if [[ -z "$sub" ]]; then 653 | sta=$(cat $PMC_CORE_SYSFS_PATH/substate_status_registers) 654 | log_output "\nPlease check substate_status_registers file for the \ 655 | advanced debug:\n" 656 | log_output "substate_status_registers:" 657 | log_output "$sta\n" 658 | fi 659 | exit 0 660 | fi 661 | else 662 | let m-- 663 | fi 664 | done 665 | exit 0 666 | #Judge only PC10 residency is available when S0ix substate is supported 667 | elif [[ -n "$s0ix_substate" ]] && 668 | [[ "$(echo "scale=2; $pkg10 > 0.00" | bc)" -eq 1 ]]; then 669 | log_output "\n\033[31mYour system supports S0ix substates, but did not \ 670 | achieve the shallowest s0i2.0\033[0m 671 | \nHere is the S0ix substates status: \n$s0ix_substate_af\n" 672 | #Debug scenario 5: No any S0ix substate residency, only PC10 residency 673 | DEBUG=5 674 | 675 | elif [[ "$(echo "scale=2; $pkg10 > 0.00" | bc)" -eq 1 ]]; then 676 | log_output "\nNeed to debug which IP blocked S0ix since PC10 is observed." 677 | #Debug scenario 4: No S0ix residency, but has PC10 residency 678 | DEBUG=4 679 | 680 | elif [[ "$(echo "scale=2; $pkg8 > 0.00" | bc)" -eq 1 ]]; then 681 | log_output "\nYour system achieved PC8 residency: $pkg8, \ 682 | but no PC10 residency:$pkg10,no S0ix residency: $slp_s0" 683 | #Debug scenario 3: No PC10 residency, but has PC8 residency 684 | DEBUG=3 685 | 686 | elif [[ "$(echo "scale=2; $pkg3 > 0.00" | bc)" -eq 1 ]]; then 687 | log_output "\nYour system achieved PC3 residency: $pkg3, \ 688 | but no PC8 residency during S2idle: $pkg8" 689 | #Debug scenario 2: No PC8 residency, but has PC3 residency 690 | DEBUG=2 691 | 692 | elif [[ "$(echo "scale=2; $pkg2 > 0.00" | bc)" -eq 1 ]]; then 693 | log_output "\nYour system achieved PC2 residency: $pkg2, \ 694 | but no PC8 residency during S2idle: $pkg8" 695 | #Debug scenario 2: No PC8 residency, but has PC2 residency 696 | DEBUG=2 697 | 698 | else 699 | #Debug scenario 0: No PC2 residency 700 | log_output "\nYour system did not achieve PC2 state or PC2 residency is low: \ 701 | \n$pkg2" 702 | DEBUG=1 703 | fi 704 | 705 | return 0 706 | } 707 | 708 | debug_no_pc2() { 709 | local cc6="" 710 | local rc6="" 711 | local turbostat_after_s2idle="" 712 | local duration=15 713 | local pc2_para=$(echo "$TURBO_COLUMNS" | awk '{print $1,$2,$3,$4}') 714 | #Run powertop --auto-tune to double check PC2 status 715 | if ! type powertop 1>/dev/null 2>&1; then 716 | log_output "\033[31mPlease install powertop tool.\033[0m\n" 717 | else 718 | powertop --auto-tune 2>&1 719 | fi 720 | 721 | echo 0 >/sys/class/rtc/rtc0/wakealarm 722 | echo +$duration >/sys/class/rtc/rtc0/wakealarm 723 | 724 | if turbostat_after_s2idle=$("$DIR"/turbostat --quiet --show "$pc2_para" \ 725 | echo freeze 2>&1 >/sys/power/state); then 726 | log_output "Turbostat output: \n$turbostat_after_s2idle" 727 | sleep 5 728 | else 729 | log_output "\nThe system failed to place S2idle entry command, please re-try.\n" 730 | exit 0 731 | fi 732 | 733 | cc6=$(echo "$turbostat_after_s2idle" | sed -n '3p' | 734 | awk -v idx=$(get_column_index "$pc2_para" "CPU%c6") '{print $idx}') 735 | log_output "\nCPU Core c6:$cc6" 736 | 737 | #Check whether CPU Core C6 residency is available 738 | if [[ "$(echo "scale=2; $cc6 > 0.00" | bc)" -eq 1 ]]; then 739 | log_output "\nYour CPU Core C6 residency is available: $cc6" 740 | else 741 | log_output "\nYour CPU Core C6 residency is not available, \ 742 | need to check which CPU idle driver is in use:" 743 | cat /sys/devices/system/cpu/cpuidle/current_driver 744 | log_output "\nCheck what's the CPU idle driver status:" 745 | grep . /sys/devices/system/cpu/cpu*/cpuidle/state*/* 2>&1 746 | return 1 747 | fi 748 | 749 | return 0 750 | } 751 | 752 | debug_pcie_link_aspm() { 753 | link_aspm_disable=$(lspci -vvv | grep "ASPM Disabled" 2>&1) 754 | if [[ -n "$link_aspm_disable" ]]; then 755 | log_output "\n\033[31mDetected PCIe device link ASPM Disabled, please investigate!\033[0m\n" 756 | log_output "\033[31m$link_aspm_disable\033[0m\n" 757 | return 0 758 | fi 759 | return 1 760 | } 761 | 762 | #Function to check PCIe bridge Link Power Management state 763 | debug_pcie_bridge_lpm() { 764 | PCI_SYSFS="/sys/bus/pci/devices" 765 | PCI_BRIDGE_CLASS="0x060400" 766 | devices=$(ls ${PCI_SYSFS}) 767 | bridge_devices=() 768 | local link_substate_cap="" 769 | local link_substate_ctl="" 770 | local pci_tree="" 771 | pci_tree=$(lspci -tvv) 772 | 773 | # Get list of pci bridge devices 774 | for dev in $devices; do 775 | if [ -d "${PCI_SYSFS}"/"${dev}" ] && 776 | [ -f "${PCI_SYSFS}"/"${dev}"/config ]; then 777 | class=$(cat "${PCI_SYSFS}"/"${dev}"/class) 778 | if [[ "${class}" == "${PCI_BRIDGE_CLASS}" ]]; then 779 | bridge_devices+=("${dev}") 780 | fi 781 | fi 782 | done 783 | 784 | link_state() { 785 | local pciests1=$1 786 | local byte1="$((16#${pciests1} >> 8))" 787 | local ltsmstate="$((16#${pciests1} & 255))" 788 | local l1msg="Link is in L1" 789 | local policy="" 790 | 791 | # Some bit manipulation to get Link Status 792 | lnkstat=$(((byte1 >> 3) & 15)) 793 | 794 | case "${lnkstat}" in 795 | 0) 796 | case "${ltsmstate}" in 797 | [0-9] | 1[0-6]) 798 | l1msg="Link is in Detect" 799 | ;; 800 | 4[2-9]) 801 | l1msg="Link is in L2, LTSMSTATE=0" 802 | ;; 803 | 59 | 60 | 61) 804 | l1msg="Link is Disabled" 805 | ;; 806 | *) 807 | l1msg="Link is not in Low Power State, LTSMSTATE=${ltsmstate}" 808 | ;; 809 | esac 810 | echo "${l1msg}" 811 | ;; 812 | 1) 813 | echo "Link is Retraining" 814 | ;; 815 | 3) 816 | case "${ltsmstate}" in 817 | 5[5-9] | 60) 818 | l1msg="Link is in L1" 819 | ;; 820 | 61 | 62) 821 | l1msg="Link is in L1.1" 822 | ;; 823 | 63 | 64) 824 | l1msg="Link is in L1.2" 825 | ;; 826 | *) 827 | l1msg="Link is other L1 state, LTSMSTATE=${ltsmstate}" 828 | ;; 829 | esac 830 | echo "${l1msg}" 831 | ;; 832 | 4) 833 | echo "Link is in L2" 834 | ;; 835 | 5) 836 | echo "Link is in L3" 837 | ;; 838 | [7-9] | 10) 839 | echo "Link is in L0" 840 | ;; 841 | *) 842 | echo "Unknown link state ${lnkstat}" 843 | ;; 844 | esac 845 | } 846 | 847 | #Let system sleep 20 seconds below, in case did not get correct PCIe bridge \ 848 | #Link state at beginning 849 | sleep 20 850 | 851 | #log_output "\nThe PCIe bridge link power management state is:" 852 | echo "Available bridge device:" "${bridge_devices[@]}" 853 | for dev in "${bridge_devices[@]}"; do 854 | #Get lower 16 bits of PCIESTS1 register 855 | pciests1=$(xxd -ps -l2 -s 0x32a "${PCI_SYSFS}"/"${dev}"/config) 856 | if [[ "$(link_state "${pciests1}")" == "Link is in L1.1" ]] || 857 | [[ "$(link_state "${pciests1}")" == "Link is in L1.2" ]] || 858 | [[ "$(link_state "${pciests1}")" == "Link is in Detect" ]] || 859 | [[ "$(link_state "${pciests1}")" == "Link is in Disabled" ]] || 860 | [[ "$(link_state "${pciests1}")" == "Link is in L2" ]] || 861 | [[ "$(link_state "${pciests1}")" == "Link is in L2, LTSMSTATE=0" ]] || 862 | [[ "$(link_state "${pciests1}")" == "Link is in L3" ]]; then 863 | log_output "\n$dev $(link_state "${pciests1}")" 864 | log_output "\nThe link power management state of PCIe bridge: $dev is OK." 865 | else 866 | PCIEPORT_L0="$dev" 867 | log_output "\nThe PCIe bridge link power management state is:" 868 | log_output "\033[31m$dev $(link_state "${pciests1}")\033[0m" 869 | log_output "\nThe link power management state of PCIe bridge: \ 870 | \033[31m$dev\033[0m is not expected. \nwhich is expected to be L1.1 or L1.2, \ 871 | or user would run this script again.\n" 872 | link_substate_cap=$(lspci -vvv -s"$dev" | grep L1SubCap) 873 | link_substate_ctl=$(lspci -vvv -s"$dev" | grep L1SubCtl1) 874 | log_output "\nThe L1SubCap of the failed $dev is:" 875 | log_output "$link_substate_cap" 876 | log_output "\nThe L1SubCtl1 of the failed $dev is:" 877 | log_output "$link_substate_ctl\n" 878 | log_output "\nChecking PCI Devices tree diagram:\n$pci_tree\n" 879 | return 1 880 | fi 881 | done 882 | 883 | #Check PCIE_ASPM default setting 884 | policy=$(grep "\[.*\]" -o /sys/module/pcie_aspm/parameters/policy 2>&1) 885 | if [[ "$policy" == "[default]" ]] || 886 | [[ "$policy" == "[powersupersave]" ]]; then 887 | log_output "\nYour system default pcie_aspm policy setting is OK.\n" 888 | else 889 | log_output "\nYour system default PCIe_aspm policy setting is not proper, \ 890 | \nsuggest to set /sys/module/pcie_aspm/parameters/policy to default or \ 891 | powersupersave.\n" 892 | return 1 893 | fi 894 | return 0 895 | } 896 | 897 | debug_no_pc8() { 898 | local cc7="" 899 | local rc6="" 900 | local turbostat_after_s2idle="" 901 | local duration=15 902 | 903 | #Run powertop --auto-tune to make sure the devices runtime PM are enabled 904 | if ! type powertop 1>/dev/null 2>&1; then 905 | log_output "\033[31mPlease install powertop tool.\033[0m\n" 906 | else 907 | powertop --auto-tune 2>&1 908 | fi 909 | 910 | echo 0 >/sys/class/rtc/rtc0/wakealarm 911 | echo +$duration >/sys/class/rtc/rtc0/wakealarm 912 | 913 | if turbostat_after_s2idle=$("$DIR"/turbostat --quiet --show "$TURBO_COLUMNS" \ 914 | echo freeze 2>&1 >/sys/power/state); then 915 | log_output "\nTurbostat output: \n\n$turbostat_after_s2idle" 916 | sleep 5 917 | else 918 | log_output "\nThe system failed to place S2idle entry command, please re-try.\n" 919 | exit 0 920 | fi 921 | 922 | TURBO_RESULT_COLUMNS=$(echo "$turbostat_after_s2idle" | sed -n '2p' | sed 's/\t/,/g') 923 | cc7=$(echo "$turbostat_after_s2idle" | sed -n '3p' | 924 | awk -v idx=$(get_column_index "$TURBO_RESULT_COLUMNS" "CPU%c7") '{print $idx}') 925 | pkg8=$(echo "$turbostat_after_s2idle" | sed -n '3p' | 926 | awk -v idx=$(get_column_index "$TURBO_RESULT_COLUMNS" "Pkg%pc8") '{print $idx}') 927 | pkg10=$(echo "$turbostat_after_s2idle" | sed -n '3p' | 928 | awk -v idx=$(get_column_index "$TURBO_RESULT_COLUMNS" "Pk%pc10") '{print $idx}') 929 | slp_s0=$(echo "$turbostat_after_s2idle" | sed -n '3p' | 930 | awk -v idx=$(get_column_index "$TURBO_RESULT_COLUMNS" "SYS%LPI") '{print $idx}') 931 | 932 | #Check whether PC8,PC10 and S0ix is available after running powertop 933 | if [[ "$(echo "scale=2; $slp_s0 > 0.00" | bc)" -eq 1 ]]; then 934 | log_output "\nS0ix residency is achieved after powertop --auto-tune" 935 | return 0 936 | elif [[ "$(echo "scale=2; $pkg10 > 0.00" | bc)" -eq 1 ]]; then 937 | log_output "\nPC10 residency achieved after powertop --auto-tune, \ 938 | but still no S0ix residency" 939 | return 0 940 | elif [[ "$(echo "scale=2; $pkg8 > 0.00" | bc)" -eq 1 ]]; then 941 | log_output "\nPC8 residency achieved after powertop --auto-tune, \ 942 | but still no PC10 and S0ix" 943 | return 0 944 | fi 945 | #Check whether CPU Core C7 residency is available 946 | if [[ "$(echo "scale=2; $cc7 > 0.00" | bc)" -eq 1 ]]; then 947 | log_output "\nYour CPU Core C7 residency is available: $cc7" 948 | else 949 | log_output "\nYour CPU Core C7 residency is not available, need to check \ 950 | which CPU idle driver is in use:" 951 | cat /sys/devices/system/cpu/cpuidle/current_driver 952 | log_output "\n\nCheck what's the CPU idle driver status:" 953 | grep . /sys/devices/system/cpu/cpu*/cpuidle/state*/* 2>&1 954 | return 1 955 | fi 956 | 957 | #Check whether PCIe Link PM is in L1 or L2, as L0 may block PC3 958 | if [[ "$(echo "scale=2; $pkg8 < 1.00" | bc)" -eq 1 ]]; then 959 | log_output "\nChecking PCIe Device D state and Bridge Link state:\n" 960 | debug_pcie_bridge_lpm 961 | pci_d3_status_check 962 | fi 963 | } 964 | 965 | debug_no_dc9() { 966 | local kbl_l=142 967 | local kbl=158 968 | local cml=165 969 | local cml_l=166 970 | local dc5_before="" 971 | local dc5_after="" 972 | local dc6_before="" 973 | local dc6_after="" 974 | local rc6_model_list="" 975 | local model="" 976 | local i="" 977 | local turbostat_after_s2idle="" 978 | local duration=15 979 | local dmc_dir="/sys/kernel/debug/dri/0/i915_dmc_info" 980 | 981 | if [ ! -f "$dmc_dir" ]; then 982 | log_output "\nPlease check if the Intel graphics i915 driver is not loaded \ 983 | or the graphic controller has been disabled?" 984 | return 0 985 | fi 986 | 987 | dc5_before=$(grep -i "DC3 -> DC5" $dmc_dir | awk '{print $(NF)}' 2>&1) 988 | dc6_before=$(grep -i "DC5 -> DC6" $dmc_dir | awk '{print $(NF)}' 2>&1) 989 | log_output "\nGFX DC5 before S2idle: $dc5_before" 990 | log_output "GFX DC6 before S2idle: $dc6_before" 991 | 992 | echo 0 >/sys/class/rtc/rtc0/wakealarm 993 | echo +$duration >/sys/class/rtc/rtc0/wakealarm 994 | 995 | if turbostat_after_s2idle=$("$DIR"/turbostat --quiet --show "$TURBO_COLUMNS" \ 996 | echo freeze 2>&1 >/sys/power/state); then 997 | log_output "\nTurbostat output: \n\n$turbostat_after_s2idle" 998 | sleep 5 999 | else 1000 | log_output "\nThe system failed to place S2idle entry command, please re-try\n" 1001 | exit 0 1002 | fi 1003 | 1004 | dc5_after=$(grep -i "DC3 -> DC5" $dmc_dir | awk '{print $(NF)}' 2>&1) 1005 | dc6_after=$(grep -i "DC5 -> DC6" $dmc_dir | awk '{print $(NF)}' 2>&1) 1006 | log_output "\nGFX DC5 after S2idle: $dc5_after" 1007 | log_output "GFX DC6 after S2idle: $dc6_after" 1008 | 1009 | #Check DC6 state for Intel® Coffee lake, Whiskey lake, Comet lake platforms 1010 | rc6_model_list="$kbl $kbl_l $cml $cml_l" 1011 | 1012 | model=$(sed -n '/model/p' /proc/cpuinfo | head -1 | awk '{print $3}' 2>&1) 1013 | 1014 | if [[ "$rc6_model_list" =~ $model ]]; then 1015 | #Check DC6 state for Intel® Coffee lake, Whiskey lake, Comet lake platforms 1016 | if [[ "$dc6_after" -gt "$dc6_before" ]]; then 1017 | log_output "\nYour system CPU Model ID is: $model, and the graphics DC6 \ 1018 | value is OK for DC9 entry." 1019 | return 0 1020 | else 1021 | log_output "\nYour system CPU Model ID is: $model, and the graphics DC6 \ 1022 | value is not expected to enter DC9, \ 1023 | \nplease check the latest display DMC FW load status:" 1024 | if dmc_check; then 1025 | return 0 1026 | fi 1027 | return 1 1028 | fi 1029 | #Check DC5 state for Intel® Broxton, Gemini lake, Ice lake and afterwards platforms 1030 | elif [[ "$dc5_after" -lt "$dc5_before" ]]; then 1031 | log_output "\nYour system CPU Model ID is: $model, and the graphics DC5 \ 1032 | value is OK for DC9 entry." 1033 | return 0 1034 | else 1035 | log_output "\nYour system CPU Model ID is: $model, and the graphics DC5 \ 1036 | value is not expected to enter DC9, \ 1037 | \nplease check the latest display DMC FW load status." 1038 | if dmc_check; then 1039 | return 0 1040 | fi 1041 | return 1 1042 | fi 1043 | } 1044 | 1045 | debug_ltr_value() { 1046 | local pc10="" 1047 | local slp_s0="" 1048 | local ltr_ip_num="" 1049 | local l="" 1050 | local counter=0 1051 | local turbostat_after_s2idle="" 1052 | local duration=10 1053 | local ltr_failed_ip="" 1054 | 1055 | echo 0 >/sys/class/rtc/rtc0/wakealarm 1056 | echo +$duration >/sys/class/rtc/rtc0/wakealarm 1057 | 1058 | if turbostat_after_s2idle=$("$DIR"/turbostat --quiet --show "$TURBO_COLUMNS" \ 1059 | echo freeze 2>&1 >/sys/power/state); then 1060 | log_output "\nTurbostat output: \n$turbostat_after_s2idle" 1061 | sleep 5 1062 | else 1063 | log_output "\nThe system failed to place S2idle entry command, please re-try.\n" 1064 | exit 0 1065 | fi 1066 | 1067 | TURBO_RESULT_COLUMNS=$(echo "$turbostat_after_s2idle" | sed -n '2p' | sed 's/\t/,/g') 1068 | pkg10=$(echo "$turbostat_after_s2idle" | sed -n '3p' | 1069 | awk -v idx=$(get_column_index "$TURBO_RESULT_COLUMNS" "Pk%pc10") '{print $idx}') 1070 | slp_s0=$(echo "$turbostat_after_s2idle" | sed -n '3p' | 1071 | awk -v idx=$(get_column_index "$TURBO_RESULT_COLUMNS" "SYS%LPI") '{print $idx}') 1072 | 1073 | #Check whether IP LTR value ignore is helpful to the PC10 and S0ix state 1074 | ltr_ip_num=$(wc -l $PMC_CORE_SYSFS_PATH/ltr_show 2>&1 | awk '{print$1}') 1075 | l=$((ltr_ip_num - 1)) 1076 | log_output "\nIP LTR Number: $l \ 1077 | \nPlease be patient, system will do $l cycles S2idle below, check if ignoring \ 1078 | \nthe IP LTR value is helpful to the PC10 and S0ix residency one by one." 1079 | 1080 | until [ $counter -gt $l ]; do 1081 | echo $counter >$PMC_CORE_SYSFS_PATH/ltr_ignore 1082 | log_output "\nLTR ignore for IP "$counter 1083 | 1084 | echo 0 >/sys/class/rtc/rtc0/wakealarm 1085 | echo +$duration >/sys/class/rtc/rtc0/wakealarm 1086 | 1087 | if turbostat_after_s2idle=$("$DIR"/turbostat --quiet --show "$TURBO_COLUMNS" \ 1088 | echo freeze 2>&1 >/sys/power/state); then 1089 | TURBO_RESULT_COLUMNS=$(echo "$turbostat_after_s2idle" | sed -n '2p' | sed 's/\t/,/g') 1090 | pkg10=$(echo "$turbostat_after_s2idle" | sed -n '3p' | 1091 | awk -v idx=$(get_column_index "$TURBO_RESULT_COLUMNS" "Pk%pc10") '{print $idx}') 1092 | slp_s0=$(echo "$turbostat_after_s2idle" | sed -n '3p' | 1093 | awk -v idx=$(get_column_index "$TURBO_RESULT_COLUMNS" "SYS%LPI") '{print $idx}') 1094 | log_output "PC10 residency is:$pc10" 1095 | log_output "S0ix residency is:$slp_s0" 1096 | else 1097 | log_output "The system failed to place S2idle entry command, please re-try.\n" 1098 | exit 0 1099 | fi 1100 | 1101 | if [ "$(echo "scale=2; $slp_s0 > 0.00" | bc)" -eq 1 ]; then 1102 | log_output "\nS0ix residency is available after IP number $counter LTR ignore\n" 1103 | let ltr_failed_ip=$l+1 && 1104 | cat "$PMC_CORE_SYSFS_PATH"/ltr_show | sed -n ''"ltr_failed_ip"'' 1105 | exit 0 1106 | elif [ "$(echo "scale=2; $pc10 > 0.00" | bc)" -eq 1 ]; then 1107 | log_output "\nNo S0ix residency, only PC10 is available after IP number \ 1108 | $counter LTR ignore:\n" 1109 | let ltr_failed_ip=$l+1 && 1110 | cat "$PMC_CORE_SYSFS_PATH"/ltr_show | sed -n ''"ltr_failed_ip"'' 1111 | return 0 1112 | break 1113 | else 1114 | log_output "\nIP Number $counter LTR ignore is not helpful to the PC10 \ 1115 | and S0ix state." 1116 | fi 1117 | counter=$((counter + 1)) 1118 | sleep 2 1119 | done 1120 | return 1 1121 | } 1122 | 1123 | ignore_ltr_all() { 1124 | local ltr_ip_num 1125 | local num 1126 | local i=0 1127 | 1128 | ltr_ip_num=$(wc -l $PMC_CORE_SYSFS_PATH/ltr_show 2>&1 | awk '{print$1}') 1129 | num=$((ltr_ip_num - 1)) 1130 | 1131 | while [ $i -ne $num ]; do 1132 | echo $i >$PMC_CORE_SYSFS_PATH/ltr_ignore 2>&1 1133 | i=$((i + 1)) 1134 | done 1135 | } 1136 | 1137 | debug_pch_ip_pg() { 1138 | local south_port_before="" 1139 | local south_port_after="" 1140 | local i=1 1141 | 1142 | south_port_before=$(grep -i On $PMC_CORE_SYSFS_PATH/pch_ip_power_gating_status | 1143 | sed -n '/\&1) 1144 | if [ -n "$south_port_before" ]; then 1145 | log_output "\nYour system south port controller did not meet S0ix requirement: \ 1146 | \033[31m$south_port_before\033[0m" 1147 | grep "$south_port_before" $PMC_CORE_SYSFS_PATH/pch_ip_power_gating_status 1148 | return 0 1149 | else 1150 | 1151 | #Grep south ports power gating state multi-cycles as it reports the runtime state 1152 | while [ $i -le 10 ]; do 1153 | sleep 3 1154 | south_port_after=$(grep -i On $PMC_CORE_SYSFS_PATH/pch_ip_power_gating_status | 1155 | sed -n '/\&1) 1156 | if [[ "$south_port_after" == "$south_port_before" ]]; then 1157 | let ++i 1158 | continue 1159 | else 1160 | log_output "\nYour system south port controller did not meet S0ix requirement: \ 1161 | \033[31m$south_port_after\033[0m" 1162 | grep "$south_port_after" $PMC_CORE_SYSFS_PATH/pch_ip_power_gating_status 1163 | return 0 1164 | fi 1165 | done 1166 | log_output "\nYour system south port controller power gating state is OK \ 1167 | after 30 seconds runtime check." 1168 | fi 1169 | return 1 1170 | } 1171 | 1172 | debug_s0ix() { 1173 | local mphy="" 1174 | local main_pll="" 1175 | local oc_pll="" 1176 | local csme="" 1177 | local i=1 1178 | 1179 | #Enable slp_s0 debug setting 1180 | echo Y >$PMC_CORE_SYSFS_PATH/slp_s0_dbg_latch 2>&1 1181 | 1182 | if rtcwake -m freeze -s 15 1>/dev/null 2>&1; then 1183 | log_output "\nChecking slp_s0_debug_status:" 1184 | else 1185 | log_output "\nSystem failed to place S2idle entry command, please re-try.\n" 1186 | exit 0 1187 | fi 1188 | 1189 | mphy=$(grep No $PMC_CORE_SYSFS_PATH/slp_s0_debug_status | 1190 | grep "MPHY_CORE_GATED" | awk '{print $2}') 1191 | main_pll=$(grep No $PMC_CORE_SYSFS_PATH/slp_s0_debug_status | 1192 | grep "MAIN_PLL_OFF" | awk '{print $2}') 1193 | oc_pll=$(grep No $PMC_CORE_SYSFS_PATH/slp_s0_debug_status | 1194 | grep "OC_PLL_OFF" | awk '{print $2}') 1195 | csme=$(grep No $PMC_CORE_SYSFS_PATH/slp_s0_debug_status | 1196 | grep "CSME_GATED" | awk '{print $2}') 1197 | 1198 | if [[ -z "$mphy" ]]; then 1199 | log_output "\nYour system ModPHY Lane Core domain power gating state is OK \ 1200 | for S0ix entry." 1201 | else 1202 | log_output "\nYour system ModPHY lane Core domain has issue blocks S0ix." 1203 | log_output "\nIsolation suggestions: \ 1204 | \nCheck ModPHY related high speed I/O controller list: \ 1205 | \ncovering from XHCI, XDCI, SATA, PCIe (all instances), Gbe and SCC (UFS)" 1206 | fi 1207 | 1208 | if [[ -z "$main_pll" ]] && [[ -z "$oc_pll" ]]; then 1209 | log_output "\nYour system Main PLL and Oscillator Crystal PLL state are OK \ 1210 | for S0ix entry." 1211 | else 1212 | log_output "\nYour system Main PLL or Oscillator Crystal PLL has issue to \ 1213 | power off during S2idle, which may block S0ix. \ 1214 | \nFailed PLL: $main_pll $oc_pll\n" 1215 | return 1 1216 | fi 1217 | 1218 | #Grep CSMe power gating state multi-cycles as it reports the runtime state 1219 | while [ $i -le 10 ]; do 1220 | sleep 3 1221 | if [ -z "$csme" ]; then 1222 | log_output "\nYour system CSMe power gating state is OK for S0ix entry.\n" 1223 | return 0 1224 | else 1225 | let ++i 1226 | continue 1227 | fi 1228 | done 1229 | log_output "\nYour system CSMe did not power gated during S2idle after 30 \ 1230 | seconds runtime check. \ 1231 | \nIsolation suggestion: \ 1232 | \nPlease check whether the latest CSME FW is updated or run this script again." 1233 | return 1 1234 | } 1235 | 1236 | debug_acpi_dsm() { 1237 | local slp_s0="" 1238 | local turbostat_after_s2idle="" 1239 | local duration=15 1240 | 1241 | echo Y >/sys/module/acpi/parameters/sleep_no_lps0 1242 | echo 0 >/sys/class/rtc/rtc0/wakealarm 1243 | echo +$duration >/sys/class/rtc/rtc0/wakealarm 1244 | 1245 | if turbostat_after_s2idle=$("$DIR"/turbostat --quiet --show "$TURBO_COLUMNS" \ 1246 | echo freeze 2>&1 >/sys/power/state); then 1247 | TURBO_RESULT_COLUMNS=$(echo "$turbostat_after_s2idle" | sed -n '2p' | sed 's/\t/,/g') 1248 | slp_s0=$(echo "$turbostat_after_s2idle" | sed -n '3p' | 1249 | awk -v idx=$(get_column_index "$TURBO_RESULT_COLUMNS" "SYS%LPI") '{print $idx}') 1250 | else 1251 | log_output "\nThe system failed to place S2idle entry command, please re-try.\n" 1252 | exit 0 1253 | fi 1254 | 1255 | if [ "$(echo "$slp_s0 > 0" | bc)" -eq 1 ]; then 1256 | log_output "\nS0ix residency is available after setting no ACPI DSM callback.\n" 1257 | exit 0 1258 | else 1259 | log_output "\nSetting no ACPI DSM callback is not helpful to the S0ix residency." 1260 | #Recover the ACPI DSM setting 1261 | echo N >/sys/module/acpi/parameters/sleep_no_lps0 1262 | fi 1263 | return 0 1264 | } 1265 | 1266 | judge_dstate_linkstate() { 1267 | [[ -n "$PCIEPORT_D0" ]] && D0="$PCIEPORT_D0" 1268 | [[ -n "$PCIEPORT_L0" ]] && L0="$PCIEPORT_L0" 1269 | 1270 | if [[ -n $D0 ]] && [[ -n $L0 ]] && 1271 | [[ "$D0" =~ $L0 ]] && [[ -n "$ASPM_ENABLE" ]]; then 1272 | log_output "\n\033[31mThe pcieroot port $L0 ASPM setting is Enabled, its \ 1273 | D state and Link PM are not expected,\nplease investigate or report a bug.\033[0m\n" 1274 | elif [[ -n $D0 ]] && [[ -n $L0 ]] && 1275 | [[ "$D0" =~ $L0 ]] && [[ -z "$ASPM_ENABLE" ]]; then 1276 | log_output "\n\033[31mThe pcieroot port $L0 ASPM setting is Disabled, and \ 1277 | its D state and Link PM are not expected,\nplease enable $L0 ASPM setting to \ 1278 | double check or report a bug.\033[0m\n" 1279 | return 1 1280 | fi 1281 | return 0 1282 | } 1283 | 1284 | ############################################################################## 1285 | if [[ $runtime == on ]]; then 1286 | log_output "\n---Check Runtime PC10 Residency during Screen ON---:" 1287 | [[ -n "$KERNEL_VER" ]] && log_output "\nThe system OS Kernel version is: 1288 | $KERNEL_VER\n" 1289 | if ! type powertop 1>/dev/null 2>&1; then 1290 | log_output "\033[31mPlease install powertop tool.\033[0m\n" 1291 | else 1292 | powertop --auto-tune 2>&1 1293 | fi 1294 | 1295 | if pc10_idle_on; then 1296 | log_output "\n" 1297 | elif dmc_check; then 1298 | log_output "\nIntel graphics i915 DMC FW is loaded. Will re-check the deeper 1299 | Package C-state by ignoring PCI Devices LTR value:\n" 1300 | 1301 | #Ignore all the PCI devices LTR values 1302 | ignore_ltr_all 1303 | log_output "All the PCI devices LTR values ignore is done!" 1304 | 1305 | if pc10_idle_on; then 1306 | log_output "\n\033[32mThe deeper CPU Package C-state is available after 1307 | PCI devices LTR ignore,please investigate the potential IP LTR issue.\033[0m\n" 1308 | exit 0 1309 | else 1310 | log_output "\nPCI devices LTR value ignore does not help the PC10, will 1311 | check PCIe Link PM states:\n" 1312 | if debug_pcie_link_aspm; then 1313 | exit 0 1314 | else 1315 | debug_pcie_bridge_lpm "$@" 1316 | exit 0 1317 | fi 1318 | fi 1319 | fi 1320 | fi 1321 | 1322 | ############################################################################## 1323 | if [[ $runtime == off ]]; then 1324 | log_output "\n---Check Runtime PC10 Residency during Screen OFF---:" 1325 | [[ -n "$KERNEL_VER" ]] && log_output "\nThe system OS Kernel version is: 1326 | $KERNEL_VER\n" 1327 | if ! type powertop 1>/dev/null 2>&1; then 1328 | log_output "\033[31mPlease install powertop tool.\033[0m\n" 1329 | else 1330 | powertop --auto-tune 2>&1 1331 | fi 1332 | if pc10_idle_off; then 1333 | log_output "\n" 1334 | elif dmc_check; then 1335 | log_output "\nIntel graphics i915 DMC FW is loaded. Will re-check the deeper 1336 | Package C-state by ignoring PCI Devices LTR value:\n" 1337 | 1338 | #Ignore all the PCI devices LTR values 1339 | ignore_ltr_all 1340 | log_output "All the PCI devices LTR values ignore is done!" 1341 | 1342 | if pc10_idle_off; then 1343 | log_output "\n\033[32mThe deeper CPU Package C-state is available after 1344 | PCI devices LTR ignore, please investigate the potential IP LTR issue.\033[0m\n" 1345 | exit 0 1346 | else 1347 | log_output "\nPCI devices LTR value ignore does not help the PC10, will 1348 | check PCIe Link PM states:\n" 1349 | if debug_pcie_link_aspm; then 1350 | exit 0 1351 | else 1352 | debug_pcie_bridge_lpm "$@" 1353 | exit 0 1354 | fi 1355 | fi 1356 | fi 1357 | fi 1358 | 1359 | ############################################################################## 1360 | if [[ $s2idle == 1 ]]; then 1361 | log_output "\n---Check S2idle path S0ix Residency---:" 1362 | [[ -n "$KERNEL_VER" ]] && log_output "\nThe system OS Kernel version is: 1363 | $KERNEL_VER" 1364 | log_output "\n---Check whether your system supports S0ix or not---:" 1365 | if slp_s0_support; then 1366 | log_output "\n" 1367 | else 1368 | exit 0 1369 | fi 1370 | 1371 | log_output "\n---Check whether intel_pmc_core sysfs files exit---:" 1372 | if pmc_core_check; then 1373 | log_output "\n" 1374 | else 1375 | log_output "\nThe intel_pmc_core sysfs missing will impact S0ix failure analyze.\n" 1376 | fi 1377 | 1378 | log_output "\n---Judge PC10, S0ix residency available status---:" 1379 | pkg_output 1380 | 1381 | case $DEBUG in 1382 | 1) 1383 | log_output "\n---Debug no PC2 residency scenario---:" 1384 | if debug_no_pc2; then 1385 | log_output "\nYour system CPU Core C6 and Intel graphics RC6 is OK, \ 1386 | \nthen this script cannot handle the exception which IP blocked PC2 state. \ 1387 | \nIf your HW is unstable, suggest to re-run this script.\n" 1388 | fi 1389 | ;; 1390 | 2) 1391 | log_output "\n---Debug no PC8 residency scenario---:" 1392 | if debug_no_pc8; then 1393 | log_output "\nYour system CPU Core C7, GFX RC6, PCIe Device D state and \ 1394 | Link PM state are OK, \nbut still did not achieve PC8 after powertop --auto-tune\n" 1395 | else 1396 | judge_dstate_linkstate 1397 | fi 1398 | ;; 1399 | 3) 1400 | log_output "\n---Debug no DC9 residency scenario---:" 1401 | if debug_no_dc9; then 1402 | log_output "\n" 1403 | else 1404 | log_output "\nYour system had potential graphics bug, did not get DC9, \ 1405 | which may block PC10.\n" 1406 | exit 0 1407 | fi 1408 | #If DC9 is OK, will check PCI devices LTR value 1409 | log_output "\n---Debug no PC10 residency scenario--Ignore IP LTR value---:" 1410 | if debug_ltr_value; then 1411 | log_output "\nThis script detects PC10 residency after IP LTR ignore. \ 1412 | \nPlease consider reporting a bug against the potential IP LTR issue \ 1413 | if the test platform is stable. \nMeanwhile this script will continue to check 1414 | the potential S0ix blocker since PC10 is available.\n" 1415 | 1416 | # When PC10 residency is achieved after IP LTR ignore, 1417 | # this script will continue to check the potential S0ix blocker 1418 | if debug_pch_ip_pg; then 1419 | log_output "\n---Debug S0ix failure scenario--Setting No ACPI DSM Callback---:" 1420 | debug_acpi_dsm 1421 | 1422 | log_output "\n---Debug PCIeports D states and link PM states---" 1423 | #Check PCI devices D states 1424 | pci_d3_status_check 1425 | #Check PCIe bridge link PM states 1426 | debug_pcie_bridge_lpm "$@" 1427 | judge_dstate_linkstate 1428 | fi 1429 | #Check ModPHY and CSMe subsystem power gating status 1430 | if [[ -e "${PMC_CORE_SYSFS_PATH}/slp_s0_dbg_latch" ]]; then 1431 | if debug_s0ix; then 1432 | log_output "\nModPHY and CSMe subsystem power gating status are OK\n" 1433 | fi 1434 | fi 1435 | #When checking no-PC10 residency scenario, if ignoring IP LTR value is not \ 1436 | #helpful, then need to check PCIeport D state and Link Power Management state 1437 | else 1438 | log_output "\n---Debug PCIeports D states and link PM states---" 1439 | #Check PCI devices D states 1440 | pci_d3_status_check 1441 | #Check PCIe bridge link PM states 1442 | debug_pcie_bridge_lpm "$@" 1443 | judge_dstate_linkstate 1444 | fi 1445 | ;; 1446 | 4) 1447 | log_output "\n---Debug S0ix failure scenario--PCH IP power gating check---:" 1448 | if debug_pch_ip_pg; then 1449 | log_output "\n---Debug S0ix failure scenario--Setting No ACPI DSM Callback---:" 1450 | debug_acpi_dsm 1451 | 1452 | log_output "\n---Debug PCIeport D states and link PM states---" 1453 | #Check PCI devices D states 1454 | pci_d3_status_check 1455 | #Check PCIe bridge link PM states 1456 | debug_pcie_bridge_lpm "$@" 1457 | judge_dstate_linkstate 1458 | fi 1459 | 1460 | #Check ModPHY and CSMe subsystem power gating status 1461 | if [[ -e "${PMC_CORE_SYSFS_PATH}/slp_s0_dbg_latch" ]]; then 1462 | if debug_s0ix; then 1463 | log_output "\nModPHY and CSMe subsystem power gating status are OK\n" 1464 | fi 1465 | fi 1466 | ;; 1467 | 5) 1468 | log_output "\n---Debug s0i2.0 substate failure scenario---:" 1469 | if [[ -e "${PMC_CORE_SYSFS_PATH}/lpm_latch_mode" ]]; then 1470 | substate_triage "$SHALLOW" "$DEEP" 1471 | fi 1472 | if debug_pch_ip_pg; then 1473 | log_output "\n---Trying S0ix workaround: setting No ACPI DSM Callback---:" 1474 | debug_acpi_dsm 1475 | 1476 | log_output "\n---Debug PCIeport D states and link PM states---" 1477 | #Check PCI devices D states 1478 | pci_d3_status_check 1479 | #Check PCIe bridge link PM states 1480 | debug_pcie_bridge_lpm "$@" 1481 | judge_dstate_linkstate 1482 | fi 1483 | ;; 1484 | esac 1485 | fi 1486 | 1487 | exit 0 1488 | --------------------------------------------------------------------------------