Skip to content

CPU Frequency Scaling

Introduction

CPU frequency scaling is a power management technique that adjusts the operating frequency of a processor based on system demands. On Raspberry Pi OS, the default configuration sets the CPU frequency to a fixed 700MHz, which provides consistent performance but may consume more power than necessary during periods of low activity.

By implementing dynamic frequency scaling, you can optimize your Raspberry Pi's power consumption and heat generation while still maintaining responsive performance when needed. This is particularly valuable for battery-powered projects, headless servers, and use cases where maximum processing power is only occasionally required.

GPU Configuration

/boot/firmware/config.txt is read by the GPU before the CPU starts up, and it contains settings for CPU frequency as well. Add the following lines:

1
2
3
4
# Enable CPU frequency scaling
force_turbo=0
# Set minimum CPU frequency (default is 700)
arm_freq_min=100

A reboot is required for these changes to take effect.

For comprehensive information about GPU and CPU configuration options, the official documentation is available at: RPiconfig - eLinux.org

Linux Kernel Configuration

By modifying the GPU settings, the CPU gains frequency scaling capabilities. However, the Linux kernel has its own control mechanisms, which by default lock the CPU frequency at 100MHz.

You can check the current, maximum, and minimum CPU frequencies using the following commands:

  • Current CPU frequency:
    cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq
    
  • Maximum CPU frequency:
    cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq
    
  • Minimum CPU frequency:
    cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq
    

The Linux kernel includes a CPU frequency governor that determines how frequency changes occur. By default, Raspberry Pi OS uses the powersave governor.

Available governors: - performance: Always runs at the maximum CPU frequency. - powersave: Always runs at the minimum CPU frequency. - ondemand: Adjusts frequency based on CPU load (Raspberry Pi OS toggles between min and max only). - conservative: Smoothly adjusts frequency based on CPU load. - userspace: Allows user-space daemons to control the CPU frequency.

These settings can be changed during runtime via sysfs:

echo ondemand > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor

To make this setting persist after reboot, there are two options:

  1. Adding the command to /etc/rc.local

    • This method executes the command after the kernel boots, which may result in a longer boot time.
  2. Enabling kernel configuration options:

    • Enable the following kernel options:
      CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND
      CONFIG_CPU_FREQ_DEFAULT_GOV_CONSERVATIVE
      
    • This method requires rebuilding the kernel but ensures full CPU power during boot.

Monitoring CPU Frequency Changes

After implementing these settings, you can monitor the CPU frequency changes in real-time to observe how your Raspberry Pi adapts to different workloads:

# Watch CPU frequency in real-time
watch -n 1 cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq

# Or create a simple load test to see frequency scaling in action
# Install stress tool if not already available
sudo apt install stress
# Run a stress test in one terminal
stress --cpu 4 --timeout 30
# While monitoring frequency in another terminal
watch -n 0.5 cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq

Conclusion

CPU frequency scaling offers an effective way to balance performance and power consumption on your Raspberry Pi. By configuring both the GPU settings in /boot/firmware/config.txt and the Linux kernel's frequency governor, you can create a system that efficiently adapts to varying workloads.

While the power savings from frequency scaling may be modest compared to more aggressive power management techniques like disabling unused hardware components, it provides an excellent compromise that preserves functionality while reducing energy usage during idle periods. This approach is particularly beneficial for always-on systems or projects where consistent but not maximum performance is required.

For optimal results, consider combining CPU frequency scaling with other power management strategies outlined in the Power Saving guide. This comprehensive approach will maximize efficiency while ensuring your Raspberry Pi performs reliably for your specific use case.