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, a technology used primarily by notebooks that enables the operating system to scale the CPU speed up or down, depending on the current system load.
In order to use scaling, the needed modules have to be loaded and then a governor has to be set. cpufrequtils, acpid and laptop-mode-tools each offer different ways of managing cpufreq. You can also use the simple CPU frequency applets included with some desktop environments instead.
Template:Package Official is a set of userspace utilities designed to assist with CPU frequency scaling. The package isn't required to use scaling, but is highly recommended because it provides useful command-line utilities and a daemon script to set the governor at boot.
Template:Package Official provides similar information to the cpufreq-info utility in this package, but not at the same level of detail.
The Template:Package Official package is available in the [extra] repository:
# pacman -S cpufrequtils
Configuring CPU scaling is a 3-part process:
- Load appropriate CPU frequency driver
- Load desired scaling governor(s)
- Select a method to manage switching the governor: manually (via /sys or cpufreq-set), the cpufrequtils #Daemon, laptop-mode-tools, acpid or using an applet/desktop environment. Different methods can be combined if desired.
- Optionally, the scaling governor can be tuned with cpufrequtils and/or the /sys interface.
CPU frequency driver
In order for frequency scaling to work properly, the operating system must first know the limits of the CPU(s). To accomplish this, a kernel module is loaded that can read and manage the specifications of the CPU(s).
Most modern notebooks and desktops can simply use the acpi-cpufreq driver. However, other options include the p4-clockmod, powernow-k8, and speedstep-centrino drivers. To see a full list of available drivers, run the following:
$ ls /lib/modules/2.6.??-ARCH/kernel/drivers/cpufreq
To load the CPU frequency driver manually:
# modprobe acpi-cpufreq
For older Intel CPUs, the command above may return with:
FATAL: Error inserting acpi_cpufreq ([...]/acpi-cpufreq.ko): No such device
In this case, replace the kernel module acpi-cpufreq with speedstep-centrino, p4-clockmod or speedstep-ich.
There is a kernel with the speedstep-centrino module patched on the AUR, it is the kernel26-pentium-m package which is located here: http://aur.archlinux.org/packages.php?ID=33104
# modprobe powernow-k8
Loading at boot
To load the driver automatically at startup, add the appropriate driver to the MODULES array within Template:Filename. For example:
MODULES=( acpi-cpufreq vboxdrv fuse fglrx iwl3945 ... )
Once the appropriate cpufreq driver is loaded, detailed information about the CPU(s) can be displayed by running:
The output should appear similar to the following:
To simply see which governors are available:
Monitoring the CPU speed in real-time can be achieved by running:
watch grep \"cpu MHz\" /proc/cpuinfo
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 Template:Filename 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, you may want to let it manage also CPU frequency scaling. In that case you just have to insert the acpi-cpufreq module to the MODULES array in Template:Filename:
And then go through the Template:Filename to define governors, frequencies and policies.
If you use laptop-mode-tools to manage cpufrequtils, then you won't need to load other modules and daemons or to set up scaling governors and interaction with ACPI events. Please refer to Laptop Mode Tools to know how to install and configure laptop-mode-tools.
Governors can be thought of as pre-configured power schemes for the CPU. These governors must be loaded as kernel modules in order to be seen by such programs as kpowersave and gnome-power-manager. One may load as many governors as desired (only one will be active at any given time).
- Template:Codeline (default)
- The performance governor is built into the kernel and runs the CPU(s) at maximum clock speed
- Template:Codeline (recommended)
- Dynamically increases/decreases the CPU(s) clock speed based on system load
- Similar to Template:Codeline, but more conservative (clock speed changes are more graceful)
- Runs the CPU at minimum speed
- Manually configured clock speeds by user
Load the desired governor(s) with Template:Codeline. For example:
# modprobe cpufreq_ondemand # modprobe cpufreq_userspace
Or, add the desired governor(s) to the MODULES array in Template:Filename and reboot.
MODULES=(acpi-cpufreq cpufreq_ondemand cpufreq_powersave)
Manually set the governor by running the Template:Codeline command (as root). However, this setting will not be saved after a reboot/shutdown. For example:
# cpufreq-set -g ondemand
Note that the previous command only sets the governor for the first processor. If you have a multicore or multiprocessor system, use the -c flag to set the governor for a specific core. For example, to set the governor for the fourth core (core numbers start from zero):
# cpufreq-set -c 3 -g ondemand
For those who would like a GUI for setting governors or frequency there is trayfreq, a GTK+ application that sits in the system tray.
Changing the Template:Codeline governor's threshold
# cat /sys/devices/system/cpu/cpufreq/ondemand/up_threshold
The value returned should be 80, the default setting as of kernel version 2.6.31. This means that the Template:Codeline governor currently increases the clock rate if a core reaches 80% utilization. The can be changed, for example:
echo "15" > /sys/devices/system/cpu/cpufreq/ondemand/up_threshold
# (sleep 30 && sh -c "echo -n 75 > /sys/devices/system/cpu/cpu0/cpufreq/ondemand/up_threshold")&Adjust to your cpu number and values.
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. Events are defined in Template:Filename. If the Template:Package Official package is installed, the file should already exist and be executable. For example, to change the scaling governor from Template:Codeline to Template:Codeline when the AC adapter is disconnected and change it back if reconnected:
cpufrequtils also includes a daemon which allows users to set the desired scaling governor and min/max clock speeds for all processor cores at boot-time, without the need for additional tools such as kpowersave.
Before starting the daemon, edit Template:Filename as root, selecting the desired governor and setting the min/max speed for your CPU(s), for example:
With the appropriate configuration, start the daemon with the following command:
# /etc/rc.d/cpufreq start
DAEMONS=(syslog-ng networkmanager @alsa @crond @cups @cpufreq)
- 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 Template:Codeline governor cannot change the frequency quickly enough when a lot of packages suddenly arrive at the monitored network interface that cannot be handled by the current processor speed.
- Some CPUs may suffer from poor performance with the default settings of the Template:Codeline governor (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 ondemand governor's threshold.
- Sometimes the deamon may not throttle to the maximum frequence but one step below. This can be solved by setting max_freq value slightly higher than the real maximum. For example, if frequence range of the CPU is from 2.00GHz to 3.00GHz, setting max_freq to 3.01GHz can be a good idea.
- Some cpu/bios configurations may have difficulties to scale to the maximum frequencies or scale to highter frequencies at all. Sadly there is only a workaround right now. Add "processor.ignore_ppc=1" to your kernel boot line and/or edit the value in /sys/module/processor/parameters/ignore_ppcfrom 0 to 1.