How can I Disable CPU Frecuency Scaling?

As a web performance addict, I’m always looking for ways to improve system performance and speed web applications. And today I will share with you the magic of CPU frecuency scaling, and a practical how to guide to disable CPU frecuency scaling to run your system at full CPU speed.

Before getting into how to disable CPU frecuency scaling, let’s understand what is CPU throttling.

What is CPU frecuency scaling?

Since Kernel v. 2.6.18 (CentOS) and 2.6.32 (Ubuntu), a new feature called Dynamic CPU frequency scaling (aka CPU throttling)  was introduced.

This CPU frecuency scaing allows a processor to run in less frequency than maximum allowed. This is done only to preserve power consumption, but the downside of this is that you are not able to use your full CPU speed.

How can I find at what speed is my CPU running?

Run this command, as you see below:

grep -E '^model name|^cpu MHz' /proc/cpuinfo

The output should be similar to this:

[[email protected]:~]grep -E '^model name|^cpu MHz' /proc/cpuinfo
model name : Intel(R) Xeon(R) CPU E3-1240 V2 @ 3.40GHz
cpu MHz : 1600.000
model name : Intel(R) Xeon(R) CPU E3-1240 V2 @ 3.40GHz
cpu MHz : 1600.000
model name : Intel(R) Xeon(R) CPU E3-1240 V2 @ 3.40GHz
cpu MHz : 1600.000
model name : Intel(R) Xeon(R) CPU E3-1240 V2 @ 3.40GHz
cpu MHz : 1600.000
model name : Intel(R) Xeon(R) CPU E3-1240 V2 @ 3.40GHz
cpu MHz : 1600.000
model name : Intel(R) Xeon(R) CPU E3-1240 V2 @ 3.40GHz
cpu MHz : 1600.000
model name : Intel(R) Xeon(R) CPU E3-1240 V2 @ 3.40GHz
cpu MHz : 1600.000
model name : Intel(R) Xeon(R) CPU E3-1240 V2 @ 3.40GHz
cpu MHz : 1600.000

As you see, the original CPU speed is @ 3.40 Ghz, however the running CPU speed in Mhz is around 1600. The CPU is running at half its total speed.

This can also be achieved with a cool CPU package called cpufrequtils / cpupoweruitls

Install cpupowerutils on CentOS/Debian

yum install cpupowerutils -y

Install cpupowerutils on Ubuntu/Debian

apt-get install cpufrequtils

Now run this command, and it will show you information about your minimum and maximum CPU speed, among other details:

cpupower frequency-info
cpupower frequency-info output
Screenshot of the cpupower frequency-info command output

The expected output should be similar to this:

[[email protected]:~]cpupower frequency-info
analyzing CPU 0:
  driver: intel_pstate
  CPUs which run at the same hardware frequency: 0
  CPUs which need to have their frequency coordinated by software: 0
  maximum transition latency:  Cannot determine or is not supported.
  hardware limits: 1.60 GHz - 3.80 GHz
  available cpufreq governors: performance powersave
  current policy: frequency should be within 1.60 GHz and 3.80 GHz.
                  The governor "powersave" may decide which speed to use
                  within this range.
  current CPU frequency: 1.60 GHz (asserted by call to hardware)
  boost state support:
    Supported: yes
    Active: yes
    3600 MHz max turbo 4 active cores
    3700 MHz max turbo 3 active cores
    3800 MHz max turbo 2 active cores
    3800 MHz max turbo 1 active cores

Disable CPU frecuency scaling on Linux (RedHat and Ubuntu)

Let’s see how to disable CPU frecuency scaling on the most popular Linux platforms.

For CentOS / RHEL users

Let’s change the cpu frequency to the maximum available speed with the following command:

cpupower frequency-set -g performance

Let’s see if there is any change in the CPU running speed again:

[[email protected]:~]grep -E '^model name|^cpu MHz' /proc/cpuinfo
model name : Intel(R) Xeon(R) CPU E3-1240 V2 @ 3.40GHz
cpu MHz : 3497.218
model name : Intel(R) Xeon(R) CPU E3-1240 V2 @ 3.40GHz
cpu MHz : 3392.296
model name : Intel(R) Xeon(R) CPU E3-1240 V2 @ 3.40GHz
cpu MHz : 3397.742
model name : Intel(R) Xeon(R) CPU E3-1240 V2 @ 3.40GHz
cpu MHz : 2283.578
model name : Intel(R) Xeon(R) CPU E3-1240 V2 @ 3.40GHz
cpu MHz : 3457.640
model name : Intel(R) Xeon(R) CPU E3-1240 V2 @ 3.40GHz
cpu MHz : 2133.234
model name : Intel(R) Xeon(R) CPU E3-1240 V2 @ 3.40GHz
cpu MHz : 1600.257
model name : Intel(R) Xeon(R) CPU E3-1240 V2 @ 3.40GHz
cpu MHz : 3740.265
[[email protected]:~]

As you see in the previous command, now the CPU is running higher than before when it is needed.

Disable CPU frecuency scaling and this will be the result: cpu running at full speed when needed
Screenshot of CPU Frecuency & Current Speed from /proc/cpuinfo

Another way to do it manually is running this command that will change CPU governor from ‘ondemand’ mode to ‘performance’ mode for all your CPUs:

for CPUFREQ in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor; do [ -f $CPUFREQ ] || continue; echo -n performance > $CPUFREQ; done

If your system is running any of any daemon that controls CPU speed, just stop them to have your system running at full CPU speed: cpuspeed, cpufreqd or powerd.

service cpuspeed stop

For Ubuntu / Debian users

Edit this file, and if it doesn’t exist, just create it:

nano -w /etc/default/cpufrequtils

Add the following line inside:

GOVERNOR="performance"

Save pressing CTRL + X, then press Y.

Next step: disable ondemand daemon to avoid losing your changes after you reboot the server, run this command:

update-rc.d ondemand disable

That’s all. Check your settings again with this command:

cpufreq-info

Conclusion

Running your CPU at full speed can really make a boost in your applications performance. Most modern CPUs already have really good cpu cooling systems, so this shouldn’t be an issue, however make sure this doesn’t cause a huge extra power consuption or CPU over-heating. As you see, you can disable CPU frecuency scaling easily for both RedHat and Debian based distributions. Please let us know if you have any issues or questions about this.

Further reading:

About the Author: Martin Keler

Leave a Reply

Your email address will not be published. Required fields are marked *