Linux power management guide for laptops
For laptops, battery life is one of the most important point to determine it’s usability, the longer is better. Bad linux power management profile could dramatically decrease the battery life, really, from 5-6 hours in windows to 2-3 hours in Linux, ultimately newbies will say Linux is very power hungry !
Most modern laptops uses the ACPI for power management, it’s much more flexible than old APM and managed by the OS, instead of BIOS. You don’t need to worry about ACPI, it’s already well integrated with Linux.
Here in this tutorial we are going to focus on normal usage like browsing, video and audio playback, word processing, note taking etc. etc, rather than totally idle state or heavy tasks like gaming.
Which power saving methods are worth to implement ?
In any UNIX like system everything could be tweaked to make it more power efficient, but few of them have noticeable power saving advantage. Bellow a few of them –
- Turn off discrete GPU like NVIDIA Optimus or AMD/ATI Hybrid Graphics
- Decrease display backlight
- CPU frequency scaling
- Spin down the hard drive
- GPU accelerated video playback
- Disable bluetooth, webcam, card reader
- Audio codec power management
- Optimize various kernel parameters
- Use power efficient network connection
- Use a lightweight desktop environment
This is a comprehensive list, there may be some useful power saving tweaks missing. Let’s dig a little deeper with those options above.
1. Turn off discrete GPU
If you are using a laptop with switchable discrete graphics card, make sure it’s turned off. This could be the biggest cause of power drain, almost tripling the power use than normal.
So how to turn off the discrete GPU ? It depends on your GPU and the Linux distro you are using.
If you are using a NVIDIA Optimus GPU and running a Debian or Debian derivative, have a look at this guide, Configure NVIDIA Optimus in Debian with bumblebee .
If you are using AMD hybrid/switchable GPU and running Ubuntu or any Ubuntu derivative, look at this guide.
The vgaswitcheroo module could be handy, just run the commands bellow to turn off the discrete graphics.
sudo -i # enter password echo OFF > /sys/kernel/debug/vgaswitcheroo/switch
Note: The vgaswitcheroo may not be always available.
2. Decrease display backlight
Laptop’s backlight is another major power consumer, reduce display brightness to a comfortable level, which should match the ambient light.
Most laptops could adjust brightness with dedicated hot keys. If you are using KDE, Gnome, Cinnamon, Unity and other heavy weight desktops, it should work out of the box.
You may need to add the acpi_backlight=vendor boot time kernel parameter to the GRUB configuration for proper hotkey function, also don’t forget to update GRUB after adding this.
Though in lightweight desktop environments, hotkey functionality may not be available. In such case use the xbacklight app to manage display brightness.
sudo apt-get install xbacklight xbacklight -set 15 # set brightness to 15 %
You could directly change the brightness through the sysfs interface. For intel GPUs, try this command,
[email protected]:~# echo 100 > /sys/class/backlight/intel_backlight/brightness
3. CPU frequency scaling
Casual tasks like browsing, reading pdf, playing audio doesn’t require massive CPU power, so under clocking the CPU saves a lot of power. Frequency scaling can intelligently scale up or down the CPU frequency according to need, or it could be set by user.
Probably need not to change anything here, as Linux kernel loads powersave or ondemand scaling governor by default, they are quite power saving and tries to always keep the CPU frequency lower.
If you are using Ubuntu and Unity desktop, there is a nice unity panel applet, indicator cpufreq. Install it
sudo apt-get install indicator-cpufreq
Intel Sandy breeze or newer CPU uses the intel_pstate cpu scaling driver after kernel 3.9, it provides two CPU scaling governor, performance and powersave which is somewhat better than acpi_cpufreq driver.
If you are using a Intel turbo boost capable CPU, you may want to disable this facility while running on battery power.
echo 1 > /sys/devices/system/cpu/intel_pstate/no_turbo # disable
echo 0 > /sys/devices/system/cpu/intel_pstate/no_turbo # enable
4. Spinning down the hard drive
Laptop hard drives could consume up to 2.5 watt power, depending on task. So spinning down hard drives during low I/O activity period could save a descend amount of power. Though power saving by hard drive spin down is controversial, as it causes lagging and spinning up the drive requires power surge.
Hard drive spin down could be set with the hdparm CLI app, install it in Debian or any Debain derivative
sudo apt-get install hdparm sudo hdparm -B /dev/sda # check current APM level
Now you could try to save some power by lowering the APM level, really works when very few apps are open and web browser is closed.
sudo hdparm -B 96 -S 0 /dev/sda
If you are using an external USB hard drive and it’s idle, i.e. just plugged in, you could completely spin down it to save a lot of power.
sudo hdparm -B 0 -S 0 /dev/sdb # external drive is /dev/sdb
5. GPU accelerated video playback
If sole purpose is to play movies and watch youtube, you should use hardware accelerated video playback when possible. It off loads the video decoding task to GPU, thus reduces CPU usage and ultimately saves some power.
Media players like VLC, MPV or recent version mplayer support hardware accelerated video decoding. Try Baka-Mplayer, a lightweight mpv based media player with GPU accelerated video decoding support and nice Qt 5 based user interface.
You should also use a browser with GPU acceleration support, most modern browsers like Chromium, Firefox, Opera supports it, here is how to enable hardware acceleration in any chromium based browser.
Avoid playing flash videos in browser, as it doesn’t support GPU decoding there.
6. Disable bluetooth, webcam, PCI-E card reader
If you rarely use bluetooth, webcam or the PCI-E card reader, it’s better to turn them off. Disable the bluetooth with rfkill or hard block it with hotkeys if available. How to turn off bluetooth with rfkill
sudo apt-get install rfkill # install rfkill sudo rfkill block bluetooth
To disable bluetooth by blacklisting related kernel modules, create a text file /etc/modprobe.d/no-bluetooth.conf and put the blacklist files bellow there.
blacklist btusb blacklist bluetooth
You could block the webcam in the same way, create a text file /etc/modprobe.d/no-webcam.conf and put the blacklist configuration there.
My laptop has a Realtek PCI-E card reader, I never used it, so I’m turning it off. Your card reader could be different, just find out which kernel driver it’s using with lspci -k and blacklist it. Blacklist configuration for Realtek RTS5209 card reader
You should also disable other unused devices too, like inbuilt GSM module or fingerprint scanner, if your laptop have any.
7. Audio codec power management
If you are not playing audio files frequently, put the sound card in idle state. As a temporary test, you could run the command bellow as root.
echo 1 > /sys/module/snd_hda_intel/parameters/power_save # as root
To make it permanent, find the Audio device, usually it’s connected through PCI-E interface.
lspci | grep -i audio
Note the PCI Bus ID and identify the kernel driver in use.
lspci -k -s 00:1b.0 # example, your Bus ID could be different
If you are using a Intel HDA sound card, create the /etc/modprobe.d/idle-audio.conf kernel driver configuration file and put the configuration bellow there.
options snd_hda_intel power_save=1
If you are using AC’97 codec based card, use this configuration
options snd_ac97_codec power_save=1
8. Optimize various kernel parameters
Add some extra kernel parameters to the GRUB configuration to make the system even more power efficient.It could be done in different ways, in Ubuntu or Debian add the extra parameters to the /etc/default/grub file inside the line GRUB_CMDLINE_LINUX_DEFAULT=”quiet” .
- If your laptop’s CPU is Intel sandy Breeze or newer, save some power by idling the GPU, add
- To enable intel GPU framebuffer compression, add
Don’t orget to run sudo update-grub after adding those kernel parameters.
Now disable some features through the sysctl.conf file, add the configurations listed bellow to the sysctl.conf file, you need root privilege to edit the file.
kernel.nmi_watchdog=0to disable NMI watchdog, it’s useless for most users.
vm.dirty_writeback_centisecs=1500to reduce writes to HDD.
Don’t forget to run sudo sysctl -p to apply the new configurations.
Runtime power management for PCI-E devices, helps to save power power on low activity PCI-E devices. An one line script to set auto power management.
sudo -i # become root, then run the script bellow. for pci_dev in /sys/bus/pci/devices/*/power/control; do echo auto > $pci_dev;done
I’m not going to play with the SATA link power management, as it may cause data loss.
9. Use power efficient network connection
Here I mean use a network adapter technology which consumes less power.
- Ethernet is most power efficient, use ethernet cable whenever possible.
- The second choice is bluetooth, if you are tethering from a phone, for this you have to enable bluetooth.
- Third choice is Wi-Fi, it consumes significantly more power than ethernet and bluetooth.
- Worst choice is mobile broadbrand, i.e. a GSM/CDMA modem, it could consume 2 to 2.5 watt power.
10. Use a lightweight desktop environment
Bloated desktops like KDE, Cinnamon, Unity draws much more power than lightweight desktops, as there are many background services, file indexing apps running on them. So It’s good to choose a lightweight desktop environment like LXDE, LXQt or XFCE while running on battery power.
How to track power usage in Linux ?
Powertop is a great app for this purpose, it provides an easy to understand result and possible hints to optimize power management.
In Debian, Ubuntu or any other derivative install powertop with apt-get
sudo apt-get install powertop
Now take a measurement and generate a report for 1 minuite in HTML format
sudo powertop --time=60 --html=power_report.html
Open up the HTML file with your favorite web browser and explore different results, the Tuning section is interesting.
Enough linux power saving and management tweaks, hope it’s simple enough and most readers will find it useful. If you have any question or suggestion please leave comments, that will make this guide even better. Also share this tutorial with friends if you like it.