Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

The strange case of the notebook that woke up at night

📅 2017-Apr-16 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ acpi, suspend, wake, wakeup ⬩ 📚 Archive

Problem

In the last week, I started noticing that my notebook, that I had suspended before going to sleep would have woken up during the night! This notebook was running Ubuntu 16.04. It took a bit of investigation to realize that the notebook was being woken up by my new Targus AMW071 wireless mouse. Some slight vibration to the desk during the night would move the mouse and it would wake up Linux from its sleep!

Solution

The list of devices that can wake up Linux from sleep is listed in the file /proc/acpi/wakeup. Each line of that file has a four-letter device code, obtained from BIOS, and whether that device is enabled (can wakeup from sleep) or disabled.

I checked which devices could wakeup my Linux:

$ cat /proc/acpi/wakeup | grep enabled
XHC   S3    *enabled   pci:0000:00:14.0
PWRB      S3    *enabled   platform:PNP0C0C:00
SLPB      S3    *enabled   platform:PNP0C0E:00
LID0      S3    *enabled   platform:PNP0C0D:00

The culprit here was XHC, the USB 3.0 hub to which the mouse was connected. PWRB and SLPB are Power buttons and LID0 is the notebook lid. So, I had to disable the XHC device in this file. Now, if the device name is written to this file, that operation toggles the enabled or disabled state for that device.

So, to disable my mouse from waking up my notebook, I created this shell script:

#!/bin/bash
# disable_wakeup.sh
echo "XHC" > /proc/acpi/wakeup

And I executed that file with superuser privileges:

$ sudo ./disable_wakeup.sh

I could see that this had disabled the mouse from waking up my notebook:

$ cat /proc/acpi/wakeup | grep enabled
PWRB      S3    *enabled   platform:PNP0C0C:00
SLPB      S3    *enabled   platform:PNP0C0E:00
LID0      S3    *enabled   platform:PNP0C0D:00

I suspended the notebook and also verified that indeed the mouse could not wake it up.

The only problem left now was that this toggle would apply only for this Linux session. A system reboot would put back the XHC device in enabled state. To run this toggle script on every system reboot:

$ sudo crontab -e
@reboot /home/joe/scripts/disable_wakeup.sh

Now I had a permanent solution that makes sure that the mouse can never wake up my Ubuntu from sleep! 😊

Reference:


© 2022 Ashwin Nanjappa • All writing under CC BY-SA license • 🐘 @codeyarns@hachyderm.io📧