Subject: setting CPU speed on running linux system
If the OS is Linux, you can manually control the CPU speed by reading and writing some virtual files in the “/proc” and “/sys” virtual file systems. You have to be root to set these. Here are some details; I hope this is helpful…
Is the system capable of software CPU speed control?
If the “directory” ** /sys/devices/system/cpu/cpu0/cpufreq ** exists, speed is controllable.
— If it does not exist, you may need to go to the BIOS and turn on EIST and any other C and P state control and visibility, then reboot
What speed is the box set to now?
Do the following:
$ cd /sys/devices/system/cpu
$ cat ./cpu0/cpufreq/cpuinfo_max_freq
3193000
$ cat ./cpu0/cpufreq/cpuinfo_min_freq
1596000
What speeds can I set to?
Do
$ cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies
It will list highest settable to lowest; example from my NHM “Smackover” DX58SO HEDT board, I see:
3193000 3192000 3059000 2926000 2793000 2660000 2527000 2394000 2261000 2128000 1995000 1862000 1729000 159600
You can choose from among those numbers to set the “high water” mark and “low water” mark for speed. If you set “high” and “low” to the same thing, it will run only at that speed.
Show me how to set all to highest settable speed!
Use the following little sh/ksh/bash script:
$ cd /sys/devices/system/cpu # a virtual directory made visible by device drivers
$ newSpeedTop=`awk '{print $1}' ./cpu0/cpufreq/scaling_available_frequencies`
$ newSpeedLow=$newSpeedTop # make them the same in this example
$ for c in ./cpu[0-9]* ; do
> echo $newSpeedTop >${c}/cpufreq/scaling_max_freq
> echo $newSpeedLow >${c}/cpufreq/scaling_min_freq
> done
$
How do I return to the default – i.e. allow machine to vary from highest to lowest?
Edit line # 3 of the script above, and re-run it. Change the line:
$ newSpeedLow=$newSpeedTop # make them the same in this example
To read
$ newSpeedLow=`awk '{print $NF}' ./cpu0/cpufreq/scaling_available_frequencies`
And then re-run the script.
Below is a fancier ‘chg_freq.sh’ script I made:
below is first line of chg_freq.sh
#!/bin/sh
if [ "x$1" == "x" ]
then
echo "have to enter a frequency. Available frequencies are:"
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies
exit
fi
echo "Available frequencies are:"
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies
# see http://www.thinkwiki.org/wiki/How_to_make_use_of_Dynamic_Frequency_Scaling
cpucount=`cat /proc/cpuinfo|grep processor|wc -l`
# load the governors if compiled as modules
modprobe cpufreq_performance cpufreq_ondemand cpufreq_conservative cpufreq_powersave cpufreq_userspace
FLROOT=/sys/devices/system/cpu
echo "display available governors"
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors
echo "display current cpu0 governor"
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
METHOD=0 # 0=use setspeed, 1=use min max
i=0
while [ $i -ne $cpucount ]
do
if [ $METHOD == 0 ]; then
FLNM="$FLROOT/cpu"$i"/cpufreq/scaling_governor"
echo "Setting $FLNM to " userspace
echo userspace > $FLNM
FLNM="$FLROOT/cpu"$i"/cpufreq/scaling_setspeed"
echo "Setting freq $FLNM to " $1
echo $1 > $FLNM
else
echo "Setting freq $FLROOT/cpu"$i"/cpufreq/cpuinfo_max_freq to " $1
FLNMAX="$FLROOT/cpu"$i"/cpufreq/cpuinfo_max_freq"
FLNMIN="$FLROOT/cpu"$i"/cpufreq/cpuinfo_min_freq"
echo $1 > $FLNMAX
echo $1 > $FLNMIN
fi
i=`expr $i + 1`
done
- RedHat EL4 64 bit all kernel versions have cpuid and msr driver built in.
- You can double check it by looking at /boot/config* file for the kernel installed.
- And look for CPUID and MSR driver config option. It it says ‘y’ then it is
- builtin the kernel. If it says ‘m’, then it is a module and modprobe is needed.
echo check cpu freq in /proc/cpuinfo
cat /proc/cpuinfo |grep -i mhz
above is last line of chg_freq.sh