Difference between revisions of "User:Stefanwilkens"

From ArchWiki
Jump to: navigation, search
(Fine-tuning governors)
(Changing the conservative governor's thresholds)
Line 114: Line 114:
 
=== Tuning conservative governor ===
 
=== Tuning conservative governor ===
  
==== Changing the conservative governor's thresholds ====
+
=====Changing the conservative governor's thresholds=====
 +
Determine the current {{ic|up_threshold}} setting by issuing the following command as root:
 +
# cat /sys/devices/system/cpu/cpufreq/conservative/up_threshold
 +
 
 +
The value returned should be {{ic|75}}, the default setting as of kernel version 3.0. This means that the {{ic|conservative}} governor currently increases the clock rate to the next highest speed if a core reaches 75% utilization. The can be changed, for example:
 +
 
 +
# echo -n 40 > /sys/devices/system/cpu/cpufreq/conservative/up_threshold
 +
 
 +
{{Note|The minimum value one can enter must be above the one in {{ic|down_threshold}}; entering a value under that results in the error, "bash: echo: write error: Invalid argument"}}
 +
 
 +
Similarly the {{ic|down_threshold}} value can be read and modified via {{ic|/sys/devices/system/cpu/cpufreq/conservative/down_threshold}}. The default value should be {{ic|20}} as of kernel version 3.0. This means that the {{ic|conservative}} governor decreases the clock rate to the next lowest speed if a core falls to 20% utilization, which is a sensible default.
 +
 
 +
While the down sampling rate can also be adjusted for the {{ic|conservative}} governor, increasing it may only help with occasional low usage CPU spikes during high usage applications, as the {{ic|down_threshold}} is a much more direct control for down scaling which does not exist on the {{ic|ondemand}} governor.
 +
 
 +
Be aware that setting {{ic|down_threshold}} too close to {{ic|up_threshold}} may result in constant CPU switching, which might be something desirable for certain users and not for others. Setting {{ic|down_threshold}} or {{ic|up_threshold}} too low may result in the CPU being clocked higher than it needs sacrificing power saving for performance, and setting {{ic|up_threshold}} too high may result in decreased performance, but reduced power consumption. Experiment to find the optimal values for your system and your needs.
  
 
=== Interaction with ACPI events ===
 
=== Interaction with ACPI events ===

Revision as of 16:10, 5 October 2012

Currently: rewrite of CPU_Frequency_Scaling#CPU_frequency_driver


Template:Article summary start Template:Article summary text Template:Article summary heading Template:Article summary end

CPU frequency scaling 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.

Tip: Since kernel 3.4 the necessary CPU frequency driver modules are loaded automatically and the recommended ondemand governor is enabled by default. User-space applications like cpupower, acpid, laptop-mode-tools, or GUI tools provided for your desktop environment, may still be used for advanced configuration.

Introduction

Configuration of CPU frequency scaling is done through three mechanics:

  • The CPU frequency driver
  • The scaling governor
  • Fine-tuning of the governor through user-space tools

Since kernel 3.4 the necessary CPU frequency driver modules are loaded automatically and the recommended ondemand governor is enabled by default. This leaves the user with a functional, on-demand, CPU frequency scaling setup requiring no intervention from user-space.

User-space applications like cpupower, acpid, laptop-mode-tools, or GUI tools provided for your desktop environment, may still be used for advanced configuration.

The CPU frequency driver

In order for frequency scaling to work properly, the operating system must first know the CPU(s) specification. To accomplish this, a kernel module must be loaded that can read and manage the CPU p(ower)-states.

Note: These modules may need related features enabled in BIOS which may be labeled as: Speedstep, Cool and Quiet, PowerNow!, or ACPI. Consult your BIOS documentation.
Tip: Since 3.4, the kernel will determine and load the appropriate driver module.

Available drivers

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-ich 
CPUFreq driver for certain mobile Intel Pentium III (Coppermine), all mobile Intel Pentium III-M (Tualatin) and all mobile Intel Pentium 4 P4-M on systems which have an Intel ICH2, ICH3 or ICH4 southbridge.
speedstep-smi 
CPUFreq driver for certain mobile Intel Pentium III (Coppermine), all mobile Intel Pentium III-M (Tualatin) on systems which have an Intel 440BX/ZX/MX southbridge.
powernow-k8 
CPUFreq driver for K8/K10 Athlon64/Opteron/Phenom processors.
powernow-k7 
CPUFreq driver for mobile AMD K7 mobile 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.


You can check if the appropriate module for your processor has been loaded with lsmod, part of kmod.

[user@host ~]$ dmesg | grep powernow
[    4.748680] powernow-k8: Found 1 AMD Phenom(tm) II X4 955 Processor (4 cpu cores) (version 2.20.00)
[    4.748709] powernow-k8:    0 : pstate 0 (3200 MHz)
[    4.748710] powernow-k8:    1 : pstate 1 (2500 MHz)
[    4.748711] powernow-k8:    2 : pstate 2 (2100 MHz)
[    4.748712] powernow-k8:    3 : pstate 3 (800 MHz)

Scaling governors

Governors can be thought of as pre-configured power schemes for the CPU, they alter the CPU's predefined power state that is exposed through the CPU frequency scaling driver. These governors can be built into the kernel or be made available as separate modules which must be loaded to be seen by user space applications. Users can load as many governors as desired, only one will be active on a CPU at any given time.

For Desktops and most systems, the ondemand governor can provide the best compromise between heat emission, power consumption, performance, and manageability. For Laptops or other mobile systems, the conservative governor can provide significant savings in power consumption.

Tip: Since kernel 3.4, the cpufreq_ondemand governor is activated by default.

Available governors:

cpufreq_ondemand
Dynamically switches between the CPU(s) available clock speeds based on system load
cpufreq_performance
The performance governor runs the CPU(s) at maximum clock speed
cpufreq_conservative
Similar to ondemand, but the CPU(s) clock speed switches gradually through all its available frequencies based on system load
cpufreq_powersave
Runs the CPU(s) at minimum speed
cpufreq_userspace
Manually configured clock speeds by user

The governors ondemand and performance are built into the kernel and do not need to be loaded as modules to be activated. 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

You can check the available governors:

cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors

The currently active governor can also be determined:

cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor

Fine-tuning governors

Improving on-demand performance

With the out-of-the-box configuration, the ondemand governor will result in a slight but measurable and noticeable loss of performance. It will not clock up the CPU when it is at lower than 95% usage, and will sample the usage at the fastest possible frequency when at full clock speeds in order to clock back down as soon as possible.

Tuning the governor for your needs can reduce the performance loss to the point where it is negligible/non-existent if you are willing to lose a lot of the power savings. If you just want to save power while idle, lowering the up_threshold to 11% and raising the sample_down_factor by an order of magnitude can accomplish this.

Tunables are available in /sys/devices/system/cpu/cpufreq/ondemand/ once the governor is loaded and selected and can be preserved at reboot using /etc/rc.local.

Starting the cpupower daemon in the background (i.e. with an @ in /etc/rc.conf) will likely cause /etc/rc.local to be processed before the cpupower daemon has a chance to change the governor. Make sure that the cpupower daemon script will have finished running before the tunables are set. Example:

/etc/rc.local
(sleep 10 && echo -n 25 > /sys/devices/system/cpu/cpufreq/ondemand/up_threshold) &

Changing the on-demand governor's threshold

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

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

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

# echo -n 15 > /sys/devices/system/cpu/cpufreq/ondemand/up_threshold

On-demand governor sampling_down_factor

sampling_down_factor is another global ondemand global tunable.

Having 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
Note: When using systemd with cpupower, the above commands can be added to /usr/lib/systemd/scripts/cpupower, at the end of the script, right before exit $fail.

Tuning conservative governor

Changing the conservative governor's thresholds

Determine the current up_threshold setting by issuing the following command as root:

# cat /sys/devices/system/cpu/cpufreq/conservative/up_threshold

The value returned should be 75, the default setting as of kernel version 3.0. This means that the conservative governor currently increases the clock rate to the next highest speed if a core reaches 75% utilization. The can be changed, for example:

# echo -n 40 > /sys/devices/system/cpu/cpufreq/conservative/up_threshold
Note: The minimum value one can enter must be above the one in down_threshold; entering a value under that results in the error, "bash: echo: write error: Invalid argument"

Similarly the down_threshold value can be read and modified via /sys/devices/system/cpu/cpufreq/conservative/down_threshold. The default value should be 20 as of kernel version 3.0. This means that the conservative governor decreases the clock rate to the next lowest speed if a core falls to 20% utilization, which is a sensible default.

While the down sampling rate can also be adjusted for the conservative governor, increasing it may only help with occasional low usage CPU spikes during high usage applications, as the down_threshold is a much more direct control for down scaling which does not exist on the ondemand governor.

Be aware that setting down_threshold too close to up_threshold may result in constant CPU switching, which might be something desirable for certain users and not for others. Setting down_threshold or up_threshold too low may result in the CPU being clocked higher than it needs sacrificing power saving for performance, and setting up_threshold too high may result in decreased performance, but reduced power consumption. Experiment to find the optimal values for your system and your needs.

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

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

[...]

etc.

User-space tools

Changing the CPU frequency scaling properties from the defaults set during boot can be done through several user-space tools.

cpupower

cpudyn

http://freecode.com/projects/cpudyn

laptop-mode

Troubleshooting

External Links