Dynamic Voltage and Frequency scaling is a framework to change the frequency and/or operating voltage of a processor(s) based on system performance requirements at the given point of time.
Frequency scaling is achieved using CPUFreq framework.
CPUfreq is a linux kernel framework that monitors the performance requirements of a processor(s) and takes decisions to increase or decrease operating frequency in order to save power and/or reduce leakage power.
CPUFreq consists two elements
Policy is set of rules the system is bound by such as min and max frequency for each cpu, availabilty of a frequency. Policy for a cpu is created during the CPUFreq framework initialization based on the frequency table.
Frequency table consists of available frequencies for all cpus in the system. Frequency table is generated/populated based on the Operating Performance Point(OPP) list for each cpu.
Operating performance Point(OPP) is a tuple consisting a frequency value and voltage required to run at the frequency. OPP table contains OPPs with a cpu/device name they are applicable to and an availabilty flag. OPP information of each device is added to OPP list.
Governor continuosly monitors the system perfomance requirements and when the requirement to change the frequency arises it checks the current cpu policy for frequency limits and requests the driver to change the frequency.
Multiple drivers can exist in the kernel but there will be only one scaling driver which performs actions based on governors decision.When the govenor request the driver to change the frequency to a target value, driver checks the frequency availability in the OPP list. If its found it scales the device to new frequency.
The following governors are available in CPUFreq frame work
'NOTE: For more information each governor refer to Linux kernel documentation @ <kernel>/Documentation/cpu-freq/governors.txt
Default governor is "performance". The default governor can be changed through 'menuconfig':
Chose the governor you want to use as default governor by selecting it from the list at: CPU Power management options ---> [*] CPU frequency scaling Default CPUFreq governor (performance) ---> (x) performance () userspace () ondemand () conservative
Multiple governors can be built and exist in the kernel by selecting them through "menuconfig".
Select the governors you want to build in to kernel. CPU Power management options ---> [*] CPU frequency scaling Default CPUFreq governor (performance) ---> [*] performance [*] userspace [*] ondemand [] conservative
Governors can be switched at any time through the 'sysfs' interface.
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
echo -n "<governor_name>" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
e.g. to switch to 'userspace' governor
echo -n "userspace" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
CPUFreq driver supports notifications of frequency changes
CPUFreq exports a lot of information to user through sysfs interface To see information pertaining to a cpu(say cpu0):
cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors
cat /sys/devices/ system/cpu/cpu0/cpufreq/scaling_governor
Voltage scaling is achieved using voltage layer and regulator framework(driver). When the CPUFreq driver scales the device frequency, voltage corresponding to the frequency(target_voltage) is looked-up in the opp list. The device scale function requests the voltage layer to scale the device voltage to the target_voltage.
The voltage layer consists of the information of all voltage domains in the system and configures all vdds during voltage layer initialization. When a vdd is configured a regulator supply handle is acquired and stored in the corresponding vdd structure.The regulators scale/set voltage function is plugged in to the vdd's voltage scale function pointer. Thus when a voltage change is requested forwarded to a vdd. The voltage layer requests the regulator framework to change the device voltage to the target voltage. Regluator driver verifies if the target voltage is in with in the limits of the voltage domain and regulator supply constraints. If all the checks go through then regulator changes the voltage of the requested device to the target voltage.
Using "userspace" governor one can change the current OPP:
echo -n "userspace" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
$cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies
Select a frequency and to change current cpu frequency do:
$echo -n "<new_frequency> > /sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed
when the frequency is changed, system voltage is also changed to meet the new requirements as part of scaling: This is done in two ways:
* when new frequency is higher (moving to high power state/opp) * Voltage is increased first then the frequency, * when new frequency is lower (moving to low power state/opp) * Frequency is reduced first then the voltage.
For all other governors user does not need to give input in order to move to a low power/high power state.
The governor takes the decision to transit based on system requirements and does the scaling of frequency and voltage.
Each governors provides some configuration options which can be set/modified through sysfs. For detailed configuration options available for each governor refer to kernel documentation on governors @<kernel>/Documentation/cpu-freq/governors.txt