To make CPU frequency scaling work under linux, these thing are needed:
1. A CPU that supports frequency scaling. (of course!)
2. Proper kernel modules installed.
- A kernel module is basically a file that tells the kernel how to handle certain type of hardware. In this case, the kernel module tells Linux kernel how to use CPU frequency scaling function. In most cases, these modules are installed by default.
3. Proper setup to load the module into kernel.
- Why it's called kernel "module" is because it can be loaded as system need it. If you are having trouble with cpu frequency scaling, then most likely the kernel module for frequency scaling is not properly loaded. This is what I am going to talk about in detail.
The example is on my laptop with AMD Sempron 3000+ CPU, and has Mandriva 2007 installed. By default CPU frequency scaling is not properly setuped.
1. Check if the kernel modules files for frequency scaling is installed.
As root:
#ls /lib/modules/$(uname -r)/kernel/arch/i386/kernel/cpu/cpufreq
Output:
acpi-cpufreq.ko.gz p4-clockmod.ko.gz speedstep-centrino.ko.gz
cpufreq-nforce2.ko.gz powernow-k6.ko.gz speedstep-ich.ko.gz
gx-suspmod.ko.gz powernow-k7.ko.gz speedstep-lib.ko.gz
longrun.ko.gz powernow-k8.ko.gz speedstep-smi.ko.gz
The folder /lib/modules is usually where kernel modules are installed. If you are using different distro it might be slightly different, but explore under /lib/modules you will find it. Or alternatively you can do:
#find / -name acpi-cpufreq.ko.gz
which will search for acpi-cpufreq.ko.gz in your file system.
If nothing is found, chances are they are missing(which is highly unlikely). But luckily, there is always rpm or deb package for it. Do a quick google search on
acpi-cpufreq.ko.gz+rpm+mandriva
showed me a lot of results. Just install the package using yum, apt-get, urpmi or whatever package manager on your distro.2. Test Load the kernel module into kernel
So which module should be loaded? It depends on your CPU, here is some reference:
powernow-k7
AMD Sempron/Athlon/MP ( K7 )
Socket Types: A, Slot A
powernow-k8
AMD Duron/Sempron/Athlon/Opteron 64 ( K8 )
Socket Types: 754, 939, 940, S1 ( 638 ), AM2 ( 940 ), F ( 1207 )
Intel Pentium 4 and Intel Celeron M
p4_clockmod
Intel Core Duo & Intel Pentium M
speedstep-centrino
You can also use
$cat /proc/cpuinfo
to get info on your CPU.So once knowing which module to load, the next step is to load it. You can use:
#modprobe [respective name]
As rootFor my Sempron, it's
#modprobe powernow-k8
If you load the wrong module, kernel will not load it and instead complain with a error message. If all modules doesn't work, try acpi-cpufreq, as it's the "generic" one.
If no error message, you can check:
#cpufreq-info
Which gave me:
cpufrequtils 0.4: cpufreq-info (C) Dominik Brodowski 2004
Report errors and bugs to linux@brodo.de, please.
analyzing CPU 0:
driver: powernow-k8
CPUs which need to switch frequency at the same time: 0
hardware limits: 800 MHz - 1.80 GHz
available frequency steps: 1.80 GHz, 1.60 GHz, 800 MHz
available cpufreq governors: ondemand, userspace, performance
current policy: frequency should be within 800 MHz and 1.80 GHz.
The governor "ondemand" may decide which speed to use
within this range.
current CPU frequency is 800 MHz.
I can see the message already shows me the cpu supports frequency scaling, and the kernel knows it.
Now it's very close to finish, just have to load another module to tell kernel when to scale cpu frequency, sort of like a "policy" for kernel to follow. Do:
#modprobe cpufreq_ondemand
#echo -e "ondemand" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
First line loads cpufreq_ondemand into kernel, there are other policies, such as:
cpufreq_conservative, cpufreq_ondemand, cpufreq_powersave, cpufreq_userspace
That are available.
Second line changes the content of
/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
to "ondemand". This tells the kernel ondemand governor is used.
If you followed me all the way here, then your Linux kernel should be able to adjust cpu frequency now.
3. Load the same thing every time system restarts
These modules are not loaded by default. So every time you reboot, you need to load them again. There are many ways to let these modules load automatically, and here's one:
Add
modprobe powernow-k8 && modprobe cpufreq_ondemand
echo -e "ondemand" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
into /etc/rc.local
content of /etc/rc.local will be executed every time system starts, so it ensure those modules to be loaded every time system restarts.
No comments:
Post a Comment