Power management
🚧 | This page is a work-in-progress. Some information contained within may be inaccurate or incomplete.
In particular: Needs fact checking by actual developers |
Power Management is a feature that turns off the power or switches system components to a low-power state when inactive in order to save the power and extend the battery life of a device.
Every power management technique can be put into two major categories:
- idle - saves the power when the system is not doing any work (e.g. by shutting down some hardware)
- active - saves the power when the system is doing some work (e.g. by scaling down the CPU frequency)
In the context of postmarketOS we mostly talk about the power management of the battery.
Power saving
CPU Frequency Scaling
The kernel can set the CPU governors that can adjust the CPU frequency.
The most used on postmarketOS is the schedutil
governor, which is designed to be more efficient than other schedulers, in terms of energy consumption. This is because schedutil
uses information about the utilization of individual CPU cores to make more intelligent decisions about when and how to scale the frequency of the CPU. Additionally, schedutil
can also help improve the overall performance of the device by ensuring that the CPU is able to operate at its maximum frequency when needed.
There are also other governors not used by default, and the most self-explanatory are:
performance
powersave
ondemand
Sleep/Suspend modes
There are many various sleep modes like Suspend-to-Idle, Standby, Suspend-to-RAM, Hibernation and combinations of these. We typically use Standby or Suspend-to-RAM to save the power when not using our devices.
The kernel's Standby mode is used for example in Phosh which just powers down the display and puts the system into a low-power mode, keeping everything working in the background.
When the device is suspended to RAM the kernel freezes all processes and then sets all peripherals (excluding the modem) to their own power saving modes or shuts them down (if we don't need them to wake up later). Saves the state of the device into RAM which it keeps self-refreshing and powered on. This saves a lot of power, at the cost of wake-up time and network messages.
Android for example uses the Doze Mode, as described on developer.android.com:
If a user leaves a device unplugged and stationary for a period of time, with the screen off, the device enters Doze mode. In Doze mode, the system attempts to conserve battery by restricting apps' access to network and CPU-intensive services. It also prevents apps from accessing the network and defers their jobs, syncs, and standard alarms.
Periodically, the system exits Doze for a brief time to let apps complete their deferred activities. During this maintenance window, the system runs all pending syncs, jobs, and alarms, and lets apps access the network.
Push notifications
It's important to receive notifications from network during sleep, but (unlike calls or SMS messages) receiving events from the network is impossible when suspended to RAM.
Some peripherals can wake up the system and in mobile devices the modem belongs to these. The modem goes only into a power-saving mode and still keeps the connection with the cellular network and if it receives a call or a message it wakes up the system.
In the Standby mode the system can keep the active connection(s) to the services on the network. The problem is we can't keep running every application and have active connection to every service because the battery drains out.
In Android after Standby the Doze Mode is used which limits background activity and apps' access to the network. And to have the notifications these apps/services use the Firebase Cloud Messaging (FCM) to "push" the messages directly onto a device, waking it up and showing the notification.
Apple's equivalent of FCM is Apple Push Notification service (APN).
The solution
On Linux we can use the UnifiedPush protocol which standardizes the connection between services, the push notification services and on-device notification systems e.g. dbus.
Power monitoring
The battery information can be displayed by system monitors, more advanced GUI and TUI apps or scripts.