CPU frequency scaling: Difference between revisions
m (Categorized: Power Management) |
No edit summary |
||
(2 intermediate revisions by one other user not shown) | |||
Line 32: | Line 32: | ||
In order to check which governors are available for your processors: | In order to check which governors are available for your processors: | ||
{{cmd|cat /sys/devices/system/cpu/cpufreq/policy*/scaling_available_governors}} | |||
cat /sys/devices/system/cpu/cpufreq/policy*/scaling_available_governors | |||
To e.g. change the governor of processor 0 to <samp>ondemand</samp>: | To e.g. change the governor of processor 0 to <samp>ondemand</samp>: | ||
{{cmd|echo ondemand > /sys/devices/system/cpu/cpufreq/policy0/scaling_governor}} | |||
echo ondemand > /sys/devices/system/cpu/cpufreq/policy0/scaling_governor | |||
To see that the governor you chose works as expected, you may compare <samp>scaling_cur_freq</samp> to <samp>scaling_min_freq</samp> and <samp>scaling_max_freq</samp> for different system loads. All of these files are located in the same folder <samp>/sys/devices/system/cpu/cpufreq/policy0</samp> as the governor settings above. | To see that the governor you chose works as expected, you may compare <samp>scaling_cur_freq</samp> to <samp>scaling_min_freq</samp> and <samp>scaling_max_freq</samp> for different system loads. All of these files are located in the same folder <samp>/sys/devices/system/cpu/cpufreq/policy0</samp> as the governor settings above. | ||
Line 45: | Line 41: | ||
== Manipulating the governor == | == Manipulating the governor == | ||
Some governors can be configured further; these settings can be found in the folders <samp>/sys/devices/system/cpu/cpufreq/*</samp>. For instance, the <samp>ondemand</samp> governor defaults to switching to a higher frequency when the CPU usage increases beyond 95%. If we wish to lower this threshold to e.g. 80%, we could run: | Some governors can be configured further; these settings can be found in the folders <samp>/sys/devices/system/cpu/cpufreq/*</samp>. For instance, the <samp>ondemand</samp> governor defaults to switching to a higher frequency when the CPU usage increases beyond 95%. If we wish to lower this threshold to e.g. 80%, we could run: | ||
{{cmd|echo 80 > /sys/devices/system/cpu/cpufreq/ondemand/up_threshold}} | |||
echo 80 > /sys/devices/system/cpu/cpufreq/ondemand/up_threshold | |||
== Automatic configuration == | == Automatic configuration == | ||
Once we have found a governor that we are satisfied with, we might want to keep it when the system is rebooted. This can be done by | Once we have found a governor that we are satisfied with, we might want to keep it when the system is rebooted. This can be done by using cpupower package: | ||
{{cmd|apk add {{pkg|cpupower}}}} | |||
< | Edit file /etc/conf.d/cpupower to configure required governor with START_OPTS and SYSFS_EXTRA: | ||
{{cat|/etc/conf.d/cpupower|<nowiki># Set the governor to ondemand for all processors | |||
START_OPTS="--governor ondemand" | |||
# | # Reduce the boost threshold to 80% | ||
SYSFS_EXTRA="ondemand/up_threshold=80" | |||
</nowiki>}} | |||
Start the cpupower daemon using the standard [[OpenRC]] commands: | |||
{{cmd|rc-update add cpupower && rc-service cpupower start}} | |||
Now, CPU frequency scaling is enabled and will be preserved after rebooting. | |||
[[Category:Power Management]] | [[Category:Power Management]] |
Latest revision as of 13:09, 19 September 2025
CPU frequency scaling is a feature of many modern processors whereby the CPU frequency can be changed at runtime. In this way, the system can be optimized for either powersaving (minimal frequency), performance (maximal frequency), or a combination (automatic switching). The latter would e.g. be optimal for a server that is idle for most of its uptime, but must sustain high CPU throughput when it does receive requests.
Electing a governor
The CPU frequency scaling is handled by a so-called CPU governor, which decides which frequencies to use and when to switch between them. The most common governors are the following:
Governor | Frequency | Switching |
---|---|---|
performance | Maximum | None |
powersave | Minimum | None |
ondemand | Automatic | Immediate |
conservative | Automatic | Gradual |
userspace | Custom | Custom |
In order to check which governors are available for your processors:
cat /sys/devices/system/cpu/cpufreq/policy*/scaling_available_governors
To e.g. change the governor of processor 0 to ondemand:
echo ondemand > /sys/devices/system/cpu/cpufreq/policy0/scaling_governor
To see that the governor you chose works as expected, you may compare scaling_cur_freq to scaling_min_freq and scaling_max_freq for different system loads. All of these files are located in the same folder /sys/devices/system/cpu/cpufreq/policy0 as the governor settings above.
Manipulating the governor
Some governors can be configured further; these settings can be found in the folders /sys/devices/system/cpu/cpufreq/*. For instance, the ondemand governor defaults to switching to a higher frequency when the CPU usage increases beyond 95%. If we wish to lower this threshold to e.g. 80%, we could run:
echo 80 > /sys/devices/system/cpu/cpufreq/ondemand/up_threshold
Automatic configuration
Once we have found a governor that we are satisfied with, we might want to keep it when the system is rebooted. This can be done by using cpupower package:
apk add cpupower
Edit file /etc/conf.d/cpupower to configure required governor with START_OPTS and SYSFS_EXTRA:
Contents of /etc/conf.d/cpupower
Start the cpupower daemon using the standard OpenRC commands:
rc-update add cpupower && rc-service cpupower start
Now, CPU frequency scaling is enabled and will be preserved after rebooting.