This guide explains how to automatically optimize CPU speed and power with auto-cpufreq in Linux. Auto-cpufreq is an automatic CPU speed and power optimizer for Linux. As the name says, auto-cpufreq will do the optimizations automatically. You don't need to do any manual changes or constant tweaking. It will actively monitor your battery's state, CPU usage (frequency and temperatures) and system load and recommend you the best tweaks to apply in order to improve your Laptop's battery life. You can then apply the recommended CPU and power optimizations temporarily or permanently.
Features of auto-cpufreq
auto-cpufreq utility comes with the following features:
- Monitoring
- Displays basic system details
- CPU frequency
- CPU temperatures
- Battery state
- System load
- CPU frequency scaling, governor and turbo boost management based on
- Battery state
- CPU usage
- System load
- Automatic CPU and power optimization (temporary and persistent).
Install auto-cpufreq in Linux
auto-cpufreq is available in AUR. So the Arch Linux users can install it using AUR helper tools, for example Yay.
$ yay -S auto-cpufreq
On other Linux distributions, make sure you have installed the following necessary prerequisites.
On DEB-based systems:
$ sudo apt install git python3-dev python3-pip python3-distro python3-psutil python3-click python3-power
On RPM-based systems:
$ sudo yum install git python-devel
$ sudo pip3 install psutil click distro power
The Python packages available in the official repositories might be bit old. To update them to their latest version, run:
$ sudo pip3 install --upgrade psutil click distro power
After installing and updating all prerequisites, git clone auto-cpufreq repository:
$ git clone https://github.com/AdnanHodzic/auto-cpufreq.git
Cd into the project's directory:
$ cd auto-cpufreq/
And start using it as described in the below section.
Automatically Optimize CPU Speed And Power With Auto-cpufreq In Linux
To run auto-cpufreq, simply do:
$ sudo python3 auto-cpufreq.py
When running auto-cpufreq without any options, you will see the help section that shows you the example usage and list of available options and modes.
There are three modes available.
- Monitor
- live
- install
Monitor mode
To run auto-cpufreq in monitor mode, run:
$ sudo python3 auto-cpufreq.py --monitor
In the monitor mode, auto-cpufreq will display the basic details of your system and list of CPU optimization suggestions like below.
----------------------------- System information ------------------------------ Linux distro: Ubuntu 18.04 bionic Linux kernel: 5.3.0-40-generic Driver: intel_pstate Architecture: x86_64 Processor: Intel(R) Core(TM) i3-2350M CPU @ 2.30GHz Cores: 4 ------------------------------ Current CPU states ------------------------------ CPU max frequency: 2300 MHz CPU frequency for each core: CPU0: 1032 MHz CPU1: 1010 MHz CPU2: 1050 MHz CPU3: 1038 MHz Temperature for each physical core: CPU0 temp: 62°C CPU1 temp: 62°C ---------------------------- CPU frequency scaling ---------------------------- Battery is: charging Suggesting use of "performance" governor Currently using: /bin/sh: Total CPU usage: 8.1 % Total system load: 0.48 Currently turbo boost is: off Suggesting to set turbo boost: on ------------------------------------------------------------------------------- "auto-cpufreq" refresh in: 5
The output will keep updating every 5 seconds. Nothing will be changed in your system. It is just a visual demonstration to show you what auto-cpufreq could do differently for your system. To abort this monitoring, simply press CTRL+c.
Live mode
To start auto-cpufreq in live mode, run:
$ sudo python3 auto-cpufreq.py --live
This mode is for evaluation purpose. All necessary changes are temporarily applied to your system. In this mode, you will display how your system would behave after permanently enabling auto-cpufreq. Please note that these changes will be lost on system reboot.
Install mode
If you'd like to automatically enable CPU optimizations across system reboots, run:
$ sudo python3 auto-cpufreq.py --install
This command will create a auto-cpufreq systemd service. The service will run automatically on every system reboot. So, all necessary changes are made will persist on reboots.
You can view the service status using command:
$ systemctl status auto-cpufreq
View logs
To view CPU optimization logs, run:
$ auto-cpufreq --log
Or,
$ sudo python3 auto-cpufreq.py --log
Please note that you have enabled the systemd service to view the logs.
Remove auto-cpufreq service
If you don't wish to permanently enable CPU optimizations across reboots, remove the auto-cpufreq using command:
$ sudo auto-cpufreq --remove
Or,
$ sudo python3 auto-cpufreq.py --remove
All persistent changes will also be removed.
Here is a short visual demo made by the developer.
Of course, there are many tools, such as CPU Power manager, TLP, Laptop Mode Tools and powertop, exists to reduce power consumption and improves overall Laptop battery life in Linux. auto-cpufreq is yet another good tool for improving laptop battery performance. Good thing is it doesn't conflict with TLP. You can use both of them in your Laptop at the same time.
Resource:
1 comment
Hi,
very good and useful article
thanks a lot