CPU Frequency Scaling: Difference between revisions

From Leo's Notes
This page was last edited on 16 July 2021, at 22:57.
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..."
 
mNo edit summary
Line 3: Line 3:
The CPU frequency also scales down as a response to high temperature.  
The CPU frequency also scales down as a response to high temperature.  


== Linux's CPU frequency governor ==
==Linux's CPU frequency governor==
You can check your current CPU governor by running:
You can check your current CPU governor by running:
{{Highlight
{{Highlight
Line 22: Line 22:
| lang = terminal
| lang = terminal
}}
}}
On systems that do not support CPU or if for some reason Linux isn't aware of this feature, <code>cpupower</code> 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===
 
=== Types of governors ===
{| class="wikitable"
{| class="wikitable"
!Governor
!Governor
Line 45: Line 43:
|}
|}


=== CPU boost frequency ===
==Intel Turbo 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 Intel CPUs support a turbo boost frequency where a CPU can clock faster than its stock speed depending on available power and thermal conditions. Refer to the CPU's specification to determine a particular CPU's turbo boost frequency.
 
I have observed on some compute servers that the CPU will run somewhere between the base frequency and the turbo boost frequency when the temperature is around the mid 70's Celsius when under full load. I'm not sure why this is the case.


=== Some helpful commands ===
==Some helpful commands==
{| class="wikitable"
{| class="wikitable"
|+
|+
Line 58: Line 58:
|-
|-
|Get average CPU core frequency
|Get average CPU core frequency
|<code><nowiki>grep MHz /proc/cpuinfo | awk '{print $4}' | awk '{temp+=$1;n++} END{printf("%f", temp/n);}'</nowiki></code>  
|<code><nowiki>grep MHz /proc/cpuinfo | awk '{print $4}' | awk '{temp+=$1;n++} END{printf("%f", temp/n);}'</nowiki></code>
|-
|-
|Get max CPU core frequency
|Get max CPU core frequency
Line 67: Line 67:
|-
|-
|Get average CPU temperature
|Get average CPU temperature
|<code><nowiki>cat /sys/class/thermal/thermal_zone*/temp | awk '{temp+=$1;n++} END{printf("%f", temp/n/1000);}'</nowiki></code>  
|<code><nowiki>cat /sys/class/thermal/thermal_zone*/temp | awk '{temp+=$1;n++} END{printf("%f", temp/n/1000);}'</nowiki></code>
|-
|-
|Get max CPU temperature
|Get max CPU temperature
|<code><nowiki>cat /sys/class/thermal/thermal_zone*/temp | sort -rn | head -n 1 | awk '{printf("%f", temp/n/1000);}'</nowiki></code>  
|<code><nowiki>cat /sys/class/thermal/thermal_zone*/temp | sort -rn | head -n 1 | awk '{printf("%f", $1/1000);}'</nowiki></code>
|}
|}

Revision as of 22:57, 16 July 2021

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

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

Intel Turbo Boost frequency

Some Intel CPUs support a turbo boost frequency where a CPU can clock faster than its stock speed depending on available power and thermal conditions. Refer to the CPU's specification to determine a particular CPU's turbo boost frequency.

I have observed on some compute servers that the CPU will run somewhere between the base frequency and the turbo boost frequency when the temperature is around the mid 70's Celsius when under full load. I'm not sure why this is the case.

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", $1/1000);}'