[systemd-devel] RFC: enable suspend to idle

Thomas Blume Thomas.Blume at suse.com
Thu Mar 1 13:40:22 UTC 2018


Hi,

It seems that major vendors are dropping support of sleep mode S3 in favor of
the new suspend to idle method.
We need to enable this new feature in order to be able to suspend to RAM on
such machines.
The kernel side of this feature has already been implemented:

https://patchwork.kernel.org/patch/9873163

but we need to activate it in userspace.
Each device, supporting suspend to idle from kernel side, has a file called
wakeup in sysfs.
Echoing "enabled" into this file will enable the feature.

As a proof of concept, I have created below udev rule and helper script, which
works on my testmachine.
Obviously, like that it isn't portable to other distros, but I'd like to get
comments whether this is the way to go.
If I get positive feedback, I'll try a portable approach using a binary helper.

udev rule:

-->
ACTION=="add",  ATTR{power/wakeup}=="disabled", IMPORT{program}="/usr/lib/udev/get-wakeup-devices.sh %p"
ENV{RESUME_FROM_IDLE}=="1", ATTR{power/wakeup}="enabled"
--<

helper script:

-->
#!/bin/sh

SYSDEVS=$(find /sys/devices/pci* -name wakeup)
NETWORKDEVS=$(lspci | sed -n '/Ethernet controller/s/^\([[:graph:]]*\).*/\1/p')
USBINPUTDEVS=$(find /sys/devices/pci*/*/usb* -name input)
OTHERDEVS=$(find /sys/devices -name wakeup | sed -n '/serio/p;/pnp/p;/LNXPWRBN/p')

#get ethernet and usb devices
for sysdev in $SYSDEVS; do
         PCIID=$(echo $sysdev | sed -n 's#/sys/devices/pci[[:digit:]]*:[[:digit:]]*/[[:digit:]]*:\([[:digit:]]*:[[:alnum:]]*.[[:alnum:]]\).*#\1#p')
         for netdev in $NETWORKDEVS; do
                 [[ "$PCIID" =~ $netdev ]] && [[ ! "$WAKEUPDEVS" =~ ${sysdev%/power/wakeup} ]] && WAKEUPDEVS+="$sysdev ";
         done
         for usbinputdev in $USBINPUTDEVS; do
                 [[ $usbinputdev =~ $PCIID ]] && [[ ! "$WAKEUPDEVS" =~ ${sysdev%/power/wakeup} ]] && WAKEUPDEVS+="$sysdev ";
         done
done

#get ps2, plug and play and power button devices
for otherdev in $OTHERDEVS; do
         [[ "$WAKEUPDEVS" =~ ${otherdev%/power/wakeup} ]] || WAKEUPDEVS+="$otherdev ";
done

[[ "$WAKEUPDEVS" =~ "$1/power/wakeup" ]] && echo "RESUME_FROM_IDLE=1"
--<


Regards
Thomas Blume

-- 
SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nürnberg)
Maxfeldstr. 5 / D-90409 Nürnberg / Phone: +49-911-740 53 - 0 / VOIP: 3919
GPG 2048R/2CD4D3E8 9A50 048F 1C73 59AA 4D2E  424E B3C6 3FD9 2CD4 D3E8


More information about the systemd-devel mailing list