How to check if a CPU governor is active in Linux

LinuxLinuxBeginner
Practice Now

Introduction

In this lab, you will learn how to check the active CPU frequency scaling governor in Linux. We will explore two primary methods: using the cpufreq-info command and examining the system files in /sys/devices/system/cpu.

You will begin by installing the necessary tools and then use cpufreq-info to identify the current governor and available options. Subsequently, you will verify this information by inspecting the relevant files within the /sys filesystem. Finally, you will use cat /proc/cpuinfo to gain further insights into your CPU's details. This lab will equip you with the knowledge to understand and verify your CPU's power management settings.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("Linux")) -.-> linux/PackagesandSoftwaresGroup(["Packages and Softwares"]) linux(("Linux")) -.-> linux/BasicFileOperationsGroup(["Basic File Operations"]) linux(("Linux")) -.-> linux/FileandDirectoryManagementGroup(["File and Directory Management"]) linux/BasicFileOperationsGroup -.-> linux/ls("Content Listing") linux/BasicFileOperationsGroup -.-> linux/cp("File Copying") linux/BasicFileOperationsGroup -.-> linux/cat("File Concatenating") linux/FileandDirectoryManagementGroup -.-> linux/cd("Directory Changing") linux/PackagesandSoftwaresGroup -.-> linux/apt("Package Handling") subgraph Lab Skills linux/ls -.-> lab-558704{{"How to check if a CPU governor is active in Linux"}} linux/cp -.-> lab-558704{{"How to check if a CPU governor is active in Linux"}} linux/cat -.-> lab-558704{{"How to check if a CPU governor is active in Linux"}} linux/cd -.-> lab-558704{{"How to check if a CPU governor is active in Linux"}} linux/apt -.-> lab-558704{{"How to check if a CPU governor is active in Linux"}} end

Check governor with cpufreq-info

In this step, we'll explore how to check the CPU frequency scaling governor using the cpufreq-info command. The CPU governor determines how the CPU adjusts its speed (frequency) based on the system load. Different governors prioritize performance or power saving.

First, we need to install the cpufrequtils package, which contains the cpufreq-info command. We'll use apt for this.

Open the terminal if you haven't already. You can find the Xfce Terminal icon on the left side of your desktop.

Type the following command to install the package:

sudo apt update
sudo apt install cpufrequtils -y

The sudo apt update command refreshes the list of available packages, and sudo apt install cpufrequtils -y installs the cpufrequtils package. The -y flag automatically confirms the installation without asking for confirmation.

Once the installation is complete, you can use cpufreq-info to check the governor.

Type the following command and press Enter:

cpufreq-info

You will see output similar to this (the exact details may vary depending on the system):

analysing CPU 0:
  driver: intel_pstate
  cpufreq usage: 0.00%
  ...
  available governors: performance powersave
  current policy: frequency 2.30 GHz, turbo boost 3.80 GHz
                  ...
  current CPU frequency: 2.30 GHz (asserted by call to hardware)
  ...

Look for the line that says available governors: and current policy:. This tells you which governors are available and which one is currently active. Common governors include performance (prioritizes speed) and powersave (prioritizes energy saving).

Understanding the CPU governor is important for optimizing system performance and power consumption.

Click Continue to proceed to the next step.

Verify governor in /sys/devices/system/cpu

In the previous step, we used cpufreq-info to see the CPU governor. Linux also exposes system information through the /sys filesystem. This filesystem provides a view into the kernel's data structures.

We can find information about the CPU governor in the /sys/devices/system/cpu directory. This directory contains subdirectories for each CPU core (e.g., cpu0, cpu1, etc.).

Let's navigate to the directory for the first CPU core, cpu0. We'll use the cd command to change directories.

Type the following command and press Enter:

cd /sys/devices/system/cpu/cpu0/cpufreq

Now that we are in the /sys/devices/system/cpu/cpu0/cpufreq directory, we can list the files to see what information is available. Use the ls command:

ls

You will see a list of files, including scaling_governor. This file contains the name of the currently active CPU governor for this core.

To view the content of the scaling_governor file, we'll use the cat command.

Type the following command and press Enter:

cat scaling_governor

The output will be the name of the current governor, for example:

powersave

This confirms the governor setting directly from the system's perspective.

You can explore other files in this directory to find more information about the CPU frequency settings, such as scaling_available_governors to see all available governors for this core.

Remember to use cd to change back to your home directory or ~/project when you are done exploring /sys.

cd ~/project

Click Continue to move on.

Inspect CPU details with cat /proc/cpuinfo

In addition to /sys, Linux provides system information through the /proc filesystem. This is another virtual filesystem that provides details about processes and other system information.

The /proc/cpuinfo file contains detailed information about the CPU(s) in your system. Let's use the cat command to view its contents.

Make sure you are in your home directory or ~/project. If not, use cd ~/project to navigate there.

Type the following command and press Enter:

cat /proc/cpuinfo

You will see a lot of output, providing details about each CPU core. The output will look similar to this (details will vary):

processor	: 0
vendor_id	: GenuineIntel
cpu family	: 6
model		: 158
model name	: Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
stepping	: 9
microcode	: 0x...
cpu MHz		: 2808.000
cache size	: 6144 KB
...

Some key pieces of information you can find in /proc/cpuinfo include:

  • processor: The index of the CPU core (starting from 0).
  • model name: The full name and speed of your CPU.
  • cpu MHz: The current speed of the CPU core in MHz.
  • cache size: The size of the CPU's cache.

You can scroll through the output to see information for all CPU cores. This file is a valuable resource for understanding the hardware specifications of your system's CPU.

Click Continue to complete this lab.

Summary

In this lab, we learned how to check the active CPU governor in Linux. We began by installing the cpufrequtils package using sudo apt update and sudo apt install cpufrequtils -y. After installation, we used the cpufreq-info command to display detailed CPU frequency information, including the available and currently active governors, such as performance and powersave.

We then explored alternative methods to verify the governor. This involved inspecting system files within the /sys/devices/system/cpu directory, which provides a programmatic interface to kernel information. Finally, we used cat /proc/cpuinfo to view general CPU details, although this command doesn't directly show the governor, it provides context about the CPU itself. Understanding the CPU governor is crucial for optimizing system performance and power efficiency.