CPU Frequency Scaling

From Leo's Notes
Revision as of 22:20, 16 July 2021 by Leo (talk | contribs) (Created page with "CPU clock frequency scales up and down with the CPU usage as a way to reduce power usage. On Linux, this behavior is governed by the CPU governor. The CPU frequency also sc...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
This page was last edited on 16 July 2021, at 22:20.

CPU clock frequency scales up and down with the CPU usage as a way to reduce power usage. On Linux, this behavior is governed by the CPU governor.

The CPU frequency also scales down as a response to high temperature.

Linux's CPU frequency governor

You can check your current CPU governor by running:

# cpupower frequency-info --governors
analyzing CPU 0:
  available cpufreq governors: performance powersave

Alternatively, you may check /sys/devices/system/cpu and see the setting for each CPU core.

# cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
performance
performance
performance
performance
performance
performance

On systems that do not support CPU or if for some reason Linux isn't aware of this feature, cpupower will return "Not Available" and the CPU pseudofiles won't be visible. On such systems, you may still see that the CPU frequency will still scale up or down depending on CPU utilization.

Types of governors

Governor Description
ondemand   Dynamically switch between CPU(s) available if at 95% CPU load
performance Run the CPU at max frequency
conservative Dynamically switch between CPU(s) available if at 75% load
powersave Run the CPU at the minimum frequency
userspace Run the CPU at user specified frequencies

CPU boost frequency

Some CPUs support a boost frequency. A CPU clocked at 2.5GHz can boost to 3.2GHz if power and thermal requirements are met. This frequency may drop as the CPU heats up.

Some helpful commands

Description Command
Get all CPU core frequencies grep MHz /proc/cpuinfo
Get average CPU core frequency grep MHz /proc/cpuinfo | awk '{print $4}' | awk '{temp+=$1;n++} END{printf("%f", temp/n);}'
Get max CPU core frequency grep MHz /proc/cpuinfo | awk '{print $4}' | sort -rn | head -n 1
Get min CPU core frequency grep MHz /proc/cpuinfo | awk '{print $4}' | sort -n | head -n 1
Get average CPU temperature cat /sys/class/thermal/thermal_zone*/temp | awk '{temp+=$1;n++} END{printf("%f", temp/n/1000);}'
Get max CPU temperature cat /sys/class/thermal/thermal_zone*/temp | sort -rn | head -n 1 | awk '{printf("%f", temp/n/1000);}'