Difference between revisions of "Power saving"

From ArchWiki
Jump to: navigation, search
(update Pkg/AUR templates (testing https://github.com/lahwaacz/wiki-scripts/blob/master/update-package-templates.py))
(merged to Power management, redirecting there)
 
(28 intermediate revisions by 9 users not shown)
Line 1: Line 1:
[[Category:Power management]]
+
#REDIRECT [[Power management]]
[[ja:Power saving]]
 
{{Related articles start}}
 
{{Related|Power management}}
 
{{Related|CPU frequency scaling}}
 
{{Related|Hybrid graphics}}
 
{{Related|Kernel modules}}
 
{{Related|sysctl}}
 
{{Related|udev}}
 
{{Related articles end}}
 
This article covers the configuration needed to turn on power saving features. 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]].
 
 
 
== Configuration ==
 
 
 
If you would like to create your own scripts and power saving settings such as by udev rules you can take the following settings as a reference.
 
 
 
{{Note|Most rules described below are also managed by tools like [[TLP]] and it is unwise to use multigoverning.}}
 
 
 
=== Audio ===
 
 
 
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
 
 
 
{{hc|/etc/modprobe.d/audio_powersave.conf|2=options snd_hda_intel power_save=1}}
 
 
 
for Intel, or use
 
 
 
options snd_ac97_codec power_save=1
 
 
 
for ac97.
 
 
 
