Power management: Difference between revisions
m (→Active State Power Management: typo fix) |
m (→SATA Active Link Power Management: style: Help:Style/Formatting and punctuation#Configuration parameters, variables, options, properties...) |
||
(274 intermediate revisions by 75 users not shown) | |||
Line 1: | Line 1: | ||
[[Category:Power management]] | [[Category:Power management]] | ||
[[es:Power management]] | [[es:Power management]] | ||
[[ja:電源管理]] | [[ja:電源管理]] | ||
[[ | [[pt:Power management]] | ||
[[ru:Power management]] | |||
[[zh-hans:Power management]] | [[zh-hans:Power management]] | ||
{{Related articles start}} | {{Related articles start}} | ||
{{Related|Power management/Suspend and hibernate}} | {{Related|Power management/Suspend and hibernate}} | ||
{{Related|Power management/Wakeup triggers}} | |||
{{Related|Display Power Management Signaling}} | {{Related|Display Power Management Signaling}} | ||
{{Related|CPU frequency scaling}} | {{Related|CPU frequency scaling}} | ||
Line 14: | Line 15: | ||
{{Related|udev}} | {{Related|udev}} | ||
{{Related articles end}} | {{Related articles end}} | ||
[[Wikipedia:Power management|Power management]] is a feature that turns off the power or switches system components to a low-power state when inactive. | |||
[[Wikipedia:Power management|Power management]] is a feature that turns off the power or switches system | |||
In Arch Linux, power management consists of two main parts: | In Arch Linux, power management consists of two main parts: | ||
Line 27: | Line 27: | ||
== Userspace tools == | == Userspace tools == | ||
Using these tools can replace setting a lot of settings by hand. | 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 [[:Category:Power management|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: | These are the more popular scripts and tools designed to help power saving: | ||
=== Console === | |||
* {{App|[[acpid]]| A daemon for delivering ACPI power management events with netlink support.| | |||
* {{App|[[acpid]]| A daemon for delivering ACPI power management events with netlink support.|https://sourceforge.net/projects/acpid2/|{{Pkg|acpid}}}} | |||
* {{App|[[Laptop Mode Tools]]|Utility to configure laptop power saving settings, considered by many to be the de facto utility for power saving though may take a bit of configuration.|https://github.com/rickysarraf/laptop-mode-tools|{{AUR|laptop-mode-tools}}}} | * {{App|[[Laptop Mode Tools]]|Utility to configure laptop power saving settings, considered by many to be the de facto utility for power saving though may take a bit of configuration.|https://github.com/rickysarraf/laptop-mode-tools|{{AUR|laptop-mode-tools}}}} | ||
* {{App| | * {{App|libsmbios|Library and tools for interacting with Dell SMBIOS tables.|https://github.com/dell/libsmbios|{{Pkg|libsmbios}}}} | ||
* {{App|[[powertop]]|A tool to diagnose issues with power consumption and power management to help set power saving settings.|https:// | * {{App|[[powertop]]|A tool to diagnose issues with power consumption and power management to help set power saving settings.|https://github.com/fenrus75/powertop|{{Pkg|powertop}}}} | ||
* [[systemd]] | * {{App|powerstat|A tool that measures power consumption using the ACPI or Intel RAPL interface.|https://github.com/ColinIanKing/powerstat|{{AUR|powerstat}}}} | ||
* {{App|[[TLP]]|Advanced power management for Linux.| | * {{App|[[systemd]]|A system and service manager.|https://freedesktop.org/wiki/Software/systemd/|{{Pkg|systemd}}}} | ||
* {{App|[[TLP]]|Advanced power management for Linux.|https://linrunner.de/tlp|{{Pkg|tlp}}}} | |||
* {{App|upower|Abstraction for enumerating power devices, listening to device events and querying history and statistics.|https://upower.freedesktop.org|{{Pkg|upower}}}} | |||
== | === Graphical === | ||
* {{App|batsignal|Lightweight battery monitor that uses libnotify to warn of low battery levels.|https://github.com/electrickite/batsignal|{{AUR|batsignal}}}} | |||
* {{App|cbatticon|Lightweight and fast battery icon that sits in your system tray.|https://github.com/valr/cbatticon|{{Pkg|cbatticon}}}} | |||
* {{App|GNOME Power Statistics|System power information and statistics for GNOME.|https://gitlab.gnome.org/GNOME/gnome-power-manager|{{Pkg|gnome-power-manager}}}} | |||
* {{App|KDE Power Devil|Power management module for Plasma.|https://invent.kde.org/plasma/powerdevil|{{Pkg|powerdevil}}}} | |||
* {{App|LXQt Power Management|Power management module for LXQt.|https://github.com/lxqt/lxqt-powermanagement|{{Pkg|lxqt-powermanagement}}}} | |||
* {{App|MATE Power Management|Power management tool for MATE.|https://github.com/mate-desktop/mate-power-manager|{{Pkg|mate-power-manager}}}} | |||
* {{App|MATE Power Statistics|System power information and statistics for MATE.|https://github.com/mate-desktop/mate-power-manager|{{Pkg|mate-power-manager}}}} | |||
* {{App|poweralertd|Daemon for delivering UPower notifications.|https://git.sr.ht/~kennylevinsen/poweralertd|{{AUR|poweralertd}}}} | |||
* {{App|powerkit|Desktop independent power manager.|https://github.com/rodlie/powerkit|{{AUR|powerkit}}}} | |||
* {{App|Xfce Power Manager|Power manager for Xfce.|https://docs.xfce.org/xfce/xfce4-power-manager/start|{{Pkg|xfce4-power-manager}}}} | |||
* {{App|vattery|Battery monitoring application written in Vala that will display the status of a laptop battery in a system tray.|https://www.jezra.net/projects/vattery.html|{{AUR|vattery}}}} | |||
== ACPI events == | |||
''systemd'' handles some power-related [[Wikipedia:Advanced_Configuration_and_Power_Interface|ACPI]] events, whose actions can be configured in {{ic|/etc/systemd/logind.conf}} or {{ic|/etc/systemd/logind.conf.d/*.conf}} — see {{man|5|logind.conf}}. On systems with no dedicated power manager, this may replace the [[acpid]] daemon which is usually used to react to these ACPI events. | ''systemd'' handles some power-related [[Wikipedia:Advanced_Configuration_and_Power_Interface|ACPI]] events, whose actions can be configured in {{ic|/etc/systemd/logind.conf}} or {{ic|/etc/systemd/logind.conf.d/*.conf}} — see {{man|5|logind.conf}}. 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 {{ic|ignore}}, {{ic|poweroff}}, {{ic|reboot}}, {{ic|halt}}, {{ic|suspend}}, {{ic|hibernate}}, {{ic|hybrid-sleep}}, {{ic|lock}} or {{ic|kexec}}. In case of hibernation and suspension, they must be properly [[Power management/Suspend and hibernate|set up]]. If an event is not configured, ''systemd'' will use a default action. | The specified action for each event can be one of {{ic|ignore}}, {{ic|poweroff}}, {{ic|reboot}}, {{ic|halt}}, {{ic|suspend}}, {{ic|hibernate}}, {{ic|hybrid-sleep}}, {{ic|suspend-then-hibernate}}, {{ic|lock}} or {{ic|kexec}}. In case of hibernation and suspension, they must be properly [[Power management/Suspend and hibernate|set up]]. If an event is not configured, ''systemd'' will use a default action. | ||
{| class="wikitable sortable" | {| class="wikitable sortable" | ||
!Event handler | !Event handler | ||
!Description | !Description | ||
Line 71: | Line 86: | ||
|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 inserted in a docking station, or more than one display is connected. | ||
|{{ic|ignore}} | |{{ic|ignore}} | ||
|- | |||
|{{ic|HandleLidSwitchExternalPower}} | |||
|Triggered when the lid is closed if the system is connected to external power. | |||
|action set for {{ic|HandleLidSwitch}} | |||
|} | |} | ||
To apply | To apply changes, [[reload]] {{ic|systemd-logind.service}}. | ||
{{Note|''systemd'' cannot handle AC and Battery ACPI events, so if you use [[Laptop Mode Tools]] or other similar tools [[acpid]] is still required.}} | {{Note| | ||
* ''systemd'' cannot handle AC and Battery ACPI events, so if you use [[Laptop Mode Tools]] or other similar tools [[acpid]] is still required. | |||
* When performing lid switches in short succession, ''logind'' will delay the suspend action for up to 90s to detect possible docks. [https://lists.freedesktop.org/archives/systemd-devel/2015-January/027131.html] This delay was made configurable with systemd v220. [https://github.com/systemd/systemd/commit/9d10cbee89ca7f82d29b9cb27bef11e23e3803ba] You can use e.g. {{ic|HoldoffTimeoutSec{{=}}30s}} in {{ic|logind.conf}} or its drop-in file. | |||
}} | |||
=== Power managers === | |||
Some [[desktop environment]]s include power managers which [ | Some [[desktop environment]]s include power managers which [https://www.freedesktop.org/wiki/Software/systemd/inhibit/ 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 {{ic|/etc/systemd/logind.conf}} or {{ic|/etc/systemd/logind.conf.d/*.conf}} 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. | 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. 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 {{ic|Handle}} options to {{ic|ignore}}. See also {{man|1|systemd-inhibit}}. | ||
=== xss-lock === | |||
{{ | {{pkg|xss-lock}} subscribes to the systemd-events {{ic|suspend}}, {{ic|hibernate}}, {{ic|lock-session}}, and {{ic|unlock-session}} 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. | ||
[[Autostart]]ing the following for example: | |||
xss-lock -- i3lock -n -i ''background_image.png'' & | $ xss-lock -- i3lock -n -i ''background_image.png'' & | ||
== | == Power saving == | ||
{{Note|See [[Laptop#Power management]] for power management specific to laptops, such as battery monitoring. See also pages specific to your CPU and GPU (e.g., [[Ryzen]], [[AMDGPU]]).}} | |||
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 [[#Userspace tools|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 [[Wikipedia:Intel Turbo Boost|dynamic overclocking]]. | |||
=== Processors with Intel HWP (Intel Hardware P-state) support === | |||
{{Merge|CPU frequency scaling|More context in the main article.}} | |||
The available energy preferences of a HWP supported processor are {{ic|default}}, {{ic|performance}}, {{ic|balance_performance}}, {{ic|balance_power}}, {{ic|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: | |||
{{hc|/etc/tmpfiles.d/energy_performance_preference.conf| | |||
w /sys/devices/system/cpu/cpufreq/policy*/energy_performance_preference - - - - balance_power | |||
{{hc|/etc/ | |||
* | |||
}} | }} | ||
See the {{man|8|x86_energy_perf_policy}} man page for more details on energy-performance policy in Intel processors. Also see {{man|8|systemd-tmpfiles}} and {{man|5|tmpfiles.d}} man pages for temporary files/directories details. | |||
==== | === Audio === | ||
== | ==== Kernel ==== | ||
= | |||
By default, audio power saving is turned off by most drivers. It can be enabled by setting the {{ic|power_save}} 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. | By default, audio power saving is turned off by most drivers. It can be enabled by setting the {{ic|power_save}} 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. | ||
{{hc|/etc/modprobe.d/audio_powersave.conf|2=options snd_hda_intel power_save=1}} | {{hc|/etc/modprobe.d/audio_powersave.conf|2= | ||
options snd_hda_intel power_save=1 | |||
}} | |||
Alternatively, use the following for ac97: | Alternatively, use the following for ac97: | ||
Line 331: | Line 159: | ||
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. {{ic|snd_hda_codec_hdmi}} in case of Intel hardware). | 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. {{ic|snd_hda_codec_hdmi}} in case of Intel hardware). | ||
==== Pops when starting and stopping playback ==== | |||
By default, audio sources that have become idle for too long are suspended. When playing a sound or using a microphone, playback or recordings may start with a pop sound. See the dedicated pages for the relevant solution: | |||
* [[Advanced Linux Sound Architecture/Troubleshooting#Pops when starting and stopping playback]] | |||
* [[PulseAudio/Troubleshooting#Pops when starting and stopping playback]] | |||
* [[PipeWire#Noticeable audio delay or audible pop/crack when starting playback]] | |||
=== Backlight === | === Backlight === | ||
Line 337: | Line 173: | ||
=== Bluetooth === | === Bluetooth === | ||
To disable bluetooth completely, [[blacklist]] the {{ic|btusb}} and {{ic|bluetooth}} modules. | To disable bluetooth completely, [[blacklist]] the {{ic|btusb}} and {{ic|bluetooth}} modules. | ||
Line 348: | Line 182: | ||
Or with udev rule: | Or with udev rule: | ||
{{hc|/etc/udev/rules.d/50-bluetooth.rules| | {{hc|/etc/udev/rules.d/50-bluetooth.rules|2= | ||
# disable bluetooth | # disable bluetooth | ||
SUBSYSTEM=="rfkill", ATTR{type}=="bluetooth", ATTR{state}="0" | SUBSYSTEM=="rfkill", ATTR{type}=="bluetooth", ATTR{state}="0" | ||
}} | |||
=== Web camera === | === Web camera === | ||
Line 359: | Line 193: | ||
=== Kernel parameters === | === Kernel parameters === | ||
This section uses | This section uses configurations in {{ic|/etc/sysctl.d/}}, which is ''"a drop-in directory for kernel sysctl parameters."'' See [http://0pointer.de/blog/projects/the-new-configuration-files The New Configuration Files] and more specifically {{man|5|sysctl.d}} for more information. | ||
==== Disabling NMI watchdog ==== | ==== Disabling NMI watchdog ==== | ||
{{Expansion|This or {{ic|nowatchdog}} as can be seen in [[Improving performance#Watchdogs]]}} | {{Expansion|This or {{ic|nowatchdog}} as can be seen in [[Improving performance#Watchdogs]]}} | ||
The [[Wikipedia:Non-maskable interrupt|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: | The [[Wikipedia:Non-maskable interrupt|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: | ||
{{hc|/etc/sysctl.d/disable_watchdog.conf|2=kernel.nmi_watchdog = 0}} | {{hc|/etc/sysctl.d/disable_watchdog.conf|2= | ||
kernel.nmi_watchdog = 0 | |||
}} | |||
or add {{ic|1=nmi_watchdog=0}} to the [[kernel line]] to disable it completely from early boot. | or add {{ic|1=nmi_watchdog=0}} to the [[kernel line]] to disable it completely from early boot. | ||
Line 374: | Line 211: | ||
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): | 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): | ||
{{hc|/etc/sysctl.d/dirty.conf|2=vm.dirty_writeback_centisecs = 6000}} | {{hc|/etc/sysctl.d/dirty.conf|2= | ||
vm.dirty_writeback_centisecs = 6000 | |||
}} | |||
To do the same for journal commits on supported filesystems (e.g. ext4, btrfs...), use {{ic|1=commit=60}} as a option in [[fstab]]. | To do the same for journal commits on supported filesystems (e.g. ext4, btrfs...), use {{ic|1=commit=60}} as a option in [[fstab]]. | ||
Note that this value is modified as a side effect of the Laptop Mode setting below. | 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. | ||
See also [[sysctl#Virtual memory]] for other parameters affecting I/O performance and power saving. | |||
==== Laptop Mode ==== | ==== Laptop Mode ==== | ||
See the [https:// | See the [https://docs.kernel.org/admin-guide/laptops/laptop-mode.html kernel documentation] on the laptop mode "knob" - "A sensible value for the knob is 5 seconds". | ||
{{hc|/etc/sysctl.d/laptop.conf|2=vm.laptop_mode = 5}} | {{hc|/etc/sysctl.d/laptop.conf|2= | ||
vm.laptop_mode = 5 | |||
}} | |||
{{Note|This setting is mainly relevant to spinning-disk drives.}} | {{Note|This setting is mainly relevant to spinning-disk drives.}} | ||
Line 391: | Line 231: | ||
=== Network interfaces === | === 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 | [[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 {{Pkg|iw}} on all wireless interfaces: | ||
{{hc|/etc/udev/rules.d/'''81'''-wifi-powersave.rules|2= | |||
ACTION=="add", SUBSYSTEM=="net", KERNEL=="wl*", RUN+="/usr/bin/iw dev $name set power_save on" | |||
}} | |||
{{ | The name of the configuration file is important. With the use of [[Network configuration#Change interface name|persistent device names]] in systemd, the above network rule, named lexicographically '''after''' {{ic|80-net-setup-link.rules}}, is applied after the device is renamed with a persistent name e.g. {{ic|wlan0}} renamed {{ic|wlp3s0}}. Be aware that the {{ic|RUN}} command is executed after all rules have been processed and must anyway use the persistent name, available in {{ic|$name}} for the matched device. | ||
==== Intel wireless cards (iwlwifi) ==== | |||
{{ | Additional power saving functions of Intel wireless cards with {{ic|iwlwifi}} 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 {{ic|/etc/modprobe.d/iwlwifi.conf}} 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. | Keep in mind that these power saving options are experimental and can cause an unstable system. | ||
Line 416: | Line 269: | ||
==== Active State Power Management ==== | ==== Active State Power Management ==== | ||
From [[Wikipedia:Active State Power Management|Wikipedia]]: | |||
: '''Active-state power management''' ('''ASPM''') is a power management mechanism for PCI Express devices to garner power savings while otherwise in a fully active state. Predominantly, this is achieved through active-state link power management; i.e., the PCI Express serial link is powered down when there is no traffic across it. It is normally used on laptops and other mobile Internet devices to extend battery life. | |||
At boot, the BIOS enables or disables ASPM based on hardware support. To check for support: | |||
# lspci -vv | grep 'ASPM.*abled;' | |||
Fetch available ASPM policies and the current system default using the following: | |||
{{hc|$ cat /sys/module/pcie_aspm/parameters/policy| | |||
[default] performance powersave powersupersave | |||
}} | |||
ASPM | ASPM might be disabled for the following reasons [https://wireless.wiki.kernel.org/en/users/documentation/ASPM]: | ||
# The BIOS disabled it for some reason (for conflicts?). | # 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). | # 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 might not have been programmed for it or may be buggy. | ||
If | If you believe that your hardware has support for ASPM despite the above, it can be force-enabled for the kernel to handle with the {{ic|1=pcie_aspm=force}} [[kernel parameter]]. | ||
{{Warning| | {{Warning| | ||
* | * Force-enabling ASPM on an unsupported system may lead to increased power consumption. Furthermore, it may cause system freezes or kernel panics, so make sure you have a way to undo the option if it is unsuitable. | ||
* | * Forcing ASPM takes place in the kernel, and therefore it may still remain disabled in hardware and not work. To check whether this is the case, run {{ic|dmesg {{!}} grep ASPM}} as root. Consult the Wiki article specific to your hardware for more information if possible. | ||
}} | }} | ||
As long as ASPM is supported and enabled, it is possible to select a desired policy for the current session. For example, switch to {{ic|powersupersave}} for the current session by doing the following: | |||
# echo powersupersave > /sys/module/pcie_aspm/parameters/policy | |||
To configure a specific ASPM state to enable upon system boot (using {{ic|powersupersave}} as an example), add {{ic|1=pcie_aspm.policy=powersupersave}} as a [[kernel parameter]]. | |||
==== PCI Runtime Power Management ==== | |||
{{hc| | {{hc|/etc/udev/rules.d/pci_pm.rules|2= | ||
SUBSYSTEM=="pci", ATTR{power/control}="auto" | |||
}} | |||
==== PCI | 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 {{ic|lspci -nn}} to get these values): | ||
{{hc|/etc/udev/rules.d/pci_pm.rules|2= | |||
# whitelist for pci autosuspend | |||
SUBSYSTEM=="pci", ATTR{vendor}=="0x1234", ATTR{device}=="0x1234", ATTR{power/control}="auto" | |||
}} | |||
Alternatively, to blacklist devices that are not working with PCI runtime power management and enable it for all other devices: | |||
{{hc|/etc/udev/rules.d/pci_pm.rules|2= | |||
# 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 ==== | ==== USB autosuspend ==== | ||
Line 453: | Line 331: | ||
The most simple and likely useless example is enabling autosuspend for all USB devices: | The most simple and likely useless example is enabling autosuspend for all USB devices: | ||
{{hc|/etc/udev/rules.d/50-usb_power_save.rules| | {{hc|/etc/udev/rules.d/50-usb_power_save.rules|2= | ||
ACTION=="add", SUBSYSTEM=="usb", TEST=="power/control", ATTR{power/control}="auto" | ACTION=="add", SUBSYSTEM=="usb", TEST=="power/control", ATTR{power/control}="auto" | ||
}} | |||
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): | 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): | ||
{{hc|/etc/udev/rules.d/50-usb_power_save.rules| | {{hc|/etc/udev/rules.d/50-usb_power_save.rules|2= | ||
# whitelist for usb autosuspend | # whitelist for usb autosuspend | ||
ACTION=="add", SUBSYSTEM=="usb", TEST=="power/control", ATTR{idVendor}=="05c6", ATTR{idProduct}=="9205", ATTR{power/control}="auto" | ACTION=="add", SUBSYSTEM=="usb", TEST=="power/control", ATTR{idVendor}=="05c6", ATTR{idProduct}=="9205", ATTR{power/control}="auto" | ||
}} | |||
Alternatively, to blacklist devices that are not working with USB autosuspend and enable it for all other devices: | Alternatively, to blacklist devices that are not working with USB autosuspend and enable it for all other devices: | ||
{{hc|/etc/udev/rules.d/50-usb_power_save.rules| | {{hc|/etc/udev/rules.d/50-usb_power_save.rules|2= | ||
# blacklist for usb autosuspend | # blacklist for usb autosuspend | ||
ACTION=="add", SUBSYSTEM=="usb", ATTR{idVendor}=="05c6", ATTR{idProduct}=="9205", GOTO="power_usb_rules_end" | ACTION=="add", SUBSYSTEM=="usb", ATTR{idVendor}=="05c6", ATTR{idProduct}=="9205", GOTO="power_usb_rules_end" | ||
Line 472: | Line 350: | ||
ACTION=="add", SUBSYSTEM=="usb", TEST=="power/control", ATTR{power/control}="auto" | ACTION=="add", SUBSYSTEM=="usb", TEST=="power/control", ATTR{power/control}="auto" | ||
LABEL="power_usb_rules_end" | LABEL="power_usb_rules_end" | ||
}} | |||
The default autosuspend idle delay time is controlled by the {{ic|autosuspend}} parameter of the {{ic|usbcore}} built-in [[kernel module]]. To set the delay to 5 seconds instead of the default 2 seconds, add the following [[kernel parameter]] for your boot loader. | |||
{{bc|1=usbcore.autosuspend=5}} | |||
{{ | Similarly to {{ic|power/control}}, the delay time can be fine-tuned per device by setting the {{ic|power/autosuspend}} attribute. This means, alternatively, autosuspend can be disabled by setting {{ic|power/autosuspend}} to -1 (i.e., never autosuspend): | ||
{{hc|/etc/udev/rules.d/50-usb_power_save.rules|2= | |||
ACTION=="add", SUBSYSTEM=="usb", ATTR{idVendor}=="05c6", ATTR{idProduct}=="9205", ATTR{power/autosuspend}="-1" | |||
}} | |||
See the [https:// | See the [https://docs.kernel.org/driver-api/usb/power-management.html Linux kernel documentation] for more information on USB power management. | ||
==== SATA Active Link Power Management ==== | ==== SATA Active Link Power Management ==== | ||
{{ | {{Accuracy|The warning at the start of the section makes it seem like all settings can lead to data loss, while the table implies it's only the lowest setting that may cause it. This should be explicitly clarified.}} | ||
{{Warning|SATA Active Link Power Management can lead to data loss on some devices. Do not enable this setting unless you have frequent backups.}} | |||
Since Linux 4.15 there is a [https://hansdegoede.livejournal.com/18412.html setting] called {{ic|med_power_with_dipm}} that matches the behaviour of Windows IRST driver settings and should not cause data loss with recent SSDs or HDDs. The power saving can be significant, ranging [https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=ebb82e3c79d2a956366d0848304a53648bd6350b from 1.0 to 1.5 Watts (when idle)]. It has become the default setting for Intel based laptops in Linux 4.16 [https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=ebb82e3c79d2a956366d0848304a53648bd6350b]. | |||
The current setting can be read from or written to {{ic|/sys/class/scsi_host/host*/link_power_management_policy}} as follows: | |||
$ grep . /sys/class/scsi_host/host*/link_power_management_policy | |||
$ echo "med_power_with_dipm" >/sys/class/scsi_host/host''N''/link_power_management_policy | |||
{ | {| class="wikitable" | ||
|+ Available ALPM settings | |||
! 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 | |||
|} | |||
{{ | You can configure link_power_management_policy settings persistently by adding an [[udev]] rules file, for example: | ||
{{hc|/etc/udev/rules.d/hd_power_save.rules|2= | |||
ACTION=="add", SUBSYSTEM=="scsi_host", KERNEL=="host*", ATTR{link_power_management_policy}="med_power_with_dipm" | |||
}} | |||
{{Note| | |||
* This adds latency when accessing a drive that has been idle, so it is one of the few settings that may be worth toggling based on whether you are on AC power. | |||
* Not all combinations of SATA host controllers and storage devices work well with the default {{ic|med_power_with_dipm}} setting. For example, as of linux-6.8.1, Intel 7 Series Chipset controllers will experience timeouts and link degradation when accessing Crucial M550 SSDs (with firmware MU02). In such cases, using the {{ic|medium_power}} setting can fix the problem. | |||
}} | |||
=== Hard disk drive === | === Hard disk drive === | ||
Line 498: | Line 417: | ||
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 {{Pkg|iotop}} to see which programs use the disk frequently. See [[Improving performance#Storage devices]] for other tips. | 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 {{Pkg|iotop}} to see which programs use the disk frequently. See [[Improving performance#Storage devices]] for other tips. | ||
Small adjustments such as setting the [[Fstab#atime options|noatime]] option can also help. If enough RAM is available, consider disabling or limiting [[swappiness]] as it has the possibility to limit a good number of disk writes. | |||
For Seagate drives with [https://www.seagate.com/files/docs/pdf/en-GB/whitepaper/tp608-powerchoice-tech-provides-gb.pdf PowerChoice] technology, tricks setting APM via [[hdparm]] will not work due to the ''EPC'' (Extended Power Conditions) feature. Rather than setting APM, you can [[install]] {{AUR|openseachest}} and fully disable EPC like so (replace ''X'' with actual drive letter): | |||
# openSeaChest_PowerControl --scan | |||
# openSeaChest_PowerControl -d /dev/sd''X'' -i | |||
# openSeaChest_PowerControl -d /dev/sd''X'' --showEPCSettings | |||
# openSeaChest_PowerControl -d /dev/sd''X'' --EPCfeature disable | |||
# openSeaChest_PowerControl -d /dev/sd''X'' --showEPCSettings | |||
Last invocation will give the following summary: | |||
=== | ========================================================================================== | ||
openSeaChest_PowerControl - openSeaChest drive utilities - NVMe Enabled | |||
Copyright (c) 2014-2023 Seagate Technology LLC and/or its Affiliates, All Rights Reserved | |||
openSeaChest_PowerControl Version: 3.3.1-4_1_1 X86_64 | |||
Build Date: Jul 4 2023 | |||
Today: Tue Jul 4 17:49:36 2023 User: root | |||
========================================================================================== | |||
/dev/sd''X'' - ST1000NM0008-2F2100 - ZFA19JG2 - SN02 - ATA | |||
===EPC Settings=== | |||
* = timer is enabled | |||
C column = Changeable | |||
S column = Savable | |||
All times are in 100 milliseconds | |||
Name Current Timer Default Timer Saved Timer Recovery Time C S | |||
Idle A 0 *10 *10 1 Y Y | |||
Idle B 0 *1200 *1200 3 Y Y | |||
Idle C 0 6000 6000 16 Y Y | |||
Standby Z 0 9000 9000 46 Y Y | |||
Zeroes in the first column confirm that parking and spindown were disabled successfully | |||
== Tools and scripts == | == Tools and scripts == | ||
Line 510: | Line 460: | ||
=== Using a script and an udev rule === | === Using a script and an udev rule === | ||
Since systemd users can suspend and hibernate through {{ic|systemctl suspend}} or {{ic|systemctl hibernate}} and handle acpi events with {{ic|/etc/systemd/logind.conf}}, it might be interesting to remove | {{Merge|Laptop#Power management|Might be a better fit for the laptop-specific page.}} | ||
Since systemd users can suspend and hibernate through {{ic|systemctl suspend}} or {{ic|systemctl hibernate}} and handle acpi events with {{ic|/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: | |||
{{hc|/etc/udev/rules.d/powersave.rules|2= | {{hc|/etc/udev/rules.d/powersave.rules|2= | ||
SUBSYSTEM=="power_supply", ATTR{online}=="0", RUN+="/path/to/your/script true" | SUBSYSTEM=="power_supply", ATTR{online}=="0", RUN+="/path/to/your/script true" | ||
SUBSYSTEM=="power_supply", ATTR{online}=="1", RUN+="/path/to/your/script false" | SUBSYSTEM=="power_supply", ATTR{online}=="1", RUN+="/path/to/your/script false" | ||
}} | |||
{{Note|You can use the same script that ''pm-powersave'' uses. You just have to make it executable and place it somewhere else (for example {{ic|/usr/local/bin/}}).}} | {{Note|You can use the same script that ''pm-powersave'' uses. You just have to make it executable and place it somewhere else (for example {{ic|/usr/local/bin/}}).}} | ||
Line 523: | Line 475: | ||
* [https://github.com/supplantr/ftw ftw], package: {{AUR|ftw-git}} | * [https://github.com/supplantr/ftw ftw], package: {{AUR|ftw-git}} | ||
* [https://github.com/Unia/powersave powersave] | * [https://github.com/Unia/powersave powersave] | ||
* [https:// | * [https://bbs.archlinux.org/viewtopic.php?id=180762 throttlectl], from {{AUR|throttlectl}} | ||
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 {{ic|/usr/lib/systemd/system-sleep/}} with the following contents: | 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 {{ic|/usr/lib/systemd/system-sleep/}} with the following contents: | ||
{{hc|/usr/lib/systemd/system-sleep/00powersave| | {{hc|/usr/lib/systemd/system-sleep/00powersave| | ||
#!/bin/sh | #!/bin/sh | ||
Line 533: | Line 485: | ||
pre) /path/to/your/script false ;; | pre) /path/to/your/script false ;; | ||
post) | post) | ||
if cat /sys/class/power_supply/AC0/online | if cat /sys/class/power_supply/AC0/online {{!}} grep 0 > /dev/null 2>&1 | ||
then | then | ||
/path/to/your/script true | /path/to/your/script true | ||
Line 542: | Line 494: | ||
esac | esac | ||
exit 0 | exit 0 | ||
}} | |||
Do not forget to make it executable! | Do not forget to make it executable! | ||
Line 548: | Line 500: | ||
{{Note|Be aware that AC0 may be different for your laptop, change it if that is the case.}} | {{Note|Be aware that AC0 may be different for your laptop, change it if that is the case.}} | ||
=== Print power settings === | |||
{{Merge|#Power saving|Might be good as an introduction? Since most of the output of the script can be used by the following sections.}} | |||
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. | 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| | {{bc|1= | ||
#!/bin/bash | #!/bin/bash | ||
Line 568: | Line 520: | ||
for ff in $(find $busdir/power -type f ! -empty 2>/dev/null) | for ff in $(find $busdir/power -type f ! -empty 2>/dev/null) | ||
do | do | ||
v=$(cat $ff 2>/dev/null | v=$(cat $ff 2>/dev/null{{!}}tr -d "\n") | ||
[[ ${#v} -gt 0 ]] && echo -e " ${ff##*/}=$v"; | [[ ${#v} -gt 0 ]] && echo -e " ${ff##*/}=$v"; | ||
v=; | v=; | ||
done | done {{!}} sort -g; | ||
done; | done; | ||
printf "\n\n\n+++ %s\n" "Kernel Modules" | printf "\n\n\n+++ %s\n" "Kernel Modules" | ||
for mod in $(lspci -k | for mod in $(lspci -k {{!}} sed -n '/in use:/s,^.*: ,,p' {{!}} sort -u) | ||
do | do | ||
echo "+ $mod"; | echo "+ $mod"; | ||
systool -v -m $mod 2> /dev/null | systool -v -m $mod 2> /dev/null {{!}} sed -n "/Parameters:/,/^$/p"; | ||
done | done | ||
}} | |||
== Allow users to shutdown == | |||
{{Style|Merged from [[Allow users to shutdown]], needs reorganization to fit into this page.}} | |||
=== Button and lid events === | |||
The suspend, poweroff and hibernate button presses and lid close events are handled by ''logind'' as described in [[#ACPI events]]. | |||
=== Using systemd-logind === | |||
If you are using {{Pkg|polkit}}, users with non-remote session can issue power-related commands as long as [[General troubleshooting#Session permissions|the session is not broken]]. | |||
To check if your session is active | |||
$ loginctl show-session $XDG_SESSION_ID --property=Active | |||
The user can then use ''systemctl'' commands in the command line, or add them to menus: | |||
$ systemctl poweroff | |||
$ systemctl reboot | |||
Other commands can be used as well, including {{ic|systemctl suspend}} and {{ic|systemctl hibernate}}. See the ''System Commands'' section in {{man|1|systemctl}}. | |||
=== Using sudo === | |||
[[Install]] {{Pkg|sudo}}, and give the user [[sudo|sudo privileges]]. The user will then be able to use the {{ic|sudo systemctl}} commands (e.g. {{ic|sudo systemctl poweroff}}, {{ic|sudo systemctl reboot}}, {{ic|sudo systemctl suspend}} and {{ic|sudo systemctl hibernate}}). See the ''System Commands'' section in {{man|1|systemctl}} | |||
==== Users without sudo privileges ==== | |||
If users should only be allowed to use shutdown commands, but not have other sudo privileges, then, as root, add the following to the end of {{ic|/etc/sudoers}} using the {{ic|visudo}} command. Substitute ''user'' for your username and ''hostname'' for the machine's hostname. | |||
''user'' ''hostname'' =NOPASSWD: /usr/bin/systemctl poweroff,/usr/bin/systemctl halt,/usr/bin/systemctl reboot | |||
Now your user can shutdown with {{ic|sudo systemctl poweroff}}, and reboot with {{ic|sudo systemctl reboot}}. Users wishing to power down a system can also use {{ic|sudo systemctl halt}}. Use the {{ic|NOPASSWD:}} tag only if you do not want to be prompted for your password. | |||
== See also == | == See also == | ||
* [ | * [https://www.thinkwiki.org/wiki/How_to_reduce_power_consumption ThinkWiki:How to reduce power consumption] | ||
* [https | * [https://ivanvojtko.blogspot.sk/2016/04/how-to-get-longer-battery-life-on-linux.html How to get longer battery life on Linux] | ||
Latest revision as of 08:43, 31 March 2024
Power management is a feature that turns off the power or switches system 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.
- Laptop Mode Tools — Utility to configure laptop power saving settings, considered by many to be the de facto utility for power saving though may take a bit of configuration.
- libsmbios — Library and tools for interacting with Dell SMBIOS tables.
- powertop — A tool to diagnose issues with power consumption and power management to help set power saving settings.
- powerstat — A tool that measures power consumption using the ACPI or Intel RAPL interface.
- systemd — A system and service manager.
- TLP — Advanced power management for Linux.
- upower — Abstraction for enumerating power devices, listening to device events and querying history and statistics.
Graphical
- batsignal — Lightweight battery monitor that uses libnotify to warn of low battery levels.
- cbatticon — Lightweight and fast battery icon that sits in your system tray.
- GNOME Power Statistics — System power information and statistics for GNOME.
- KDE Power Devil — Power management module for Plasma.
- LXQt Power Management — Power management module for LXQt.
- MATE Power Management — Power management tool for MATE.
- MATE Power Statistics — System power information and statistics for MATE.
- poweralertd — Daemon for delivering UPower notifications.
- powerkit — Desktop independent power manager.
- Xfce Power Manager — Power manager for Xfce.
- vattery — Battery monitoring application written in Vala that will display the status of a laptop battery in a system tray.
ACPI events
systemd handles some power-related ACPI events, whose actions can be configured in /etc/systemd/logind.conf
or /etc/systemd/logind.conf.d/*.conf
— see logind.conf(5). 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 ignore
, poweroff
, reboot
, halt
, suspend
, hibernate
, hybrid-sleep
, suspend-then-hibernate
, lock
or kexec
. 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 |
---|---|---|
HandlePowerKey
|
Triggered when the power key/button is pressed. | poweroff
|
HandleSuspendKey
|
Triggered when the suspend key/button is pressed. | suspend
|
HandleHibernateKey
|
Triggered when the hibernate key/button is pressed. | hibernate
|
HandleLidSwitch
|
Triggered when the lid is closed, except in the cases below. | suspend
|
HandleLidSwitchDocked
|
Triggered when the lid is closed if the system is inserted in a docking station, or more than one display is connected. | ignore
|
HandleLidSwitchExternalPower
|
Triggered when the lid is closed if the system is connected to external power. | action set for HandleLidSwitch
|
To apply changes, reload systemd-logind.service
.
- systemd cannot handle AC and Battery ACPI events, so if you use Laptop Mode Tools or other similar tools acpid is still required.
- When performing lid switches in short succession, logind will delay the suspend action for up to 90s to detect possible docks. [1] This delay was made configurable with systemd v220. [2] You can use e.g.
HoldoffTimeoutSec=30s
inlogind.conf
or its drop-in file.
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 /etc/systemd/logind.conf.d/*.conf
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. 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 Handle
options to ignore
. See also systemd-inhibit(1).
xss-lock
xss-lock subscribes to the systemd-events suspend
, hibernate
, lock-session
, and unlock-session
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.
Autostarting the following for example:
$ xss-lock -- i3lock -n -i background_image.png &
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 default
, performance
, balance_performance
, balance_power
, 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:
/etc/tmpfiles.d/energy_performance_preference.conf
w /sys/devices/system/cpu/cpufreq/policy*/energy_performance_preference - - - - balance_power
See the x86_energy_perf_policy(8) man page for more details on energy-performance policy in Intel processors. Also see systemd-tmpfiles(8) and tmpfiles.d(5) man pages for temporary files/directories details.
Audio
Kernel
By default, audio power saving is turned off by most drivers. It can be enabled by setting the power_save
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
- To retrieve the manufacturer and the corresponding kernel driver which is used for your sound card, run
lspci -k
. - Toggling the audio card's power state can cause a popping sound or noticeable latency on some broken hardware.
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. snd_hda_codec_hdmi
in case of Intel hardware).
Pops when starting and stopping playback
By default, audio sources that have become idle for too long are suspended. When playing a sound or using a microphone, playback or recordings may start with a pop sound. See the dedicated pages for the relevant solution:
- Advanced Linux Sound Architecture/Troubleshooting#Pops when starting and stopping playback
- PulseAudio/Troubleshooting#Pops when starting and stopping playback
- PipeWire#Noticeable audio delay or audible pop/crack when starting playback
Backlight
See Backlight.
Bluetooth
To disable bluetooth completely, blacklist the btusb
and bluetooth
modules.
To turn off bluetooth only temporarily, use rfkill:
# rfkill block bluetooth
Or with udev rule:
/etc/udev/rules.d/50-bluetooth.rules
# disable bluetooth SUBSYSTEM=="rfkill", ATTR{type}=="bluetooth", ATTR{state}="0"
Web camera
If you will not use integrated web camera then blacklist the uvcvideo
module.
Kernel parameters
This section uses configurations in /etc/sysctl.d/
, which is "a drop-in directory for kernel sysctl parameters." See The New Configuration Files and more specifically sysctl.d(5) 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:
/etc/sysctl.d/disable_watchdog.conf
kernel.nmi_watchdog = 0
or add nmi_watchdog=0
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):
/etc/sysctl.d/dirty.conf
vm.dirty_writeback_centisecs = 6000
To do the same for journal commits on supported filesystems (e.g. ext4, btrfs...), use commit=60
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 iw on all wireless interfaces:
/etc/udev/rules.d/81-wifi-powersave.rules
ACTION=="add", SUBSYSTEM=="net", KERNEL=="wl*", RUN+="/usr/bin/iw dev $name set power_save on"
The name of the configuration file is important. With the use of persistent device names in systemd, the above network rule, named lexicographically after 80-net-setup-link.rules
, is applied after the device is renamed with a persistent name e.g. wlan0
renamed wlp3s0
. Be aware that the RUN
command is executed after all rules have been processed and must anyway use the persistent name, available in $name
for the matched device.
Intel wireless cards (iwlwifi)
Additional power saving functions of Intel wireless cards with iwlwifi
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 /etc/modprobe.d/iwlwifi.conf
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.
Bus power management
Active State Power Management
From Wikipedia:
- Active-state power management (ASPM) is a power management mechanism for PCI Express devices to garner power savings while otherwise in a fully active state. Predominantly, this is achieved through active-state link power management; i.e., the PCI Express serial link is powered down when there is no traffic across it. It is normally used on laptops and other mobile Internet devices to extend battery life.
At boot, the BIOS enables or disables ASPM based on hardware support. To check for support:
# lspci -vv | grep 'ASPM.*abled;'
Fetch available ASPM policies and the current system default using the following:
$ cat /sys/module/pcie_aspm/parameters/policy
[default] performance powersave powersupersave
ASPM might be disabled for the following reasons [3]:
- 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 or may be buggy.
If you believe that your hardware has support for ASPM despite the above, it can be force-enabled for the kernel to handle with the pcie_aspm=force
kernel parameter.
- Force-enabling ASPM on an unsupported system may lead to increased power consumption. Furthermore, it may cause system freezes or kernel panics, so make sure you have a way to undo the option if it is unsuitable.
- Forcing ASPM takes place in the kernel, and therefore it may still remain disabled in hardware and not work. To check whether this is the case, run
dmesg | grep ASPM
as root. Consult the Wiki article specific to your hardware for more information if possible.
As long as ASPM is supported and enabled, it is possible to select a desired policy for the current session. For example, switch to powersupersave
for the current session by doing the following:
# echo powersupersave > /sys/module/pcie_aspm/parameters/policy
To configure a specific ASPM state to enable upon system boot (using powersupersave
as an example), add pcie_aspm.policy=powersupersave
as a kernel parameter.
PCI Runtime Power Management
/etc/udev/rules.d/pci_pm.rules
SUBSYSTEM=="pci", ATTR{power/control}="auto"
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 lspci -nn
to get these values):
/etc/udev/rules.d/pci_pm.rules
# whitelist for pci autosuspend SUBSYSTEM=="pci", ATTR{vendor}=="0x1234", ATTR{device}=="0x1234", ATTR{power/control}="auto"
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:
/etc/udev/rules.d/50-usb_power_save.rules
ACTION=="add", SUBSYSTEM=="usb", TEST=="power/control", ATTR{power/control}="auto"
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):
/etc/udev/rules.d/50-usb_power_save.rules
# whitelist for usb autosuspend ACTION=="add", SUBSYSTEM=="usb", TEST=="power/control", ATTR{idVendor}=="05c6", ATTR{idProduct}=="9205", ATTR{power/control}="auto"
Alternatively, to blacklist devices that are not working with USB autosuspend and enable it for all other devices:
/etc/udev/rules.d/50-usb_power_save.rules
# blacklist for usb autosuspend ACTION=="add", SUBSYSTEM=="usb", ATTR{idVendor}=="05c6", ATTR{idProduct}=="9205", GOTO="power_usb_rules_end" ACTION=="add", SUBSYSTEM=="usb", TEST=="power/control", ATTR{power/control}="auto" LABEL="power_usb_rules_end"
The default autosuspend idle delay time is controlled by the autosuspend
parameter of the usbcore
built-in kernel module. To set the delay to 5 seconds instead of the default 2 seconds, add the following kernel parameter for your boot loader.
usbcore.autosuspend=5
Similarly to power/control
, the delay time can be fine-tuned per device by setting the power/autosuspend
attribute. This means, alternatively, autosuspend can be disabled by setting power/autosuspend
to -1 (i.e., never autosuspend):
/etc/udev/rules.d/50-usb_power_save.rules
ACTION=="add", SUBSYSTEM=="usb", ATTR{idVendor}=="05c6", ATTR{idProduct}=="9205", ATTR{power/autosuspend}="-1"
See the Linux kernel documentation for more information on USB power management.
SATA Active Link Power Management
Since Linux 4.15 there is a setting called med_power_with_dipm
that matches the behaviour of Windows IRST driver settings and should not cause data loss with recent SSDs or HDDs. The power saving can be significant, ranging from 1.0 to 1.5 Watts (when idle). It has become the default setting for Intel based laptops in Linux 4.16 [4].
The current setting can be read from or written to /sys/class/scsi_host/host*/link_power_management_policy
as follows:
$ grep . /sys/class/scsi_host/host*/link_power_management_policy $ echo "med_power_with_dipm" >/sys/class/scsi_host/hostN/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 |
You can configure link_power_management_policy settings persistently by adding an udev rules file, for example:
/etc/udev/rules.d/hd_power_save.rules
ACTION=="add", SUBSYSTEM=="scsi_host", KERNEL=="host*", ATTR{link_power_management_policy}="med_power_with_dipm"
- This adds latency when accessing a drive that has been idle, so it is one of the few settings that may be worth toggling based on whether you are on AC power.
- Not all combinations of SATA host controllers and storage devices work well with the default
med_power_with_dipm
setting. For example, as of linux-6.8.1, Intel 7 Series Chipset controllers will experience timeouts and link degradation when accessing Crucial M550 SSDs (with firmware MU02). In such cases, using themedium_power
setting can fix the problem.
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.
Small adjustments such as setting the noatime option can also help. If enough RAM is available, consider disabling or limiting swappiness as it has the possibility to limit a good number of disk writes.
For Seagate drives with PowerChoice technology, tricks setting APM via hdparm will not work due to the EPC (Extended Power Conditions) feature. Rather than setting APM, you can install openseachestAUR and fully disable EPC like so (replace X with actual drive letter):
# openSeaChest_PowerControl --scan # openSeaChest_PowerControl -d /dev/sdX -i # openSeaChest_PowerControl -d /dev/sdX --showEPCSettings # openSeaChest_PowerControl -d /dev/sdX --EPCfeature disable # openSeaChest_PowerControl -d /dev/sdX --showEPCSettings
Last invocation will give the following summary:
========================================================================================== openSeaChest_PowerControl - openSeaChest drive utilities - NVMe Enabled Copyright (c) 2014-2023 Seagate Technology LLC and/or its Affiliates, All Rights Reserved openSeaChest_PowerControl Version: 3.3.1-4_1_1 X86_64 Build Date: Jul 4 2023 Today: Tue Jul 4 17:49:36 2023 User: root ========================================================================================== /dev/sdX - ST1000NM0008-2F2100 - ZFA19JG2 - SN02 - ATA ===EPC Settings=== * = timer is enabled C column = Changeable S column = Savable All times are in 100 milliseconds Name Current Timer Default Timer Saved Timer Recovery Time C S Idle A 0 *10 *10 1 Y Y Idle B 0 *1200 *1200 3 Y Y Idle C 0 6000 6000 16 Y Y Standby Z 0 9000 9000 46 Y Y
Zeroes in the first column confirm that parking and spindown were disabled successfully
Tools and scripts
Using a script and an udev rule
Since systemd users can suspend and hibernate through systemctl suspend
or systemctl hibernate
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:
/etc/udev/rules.d/powersave.rules
SUBSYSTEM=="power_supply", ATTR{online}=="0", RUN+="/path/to/your/script true" SUBSYSTEM=="power_supply", ATTR{online}=="1", RUN+="/path/to/your/script false"
/usr/local/bin/
).Examples of powersave scripts:
- ftw, package: ftw-gitAUR
- powersave
- throttlectl, from throttlectlAUR
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.
#!/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
Allow users to shutdown
Button and lid events
The suspend, poweroff and hibernate button presses and lid close events are handled by logind as described in #ACPI events.
Using systemd-logind
If you are using polkit, users with non-remote session can issue power-related commands as long as the session is not broken.
To check if your session is active
$ loginctl show-session $XDG_SESSION_ID --property=Active
The user can then use systemctl commands in the command line, or add them to menus:
$ systemctl poweroff $ systemctl reboot
Other commands can be used as well, including systemctl suspend
and systemctl hibernate
. See the System Commands section in systemctl(1).
Using sudo
Install sudo, and give the user sudo privileges. The user will then be able to use the sudo systemctl
commands (e.g. sudo systemctl poweroff
, sudo systemctl reboot
, sudo systemctl suspend
and sudo systemctl hibernate
). See the System Commands section in systemctl(1)
Users without sudo privileges
If users should only be allowed to use shutdown commands, but not have other sudo privileges, then, as root, add the following to the end of /etc/sudoers
using the visudo
command. Substitute user for your username and hostname for the machine's hostname.
user hostname =NOPASSWD: /usr/bin/systemctl poweroff,/usr/bin/systemctl halt,/usr/bin/systemctl reboot
Now your user can shutdown with sudo systemctl poweroff
, and reboot with sudo systemctl reboot
. Users wishing to power down a system can also use sudo systemctl halt
. Use the NOPASSWD:
tag only if you do not want to be prompted for your password.