PowerTop – Monitors Total Power Usage and Improve Linux Laptop Battery Life
One of the most important characteristics of a good Linux machine especially with laptops is power management in terms of prolonging battery life. Linux has utilities that can help you to monitor and keep track of your battery performance, though many of us still face problems in getting the right power settings to manage power consumption and improve battery life.
In this article we are going to look at a Linux utility called PowerTOP that helps you to get the appropriate system settings to manage power on your Linux machine.
What is PowerTOP?
PowerTOP is a terminal-based diagnosis tool developed by Intel that helps you to monitor power usage by programs running on a Linux system when it is not plugged on to a power source.
An important feature of PowerTOP is that it provides an interactive mode which allows a user to experiment with different power management settings.
PowerTOP requires the following components:
- Development Tools such as C++, g++, libstdc++, autoconf, automake, and libtool.
- In addition to the above, it also requires pciutils-devel, ncurses-devel and libnl-devel components
- kernel version => 2.6.38
How to Install Powertop in Linux
PowerTOP can be easily available to install from system default repositories by using your respective package manager.
$ sudo apt-get install powertop [On Debian based systems] # yum install powertop [On RedHat based systems] # dnf install powertop [On Fedora 22+ systems]
Important: Please note that installing powertop from the default system repositories, will get you a older version.
If you’re looking to install most recent version (i.e. v2.7 released on 24 Nov, 2014) of powertop, you have to build it and install it from source, for this you must have following dependencies install on the system.
------------------- On Debian based Systems ------------------- # apt-get install build-essential ncurses-dev libnl-dev pciutils-dev libpci-dev libtool
------------------- On RedHat based Systems ------------------- # yum install gcc-c++ ncurses-devel libnl-devel pciutils-devel libtool
After installing all the above required packages, now it’s time to download most latest version of PowerTop and install it as suggested:
# wget https://01.org/sites/default/files/downloads/powertop/powertop-2.7.tar.gz # tar -xvf powertop-2.7.tar.gz # cd powertop-2.7/ # ./configure # make && make install
How Do I use PowerTop in Linux?
To use this tool, one needs root privileges because all the information required by powertop to measure power usage by applications is gathered directly from the system hardware.
Try to use it with laptop battery power to see the effects on the system. It shows the total power usage by the system and by the individual components of the system listed in different categories: devices, processes, system timer, kernel works and interrupts.
Understanding PowerTop Options and Usage
To set all the tunabale options to the best settings without the interactive mode, use the
To run it in calibration mode, use the
--calibrate option. If you run powertop on laptop battery, it tracks power consumption as well as processes running on the system and after getting enough power measurements, it reports power estimates.
You can then use this option to get more appropriate estimates when using this option, to implement a calibration cycle through different display levels and workloads.
To run it in debug mode, use the
You can also generate a report for data analysis by using the
--csv=filename. The report generated is called a CSV report and when you do not spell out a file name, a default name powertop.csv is used.
To generate a html report file, use the
--html=filename option. You can specify for how long in seconds a report can be generated by using the
You can specify a workload file to execute as part of the calibration before generating a report by using the
To show help messages use the
--help option or view the manpage.
To specify the number of times a test should be run by using the
PowerTop Usage with Examples
If you run powertop without any of the above options, it starts in an interactive mode as shown in the output below.
The overview screen
This display screen allows you to view a list of the system components that are either sending wake-ups to the CPU most frequently or are using the most power on the system.
The Idle stats screen
It displays various information about processor C-states.
The Frequency stats screen
This screen displays the frequency of wake-ups to the CPU.
The Device stats screen
It provides information similar to the Overview display screen but only for devices.
The Tunables screen
It provides suggestions for optimizing your system for good power consumption.
As you can see from the output above, there are different display screens available and to switch between them, you can use Tab and Shift+Tab keys. Exit powertop by pressing the Esc key as listed at the bottom of the screen.
It displays the number times your system wakes up each second, when you view the device stats display screen, it shows statistics of power usage by different hardware components and drivers.
To maximize battery power, you have to minimize system wake-ups. And to do this, you can use the Tunables display screen.
“Bad” identifies a setting that is not saving power, but may be good for the performance of your system.
Then “Good” identifies a setting that is saving power. Hit [Enter] key on any tunable to switch it to the other setting.
The example below shows output when using the
# powertop --calibrate
After the calibration cycles, powertop will show the overview screen with a summary of operations as below.
Generating PowerTop CSV Report
The next example shows generating a CSV report for twenty seconds.
# powertop --csv=powertop_report.txt --time=20s
Now let’s view the CSV report using cat command.
# cat powertop_report.csv
Generate PowerTop HTML Report
You can generate a html report as follows, the html file extension is added automatically to the filename.
# powertop --html=powertop
The sample html report file as viewed from a browser.
This tool also has a daemon service that helps to automatically set all tunables to “Good” for optimal power saving, and you can use it as follows:
# systmctl start powertop.service
To make the daemon service start at boot time, run the following command:
# systemctl enable powertop.service
You need to take caution when using daemon service because certain tunables pose a risk of data loss or weird system hardware behavior. This is evident with the “VM writeback timeout” settings that affects the time your system waits before writing any changes of data to the actual disk.
When the system loses all it power, then you risk losing all changes made on data for the last few seconds. Therefore you have to choose between saving power and securing your data.
Try to use this tool for some period of time and observe the performance of your battery. You can post a comment to tell us about many other similar tools or add information on usage of powertop, about error you encountered. Remember to always stay connected to Tecmint to get more of such guides.