cpufrequtils

From ArchWiki

Jump to: navigation, search
Article summary
An overview of the popular userspace tools for the kernel CPUfreq subsystem.
Available in languages
English
Русский
Español
Português
简体中文
Türkçe
Related articles
pm-utils
powernowd

cpufrequtils is a set of utilities designed to assist 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 and/or power scheme. For instance, CPU frequency scaling can run a 2GHz processor at 1GHz when a notebook is on battery power, thereby conserving battery life and lowering core temperatures.

When used in conjunction with pm-utils, notebook owners are provided with a complete power management suite.

Note that cpufrequtils is not the only way one can manage/throttle one's CPU. powernowd is a simple alternative for adjusting the speed of your CPU depending on system load.

This article covers installation and basic configuration of the cpufrequtils package.

Note: cpufrequtils is not the same as cpufreqd. Never run both cpufreqd and cpufreq daemons.

Contents

Installation

The cpufrequtils package is available in the [extra] repository:

# pacman -Sy cpufrequtils

Configuration

Configuring CPU scaling is a 3-part process:

  1. Load appropriate CPU frequency driver
  2. Load desired scaling governor(s)
  3. Configure and load frequency scaling daemon (optional)

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-k6, powernow-k7, powernow-k8, and speedstep-centrino drivers.

Tip: For an AMD "K10" CPU like Phenom X4, use the powernow-k8 driver.

To load the CPU frequency driver manually:

Intel:

# 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.

AMD:

# modprobe powernow-k{6,7,8}

Not all of the powernow-k* drivers may be available or necessary. If loading one of them fails, try loading them individually.

To load the driver automatically at startup, add the appropriate driver to the MODULES array within /etc/rc.conf. 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:

$ cpufreq-info

The output should appear similar to the following:

Command: cpufreq-info
 analyzing CPU 0:
  driver: acpi-cpufreq
  CPUs which need to switch frequency at the same time: 0 1
  hardware limits: 1000 MHz - 2.00 GHz
  available frequency steps: 2.00 GHz, 1.67 GHz, 1.33 GHz, 1000 MHz
  available cpufreq governors: ondemand, performance
  current policy: frequency should be within 1000 MHz and 2.00 GHz.
                  The governor "performance" may decide which speed to use
                  within this range.
  current CPU frequency is 2.00 GHz.
 analyzing CPU 1:
  driver: acpi-cpufreq
  CPUs which need to switch frequency at the same time: 0 1
  hardware limits: 1000 MHz - 2.00 GHz
  available frequency steps: 2.00 GHz, 1.67 GHz, 1.33 GHz, 1000 MHz
  available cpufreq governors: ondemand, performance
  current policy: frequency should be within 1000 MHz and 2.00 GHz.
                  The governor "performance" may decide which speed to use
                  within this range.
  current CPU frequency is 2.00 GHz.

Monitoring the CPU speed in real-time can be achieved by running:

watch grep \"cpu MHz\" /proc/cpuinfo

Scaling governors

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).

Available governors:

performance (default)
The performance governor is built into the kernel and runs the CPU(s) at maximum clock speed
cpufreq_ondemand (recommended)
Dynamically increases/decreases the CPU(s) clock speed based on system load
cpufreq_conservative
Similar to ondemand, but more conservative (clock speed changes are more graceful)
cpufreq_powersave
Runs the CPU at minimum speed
cpufreq_userspace
Manually configured clock speeds by user

Add the desired governor(s) to the MODULES array in /etc/rc.conf:

MODULES=(acpi-cpufreq cpufreq_ondemand cpufreq_powersave vboxdrv fuse fglrx iwl3945 ... )

Alternatively, manually set the governor by running the cpufreq-set command (as root). However, this setting will not be saved after a reboot/shutdown. For example:

# cpufreq-set -g ondemand

Run cpufreq-set --help or man cpufreq-set for more information.

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 /etc/acpi/handler.sh. If the acpid package is installed, the file should already exist and be executable. For example, to change the scaling governor from performance to conservative when the AC adapter is disconnected and change it back if reconnected:

File: /etc/acpi/handler.sh
[...]

 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
 ;;

[...]

Changing the ondemand governor's threshold

To change when the ondemand governor switches to a higher multiplier, one can manipulate /sys/devices/system/cpu/cpu#/cpufreq/ondemand/up_threshold. Determine the current setting by issuing the following command as root:

# cat /sys/devices/system/cpu/cpu0/cpufreq/ondemand/up_threshold

The value returned should be 95, the default setting as of kernel version 2.6.31. This means that the ondemand governor currently increases the clock rate if a core reaches 95% utilization. The can be changed, for example:

# echo 50 > /sys/devices/system/cpu/cpu0/cpufreq/ondemand/up_threshold

The governor will now switch to a higher clock rate if a core reaches 50% utilization.

To re-apply this setting during boot, add the command to /etc/rc.local.

Tip: One user found it necessary to use (sleep 2 && echo 50 > /sys/devices/system/cpu/cpu0/cpufreq/ondemand/up_threshold) & or the command would fail with a "path not found" message during boot.
Note: Adjusting only cpu0 should work fine on multi-core systems, as other entries that belong to the same physical processor are adjusted automatically.

Daemon mode

cpufrequtils also installs a daemon which allows users to set the desired scaling governor and min/max clock speeds at boot-time, without the need for additional tools such as kpowersave. This is a perfect solution for those running a lightweight desktop, such as Openbox.

Before starting the daemon, edit /etc/conf.d/cpufreq as root, selecting the desired governor and setting the min/max speed for your CPU(s), for example:

File: /etc/conf.d/cpufreq
#configuration for cpufreq control

# valid governors:
#  ondemand, performance, powersave,
#  conservative, userspace
governor="ondemand"

# valid suffixes: Hz, kHz (default), MHz, GHz, THz
min_freq="1GHz"
max_freq="2GHz"
Note: The exact min/max values of the CPU(s) can be determined by running cpufreq-info after loading the CPU driver (e.g. modprobe acpi-cpufreq). 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:

# /etc/rc.d/cpufreq start

To start the daemon automatically at startup, add cpufreq to the DAEMONS array in /etc/rc.conf, for example:

DAEMONS=(syslog-ng hal cpufreq dhcdbd networkmanager !network !netfs @alsa @crond @cups @fam @ntpd @sshd)

Troubleshooting

  • 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 ondemand 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 ondemand 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.
Personal tools