12
  • How can I upper limit my CPU frequency by a value?

  • cpufreq offers fixing the frequency to a constant value, instead of letting it vary in a range.

  • It also offers conservative, on demand, powersave, and performance. I don't know what they mean. but they don't limit the frequency either. What do the four settings mean actually? In other words, what are their policies?

Tim
  • 25,177
  • what CPU do you have? From your description it sounds as though you are using the acpi cpufreq driver, please confirm. Do "cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_driver" – Doug Smythies Feb 21 '15 at 00:18
  • T400's intel core duo. Yes, acpi-cpufreq. – Tim Feb 21 '15 at 00:33

2 Answers2

18

Question 2: This answer is for the acpi-cpufreq CPU frequency scaling driver driver:

The way to check which CPU frequency driver you are using is to do:

cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_driver

The conservative mode has a slower load-versus-CPU-frequency response curve, meaning it takes a little more load on the CPU to before the CPU frequency climbs.

The ondemand mode has a faster load-versus-CPU-frequency response curve, meaning it takes a little less load on the CPU before the CPU frequency climbs.

The driver uses hysteresis, so the increasing and decreasing load versus CPU frequency curves are not the same.

The powersave mode locks the requested p-state at the lowest value for the processor. The result is the CPU is always at the lowest clock frequency.

performance mode locks the target pstate at the highest value for the processor. However, note that some processors can back-off under no load by themselves. For simplicity, just think of it as the CPU always being at the highest frequency.

Question 1: Yes, you can limit the upper frequency.

First get a list of the available frequencies (example from my computer):

doug@s15:~/temp$ cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies
3401000 3400000 3300000 3100000 3000000 2900000 2800000 2600000 2500000 2400000 2200000 2100000 2000000 1900000 1700000 1600000

Then decide what you want the maximum frequency to be, noting that it must be from the list. Then set it:

echo 2600000 | sudo tee /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq

And repeat for all CPUs.

A script version might be preferred, run as sudo:

#! /bin/bash
cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_max_freq
for file in /sys/devices/system/cpu/cpu*/cpufreq/scaling_max_freq; do echo "2900000" > $file; done
cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_max_freq
Doug Smythies
  • 15,448
  • 5
  • 44
  • 61
  • thanks! what does "cpu frequency response curve." mean? What does " a slower load verses cpu frequency response curve" mean? Does powersave == always lowest freq, and performance == always highest freq? – Tim Feb 21 '15 at 00:35
  • Thanks. Is there some way to upper limit GPU freq or fix it to a different GPU freq? – Tim Feb 21 '15 at 03:29
  • I am a server guy, and don't know anything about GPU stuff. Perhaps start a new question for it. – Doug Smythies Feb 21 '15 at 03:31
  • scaling_available_frequencies does not exist. (Ubuntu 20.04). The other files do. So I don't know what frequencies I can choose from. – CPBL Jul 29 '20 at 00:53
  • @CPBL : If scaling_available_frequencies exist or not is a function of the CPU frequency scaling driver. The answer was written for the acpi-cpufreq driver, which apparently you are not using. – Doug Smythies Jul 29 '20 at 02:36
  • thanks. Hm, Maybe your first comment to the OP should be part of your answer? First line in your answer could use more explanation for the nonexpert audience – CPBL Jul 29 '20 at 13:12
  • @CPBL ; O.K. edited my old answer. – Doug Smythies Jul 29 '20 at 13:34
  • @CPBL Check the scaling_driver, if it's something like intel_pstate, then you would need to turn it off to manually limit/set the CPU frequency. – Pavin Joseph Apr 01 '21 at 05:07
  • This is an excellent answer, I would suggest augmenting it with some information on other scaling drivers and a link to the Debian wiki which I found very useful in making the changes persist across reboots. https://wiki.debian.org/CpuFrequencyScaling

    For some reason, I couldn't get a file lock while editing the scaling_max_freq file, so had to do it using sysfsutils and /etc/sysfs.conf

    – Pavin Joseph Apr 01 '21 at 05:16
3

A oneliner temporary solution which may help in some cases;

for i in {0..3}; do sudo cpufreq-set -c ${i} -g powersave --min 500Mhz --max 2600Mhz; done

Feel free to adapt the max number of CPU cores (here = 3) to yours.

Or even better, with the -r flag:

sudo cpufreq-set -r -g performance --min 500Mhz --max 2600Mhz

From the man:

-r --related
    modify all hardware-related CPUs at the same time
s.k
  • 1,280