Disable CPU Turbo Boost temporarily (ideal for not heating the CPU while compiling linux kernel for an hour)


Share Button

I just want to share a little tip about disabling the turbo, or throtling your CPU’s to avoid overheating. Ideal while compiling the linux kernel or playing a game.

CPU Turbo is the automatic overclock that all modern Intel CPUs do. My desktop CPU is an i7 4770K that can go from 3.5GHz to 3.9GHz (on turbo). My laptop is an i5 that can go from 1.7GHz to 2.6GHz. The exact model is i5 3317U (it is an Ultra low voltage ivy bridge model).

As the CPU increases speed, it increases power consumption much faster than linear.

The CPU normally runs at a much lower idle clock, such as 0.8GHz (800MHz), and the scaling governor puts each core at max clock speed when its utilization goes high. When compiling the kernel (which takes about an hour with my laptop’s i5), all four logical cores get put in the maximum frequency which is 1.701GHz. The scaling governor doesn’t actually decides when to turbo, the CPU does it by itself when it runs at max frequency.

But what if I want to run at max nominal clock, and not jump to turbo to save power and decrease temperature?

There is a little trick to disable turbo. My CPU lists the following available maxclocks:

# cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies 
1701000 1700000 1600000 1500000 1400000 1300000 1200000 1100000 1000000 900000 800000 799000

Funny, it lists both 1.701GHz and 1.7GHz in my laptop. And turbo clocks are not listed (that is because turbo is out of the control of the OS, and is an automatic hardware feature).

The CPU will apply turbo if the OS told it to run at 1.701GHz, but won’t turbo if the OS tells it to run at less than that, like 1.6GHz.

It’s the same for my desktop i7:

$ cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies 
3501000 3500000 3300000 3100000 2900000 2700000 2500000 2300000 2100000 2000000 1800000 1600000 1400000 1200000 1000000 800000

The CPU will turbo when told to run at 3.501GHz but not when told to run at 3.3GHz.

Disabling Turbo Boost (until next reboot or undo)

First, get the third max frequency that your CPU supports by looking at ‘scaling_available_frequencies’.

For my laptop, that it is 1600000

Then, ‘echo’ this number into the scaling_max_freq file for each CPU, by doing this in a console:

$ sudo su
# for a in /sys/devices/system/cpu/cpu?; do echo 1600000 > $a/cpufreq/scaling_max_freq ; done

Done, the max CPU clock is just a little less than nominal clock, and turbo will not kick in.

To undo and reenable turbo: ‘echo’ the very max frequency that your CPU supports (1701000) in my case:

# for a in /sys/devices/system/cpu/cpu?; do echo 1701000 > $a/cpufreq/scaling_max_freq ; done

If you want to actually go lower, you can. For instance, you can put the max to 1.4GHz to save power but still have some speed:

# for a in /sys/devices/system/cpu/cpu?; do echo 1400000 > $a/cpufreq/scaling_max_freq ; done

Don’t worry about making mistakes. You can’t. It won’t accept ‘echo’ of speeds that are outside of ‘scaling_available_frequencies’.

How to tell if it worked

The ‘turbostat’ tool comes in linux-tools package. It is the only tool I found that actually tells you when the Turbo is being applied, and it also shows you more data, such as the temperature of each CPU core.

Compiling the linux kernel with turbo enabled on my laptop:

cor CPU    %c0  GHz  TSC SMI    %c1    %c3    %c6    %c7 CTMP PTMP   %pc2   %pc3   %pc6   %pc7  Pkg_W  Cor_W GFX_W
         97.55 2.39 1.70   0   2.45   0.00   0.00   0.00   82   82   0.00   0.00   0.00   0.00  12.13   9.88  0.00
  0   0  97.44 2.39 1.70   0   2.56   0.00   0.00   0.00   81   82   0.00   0.00   0.00   0.00  12.13   9.88  0.00
  0   1  97.24 2.39 1.70   0   2.76
  1   2  98.60 2.39 1.70   0   1.40   0.00   0.00   0.00   82
  1   3  96.94 2.39 1.70   0   3.06

You can see that all four cores are running at 2.39GHz (that is the max speed for four hyperthreading cores being active on turbo, if it was only one core, the turbo would be 2.6GHz).

You can also see that the CTMP (core temperature) is above 80 degrees celcius. PTMP is the package temperature, and Pkg_W is how many watts the whole CPU package is consuming. In this case, 12.1 watts.

Now, lets see if the tip to disable turbo actually works:

# for a in /sys/devices/system/cpu/cpu?; do echo 1600000 > $a/cpufreq/scaling_max_freq ; done 

# turbostat

cor CPU    %c0  GHz  TSC SMI    %c1    %c3    %c6    %c7 CTMP PTMP   %pc2   %pc3   %pc6   %pc7  Pkg_W  Cor_W GFX_W
         98.14 1.60 1.70   0   1.86   0.00   0.00   0.00   72   71   0.00   0.00   0.00   0.00   7.21   5.17  0.01
  0   0  99.05 1.60 1.70   0   0.95   0.00   0.00   0.00   72   71   0.00   0.00   0.00   0.00   7.21   5.17  0.01
  0   1  98.19 1.60 1.70   0   1.81
  1   2  98.07 1.60 1.70   0   1.93   0.00   0.00   0.00   68
  1   3  97.25 1.60 1.70   0   2.75

Temperature dropped 10 degrees, and power consumption dropped from 12 watts to 7.2 watts.

That’s more like it. The kernel will take a little bit longer to compile, but you won’t burn your lap while it does.

And some games have plenty of CPU already to run, it’s just that turbo kicks in when the CPUs are active, even when turbo is not necessary to run the game at max speed.

I hope all of you enjoyed these tips.


— Juan Manuel Cabo


Share Button

Leave a Reply

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

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