CPU frequency scaling
zh-CN:CPU Frequency Scaling Template:Article summary start Template:Article summary text Template:Article summary heading Template:Article summary wiki Template:Article summary wiki Template:Article summary wiki Template:Article summary end
cpufreq refers to the kernel infrastructure that implements CPU frequency scaling. This technology enables the operating system to scale the CPU speed up or down in order to save power. CPU frequencies can be scaled automatically depending on the system load, in response to ACPI events, or manually by userspace programs.
Since kernel 3.4 the necessary modules are loaded automatically and the recommended ondemand governor is enabled by default. However, userspace applications like cpupower, acpid, laptop-mode-tools, or GUI tools provided for your desktop environment, may still be used for advanced configuration.
- 1 CpuPower
- 1.1 Configuring CPUPOWER
- 1.2 CPU frequency driver
- 1.3 Scaling governors
- 1.4 Tuning Governors
- 1.5 Setting Maximum and Minimum Frequencies
- 1.6 Daemon
- 1.7 Privilege Granting Under GNOME
- 1.8 Laptop Mode Tools
- 1.9 Troubleshooting
is a set of userspace utilities designed to assist with CPU frequency scaling. The package is not required to use scaling, but is highly recommended because it provides useful command-line utilities and a service to change the governor at boot.
The configuration file for
/etc/conf.d/cpupower. This configuration file is read by a bash script in
/usr/lib/systemd/scripts/cpupower which is activated by
Remember to enable theservice to ensure your saved settings work on bootup :
# systemctl enable cpupower.service
CPU frequency driver
requires modules to know the limits of the native cpu. To see a full list of available modules, run the following:
$ ls /lib/modules/$(uname -r)/kernel/drivers/cpufreq/
The following table is a partial list of available frequency drivers (Adapted from kernel source file
|acpi_cpufreq||CPUFreq driver which utilizes the ACPI Processor Performance States. This driver also supports Intel Enhanced SpeedStep (previously supported by the deprecated speedstep-centrino module).|
|speedstep-lib||CPUFreq drive for Intel speedstep enabled processors (mostly atoms and older pentiums (< 3))|
|powernow-k8||CPUFreq driver for K8/K10 Athlon64/Opteron/Phenom processors.|
|cpufreq-nforce2||CPUFreq driver for FSB changing on nVidia nForce2 platforms. (AMD K7, Socket A)|
|pcc-cpufreq||This driver supports Processor Clocking Control interface by Hewlett-Packard and Microsoft Corporation which is useful on some Proliant servers.|
|p4_clockmod||CPUFreq driver for Intel Pentium 4 / Xeon / Celeron processors. When enabled it will lower CPU temperature by skipping clocks.|
You probably want to use a Speedstep driver instead.
FATAL: Error inserting <module> ([...]/<module>.ko): No such device
echo <module> > /etc/modules-load.d/<module>
Load the appropriate cpu module with
# modprobe <module.
Once the appropriate cpufreq driver is loaded, detailed information about the CPU(s) can be displayed by running:
$ cpupower frequency-info
analyzing CPU 0: driver: acpi-cpufreq CPUs which run at the same hardware frequency: 0 1 2 3 CPUs which need to have their frequency coordinated by software: 0 maximum transition latency: 10.0 us. hardware limits: 1.20 GHz - 2.40 GHz available frequency steps: 2.40 GHz, 2.40 GHz, 2.27 GHz, 2.13 GHz, 2.00 GHz, 1.87 GHz, 1.73 GHz, 1.60 GHz, 1.47 GHz, 1.33 GHz, 1.20 GHz available cpufreq governors: ondemand, performance current policy: frequency should be within 1.20 GHz and 2.40 GHz. The governor "ondemand" may decide which speed to use within this range. current CPU frequency is 1.20 GHz. boost state support: Supported: yes Active: yes 25500 MHz max turbo 4 active cores 25500 MHz max turbo 3 active cores 25500 MHz max turbo 2 active cores 25500 MHz max turbo 1 active cores
Governors can be thought of as pre-configured power schemes for the CPU. Some of the governors must be loaded as kernel modules in order to be seen by user space programs. One may load as many governors as desired (only one will be active on a CPU at any given time).
cpufreq_ondemand(default and recommended)
- Dynamically switches between the CPU(s) available clock speeds based on system load
- The performance governor runs the CPU(s) at maximum clock speed
- Similar to
ondemand, but the CPU(s) clock speed switches gradually through all its available frequencies based on system load
- Runs the CPU(s) at minimum speed
- Manually configured clock speeds by user
For Desktops and most systems, the ondemand governor can provide the best compromise between heat emission, power consumption, performance, and manageability. Since it is the default and built into the kernel, loading the CPU frequency driver should be sufficient to activate it. For Laptops or other mobile systems, the conservative governor can possibly provide significant savings in power consumption.
performance are built into the kernel and do not need to be loaded as modules. If you want to use one of the other governors, you have to load them with
modprobe. For example:
# modprobe cpufreq_powersave # modprobe cpufreq_userspace
Or, add a file specifying the desired governor(s) to
/etc/modules-load.d/ and reboot.
# Load cpufreq governors cpufreq_powersave cpufreq_userspace
To see which governors have been loaded and which frequencies are supported:
# cpupower frequency-info
Manually set the governor by running the
cpupower command (as root). For example:
# cpupower frequency-set -g performance
Additional options such as upper and lower frequency bounds used by the governor can optionally be set by using the
-d options. For example, to set the second core's upper frequency bound as 2.00GHz and its lower bound as 1.00 GHz:
# cpupower -c 1 frequency-set -g ondemand -u 2.00Ghz -d 1.00Ghz
To manually set a processor to a specific frequency the userspace governor is used. For example, to set core 0 to 2.50Ghz and core 1 to 800Mhz:
# cpupower -c 0 frequency-set -f 2.50Ghz # cpupower -c 1 frequency-set -f 800Mhz
cpupower --help or
man cpupower for more information.
For those who would like a GUI for setting governors or frequency there is trayfreq, a GTK+ application that sits in the system tray.
The monitoring of CPU clock in real-time is accomplished by running:
$ watch grep \"cpu MHz\" /proc/cpuinfo
/etc/conf.d/cpupowerpersistent on boot, enable cpupower via systemd
# systemctl enable cpupower.service
/etc/conf.d/cpupower. <percent> is the percentage of cpu load; <governor> is the cpupower governor
To set the threshold for stepping up to another frequency
echo -n <percent> > /sys/devices/system/cpu/cpufreq/<governor>/up_threshold
To set the threshold for stepping down to another frequency
echo -n <percent> > /sys/devices/system/cpu/cpufreq/<governor>/down_threshold
Setting Maximum and Minimum Frequencies
/etc/conf.d/cpupower. To adjust for only a single cpu core:
-c <core #>. <clock_freq> is a clock frequency with units : GHz,MHz
To set the maximum clock frequency
cpupower frequency-set -u <clock_freq>
To set the minimum clock frequency
cpupower frequency-set -d <clock_freq>
To set the cpu to run at a specified frequency
cpupower frequency-set -f <clock_freq>
On-demand governor sampling_down_factor
sampling_down_factor is another global ondemand global tunable.
sampling_down_factor set to
1 makes no changes from existing behavior, but having
sampling_down_factor set to a value greater than 1 (e.g. 100) causes it to act as a multiplier for the scheduling interval for re-evaluating load when the CPU is at its highest clock frequency due to high load. This improves performance by reducing the overhead of load evaluation and helping the CPU stay at its highest clock frequency when it is truly busy, rather than shifting back and forth in speed. This tunable has no effect on behavior at lower frequencies/lower CPU loads.
Read the value (default: 1):
# cat /sys/devices/system/cpu/cpufreq/ondemand/sampling_down_factor
Set the value:
# echo -n 10 > /sys/devices/system/cpu/cpufreq/ondemand/sampling_down_factor
Interaction with ACPI events
Users may configure scaling governors to switch automatically based on different ACPI events such as connecting the AC adapter or closing a laptop lid. A quick example is given below, however it may be worth reading full article on acpid.
Events are defined in
/etc/acpi/handler.sh. If the package is installed, the file should already exist and be executable. For example, to change the scaling governor from
conservative when the AC adapter is disconnected and change it back if reconnected:
[...] ac_adapter) case "$2" in AC*) case "$4" in 00000000) echo "conservative" >/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor echo -n $minspeed >$setspeed #/etc/laptop-mode/laptop-mode start ;; 00000001) echo "performance" >/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor echo -n $maxspeed >$setspeed #/etc/laptop-mode/laptop-mode stop ;; esac ;; *) logger "ACPI action undefined: $2" ;; esac ;; [...]
includes a daemon which allows users to set the desired scaling governor and min/max clock speeds for all processor cores at boot-time.
Before starting the daemon, edit
/etc/conf.d/cpupower as root, selecting the desired governor and setting the min/max speed for your CPU(s).
cpupower frequency-info. However, these values are optional. Users may omit them entirely by deleting or commenting out the min/max_freq lines; scaling will work automatically.
With the appropriate configuration, start the daemon with the following command:
# systemctl start cpupower
To start the daemon automatically at startup:
# systemctl enable cpupower
Privilege Granting Under GNOME
GNOME has a nice applet to change the governor on the fly. To use it without the need to enter the root password, simply create
/var/lib/polkit-1/localauthority/50-local.d/org.gnome.cpufreqselector.pkla and populate it with the following:
[org.gnome.cpufreqselector] Identity=unix-user:USER Action=org.gnome.cpufreqselector ResultAny=no ResultInactive=no ResultActive=yes
Where the word
USER is replaced with the username of interest.
Laptop Mode Tools
If you are already using or plan to use Laptop Mode Tools for other power saving solutions, then you may want to let it also manage CPU frequency scaling. To do so, you just have to insert the appropriate frequency driver to the
/etc/modules.d/ directory. (see #CPU frequency driver above) and then go through the
/etc/laptop-mode/conf.d/cpufreq.conf file to define governors, frequencies and policies. You will not need to load other modules and daemons or to set up scaling governors and interaction with ACPI events. Please refer to Laptop Mode Tools for more details.
- Some applications, like ntop, do not respond well to automatic frequency scaling. In the case of ntop it can result in segmentation faults and lots of lost information as even the
on-demandgovernor cannot change the frequency quickly enough when a lot of packets suddenly arrive at the monitored network interface that cannot be handled by the current processor speed.
- Some CPU's may suffer from poor performance with the default settings of the
on-demandgovernor (e.g. flash videos not playing smoothly or stuttering window animations). Instead of completely disabling frequency scaling to resolve these issues, the aggressiveness of frequency scaling can be increased by lowering the up_threshold sysctl variable for each CPU. See #Changing the on-demand governor's threshold.
- Sometimes the on-demand governor may not throttle to the maximum frequency but one step below. This can be solved by setting max_freq value slightly higher than the real maximum. For example, if frequency range of the CPU is from 2.00 GHz to 3.00 GHz, setting max_freq to 3.01 GHz can be a good idea.
- Some combinations of ALSA drivers and sound chips may cause audio skipping as the governor changes between frequencies, switching back to a non-changing governor seems to stop the audio skipping.
BIOS frequency limitation
Some CPU/BIOS configurations may have difficulties to scale to the maximum frequency or scale to higher frequencies at all. This is most likely caused by BIOS events telling the OS to limit the frequency resulting in
/sys/devices/system/cpu/cpu0/cpufreq/bios_limit set to a lower value.
Either you just made a specific Setting in the BIOS Setup Utility, (Frequency, Thermal Management, etc.) you can blame a buggy/outdated BIOS or the BIOS might have a serious reason for throttling the CPU on it's own.
Reasons like that can be (assuming your machine's a notebook) that the battery is removed (or near death) so you're on AC-power only. In this case a weak AC-source might not supply enough electricity to fulfill extreme peak demands by the overall system and as there is no battery to assist this could lead to data loss, data corruption or in worst case even hardware damage!
Not all BIOS'es limit the CPU-Frequency in this case, but for example most IBM/Lenove Thinkpads do. Refer to thinkwiki for more thinkpad related info on this topic.
If you checked there's not just an odd BIOS setting and you know what you're doing you can make the Kernel ignore these BIOS-limitations.
A special parameter has to be passed to the processor module.
For trying this temporarily change the value in
For setting it permanent refer to Kernel modules or just read on.
processor.ignore_ppc=1 to your kernel boot line or create
# If the frequency of your machine gets wrongly limited by BIOS, this should help options processor ignore_ppc=1