{{Accuracy|This article needs cleanup as far as kernel cpufreq and userspace cpufrequtils and cpupower are concerned.}}

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.

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.

Line 26:

Line 25:

Since kernel 3.4 the necessary modules are loaded automatically and the recommended [[CPU_Frequency_Scaling#Scaling_governors|ondemand governor]] is enabled by default. However, userspace applications like [[#cpupower|cpupower]], [[acpid]], [[laptop-mode-tools]], or GUI tools provided for your desktop environment, may still be used for advanced configuration.

Since kernel 3.4 the necessary modules are loaded automatically and the recommended [[CPU_Frequency_Scaling#Scaling_governors|ondemand governor]] is enabled by default. However, userspace applications like [[#cpupower|cpupower]], [[acpid]], [[laptop-mode-tools]], or GUI tools provided for your desktop environment, may still be used for advanced configuration.

−

== Cpupower ==

+

== Userspace tools (cpupower) ==

+

{{Pkg|cpupower}} 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.

{{Pkg|cpupower}} 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 {{Pkg|cpupower}} is located in {{ic|/etc/default/cpupower}}. This configuration file is read by a bash script in {{ic|/usr/lib/systemd/scripts/cpupower}} which is activated by {{ic|systemd}} with {{ic|cpupower.service}}. You may want to enable cpupower [[systemd]] service to start it at boot.

+

+

A frontend for gnome-shell can be found at [https://extensions.gnome.org/extension/444/cpu-freq/ CPU Freq].

−

== Configuring Cpupower Service/Daemon ==

+

=== CPU frequency driver ===

−

The configuration file for {{Pkg|cpupower}} is located in {{ic|/etc/conf.d/cpupower}}. This configuration file is read by a bash script in {{ic|/usr/lib/systemd/scripts/cpupower}} which is activated by {{ic|systemd}} with {{ic|cpupower.service}}.

−

Remember to enable the {{Pkg|cpupower}} {{Pkg|systemd}} service to ensure your saved settings work on bootup :

+

{{Note|

−

{{bc|<nowiki>

+

* As of kernel 3.4, the native cpu module is loaded automatically.

−

# systemctl enable cpupower.service

+

* Starting with kernel 3.9, the new {{ic|pstate}} power scaling driver is used automatically for modern Intel cpus instead of the other drivers below. This driver takes priority over other drivers and in fact is inbuilt as opposed to being a module. This driver is currently automatically used for Sandy Bridge and Ivy Bridge type cpus. If you encounter a problem while using this driver, add {{ic|intel_pstate&#61;disable}} to your kernel line. You can use the same user space utilities with this driver but cannot control it.

−

</nowiki>}}

+

}}

−

=== CPU frequency driver ===

+

{{Pkg|cpupower}} requires modules (see table below) to know the limits of the native cpu. To see a full list of available modules, run

{{Pkg|cpupower}} requires modules (see table below) to know the limits of the native cpu. To see a full list of available modules, run the following {{ic|$ ls /lib/modules/${uname -r)/kernel/drivers/cpufreq/}}

+

$ ls /lib/modules/$(uname -r)/kernel/drivers/cpufreq/

−

{{Tip|Load the appropriate module with {{ic|# modprobe <module>}}. To load the module at boot, run {{ic|# echo <module> > /etc/modules-load.d/<module>}}. The following error message is displayed if it is the wrong module : {{bc|<nowiki>

+

{{Tip|To load the module at boot, run

−

FATAL: Error inserting <module> ([...]/<module>.ko): No such device

+

{{bc|<nowiki>

+

# echo <module> >/etc/modules-load.d/<module>.conf

</nowiki>}}}}

</nowiki>}}}}

+

{{Note|Loading the wrong module will result in an error "No such device"}}

Once the appropriate cpufreq driver is loaded, detailed information about the CPU(s) can be displayed by running {{ic|$ cpupower frequency-info}}

+

Once the appropriate cpufreq driver is loaded, detailed information about the CPU(s) can be displayed by running

+

+

$ cpupower frequency-info

=== Scaling governors ===

=== Scaling governors ===

−

Governors (see table below) are power schemes for the cpu. Only one may be active at a time.

+

Governors (see table below) are power schemes for the cpu. Only one may be active at a time. For details, see the [https://www.kernel.org/doc/Documentation/cpu-freq/governors.txt official documentation] in the kernel source.

The sampling rate determines how frequently the governor checks to tune the cpu

The sampling rate determines how frequently the governor checks to tune the cpu

Setting {{ic|sampling_down_factor}} greater than 1 improves performance by reducing the overhead of load evaluation and keeping the CPU at its highest clock frequency due to high load. This tunable has no effect on behavior at lower CPU frequencies/loads.

Setting {{ic|sampling_down_factor}} greater than 1 improves performance by reducing the overhead of load evaluation and keeping the CPU at its highest clock frequency due to high load. This tunable has no effect on behavior at lower CPU frequencies/loads.

{{Note|The governor, maximum, and minimum frequencies can be set in {{ic|/etc/default/cpupower}}. To adjust for only a single cpu core: {{ic| -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''

−

=== Setting Maximum and Minimum Frequencies ===

+

To set the cpu to run at a specified frequency:

−

{{Note|The governor, maximum, and minimum frequencies can be set in {{ic|/etc/conf.d/cpupower}}. To adjust for only a single cpu core: {{ic| -c <core #>}}. <clock_freq> is a clock frequency with units : GHz,MHz}}

+

# cpupower frequency-set -f ''clock_freq''

−

To set the maximum clock frequency

−

{{bc|<nowiki>

−

cpupower frequency-set -u <clock_freq>

−

</nowiki>}}

−

To set the minimum clock frequency

−

{{bc|<nowiki>

−

cpupower frequency-set -d <clock_freq>

−

</nowiki>}}

−

To set the cpu to run at a specified frequency

−

{{bc|<nowiki>

−

cpupower frequency-set -f <clock_freq>

−

</nowiki>}}

== Interaction with ACPI events ==

== Interaction with ACPI events ==

Line 136:

Line 156:

Events are defined in {{ic|/etc/acpi/handler.sh}}. If the {{Pkg|acpid}} package is installed, the file should already exist and be executable. For example, to change the scaling governor from {{ic|performance}} to {{ic|conservative}} when the AC adapter is disconnected and change it back if reconnected:

Events are defined in {{ic|/etc/acpi/handler.sh}}. If the {{Pkg|acpid}} package is installed, the file should already exist and be executable. For example, to change the scaling governor from {{ic|performance}} to {{ic|conservative}} when the AC adapter is disconnected and change it back if reconnected:

−

{{hc

+

{{hc|/etc/acpi/handler.sh|<nowiki>

−

|/etc/acpi/handler.sh

−

|<nowiki>

[...]

[...]

Line 165:

Line 183:

−

== Privilege Granting Under GNOME ==

+

== Privilege granting under GNOME ==

−

{{Note|Systemd introduced logind which handles consolekit and policykit actions. The following code below does not work}}

+

+

{{Note|Systemd introduced logind which handles consolekit and policykit actions. The following code below does not work. With logind, simply edit in the file {{ic|/usr/share/polkit-1/actions/org.gnome.cpufreqselector.policy}} the <defaults> elements according to your needs and the polkit manual [http://www.freedesktop.org/software/polkit/docs/latest/polkit.8.html].}}

[[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 {{ic|/var/lib/polkit-1/localauthority/50-local.d/org.gnome.cpufreqselector.pkla}} and populate it with the following:

[[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 {{ic|/var/lib/polkit-1/localauthority/50-local.d/org.gnome.cpufreqselector.pkla}} and populate it with the following:

−

{{bc|<nowiki>[org.gnome.cpufreqselector]

+

{{bc|<nowiki>

−

Identity=unix-user:USER

+

[org.gnome.cpufreqselector]

+

Identity=unix-user:''user''

Action=org.gnome.cpufreqselector

Action=org.gnome.cpufreqselector

ResultAny=no

ResultAny=no

ResultInactive=no

ResultInactive=no

−

ResultActive=yes</nowiki>}}0

+

ResultActive=yes

+

</nowiki>}}

−

Where the word {{ic|USER}} is replaced with the username of interest.

+

Where the word ''user'' is replaced with the username of interest.

The {{AUR|desktop-privileges}} package in the [[Arch User Repository|AUR]] contains a similar {{ic|.pkla}} file for authorizing all users of the {{ic|power}} [[Users and Groups|group]] to change the governor.

The {{AUR|desktop-privileges}} package in the [[Arch User Repository|AUR]] contains a similar {{ic|.pkla}} file for authorizing all users of the {{ic|power}} [[Users and Groups|group]] to change the governor.

== Laptop Mode Tools ==

== 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 {{ic|/etc/modules.d/}} directory. (see [[#CPU frequency driver]] above) and then go through the {{ic|/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.

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 {{ic|/etc/modules.d/}} directory. (see [[#CPU frequency driver]] above) and then go through the {{ic|/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.

== Troubleshooting ==

== Troubleshooting ==

+

{{accuracy}}

{{accuracy}}

* 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 {{ic|on-demand}} governor 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 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 {{ic|on-demand}} governor 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 {{ic|on-demand}} 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 on-demand governor's threshold]].

+

* Some CPU's may suffer from poor performance with the default settings of the {{ic|on-demand}} 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 on-demand governor's threshold|how to change 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.

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

Line 195:

Line 218:

=== BIOS frequency limitation ===

=== 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 {{ic|/sys/devices/system/cpu/cpu0/cpufreq/bios_limit}} set to a lower value.

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 {{ic|/sys/devices/system/cpu/cpu0/cpufreq/bios_limit}} set to a lower value.

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.

Userspace tools (cpupower)

cpupower 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 cpupower is located in /etc/default/cpupower. This configuration file is read by a bash script in /usr/lib/systemd/scripts/cpupower which is activated by systemd with cpupower.service. You may want to enable cpupower systemd service to start it at boot.

CPU frequency driver

Note:

As of kernel 3.4, the native cpu module is loaded automatically.

Starting with kernel 3.9, the new pstate power scaling driver is used automatically for modern Intel cpus instead of the other drivers below. This driver takes priority over other drivers and in fact is inbuilt as opposed to being a module. This driver is currently automatically used for Sandy Bridge and Ivy Bridge type cpus. If you encounter a problem while using this driver, add intel_pstate=disable to your kernel line. You can use the same user space utilities with this driver but cannot control it.

cpupower requires modules (see table below) to know the limits of the native cpu. To see a full list of available modules, run

$ ls /lib/modules/$(uname -r)/kernel/drivers/cpufreq/

Tip: To load the module at boot, run

# echo <module> >/etc/modules-load.d/<module>.conf

Note: Loading the wrong module will result in an error "No such device"

Sampling rate

The sampling rate determines how frequently the governor checks to tune the cpu
Setting sampling_down_factor greater than 1 improves performance by reducing the overhead of load evaluation and keeping the CPU at its highest clock frequency due to high load. This tunable has no effect on behavior at lower CPU frequencies/loads.

Setting maximum and minimum frequencies

Note: The governor, maximum, and minimum frequencies can be set in /etc/default/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

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:

Privilege granting under GNOME

Note: Systemd introduced logind which handles consolekit and policykit actions. The following code below does not work. With logind, simply edit in the file /usr/share/polkit-1/actions/org.gnome.cpufreqselector.policy the <defaults> elements according to your needs and the polkit manual [1].

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:

The desktop-privilegesAUR package in the AUR contains a similar .pkla file for authorizing all users of the powergroup to change the governor.

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.

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 on-demand governor 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-demand 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_thresholdsysctl variable for each CPU. See how to change 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!