December 29, 2023
In the world of computing, achieving an optimal balance between performance and power efficiency is crucial. One way modern systems manage this balance is through CPU frequency scaling, a feature deeply integrated into Linux systems like Ubuntu.
CPU frequency scaling, also known as CPU scaling or dynamic frequency scaling, refers to the ability of a processor to dynamically adjust its clock speed (measured in GHz) based on the workload it’s handling. This feature allows the CPU to operate at different frequencies, conserving power during idle or lighter tasks and ramping up performance when required.
In Linux, CPU frequency scaling is managed by the kernel through various governors. Each governor represents a specific policy for adjusting the CPU frequency. Common governors include “performance,” “ondemand,” “powersave,” and “userspace.”
Performance Governor: This governor keeps the CPU at its maximum clock speed regardless of the workload, prioritizing performance over power efficiency.
Ondemand Governor: The ondemand governor dynamically adjusts the CPU frequency based on the system load, allowing it to scale up when necessary and scale down during lighter loads to save power.
Powersave Governor: Focused on energy efficiency, this governor keeps the CPU at its lowest frequency, ideal for situations where power consumption is a primary concern.
Userspace Governor: Userspace allows users or applications to manually control the CPU frequency, providing flexibility for custom management.
In Ubuntu and other Linux distributions, managing CPU frequency scaling can be done through terminal commands:
cpufreq-info: Provides information about the current CPU frequency scaling configuration.
cpufreq-set: Allows changing the CPU frequency scaling governor. For example,
sudo cpufreq-set -g performance sets the governor to “performance.”
While setting the CPU governor to “performance” might provide consistent high performance, it can lead to increased power consumption and higher temperatures. Conversely, using governors like “ondemand” or “powersave” enables a more balanced approach by dynamically adjusting CPU frequencies based on the workload.
It’s noteworthy that this Ubuntu install, version 22.04 LTS, is running on an iMac mid-2011. Interestingly, Ubuntu OS tends to run significantly cooler compared to the previous MacOS 10.13.6. However, in some scenarios—such as running other tasks while streaming YouTube videos in default out-of-the-box playback settings—the Ubuntu system experiences occasional video pauses, an issue that was not encountered in MacOS 10.13.6.
Changing CPU governors in Linux can impact the overall operation of the machine. While setting the governor to “performance” may lead to smoother operation for certain tasks, it may also introduce more energy usage and increased heat due to the CPU constantly running at higher frequencies. It’s a trade-off between performance and power efficiency.
It’s worth noting that in the mentioned scenario, the Ubuntu system experiences occasional video pauses during YouTube playback, specifically with video stuttering from time to time. Interestingly, this issue does not affect the audio playback, indicating a potential system-specific video rendering challenge.
CPU frequency scaling in Linux offers a flexible mechanism to balance system performance and power efficiency. Understanding and appropriately managing CPU frequency governors can significantly impact system behavior, optimizing it for diverse computing needs, whether it’s high-performance tasks or energy-conscious operations. Users can leverage these tools to tailor their system’s behavior according to their specific requirements, ensuring an efficient and responsive computing experience.