Linux Power Management

Utilities for monitoring and configuring power management settings on your Linux device.

Linux Power Management

Introduction

Power management in Linux has come a long way in the last few years. With the advent of netbooks and other mobile platforms like phones and tablets, the need for better battery life and thermal controls under Linux has led to innovative solutions that work out of the box in most distributions. That being said, there are a number of configuration options and programs which you may wish to learn about which can net you better control of your mobile Linux platform.

Powertop

Powertop is a great tool for easily finding processes which eat up battery life as well as enabling power management related kernel parameters. It also displays the discharge rate of a device as reported by a battery in Watts.

Powertop requires a certain amount of collected data to be able to accurately calculate the battery life left. Simply keep powertop running without charging the device to collect this data.

It may be necessary to calibrate powertop for more accurate predictions of power usage. To do this, run sudo powertop --calibrate. This will take several minutes while powertop measures each individual component available. I did notice calibrate caused my wifi card to be put in an inconsistent state which only a reboot was able to recover from. So run with caution.

To automatically enable all power management features as found by powertop, execute the following command:

sudo powertop --auto-tune

To enable these settings on boot, create the following Systemd service file:

/etc/systemd/system/powertop.service

[Unit]
Description=Powertop Autotune

[Service]
Type=oneshot
ExecStart=/usr/sbin/powertop --auto-tune

[Install]
WantedBy=multi-user.target

Note: powertop is placed in either /usr/sbin/ or /usr/bin/ based on the distribution you are using. Run which powertop to determine the correct path to use for ExecStart in the service file.

Be sure to run systemctl enable powertop to run the service on boot.

lm-sensors

lm-sensors is a great utility for displaying thermal temperatures as well as fan speeds of a system. Before you can run the sensors program, you must first run sensors-detect so that lm-sensors can probe your system for devices that report temperature data.

$ sensors
coretemp-isa-0000
Adapter: ISA adapter
Core 0:       +42.0°C  (high = +80.0°C, crit = +100.0°C)
Core 1:       +41.0°C  (high = +80.0°C, crit = +100.0°C)
Core 2:       +43.0°C  (high = +80.0°C, crit = +100.0°C)
Core 3:       +41.0°C  (high = +80.0°C, crit = +100.0°C)

it8720-isa-0a10
Adapter: ISA adapter
in0:          +0.83 V  (min =  +0.00 V, max =  +4.08 V)
in1:          +0.03 V  (min =  +0.00 V, max =  +4.08 V)
in2:          +3.31 V  (min =  +0.00 V, max =  +4.08 V)
+5V:          +2.99 V  (min =  +0.00 V, max =  +4.08 V)
in4:          +3.06 V  (min =  +0.00 V, max =  +4.08 V)
in5:          +3.01 V  (min =  +0.00 V, max =  +4.08 V)
in6:          +2.14 V  (min =  +0.00 V, max =  +4.08 V)
5VSB:         +2.99 V  (min =  +0.00 V, max =  +4.08 V)
Vbat:         +3.30 V
fan1:        1190 RPM  (min =    0 RPM)
fan2:           0 RPM  (min =    0 RPM)
fan3:           0 RPM  (min =    0 RPM)
temp1:        +41.0°C  (low  =  +0.0°C, high = +127.0°C)  sensor = thermistor
temp2:        +42.0°C  (low  =  +0.0°C, high = +127.0°C)  sensor = thermistor
temp3:       +127.0°C  (low  =  +0.0°C, high = +127.0°C)  ALARM  sensor = thermistor
cpu0_vid:    +1.219 V
intrusion0:  ALARM

To continuously run the sensors program every 2 seconds, you can execute this command:

watch -n 2 sensors

cpupower

cpupower is a process for displaying CPU information, such as processor speed and C-state and idle statistics. It can also be used for selecting or displaying the configured CPU governor.

Example output of my idling i7 930:

$ sudo cpupower monitor
    |Nehalem                    || Mperf              || Idle_Stats
CPU | C3   | C6   | PC3  | PC6  || C0   | Cx   | Freq || POLL | C1-N | C1E- | C3-N | C6-N
   0|  0.32| 94.21|  0.00|  0.00||  1.67| 98.33|  1674||  0.00|  2.43|  0.00|  0.06| 95.92
   4|  0.32| 94.21|  0.00|  0.00||  0.57| 99.43|  1607||  0.00|  0.00|  0.02|  0.33| 99.23
   1|  0.17| 28.13|  0.00|  0.00||  0.94| 99.06|  1708||  0.00| 70.47|  0.00|  0.04| 28.58
   5|  0.17| 28.14|  0.00|  0.00||  0.09| 99.91|  1698||  0.00|  0.00|  0.00|  0.20| 99.71
   2|  0.29| 91.48|  0.00|  0.00||  3.21| 96.79|  1708||  0.00|  4.10|  0.00|  0.03| 92.71
   6|  0.29| 91.48|  0.00|  0.00||  0.22| 99.78|  1613||  0.00|  0.00|  0.00|  0.32| 99.52
   3|  0.11| 27.48|  0.00|  0.00||  2.91| 97.09|  1790||  0.00| 17.74|  0.01|  0.14| 79.23
   7|  0.11| 27.47|  0.00|  0.00||  0.15| 99.85|  2294||  0.00| 70.57|  0.00|  0.00| 29.30

Noteable Mentions

i7z

i7z is a great little utility for reporting CPU sleep states on your Intel processor. It can be used to debug which C-state each core of your processor is in at any given moment in time.

laptop-mode-tools

Laptop Mode Tools used to be the defacto standard for enabling power management features in Linux. It is not really needed anymore as most of the configuration changes that can be done through it are now enabled by default in the Linux kernel. It is worth a mention though.

TLP

TLP is an easy to use service which can help squeeze additional battery life out of a Linux system. I have heard mixed reviews concerning the helpfulness of this utility. Running too advanced of a configuration can lead to stability issues when using BTRFS.

Conclusion

We have looked at some of the excellent utilities for monitoring and tweaking power management features on mobile devices. Linux comes with sane defaults which should allow battery life comparable to other [proprietary] operating systems.