Can I upper limit the CPU frequency?
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
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