{{Note|Toggling the audio card's power state can cause a popping sound or noticeable latency on some broken hardware.}}
 
 
 
=== Backlight ===
 
 
 
See [[Backlight]].
 
 
 
=== Bluetooth ===
 
 
 
{{expansion|reason=The device should likely be disabled with hciconfig first.}}
 
 
 
To disable bluetooth completely, [[Kernel_modules#Blacklisting|blacklist]] the {{ic|btusb}} and {{ic|bluetooth}} modules.
 
 
 
To turn off bluetooth only temporarily, use {{Pkg|rfkill}}:
 
 
 
# rfkill block bluetooth
 
 
 
Or with udev rule:
 
 
 
{{hc|/etc/udev/rules.d/50-bluetooth.rules|<nowiki>
 
# disable bluetooth
 
SUBSYSTEM=="rfkill", ATTR{type}=="bluetooth", ATTR{state}="0"
 
</nowiki>}}
 
 
 
Or just [[enable]] the instantiated {{ic|rfkill-block@bluetooth.service}} provided by the {{Pkg|rfkill}} package.
 
 
 
=== Web camera ===
 
 
 
If you will not use integrated web camera then [[Kernel_modules#Blacklisting|blacklist]] the {{ic|uvcvideo}} module.
 
 
 
=== Kernel parameters ===
 
 
 
This section uses configs 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 [http://0pointer.de/public/systemd-man/sysctl.d.html systemd's sysctl.d man page] for more information.
 
 
 
==== Disabling NMI watchdog ====
 
 
 
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}}
 
 
 
or add {{ic|1=nmi_watchdog=0}} to the [[kernel parameter|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):
 
 
 
{{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]].
 
 
 
See also [[sysctl#Virtual memory]] for other parameters affecting I/O performance and power saving.
 
 
 
==== Laptop Mode ====
 
 
 
See the [https://www.kernel.org/doc/Documentation/laptops/laptop-mode.txt 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}}
 
 
 
=== Network interfaces ===
 
 
 
[[Wikipedia:Wake-on-LAN|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. Disabling for all Ethernet interfaces:
 
 
 
{{hc|/etc/udev/rules.d/70-disable_wol.rules|2=ACTION=="add", SUBSYSTEM=="net", KERNEL=="eth*", RUN+="/usr/bin/ethtool -s %k wol d"}}
 
 
 
To enable powersaving on all wireless interfaces:
 
 
 
{{hc|/etc/udev/rules.d/70-wifi-powersave.rules|2=ACTION=="add", SUBSYSTEM=="net", KERNEL=="wlan*", RUN+="/usr/bin/iw dev %k set power_save on"}}
 
 
 
In these examples, {{ic|%k}} is a specifier for the kernel name of the matched device.  For example, if it finds that the rule is applicable to {{ic|wlan0}}, the {{ic|%k}} specifier will be replaced with {{ic|wlan0}}. To apply the rules to only a particular interface, just replace the pattern {{ic|eth*}} and specifier {{ic|%k}} with the desired interface name. For more information, see [http://www.reactivated.net/writing_udev_rules.html Writing udev rules].
 
 
 
In this case, the name of the configuration file is important. Due to the introduction of [[Network configuration#Device_names|persistent device names]] via {{ic|80-net-name-slot.rules}} in systemd v197, it is important that the network powersave rules are named lexicographically before {{ic|80-net-name-slot.rules}}, so that they are applied before the devices are named e.g. {{ic|enp2s0}}.
 
 
 
=== Bus power management ===
 
 
 
==== Active State Power Management ====
 
 
 
If the computer is believed not to support [[Wikipedia:Active State Power Management|ASPM]] it and will be disabled on boot:
 
 
 
$ lspci -vv | grep ASPM.*abled\;
 
 
 
ASPM is handled by the BIOS, if ASPM is disabled it will be because [[http://wireless.kernel.org/en/users/Documentation/ASPM ref]]:
 
 
 
# 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 {{ic|1=pcie_aspm=force}} [[kernel parameter]].
 
 
 
{{Warning|
 
* 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.
 
}}
 
 
 
To adjust to {{ic|powersave}} do (the following command will not work unless enabled):
 
 
 
echo powersave | tee /sys/module/pcie_aspm/parameters/policy
 
 
 
By default it looks like this:
 
 
 
{{hc|$ cat /sys/module/pcie_aspm/parameters/policy|[default] performance powersave}}
 
 
 
==== PCI Runtime Power Management ====
 
 
 
{{hc|/etc/udev/rules.d/pci_pm.rules|2=ACTION=="add", SUBSYSTEM=="pci", ATTR{power/control}="auto"}}
 
 
 
==== Device power management ====
 
 
 
{{Accuracy|Mass enabling for nearly all devices has negative side effects (unwanted devices such as USB are included, worse performance of the udev rule since matching devices that enable power management by default is useless, harder troubleshooting, etc). Enabling per bus/class for the devices that need it should be recommended instead.}}
 
 
 
Enable power management for (almost) all devices, ''including USB'':
 
 
 
{{hc|/etc/udev/rules.d/dev_power_save.rules|<nowiki>
 
# Various subsystems runtime power management (by bus or class)
 
ACTION=="add", SUBSYSTEMS=="*", TEST=="power/control", ATTR{power/control}="auto"
 
 
 
# Various subsystems power saving (by module)
 
ACTION=="add", SUBSYSTEMS=="*", TEST=="parameters/power_save", ATTR{parameters/power_save}="1" </nowiki>}}
 
 
 
To list the various devices affected:
 
ls /sys/bus/*/devices/*/power/control
 
ls /sys/class/*/*/power/control
 
ls /sys/module/*/parameters/power_save
 
 
 
To enable power management for all systems ''except USB'', you could replace the first rule with individual rules for each subsystem instead (/sys/bus/''some_subsystem'', /sys/class/''some_subsystem''):
 
ACTION=="add", SUBSYSTEM=="some_subsystem", TEST=="power/control", ATTR{power/control}="auto"
 
 
 
==== 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:
 
 
 
{{hc|/etc/udev/rules.d/50-usb_power_save.rules|<nowiki>
 
ACTION=="add", SUBSYSTEM=="usb", TEST=="power/control", ATTR{power/control}="auto"
 
</nowiki>}}
 
 
 
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|<nowiki>
 
# whitelist for usb autosuspend
 
ACTION=="add", SUBSYSTEM=="usb", TEST=="power/control", ATTR{idVendor}=="05c6", ATTR{idProduct}=="9205", ATTR{power/control}="auto"
 
</nowiki>}}
 
 
 
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|<nowiki>
 
# 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"
 
</nowiki>}}
 
 
 
The default autosuspend idle delay time is controlled by the {{ic|autosuspend}} parameter of the {{ic|usbcore}} [[kernel module]]. To set the delay to 5 seconds instead of the default 2 seconds:
 
 
 
{{hc|/etc/modprobe.d/usb-autosuspend.conf|<nowiki>
 
options usbcore autosuspend=5
 
</nowiki>}}
 
 
 
Similarly to {{ic|power/control}}, the delay time can be fine-tuned per device by setting the {{ic|power/autosuspend}} attribute.
 
 
 
See the [https://www.kernel.org/doc/Documentation/usb/power-management.txt Linux kernel documentation] for more information on USB power management.
 
 
 
==== SATA Active Link Power Management ====
 
 
 
{{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.}}
 
 
 
{{hc|/etc/udev/rules.d/hd_power_save.rules|2=ACTION=="add", SUBSYSTEM=="scsi_host", KERNEL=="host*", ATTR{link_power_management_policy}="min_power"}}
 
 
 
{{Warning|SATA Active Link Power Management can lead to data loss on some devices (e.g. Lenovo T440s [http://lkml.indiana.edu/hypermail/linux/kernel/1401.2/02171.html is known to suffer] this 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 {{Pkg|iotop}} to see which programs use the disk frequently. See [[Solid State Drives#Tips for minimizing disk reads/writes]] for other tips, most of them are not specific to SSDs.
 
 
 
Also little things like setting the [[Fstab#atime options|noatime]] option can help. If enough RAM is available, consider disabling or limiting [[Swap#Swappiness|swappiness]] as it has the possibility to limit a good number of disk writes.
 
 
 
=== CD/DVD spin down ===
 
 
 
{{Expansion|something similar without using udisks?}}
 
 
 
To allow the CD/DVD rom to spin down after a while using [[udisks]]:
 
 
 
# udisks --inhibit-polling /dev/sr0
 
 
 
== Tools and scripts ==
 
 
 
=== Packages ===
 
 
 
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 similar.  Have a look at the [[:Category:Power management|power management category]] to get an overview on what power management options exist in Archlinux.
 
 
 
These are the more popular scripts and tools designed to help power saving:
 
 
 
* {{App| [[acpid]] | A daemon for delivering ACPI power management events with netlink support.|http://sourceforge.net/projects/acpid2/|{{Pkg|acpid}}}}
 
* {{App|ftw| Script to configure udev rules to save power.|https://github.com/supplantr/ftw|{{AUR|ftw-git}}}}
 
* {{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| [[pm-utils]] | Suspend and powerstate setting framework (largely undeveloped now).|http://pm-utils.freedesktop.org/|{{Pkg|pm-utils}}}}
 
* {{App| [[Powerdown]] | Scripts that combine different settings to make the computer consume less energy.|https://github.com/taylorchu/powerdown|{{Aur|powerdown-git}}}}
 
* {{App| [[powertop]] | A tool to diagnose issues with power consumption and power management to help set power saving settings.|https://01.org/powertop/|{{Pkg|powertop}}}}
 
* {{App| [[TLP]] | Advanced power management for Linux.|http://linrunner.de/en/tlp/docs/tlp-linux-advanced-power-management.html|{{Pkg|tlp}}}}
 
 
 
=== 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 [[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=<nowiki>
 
SUBSYSTEM=="power_supply", ATTR{online}=="0", RUN+="/path/to/your/script true"
 
SUBSYSTEM=="power_supply", ATTR{online}=="1", RUN+="/path/to/your/script false"
 
</nowiki>}}
 
 
 
{{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/}}).}}
 
 
 
Examples of powersave scripts can be found here: [[powerdown]], [https://github.com/Unia/powersave powersave].
 
 
 
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|<nowiki>
 
#!/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
 
</nowiki>}}
 
 
 
Do not forget to make it executable!
 
 
 
{{Note|Be aware that AC0 may be different for your laptop, change it if that is the case.}}
 
 
 
Now you do not need pm-utils anymore. Depending on your configuration, it may be a dependency of some other package. If you wish to remove it anyway, run {{ic|pacman -Rdd pm-utils}}.
 
 
 
=== 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|<nowiki>
 
#!/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
 
</nowiki>}}
 
 
 
== See also ==
 
 
 
* [http://www.thinkwiki.org/wiki/How_to_reduce_power_consumption ThinkWiki:How to reduce power consumption]
 
* [http://forum.manjaro.org/index.php?topic=1166.0 Manjro BBS topic]
 
* [https://wiki.ubuntu.com/Kernel/PowerManagement/PowerSavingTweaks Ubuntu Wiki's Power Saving Tweaks]
 

Latest revision as of 12:30, 23 April 2015

Redirect to: