Translation(s): ?English - Русский
CPU frequency scaling
Dynamic CPU frequency scaling (also known as CPU throttling) is a technique in computer architecture where a processor is run at a less-than-maximum frequency in order to conserve power (src: Wikipedia).
The Linux kernel CPUfreq subsystem provides this ability on Debian Linux systems.
Contents
With cpupower
To get the current state:
$ sudo cpupower frequency-info analyzing CPU 0: driver: intel_pstate CPUs which run at the same hardware frequency: 0 CPUs which need to have their frequency coordinated by software: 0 maximum transition latency: Cannot determine or is not supported. hardware limits: 800 MHz - 3.20 GHz available cpufreq governors: performance powersave current policy: frequency should be within 800 MHz and 3.20 GHz. The governor "powersave" may decide which speed to use within this range. current CPU frequency: Unable to call hardware current CPU frequency: 1.74 GHz (asserted by call to kernel) boost state support: Supported: yes Active: yes
The 'available cpufreq governors' field shows which governors are currently available, and 'current policy' shows which policy is currently in use. To switch to another policy, use sudo cpupower frequency-set -g powersave
With cpufrequtils
cpufreq is being replaced by cpupower.
Enabling
Note: In most cases, this should be enabled automatically during Debian installation.
Install the cpufrequtils package:
aptitude install cpufrequtils
Configuration
Specify the governor to use at boot
Edit /etc/default/cpufrequtils (you might need to create it if it doesn't exist). Specify the governor with the GOVERNOR variable:
# valid values: userspace conservative powersave ondemand performance # get them from cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors GOVERNOR="conservative"
Keeping the governor settings between boots
Install sysfsutils:
aptitude install sysfsutils
The sysfs values will be configured in /etc/sysfs.conf.
Here are some examples for the conservative governor:
# by default it's 444, so we have to change permissions to be able to change values mode devices/system/cpu/cpufreq/conservative = 644 devices/system/cpu/cpufreq/conservative/freq_step = 10 devices/system/cpu/cpufreq/conservative/up_threshold = 45 devices/system/cpu/cpufreq/conservative/ignore_nice_load = 1 devices/system/cpu/cpufreq/conservative/sampling_down_factor = 10
After you made the changes in /etc/sysfs.conf, apply them with /etc/init.d/sysfsutils start or with service sysfsutils start.
Troubleshooting
Check how CPU is configured
Either add "CPU Frequency Scaling Monitor" to your GNOME panel, or install the package cpufrequtils and run the command cpufreq-info, which prints one block like this per core:
analyzing CPU 0: driver: acpi-cpufreq CPUs which need to switch frequency at the same time: 0 hardware limits: 1000 MHz - 1.83 GHz available frequency steps: 1.83 GHz, 1.33 GHz, 1000 MHz available cpufreq governors: userspace, powersave, conservative, ondemand, performance current policy: frequency should be within 1000 MHz and 1.83 GHz. The governor "ondemand" may decide which speed to use within this range. current CPU frequency is 1000 MHz (asserted by call to hardware). cpufreq stats: 1.83 GHz:10.34%, 1.33 GHz:0.62%, 1000 MHz:89.04% (1068280)
There are two important pieces of information:
The statement The governor "ondemand", which means that this governor is loaded and enabled.
The statement current CPU frequency is XXXX MHz; if XXXX is lower than maximum speed, it probably means that it's working.
Governor
The governor decides what frequency should be used (it uses the CPUFreq driver to actually switch the CPU's policy). As explained above, since Lenny, the CPUFreq modules should be loaded using cpufrequtils.
In most cases, ondemand is the recommended governor. CPUFreq governors are actually modules (even though governors are modules, you should use cpufreq-info to know if the governors are loaded, and which one is active).
For more information about governors, read governors.txt (available in /usr/share/doc/linux-doc-2.6.32/Documentation/cpu-freq/ from the package linux-doc-2.6, you can read the latest version from kernel.org).
Userland governors
The userland-based governors (e.g. cpufreqd) are usually not needed any more.
Drivers
As explained above, the governor defines the frequency scaling policy, but it doesn't instruct the CPU to change the speed directly... it needs a driver for that. cpufrequtils has an init script that should load the appropriate driver at boot time.
The list of CPUFreq drivers available on your system can be obtained by running:
/sbin/modinfo /lib/modules/$(uname -r)/kernel/arch/*/kernel/cpu/cpufreq/* | grep "^[fd]"
or from linux kernel version 3.2:
/sbin/modinfo /lib/modules/$(uname -r)/kernel/drivers/cpufreq/* | grep "^[fd]"
For more information about governors, read cpu-drivers.txt (available in /usr/share/doc/linux-doc-2.6.32/Documentation/cpu-freq/ from the package linux-doc-2.6, you can read the latest version from kernel.org).
GOVERNOR variable from /etc/default/cpufrequtils not taking effect
So, you configured the GOVERNOR variable in /etc/default/cpufrequtils and after reboot you notice by running cpufreq-info that the active governor is still "ondemand".
This may happen if you have laptop-mode-tools installed. laptop-mode configures the active governor via the following variables: BATT_CPU_GOVERNOR, LM_AC_CPU_GOVERNOR, NOLM_AC_CPU_GOVERNOR. You can override them to your liking in /etc/laptop-mode/laptop-mode.conf:
BATT_CPU_GOVERNOR=powersave LM_AC_CPU_GOVERNOR=conservative NOLM_AC_CPU_GOVERNOR=ondemand
If you use laptop-mode to set the governor, you can disable /etc/init.d/cpufrequtils from starting at boot to save a few miliseconds:
update-rc.d -f cpufrequtils remove
See Also
The documentation in /usr/share/doc/linux-doc-2.6.32/Documentation/cpu-freq/
cpufrequtils's documentation (esp. cpufreq-info(1) and cpufreq-set(1))
powertop is a tool to check what prevents the kernel from going to sleep mode (also read http://www.lesswatts.org/projects/powertop).
External Links
http://kernel.org/doc/Documentation/cpu-freq/cpu-drivers.txt
http://www.pantz.org/software/cpufreq/usingcpufreqonlinux.html