CPU Frequency Scaling and Power Management
Modern processors support dynamic frequency and voltage scaling (DVFS) enabling power-efficient operation while maintaining performance when needed. Strategic CPU frequency management balances energy consumption, thermal considerations, and latency requirements. This guide covers CPU frequency scaling governors, turbo boost management, and power-aware deployment strategies.
Table of Contents
- CPU Frequency Fundamentals
- Frequency Scaling Governors
- intel_pstate Driver
- AMD Ryzen ACPI Scaling
- Turbo Boost Management
- CPU States (P-states and C-states)
- Power Management Strategies
- Monitoring CPU Frequencies
- Conclusion
CPU Frequency Fundamentals
Understanding CPU Scaling
# Check current CPU frequency
cat /proc/cpuinfo | grep "cpu MHz"
# Maximum and minimum frequency per CPU
watch -n 1 'cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq'
watch -n 1 'cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq'
# Current scaling frequency
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq
# Available frequency steps
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies
Power vs Performance Tradeoff
# At lower frequencies:
# - Reduced power consumption (quadratic with voltage)
# - Lower heat output
# - Increased latency
# - Reduced throughput
# At higher frequencies:
# - Maximum performance
# - Higher power consumption
# - Increased thermal output
# - Lower latency
# Typical energy savings:
# - 50% frequency reduction = 60-70% power reduction
# - But performance reduced proportionally or more
Frequency Scaling Governors
Available Governors
# List available governors
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors
# Output typical:
# powersave performance schedutil ondemand conservative
# Current governor
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
# Governor characteristics:
# - powersave: Minimize frequency, minimize power
# - performance: Maximum frequency always
# - ondemand: Scale based on CPU load dynamically
# - conservative: Gradual frequency changes
# - schedutil: Kernel scheduler driven (modern, default)
Selecting Governors
# Set performance governor (latency-sensitive applications)
for cpu in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor; do
echo "performance" | sudo tee $cpu
done
# Set powersave governor (power-optimized workloads)
for cpu in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor; do
echo "powersave" | sudo tee $cpu
done
# Set ondemand governor (balanced approach)
for cpu in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor; do
echo "ondemand" | sudo tee $cpu
done
# Verify change
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
ondemand Governor Tuning
# ondemand parameters
ls /sys/devices/system/cpu/cpufreq/ondemand/
# Sampling rate (default 10000 = 10ms)
cat /sys/devices/system/cpu/cpufreq/ondemand/sampling_rate
echo 5000 | sudo tee /sys/devices/system/cpu/cpufreq/ondemand/sampling_rate
# Up threshold (default 80%)
# Frequency increases when CPU load exceeds this
cat /sys/devices/system/cpu/cpufreq/ondemand/up_threshold
echo 60 | sudo tee /sys/devices/system/cpu/cpufreq/ondemand/up_threshold
# Powersave bias (0=performance, 1000=powersave)
cat /sys/devices/system/cpu/cpufreq/ondemand/powersave_bias
echo 500 | sudo tee /sys/devices/system/cpu/cpufreq/ondemand/powersave_bias
conservative Governor Tuning
# conservative parameters (gradual frequency changes)
ls /sys/devices/system/cpu/cpufreq/conservative/
# Frequency scaling down threshold
cat /sys/devices/system/cpu/cpufreq/conservative/down_threshold
echo 20 | sudo tee /sys/devices/system/cpu/cpufreq/conservative/down_threshold
# Frequency scaling step (default 5%)
cat /sys/devices/system/cpu/cpufreq/conservative/freq_step
echo 10 | sudo tee /sys/devices/system/cpu/cpufreq/conservative/freq_step
intel_pstate Driver
Intel CPU Frequency Scaling
# Check if intel_pstate is active
cat /sys/devices/system/cpu/cpu0/cpufreq/driver
# intel_pstate specific parameters
ls /sys/devices/system/cpu/intel_pstate/
# Min/max performance percentage
cat /sys/devices/system/cpu/intel_pstate/min_perf_pct
cat /sys/devices/system/cpu/intel_pstate/max_perf_pct
# Set maximum performance (all turbo capability)
echo 100 | sudo tee /sys/devices/system/cpu/intel_pstate/max_perf_pct
# Set minimum performance (power saving)
echo 50 | sudo tee /sys/devices/system/cpu/intel_pstate/min_perf_pct
# No turbo (disable turbo boost)
cat /sys/devices/system/cpu/intel_pstate/no_turbo
echo 1 | sudo tee /sys/devices/system/cpu/intel_pstate/no_turbo
# Energy Performance Preference (HWP - Hardware P-States)
# High performance: 0
# Balanced: 50
# Power saving: 100
if [ -f /sys/devices/system/cpu/cpu0/cpufreq/energy_performance_preference ]; then
echo "performance" | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/energy_performance_preference
fi
AMD Ryzen ACPI Scaling
AMD CPU Frequency Configuration
# Check AMD frequency scaling driver
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_driver
# AMD-specific governor
# Prefer 'amd_pstate' if available (newer)
# Falls back to 'acpi-cpufreq' on older systems
# AMD amd_pstate parameters
ls /sys/devices/system/cpu/cpufreq/amd-pstate*
# CPU governor selection
echo "schedutil" | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
Turbo Boost Management
Intel Turbo Boost
# Check turbo boost status
cat /sys/devices/system/cpu/intel_pstate/no_turbo
# Output: 0 = enabled, 1 = disabled
# Disable turbo boost (power saving, consistent frequency)
echo 1 | sudo tee /sys/devices/system/cpu/intel_pstate/no_turbo
# Enable turbo boost (maximum performance)
echo 0 | sudo tee /sys/devices/system/cpu/intel_pstate/no_turbo
# Monitor turbo boost usage
watch -n 1 'cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq'
AMD Boost Control
# Check AMD boost status
cat /sys/devices/system/cpu/cpufreq/boost
# Disable boost (power and thermal management)
echo 0 | sudo tee /sys/devices/system/cpu/cpufreq/boost
# Enable boost (maximum performance)
echo 1 | sudo tee /sys/devices/system/cpu/cpufreq/boost
# Monitor boost state
watch -n 1 'cat /sys/devices/system/cpu/cpufreq/boost'
CPU States (P-states and C-states)
P-states (Performance States)
# List available P-states
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies
# P-states determine CPU frequency
# P0: Highest frequency (maximum performance)
# P1: Reduced frequency
# ...
# Pn: Minimum frequency (power saving)
# Lock to specific P-state
echo 2400000 | sudo tee /sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed
# Return to automatic scaling
echo "powersave" | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
C-states (Sleep States)
# Check available C-states
cat /sys/devices/system/cpu/cpu0/cpuidle/states/*/name
# Typical C-states:
# C0: Running (P-state controls frequency)
# C1: Halt (minimal latency, minimal power saving)
# C2: Stop grant (deeper sleep)
# C3: Sleep (deepest, highest latency)
# Monitor C-state residency
watch -n 1 'cat /sys/devices/system/cpu/cpu0/cpuidle/*/time'
# Disable deeper C-states for latency-sensitive workloads
# Kernel parameter: processor.max_cstate=1
# Add to GRUB: GRUB_CMDLINE_LINUX="processor.max_cstate=1"
Power Management Strategies
Server Workload Strategy
# Database server (predictable load, latency critical)
# Strategy: Performance mode, no turbo boost variability
echo "performance" | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
# Web server (variable load, throughput important)
# Strategy: schedutil governor, enable turbo boost
echo "schedutil" | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
echo 0 | sudo tee /sys/devices/system/cpu/intel_pstate/no_turbo
# Batch processing (throughput optimized)
# Strategy: Performance + turbo, disable C-states
echo "performance" | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
echo 0 | sudo tee /sys/devices/system/cpu/intel_pstate/no_turbo
# Power-optimized (max power saving)
echo "powersave" | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
echo 1 | sudo tee /sys/devices/system/cpu/intel_pstate/no_turbo
Persistent Configuration
# Create frequency scaling service
cat > /etc/systemd/system/cpu-frequency.service <<'EOF'
[Unit]
Description=Set CPU Frequency Governor
After=sysfs.mount
DefaultDependencies=no
[Service]
Type=oneshot
ExecStart=/bin/bash -c 'echo schedutil | tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor'
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl daemon-reload
sudo systemctl enable cpu-frequency.service
sudo systemctl start cpu-frequency.service
# Or via sysctl
echo 'MODULES=cpufreq_ondemand' | sudo tee -a /etc/default/grub
# Then update GRUB and reboot
Monitoring CPU Frequencies
Real-time CPU Frequency Monitoring
# Watch CPU frequencies
watch -n 1 'cat /proc/cpuinfo | grep "cpu MHz"'
# All CPU frequencies
for i in {0..7}; do
echo "CPU$i: $(cat /sys/devices/system/cpu/cpu$i/cpufreq/scaling_cur_freq) kHz"
done
# Average frequency across CPUs
awk '/cpu MHz/ {sum+=$4; count++} END {print "Average: " sum/count " MHz"}' /proc/cpuinfo
# Monitor with turbostat (Intel)
sudo apt-get install -y linux-tools-common
sudo turbostat --interval 1
Power Consumption Estimation
# Estimate power from frequency/voltage
# Power = C * V^2 * f (approximately)
# Where C=capacitance, V=voltage, f=frequency
# Higher frequency:
# 3.5 GHz at turbo = ~150W per core
# 2.0 GHz at base = ~50W per core
# Monitor power consumption (if available)
cat /sys/class/powercap/intel-rapl:0/energy_uj
cat /sys/class/powercap/intel-rapl:1/energy_uj
Conclusion
CPU frequency scaling provides powerful tools for balancing performance and power efficiency. Strategic governor selection, turbo boost management, and C-state configuration align CPU behavior with workload requirements. Understanding the tradeoffs between latency, throughput, and power consumption enables infrastructure teams to optimize for specific use cases. Modern automatic governors like schedutil often provide near-optimal results without manual tuning, while specific workloads benefit from explicit configuration. Regular monitoring ensures frequency scaling operates as intended, delivering both performance and efficiency in production environments.


