Tuesday 4 February 2020

Ubuntu Linux on Lenovo Yoga S940: laptop randomly wakes up from sleep


First it appeared that the laptop would properly go to sleep when the lid was closed. But after I carried the laptop in the backpack it often was on. I also saw some characters in the password field. Perhaps some keys  were accidentally  pressed through the lid due  to its flex. The other hypothesis is that some devices such as USB controllers or wifi card could wake up the laptop.


It turned out that the default sleep state was S0 or s2idle (more on ACPI states).
In this state computer reduces the power consumption but CPU and RAM are still powered up. The con of this mode is increased power consumption and the fact that it was randomly waking up. Pro is that computer wakes up very quickly. Another option is suspend to RAM, also called deep sleep or ACPI state S3. I followed the instruction and changed the default sleep state from S1 to S3. The wake up time is still fast and we save a lot of battery comparing to suspend.

The default sleep state in ubuntu linux is stored in the file
/sys/power/mem_sleep
Output of
cat  /sys/power/mem_sleep

on my laptop was following

[s2idle] deep

To change the default sleep state from idle to deep (S1 and S3 correspondingly) I ran

echo deep > /sys/power/mem_sleep

It is important to run this command as a root. Sudo would not do the job because only echo will be executed with the root status and > would have normal status and will not be able to write into the file.

After the reboot the sleep state would be reverted to idle. To avoid it as was indicated in the instruction I added
mem_sleep_default=deep
into the GRUB_CMDLINE_LINUX_DEFAULT line in the file /etc/default/grub.
Initial line was
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
and became
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash mem_sleep_default=deep"

don't forget  to run
sudo update-grub.

Now laptop goes to sleep and wakes up with no problems only when I open the lid.

No comments: