Home Linux Tips & Tricks How To Optimize Performance And Battery Life With Auto-cpufreq In Linux

How To Optimize Performance And Battery Life With Auto-cpufreq In Linux

Automatically Optimize CPU Speed and Power with Auto-cpufreq in Linux.

By sk
Published: Updated: 697 views

In this detailed tutorial, we will discuss how to optimize and improve your Laptop battery life using auto-cpufreq in Linux. With the help of auto-cpufreq tool, you can happily say goodbye to Charger Anxiety and boost the Battery Life without sacrificing performance.

Introduction

Laptops are fantastic for their portability, but battery life can often be a concern. We all know the struggle of scrambling to find an outlet when our trusty machine decides to call it quits.

This is where CPU frequency scaling comes in, also known as dynamic voltage and frequency scaling (DVFS).

DVFS a technology that adjusts your Central Processing Unit's (CPU) clock speed and voltage based on workload. The faster the CPU runs, the more power it consumes.

Linux offers built-in governors for CPU frequency scaling, but they might not always strike the perfect balance between performance and battery efficiency.

This is where auto-cpufreq, an intelligent tool for automatic CPU frequency management, comes into play. It acts as an optimizer, constantly monitoring factors like battery health, CPU usage, temperature, and overall system load.

By analyzing this data, auto-cpufreq can dynamically adjust your CPU's governor and settings, prioritizing either performance or power saving depending on your needs.

In essence, auto-cpufreq helps you achieve the best of both worlds: extended battery life for those long work sessions on the go, without sacrificing performance when you need that extra processing power.

What is auto-cpufreq?

auto-cpufreq is an automatic CPU speed and power optimizer for Linux. It is designed to optimize CPU frequency scaling based on the current system load and power status. It dynamically adjusts the CPU frequency and governor settings to balance performance and power consumption efficiently.

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.

The auto-cpufreq tool is especially useful for laptops and portable devices where battery life and thermal management are crucial.

While auto-cpufreq was developed to improve performance and battery life on laptops, it can also be used on desktops and servers to lower power consumption.

Why do We Need auto-cpufreq?

Here are some key reasons why auto-cpufreq is beneficial:

1. Power Savings

Battery Life:

By reducing the CPU frequency during low load conditions, auto-cpufreq helps extend battery life on laptops and other battery-powered devices.

Energy Efficiency:

Lowering the CPU frequency when full performance is not needed reduces overall energy consumption, which is beneficial for both the environment and your electricity bill.

2. Performance Optimization

Dynamic Scaling:

auto-cpufreq adjusts CPU performance dynamically based on the system's workload, ensuring that you have enough performance when needed and saving power when the system is idle or under low load.

Thermal Management:

By managing CPU frequency and power states, auto-cpufreq can help reduce heat generation, which is important for maintaining system stability and prolonging the lifespan of hardware components.

3. Ease of Use

Automation:

Once installed and configured, auto-cpufreq works automatically without the need for manual intervention, making it easy for users to benefit from power savings and performance optimizations without having to constantly adjust settings.

Minimal Configuration:

The tool requires minimal setup and works well out of the box, making it accessible even for users who are not familiar with CPU frequency scaling.

How It Works

CPU Governors:

Linux provides several CPU frequency scaling governors like performance, powersave, ondemand, and conservative. auto-cpufreq switches between these governors based on the current system state.

Monitoring:

It continuously monitors system metrics such as CPU load, battery status, and thermal readings to make real-time adjustments to the CPU frequency.

Install auto-cpufreq

[Important NOTE]
auto-cpufreq is designed to replace TLP. Before installing auto-cpufreq, it is recommended to remove TLP to avoid conflicts, such as overheating, which can occur if both tools try to manage CPU frequencies simultaneously. Only use both tools together if you are sure of what you are doing.

Installing and configuring auto-cpufreq on Linux involves a few steps.

Here’s how you can install and configure it on Debian and its derivatives such as Ubuntu:

Step 1: Update Your System

First, make sure your system is up to date by running:

sudo apt update
sudo apt upgrade

Step 2: Install Dependencies

auto-cpufreq requires some dependencies that need to be installed first. You can do this with:

sudo apt install git curl python3 python3-pip

Step 3: Clone the auto-cpufreq Repository

Next, clone the auto-cpufreq repository from GitHub:

git clone https://github.com/AdnanHodzic/auto-cpufreq.git

Step 4: Install auto-cpufreq

Navigate to the cloned repository and install auto-cpufreq:

cd auto-cpufreq
sudo ./auto-cpufreq-installer

Step 5: Install auto-cpufreq daemon

Once auto-cpufreq is installed, we need to install the daemon.

To install auto-cpufreq daemon, run:

sudo auto-cpufreq --install

This will deploy and start the daemon as a systemd service. After the daemon is installed, auto-cpufreq is available as a binary and runs in the background.

You must install this daemon if you prefer to apply permanent automatic CPU optimizations.

Step 6: Start and Enable auto-cpufreq

Once installed, you can start and enable auto-cpufreq to run automatically at boot:

sudo systemctl enable auto-cpufreq
sudo systemctl start auto-cpufreq

Step 6: Verify Installation

You can check the status of auto-cpufreq to ensure it’s running correctly:

sudo systemctl status auto-cpufreq

Install thermald (Optional but Recommended)

The Linux Thermal Daemon (thermald) monitors and controls the temperature on laptops and tablets with Intel Sandy Bridge and newer CPUs. When the system temperature reaches a certain threshold, thermald activates various cooling methods to lower it.

