Search code examples
linuxlinux-kernellinux-device-drivercpucpu-speed

How to set and lock cpu freq in linux


I am working under linux and what I want to do is to lock cpu to a certain frequency, disable cpu automatic freq change.

Could anyone indicate how to do it in driver or kernel ?

Thanks.


Solution

  • what I want to do is to lock cpu to a certain frequency, disable cpu automatic freq change.

    You can use kernel modules to do this for you already and there are user space programs that you can run to disable it. Look for Disable Frequency scaling.

    on Debian the package can be installed as follows

    aptitude install cpufrequtils
    

    The read the docs from there. If you want to get a bit more hands by loading kernel modules, for Intel the one you need to load is...

    acpi-cpufreq
    

    If you're running Linux in something like a VirtualBox and trying to load this it will likely fail because acpi will be disabled. You can find out what you need to do here to control this from command line.

    http://www.thinkwiki.org/wiki/How_to_make_use_of_Dynamic_Frequency_Scaling

    If you want to see how this is done in a kernel module the source code you need can be found here.

    http://lxr.free-electrons.com/source/drivers/cpufreq/acpi-cpufreq.c

    You would likely need to read the source for one of the governor modules to understand how this works.

    If possible I'd control this from userspace.