Power management
Power management is a feature that turns off the power or switches system's components to a low-power state when inactive.
In Arch Linux, power management consists of two main parts:
- Configuration of the Linux kernel, which interacts with the hardware.
- Configuration of userspace tools, which interact with the kernel and react to its events. Many userspace tools also allow to modify kernel configuration in a "user-friendly" way. See #Userspace tools for the options.
Userspace tools
Using these tools can replace setting a lot of settings by hand. Only run one of these tools to avoid possible conflicts as they all work more or less similarly. Have a look at the power management category to get an overview on what power management options exist in Arch Linux.
These are the more popular scripts and tools designed to help power saving:
Console
- acpid — A daemon for delivering ACPI power management events with netlink support.
- TLP — Advanced power management for Linux.
Graphical
- batsignal — Lightweight battery monitor that uses libnotify to warn of low battery levels.
- Xfce Power Manager — Power manager for Xfce.
Power management with systemd
ACPI events
systemd handles some power-related ACPI events, whose actions can be configured in /etc/systemd/logind.conf
or — see . On systems with no dedicated power manager, this may replace the acpid daemon which is usually used to react to these ACPI events.
The specified action for each event can be one of , , , , , hibernate
, hybrid-sleep
, , or . In case of hibernation and suspension, they must be properly set up. If an event is not configured, systemd will use a default action.
Event handler | Description | Default action |
---|---|---|
Triggered when the power key/button is pressed. | ||
Triggered when the suspend key/button is pressed. | ||
Triggered when the hibernate key/button is pressed. | hibernate | |
Triggered when the lid is closed, except in the cases below. | ||
Triggered when the lid is closed if the system is inserted in a docking station, or more than one display is connected. | ||
Triggered when the lid is closed if the system is connected to external power. | action set for |
To apply any changes, signal systemd-logind
with HUP
:
# systemctl kill -s HUP systemd-logind
Power managers
Some desktop environments include power managers which inhibit (temporarily turn off) some or all of the systemd ACPI settings. If such a power manager is running, then the actions for ACPI events can be configured in the power manager alone. Changes to /etc/systemd/logind.conf
or need be made only if you wish to configure behaviour for a particular event that is not inhibited by the power manager.
Note that if the power manager does not inhibit systemd for the appropriate events you can end up with a situation where systemd suspends your system and then when the system is woken up the other power manager suspends it again. As of December 2016, the power managers of KDE, GNOME, Xfce and MATE issue the necessary inhibited commands. If the inhibited commands are not being issued, such as when using acpid or others to handle ACPI events, set the options to . See also .
xss-lock
subscribes to the systemd-events , hibernate
, , and with appropriate actions (run locker and wait for user to unlock or kill locker). xss-lock also reacts to DPMS events and runs or kills the locker in response.
Start xss-lock in your autostart, for example
xss-lock -- i3lock -n -i background_image.png &
Suspend and hibernate
systemd provides commands to suspend to RAM or hibernate using the kernel's native suspend/resume functionality. There are also mechanisms to add hooks to customize pre- and post-suspend actions.
should work out of the box, for to work on your system you need to follow the instructions at Suspend and hibernate#Hibernation.
There are also two modes combining suspend and hibernate:
systemctl hybrid-sleep
suspends the system both to RAM and disk, so a complete power loss does not result in lost data. This mode is also called suspend to both.- initially suspends the system to RAM and if it is not interrupted within the delay specified by in systemd-sleep.conf(5), then the system will be woken using an RTC alarm and hibernated.
Hybrid-sleep on suspend or hibernation request
It is possible to configure systemd to always do a hybrid-sleep even on a suspend or hibernation request.
The default suspend and hibernation action can be configured in the file. To set both actions to hybrid-sleep:
See the manual page for details and the linux kernel documentation on power states.
Disabling suspend
When using a device as e.g a server, suspending might not be needed or it could even be undesired. Any sleep state can be configured:
Suspend/resume service files
Service files can be hooked into suspend.target, hibernate.target, sleep.target, hybrid-sleep.target and suspend-then-hibernate.target to execute actions before or after suspend/hibernate. Separate files should be created for user actions and root/system actions. Enable the and resume@user
services to have them started at boot. Examples:
For root/system actions (enable the and root-suspend
services to have them started at boot):
Combined Suspend/resume service file
With the combined suspend/resume service file, a single hook does all the work for different phases (sleep/resume) and for different targets (suspend/hibernate/hybrid-sleep).
Example and explanation:
RemainAfterExit=yes
: After started, the service is considered active until it is explicitly stopped.- : When active, the service will be stopped if no other active service requires it. In this specific example, it will be stopped after sleep.target is stopped.
- Because sleep.target is pulled in by suspend.target, hibernate.target and hybrid-sleep.target and because sleep.target itself is a StopWhenUnneeded service, the hook is guaranteed to start/stop properly for different tasks.
Generic service template
In this example, we create a template service which we can then use to hook any existing systemd service to power events:
Then enable an instance of this template by specifying the basename of an existing systemd service after the , i.e., . See for more details on templates.
Hooks in /usr/lib/systemd/system-sleep
systemd runs all executables in /usr/lib/systemd/system-sleep/
, passing two arguments to each of them:
- Argument 1: either or , depending on whether the machine is going to sleep or waking up
- Argument 2: ,
hibernate
orhybrid-sleep
, depending on which is being invoked
systemd will run these scripts concurrently and not one after another.
The output of any custom script will be logged by systemd-suspend.service, systemd-hibernate.service or systemd-hybrid-sleep.service. You can see its output in systemd's journalctl:
# journalctl -b -u systemd-suspend.service
An example of a custom sleep script:
Do not forget to make your script executable.
See and for more details.
Delayed lid switch action
When performing lid switches in short succession, logind will delay the suspend action for up to 90s to detect possible docks. This delay was made configurable with systemd v220:
Suspend from corresponding laptop Fn key not working
If, regardless of the setting in logind.conf, the sleep button does not work (pressing it does not even produce a message in syslog), then logind is probably not watching the keyboard device. Do:
# journalctl --grep="Watching system buttons"
You might see something like this:
May 25 21:28:19 vmarch.lan systemd-logind[210]: Watching system buttons on /dev/input/event2 (Power Button) May 25 21:28:19 vmarch.lan systemd-logind[210]: Watching system buttons on /dev/input/event3 (Sleep Button) May 25 21:28:19 vmarch.lan systemd-logind[210]: Watching system buttons on /dev/input/event4 (Video Bus)
Notice no keyboard device. Now obtain ATTRS{name} for the parent keyboard device :
Now write a custom udev rule to add the "power-switch" tag:
Restart systemd-udevd.service
, reload rules by running as root, and restart .
Now you should see in syslog.
PC will not wake from sleep on A520I and B550I motherboards
On some motherboards with A520i and B550i chipsets, the system will not completely enter the sleep state or come out of it. Symptoms include the system entering sleep and the monitor turning off while internal LEDs on the motherboard or the power LED stay on. Subsequently, the system will not come back from this state and require a hard power off. If you have similar issues with AMD, first make sure your system is fully updated and check whether the AMD microcode package is installed.
Verify the line starting with has the enabled status:
$ cat /proc/acpi/wakeup
Device S-state Status Sysfs node GP12 S4 *enabled pci:0000:00:07.1 GP13 S4 *enabled pci:0000:00:08.1 XHC0 S4 *enabled pci:0000:0b:00.3 GP30 S4 *disabled GP31 S4 *disabled PS2K S3 *disabled '''GPP0''' S4 '''*enabled''' pci:0000:00:01.1 GPP8 S4 *enabled pci:0000:00:03.1 PTXH S4 *enabled pci:0000:05:00.0 PT20 S4 *disabled PT24 S4 *disabled PT26 S4 *disabled PT27 S4 *disabled PT28 S4 *enabled pci:0000:06:08.0 PT29 S4 *enabled pci:0000:06:09.0
If that is enabled, you can run the following command:
# echo GPP0 > /proc/acpi/wakeup
Now test by running and let the system go to sleep. Then try to wake the system after a few seconds. If it works, you can make the workaround permanent. Create a systemd unit file:
Do a daemon-reload and start/enable the newly created unit.
Power saving
This section is a reference for creating custom scripts and power saving settings such as by udev rules. Make sure that the settings are not managed by some other utility to avoid conflicts.
Almost all of the features listed here are worth using whether or not the computer is on AC or battery power. Most have negligible performance impact and are just not enabled by default because of commonly broken hardware/drivers. Reducing power usage means reducing heat, which can even lead to higher performance on a modern Intel or AMD CPU, thanks to dynamic overclocking.
Processors with Intel HWP (Intel Hardware P-state) support
The available energy preferences of a HWP supported processor are , , , , power
.
This can be validated by running
$ cat /sys/devices/system/cpu/cpufreq/policy?/energy_performance_available_preferences
To conserve more energy, you can configuration by creating the following file:
See the and man pages for details.
Kernel
By default, audio power saving is turned off by most drivers. It can be enabled by setting the parameter; a time (in seconds) to go into idle mode. To idle the audio card after one second, create the following file for Intel soundcards.
/etc/modprobe.d/audio_powersave.conf
options snd_hda_intel power_save=1
Alternatively, use the following for ac97:
options snd_ac97_codec power_save=1
It is also possible to further reduce the audio power requirements by disabling the HDMI audio output, which can done by blacklisting the appropriate kernel modules (e.g. in case of Intel hardware).
PulseAudio
By default, PulseAudio suspends any audio sources that have become idle for too long. When using an external USB microphone, recordings may start with a pop sound. As a workaround, comment out the following line in :
load-module module-suspend-on-idle
Afterwards, restart PulseAudio with .
Backlight
See Backlight.
Bluetooth
To disable bluetooth completely, blacklist the and bluetooth
modules.
To turn off bluetooth only temporarily, use rfkill:
# rfkill block bluetooth
Or with udev rule:
Web camera
If you will not use integrated web camera then blacklist the module.
Kernel parameters
This section uses configurations in , which is "a drop-in directory for kernel sysctl parameters." See The New Configuration Files and more specifically for more information.
Disabling NMI watchdog
The NMI watchdog is a debugging feature to catch hardware hangs that cause a kernel panic. On some systems it can generate a lot of interrupts, causing a noticeable increase in power usage:
or add to the kernel line to disable it completely from early boot.
Writeback Time
Increasing the virtual memory dirty writeback time helps to aggregate disk I/O together, thus reducing spanned disk writes, and increasing power saving. To set the value to 60 seconds (default is 5 seconds):
To do the same for journal commits on supported filesystems (e.g. ext4, btrfs...), use as a option in fstab.
Note that this value is modified as a side effect of the Laptop Mode setting below. See also sysctl#Virtual memory for other parameters affecting I/O performance and power saving.
Laptop Mode
See the kernel documentation on the laptop mode "knob". "A sensible value for the knob is 5 seconds."
/etc/sysctl.d/laptop.conf
vm.laptop_mode = 5
Network interfaces
Wake-on-LAN can be a useful feature, but if you are not making use of it then it is simply draining extra power waiting for a magic packet while in suspend. You can adapt the Wake-on-LAN#udev rule to disable the feature for all ethernet interfaces. To enable powersaving with on all wireless interfaces:
The name of the configuration file is important. With the use of persistent device names in systemd, the above network rule, named lexicographically after , is applied after the device is renamed with a persistent name e.g. renamed wlp3s0
. Be aware that the command is executed after all rules have been processed and must anyway use the persistent name, available in for the matched device.
Intel wireless cards (iwlwifi)
Additional power saving functions of Intel wireless cards with driver can be enabled by passing the correct parameters to the kernel module. Making them persistent can be achieved by adding the lines below to the file:
options iwlwifi power_save=1
This option will probably increase your median latency:
options iwlwifi uapsd_disable=0
On kernels < 5.4 you can use this option, but it will probably decrease your maximum throughput:
options iwlwifi d0i3_disable=0
Depending on your wireless card one of these two options will apply.
options iwlmvm power_scheme=3
options iwldvm force_cam=0
You can check which one is relevant by checking which of these modules is running using
# lsmod | grep '^iwl.vm'
Keep in mind that these power saving options are experimental and can cause an unstable system.
Active State Power Management
If the computer is believed not to support ASPM it will be disabled on boot:
# lspci -vv | grep 'ASPM.*abled;'
ASPM is handled by the BIOS, if ASPM is disabled it will be because :
- The BIOS disabled it for some reason (for conflicts?).
- PCIE requires ASPM but L0s are optional (so L0s might be disabled and only L1 enabled).
- The BIOS might not have been programmed for it.
- The BIOS is buggy.
If believing the computer has support for ASPM it can be forced on for the kernel to handle with the kernel parameter.
- Forcing on ASPM can cause a freeze/panic, so make sure you have a way to undo the option if it does not work.
- On systems that do not support it forcing on ASPM can even increase power consumption.
- This forces ASPM in kernel while it can still remain disabled in hardware and not work. To check whether this is the case, run
dmesg | grep ASPM
as root. If so, consult the Wiki article specific to your hardware.
To adjust to do (the following command will not work unless enabled):
# echo powersave > /sys/module/pcie_aspm/parameters/policy
By default it looks like this:
PCI Runtime Power Management
The rule above powers all unused devices down, but some devices will not wake up again. To allow runtime power management only for devices that are known to work, use simple matching against vendor and device IDs (use to get these values):
Alternatively, to blacklist devices that are not working with PCI runtime power management and enable it for all other devices:
/etc/udev/rules.d/pci_pm.rules
# blacklist for pci runtime power management SUBSYSTEM=="pci", ATTR{vendor}=="0x1234", ATTR{device}=="0x1234", ATTR{power/control}="on", GOTO="pci_pm_end" SUBSYSTEM=="pci", ATTR{power/control}="auto" LABEL="pci_pm_end"
USB autosuspend
The Linux kernel can automatically suspend USB devices when they are not in use. This can sometimes save quite a bit of power, however some USB devices are not compatible with USB power saving and start to misbehave (common for USB mice/keyboards). udev rules based on whitelist or blacklist filtering can help to mitigate the problem.
The most simple and likely useless example is enabling autosuspend for all USB devices:
To allow autosuspend only for devices that are known to work, use simple matching against vendor and product IDs (use lsusb to get these values):
Alternatively, to blacklist devices that are not working with USB autosuspend and enable it for all other devices:
The default autosuspend idle delay time is controlled by the parameter of the built-in kernel module. To set the delay to 5 seconds instead of the default 2 seconds, add the following kernel parameter for your bootloader.
usbcore.autosuspend=5
Similarly to , the delay time can be fine-tuned per device by setting the attribute. This means, alternatively, autosuspend can be disabled by setting to -1 (i.e., never autosuspend):
See the Linux kernel documentation for more information on USB power management.
SATA Active Link Power Management
Since Linux 4.15 there is a new setting called that matches the behaviour of Windows IRST driver settings and should not cause data loss with recent SSD/HDD drives. The power saving can be significant, ranging from 1.0 to 1.5 Watts (when idle). It will become a default setting for Intel based laptops in Linux 4.16 .
The current setting can be read from as follows:
$ cat /sys/class/scsi_host/host*/link_power_management_policy
Setting | Description | Power saving |
---|---|---|
max_performance | current default | None |
medium_power | - | ~1.0 Watts |
med_power_with_dipm | recommended setting | ~1.5 Watts |
min_power | WARNING: possible data loss | ~1.5 Watts |
Hard disk drive
See hdparm#Power management configuration for drive parameters that can be set.
Power saving is not effective when too many programs are frequently writing to the disk. Tracking all programs, and how and when they write to disk is the way to limit disk usage. Use iotop to see which programs use the disk frequently. See Improving performance#Storage devices for other tips.
Also little things like setting the noatime option can help. If enough RAM is available, consider disabling or limiting swappiness as it has the possibility to limit a good number of disk writes.
Tools and scripts
Using a script and an udev rule
Since systemd users can suspend and hibernate through or and handle acpi events with /etc/systemd/logind.conf
, it might be interesting to remove pm-utils and acpid. There is just one thing systemd cannot do (as of systemd-204): power management depending on whether the system is running on AC or battery. To fill this gap, you can create a single udev rule that runs a script when the AC adapter is plugged and unplugged:
Examples of powersave scripts:
- ftw, package:
- powersave
- throttlectl, from
The above udev rule should work as expected, but if your power settings are not updated after a suspend or hibernate cycle, you should add a script in /usr/lib/systemd/system-sleep/
with the following contents:
/usr/lib/systemd/system-sleep/00powersave
#!/bin/sh case $1 in pre) /path/to/your/script false ;; post) if cat /sys/class/power_supply/AC0/online | grep 0 > /dev/null 2>&1 then /path/to/your/script true else /path/to/your/script false fi ;; esac exit 0
Do not forget to make it executable!
Print power settings
This script prints power settings and a variety of other properties for USB and PCI devices. Note that root permissions are needed to see all settings.
{{bc|1=
- !/bin/bash
for i in $(find /sys/devices -name "bMaxPower") do busdir=${i%/*} busnum=$(<$busdir/busnum) devnum=$(<$busdir/devnum) title=$(lsusb -s $busnum:$devnum)
printf "\n\n+++ %s\n -%s\n" "$title" "$busdir"
for ff in $(find $busdir/power -type f ! -empty 2>/dev/null) do v=$(cat $ff 2>/dev/null|tr -d "\n") [[ ${#v} -gt 0 ]] && echo -e " ${ff##*/}=$v"; v=; done | sort -g; done;
printf "\n\n\n+++ %s\n" "Kernel Modules" for mod in $(lspci -k | sed -n '/in use:/s,^.*: ,,p' | sort -u) do echo "+ $mod"; systool -v -m $mod 2> /dev/null | sed -n "/Parameters:/,/^$/p"; done }}