Thermald doesn't conflict with auto-cpufreq in any way. Even the developer of auto-coufreq recommends to run thermald alongside it.

Thermald operates in two modes:

  1. Zero Configuration Mode: This mode is suitable for most users. It utilizes the DTS temperature sensor and employs cooling methods such as the Intel P-state driver, power clamp driver, Running Average Power Limit control, and cpufreq.
  2. User-Defined Configuration Mode: This mode allows for customization using an ACPI-style configuration in a thermal XML file. It can fix buggy ACPI configurations or fine-tune settings by adding more sensors and cooling devices.

To install thermald on a Debian-based system, run the following command:

sudo apt install thermald

This command will install the thermald tool on your system, enabling you to monitor and control the temperature along with auto-cpufreq.

Configuration

By default, auto-cpufreq does not require additional configuration to work effectively. However, if you need to adjust its behavior, you can do so by modifying its configuration file. For more details, check the official instructions on configuring auto-cpufreq.

View Stats

We can view the current CPU stats and CPU frequency scaling optmizations made by the auto-cpufreq daemon using command:

auto-cpufreq --stats

Sample Output:

Note: You can quit stats mode by pressing "ctrl+c"  
Optimal total CPU usage: 4.0 %, high average core temp: 65.0 °C
setting turbo boost: off
Warning: Changing CPU turbo is not supported. Skipping.

-------------------------------------------------------------------------------

               "auto-cpufreq" is about to refresh ...
               Executed on: June 15 (Saturday) - 16:44:42

-------------------------------------------------------------------------------

Linux distro: Debian GNU/Linux 12 bookworm
Linux kernel: 6.1.0-21-amd64
Processor: Intel(R) Core(TM) i3-2350M CPU @ 2.30GHz
Cores: 4
Architecture: x86_64
Driver: intel_cpufreq

------------------------------ Current CPU stats ------------------------------

CPU max frequency: 2300 MHz
CPU min frequency: 800 MHz

Core    Usage   Temperature     Frequency
CPU0      3.9%        65 °C      2300 MHz
CPU1      1.0%        62 °C      2300 MHz
CPU2      1.0%        65 °C      2026 MHz
CPU3      1.0%        62 °C      2042 MHz

CPU fan speed: 4003 RPM

---------------------------- CPU frequency scaling ----------------------------

Battery is: charging

Setting to use: "performance" governor
Not setting EPP (not supported by system)

Total CPU usage: 1.7 %
Total system load: 0.43
Average temp. of all cores: 63.50 °C  

Load optimal (load average: 0.43, 0.52, 0.53)
Optimal total CPU usage: 1.7 %, high average core temp: 63.5 °C
setting turbo boost: off
Warning: Changing CPU turbo is not supported. Skipping.

-------------------------------------------------------------------------------

               "auto-cpufreq" is about to refresh ...
               Executed on: June 15 (Saturday) - 16:44:47

-------------------------------------------------------------------------------

The stats will keep updating until you manually stop them by pressing Ctrl+c.

auto-cpufreq GUI

Starting with version 2.0, auto-cpufreq comes with a GUI. If you want to use this GUI, you must install auto-cpufreq daemon.

auto-cpufreq GUI
auto-cpufreq GUI

By default, auto-cpufreq will use "performance" governor, which is the default. You can switch to "powesave" governor if you want to.

Modes

auto-cpufreq supports three modes:

  • Monitor (No changes)
  • Live (Temporary changes)
  • Daemon (Permanent changes)

Monitor Mode:

In this mode, no changes will be made. If you just want to monitor and see the suggestions for optimizations, you can run auto-cpufreq in monitor mode.

To run auto-cpufreq in monitor mode, use:

sudo auto-cpufreq --monitor

Live Mode:

This mode is for evaluation purpose. All necessary changes are temporarily applied to your system.

In this mode, temporary changes will be made based on the system load. If you want to monitor and make temporary CPU optimizations, you can run auto-cpufreq in live mode.

To run auto-cpufreq in live mode without installing it as a service, use:

sudo auto-cpufreq --live

In the live mode, you will see how your system would behave after permanently enabling auto-cpufreq. Please note that these changes will be lost on system reboot.

Daemon Mode

This mode will create a auto-cpufreq systemd service. The service will run automatically on every system reboot. So, all necessary changes that are made will persist across system reboots.

Install and enable auto-cpufreq daemon as shown in the installation section above if you want to apply permanent automatic CPU optimizations on your system.

Remove auto-cpufreq Service

If you don't wish to permanently enable CPU optimizations across reboots, remove the auto-cpufreq daemon using command:

sudo auto-cpufreq --remove

Uninstall auto-cpufreq

If you need to uninstall auto-cpufreq, run:

sudo auto-cpufreq-installer --uninstall

Summary

In this tutorial, we discussed how to install and configure auot-cpufreq in Linux to improve performance and battery life on Laptops, lower power consumption in Desktops and Servers.

auto-cpufreq tool helps you to optimize your CPU frequency scaling based on the current system load.

It is a valuable tool for managing CPU frequency dynamically to achieve a balance between performance and power efficiency.

It is particularly useful for users who want to maximize their device's battery life and manage heat without sacrificing the ability to perform demanding tasks when needed.

By automating the process of CPU frequency scaling, auto-cpufreq provides an easy-to-use solution for optimizing system performance and power consumption.

I strongly recommend you to install it after installing a Linux distribution on your Laptop, Desktop or Server.

Resources:


Related read:


You May Also Like

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. By using this site, we will assume that you're OK with it. Accept Read More