Opportunistic Sleep

From postmarketOS Wiki

Opportunistic sleep is a form of device power management which essentially flips the desktop setup on it's head. On your desktop PC you will put it to sleep when you're going out, or going to bed for example, or maybe if it's been idle for some set time period. Usually your PC will sleep until you manually wake it up again, you don't expect to receive notifications during this time.

Usage

Opportunistic sleep can be enabled with the following:

echo "mem" | sudo tee /sys/power/autosleep

With opportunistic sleep, the device will try to suspend whenever possible, sleeping can be prevented by taking a wakelock:

echo "my_wakelock" | sudo tee /sys/power/wake_lock

And can be allowed again by dropping it:

echo "my_wakelock" | sudo tee /sys/power/wake_unlock

The general idea here is that a wakeup would occur in the kernel (e.g when a sensor device detects an event), the kernel would wakeup and various userspace services could obtain independant (deadlock free!) wakelocks, handle events and then unlock them, allowing the kernel to suspend again.

The caveat here is that some service is required to handle this, otherwise when waking up your device it would shortly go to sleep again. A wakelock must be held while the display is on.

Stated

Note Stated is very work in progress, it isn't ready for use or packaged for postmarketOS yet

stated is a daemon being developed by the Droidian developers which aims to bring Android-style opportunistic sleep to Linux mobile devices, despite it being developed by Droidan, mainline kernels implement wakelock and autosleep support, so it should be feasible to run it on postmarketOS once it becomes more usable.

Required kernel config options

The following options are required for opportunistic sleep to work properly:

CONFIG_PM_WAKELOCKS=y
CONFIG_PM_AUTOSLEEP=y

See also