The CPUFreq subsystem of the Linux kernel allows one to modify the CPU clock speeds on the fly depending on the system needs. Most Linux distributions use the ondemand CPUFreq governor by default to reduce overall power consumption but also provide performance when needed. However, on a laptop computer I prefer to have continuous high performance via the performance governor when it is connected to AC power and drop back to ondemand governor when on battery power. This results in an overall improvement in the responsiveness of the system when connected to AC power even under heavy loads.
The switching of governors can be easily automated using the acpid service that is installed on most modern Linux distributions. The procedure below describes the method for Ubuntu 12.04 but should work with minor modifications on most distributions.
- Start by installing the
cpufrequtilspackage and ensuring thatacpidis installed using the command:sudo apt-get install cpufrequtils acpid
- Create a file named
/etc/acpi/events/governorwith the following contents:# /etc/acpi/events/governor # Called when the user connects ac power to us # event=ac_adapter action=/etc/acpi/governor.sh
- Similarly, create a file named
/etc/acpi/governor.shwith the following contents:#!/bin/sh # # /etc/acpi/governor.sh # # Load the functions related to the state of the AC power. # POWER_FUNCS=/usr/share/acpi-support/power-funcs test -f ${POWER_FUNCS} || exit 0 . ${POWER_FUNCS} # # Utilities used by this script. # LOGGER="/usr/bin/logger -t governor.sh" CPUFREQSET="/usr/bin/cpufreq-set" SEQ="/usr/bin/seq" AC_GOVERNOR="performance" BATTERY_GOVERNOR="ondemand" # # Get the state of the AC power. # getState # # Select the governor based on the state of the AC power. # GOVERNOR="ondemand" case "$STATE" in "AC") GOVERNOR=${AC_GOVERNOR} ;; *) GOVERNOR=${BATTERY_GOVERNOR} ;; esac # # Get the number of CPUs. # NUM_OF_CPUS=`/bin/ls /sys/devices/system/cpu/ | grep -E "cpu[0-9]+" | wc -l` # # Set the governor for all the CPUs. # $LOGGER "Setting governor to ${GOVERNOR}." for cpu_num in `${SEQ} 0 $[ NUM_OF_CPUS - 1 ]` do $CPUFREQSET -c ${cpu_num} -g ${GOVERNOR} done - Finally, reload the
acpidconfiguration using following command:sudo service acpid reload






