Understanding how to monitor and optimize power usage on Linux can come in quite handy. We’re here to discuss just that, so read on.
While not all of you know may know this, the power consumption in the Linux operating system is comparatively higher than in Windows or macOS. Because of just 21% of the market share, little attention has been given to this area.
Despite the various tools in Linux to monitor and keep track of your battery, most users still face numerous challenges in making the correct settings and optimizing battery life.
How to Monitor and Optimize Power Usage on Linux
We’re here to explicitly discuss the utility called PowerTop that can be used to get the appropriate system settings for the power.
The PowerTop tool
Developed by Intel, this tool allows a user to analyze the power consumed by various programs running on the system. The system should not be plugged into a power source at that time. Also, most of the commands of powertop (such as calibrate) can be run only on a laptop.
The tool also features an interactive mode in which the user can see the various settings and the power consumed by applications when using these settings. The tool provides the power usage information for the following components of the system: process, kernel, device, timer, and interrupt handler.
Installation of PowerTop tool
The PowerTool requires various tools for its proper functioning. This includes
libnl-devel. In addition, the kernel version should be above 2.6.38. You can then use the package manager to install the PowerTop in Linux. For instance, on Fedora, you can run the following command:
$ dnf install powertop
On Debian, the following command can be used to install:
$ sudo apt-get install powertop
On Redhat Linux, use the following command:
$ yum install powertop
Besides, this tool can be built from the source, specifically when you want the latest version and new features. The following command can be used to install the prerequisite tools first:
# apt-get install build-essential ncurses-dev libnl-dev pciutils-dev libpci-dev libtool # yum install gcc-c++ ncurses-devel libnl-devel pciutils-devel libtool
Then, run the following commands to install the tool from the source:
# wget https.//01.org/sites/default/files/download/powertop/powertop-2.7.tar.gz # tar -xvf powertop-2.7.tar.gz # cd powertop-2.7/ # ./configure # make && make install
Usage of Power Top
Now we will discuss the primary usage of the PowerTop tool. To run the following examples, you should have the root privileges. Note that the following commands should be run on your battery power to analyze the effects of these commands.
Auto-tune and calibrate the mode
To set all the parameters to their optimum value, use the
--auto-tune option. This will run the tool without interactive mode. To run in calibration mode, run with the
--calibrate option. This will track the power consumption and the processes for several settings and then report these measurements.
# powertop --calibrate
You can also export the report for further analysis by using
-csv=file-name. Similarly, there are options for exporting in HTML; the report can be generated in seconds. The following command exports the output in CSV format:
# powertop --csv=powertop_report.txt --time=20s
The CSV file can then be used for further analysis in offline mode. For HTML, you can use the following command:
# powertop --html=powertop
When PowerTop is run without specifying any options, it runs in interactive mode. On your terminal, type the following command:
It will open an application. The first screen will display the list of processes and components using the highest power on the CPU. Then, there is an idle stats screen displaying information about processor states.
The frequency stats screen displays the frequency of wakeups. The device stats screen shows the power usage by the devices. The tunable screen displays suggestions for optimizing power consumption. You can experiment with various settings and set the tunable parameters.
There is a daemon service that can be used to set all the tunables to Good for optimal power saving. The following command illustrates:
# systemctl start powertop.service
You can also set the daemon service to start at boot time with the following command:
$ systemctl enable powertop.service
Tip: When using the daemon service, exercise caution. It may cause data loss or weird hardware behavior for specific parameters.
Other tools for monitoring power usage
Note that a GUI tool called “Power Statistics” in Linux can be used to observe power consumption. Also, the
upower utility can be used in Linux. To use this tool, type the following command:
There is also a tool called
acpi that can also be used with the following command:
batstat command can also be used to monitor the power usage statistics with the following command:
Tip: The PowerTop tool can be handy in identifying the buggy behavior of the applications and isolating those processes.
We discussed the PowerTop tool available in Linux for optimization of power usage in Linux. Identifying the components in the system is essential, as it can help maximize battery life or reduce the energy consumption of battery-mounted rack devices in a data center. We discuss the various screens displayed as the output of the tool and the multiple options that can be used with the tool.
Finally, we also discussed various other tools that can be used for monitoring power usage in Linux. For optimum power consumption in Linux, ensure low screen brightness, limit USB devices, enable TLP, disable screen savers, etc.
If this guide helped you, please share it.