For people running Linux on their laptop, have you experienced this strange problem regarding laptop sleep where your screen would become strangely unresponsive after waking up? Are you using an Intel CPU? And if you're using a discrete GPU (most likely NVIDIA), then does it disconnect for no reason after some time? If at least the first two are "yes", you should see if these steps will solve the problem you are having.
Step 1. List all C-states available from your CPU
C-states are designed to lower your machine's overall power consumption when your laptop is sleeping. Open a terminal and run this command to expose available C-states:
$ grep . /sys/devices/system/cpu/cpu0/cpuidle/state*/name
Here is an example output provided by my machine:
/sys/devices/system/cpu/cpu0/cpuidle/state0/name:POLL /sys/devices/system/cpu/cpu0/cpuidle/state1/name:C1E /sys/devices/system/cpu/cpu0/cpuidle/state2/name:C6 /sys/devices/system/cpu/cpu0/cpuidle/state3/name:C8
Generally, the higher the C-state number is, the more aggressive the CPU will be in terms of power saving. See this webpage for additional info: https://www.thomas-krenn.com/en/wiki/Processor_P-states_and_C-states
Take note of the command's output and the order of C-states' appearance. Assume that the list's index begins at 0, taking my example output as the basis, "POLL" would have an index of 0, "C1E" an index of 1, "C6" an index of 2, and "C8" an index of 3. This will be relevant soon.
Step 2. Review the current maximum possible C-state your laptop can access
Run this command in the terminal to examine this:
$ cat /sys/module/intel_idle/parameters/max_cstate
See its output and check if it matches any of the index which we noted earlier. If the index that this command outputs does not exist in the indexed list of C-states you reviewed, then there is a good chance this is causing the underlying problems that the post's introduction text laid out.
For example, my laptop outputted this index:
9
This index, when compared against the earlier list which I indexed, does not exist.
Step 3. Modify your OS's kernel parameters to declare the maximum C-state
This is where you may need to consult your OS's instructions for editing the kernel parameters, as distros may handle these differently from one another.
For Arch Linux, go to this page: https://wiki.archlinux.org/title/Kernel_parameters#Boot_loader_configuration
For Fedora Linux, go to this page: https://docs.fedoraproject.org/en-US/quick-docs/grub2-bootloader/
Since many distributions use the GRUB 2 bootloader, I will assume you are using it. Use any text editor (nano, micro, Kate, KWrite, whatever) to edit "/etc/default/grub". Kernel parameters may be located in either the "GRUB_CMDLINE_DEFAULT" or the "GRUB_CMDLINE_LINUX_DEFAULT" variable. For example, the file initially looked like this on my laptop:
GRUB_TIMEOUT=5 GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)" GRUB_DEFAULT=saved GRUB_DISABLE_SUBMENU=true GRUB_TERMINAL_OUTPUT="console" GRUB_CMDLINE_LINUX="rhgb quiet rd.driver.blacklist=nouveau,nova_core modprobe.blacklist=nouveau,nova_core" GRUB_DISABLE_RECOVERY="true" GRUB_ENABLE_BLSCFG=true
Consult the indexed C-state list you made and look at the index of the highest C-state number available. There, add this kernel parameter, with "n" being the index you looked at:
intel_idle.max_cstate=n
For example on my machine, the highest C-state "C8" has an index of 3, so on my side I will add "intel_idle.max_cstate=3" to the parameters. The resulting file now looks like this:
GRUB_TIMEOUT=5 GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)" GRUB_DEFAULT=saved GRUB_DISABLE_SUBMENU=true GRUB_TERMINAL_OUTPUT="console" GRUB_CMDLINE_LINUX="rhgb quiet rd.driver.blacklist=nouveau,nova_core modprobe.blacklist=nouveau,nova_core intel_idle.max_cstate=3" GRUB_DISABLE_RECOVERY="true" GRUB_ENABLE_BLSCFG=true
Save the edited "/etc/default/grub" file as root, and then regenerate the GRUB 2 configuration file. On some distributions, including Arch Linux with GRUB 2, the command may be:
$ sudo grub-mkconfig -o /boot/grub/grub.cfg
However, other distributions including Fedora Linux may require this command to be used instead:
$ sudo grub2-mkconfig -o /boot/grub2/grub.cfg
Step 4. Restart your machine, and test sleeping & long-term usage
If the laptop can sleep and wake up consistently without any problem, and if you can use it without any symptoms in the middle of your work (e.g. discrete graphics card disconnecting), then you're good to go.
Extra: My rambling regarding this same problem 6 months ago: https://tsuchikyo-a.tumblr.com/post/805453371150565376









