The Bridge tool includes intelligent CPU power management that automatically switches between performance and power-saving modes based on workload demand. This feature uses the Linux Intel P-State driver or generic cpufreq subsystem to control CPU frequency scaling.
Performance Mode (Active State)
- Triggered when: Remote trigger file exists
- Action: Port forwarding is active, data transfer in progress
- CPU Setting:
performancegovernor orperformanceenergy preference - Effect: Maximum CPU frequency, optimal throughput
Powersave Mode (Idle State)
- Triggered when: Remote trigger file is absent
- Action: Only periodic file checking (every 15 minutes by default)
- User Check: Automatically detects logged-in users
- CPU Setting:
powersavegovernor orpowerenergy preference (only if no users logged in) - Effect: Reduced CPU frequency, lower power consumption
- Protection: Skips CPU power changes when interactive user sessions are detected
The tool automatically detects and uses the best available interface:
-
Intel P-State with HWP (Hardware P-States)
- Preferred method on modern Intel CPUs
- Uses
energy_performance_preferenceinterface - Available preferences:
default,performance,balance_performance,balance_power,power
-
Generic CPUFreq
- Fallback for older systems or non-Intel CPUs
- Uses
scaling_governorinterface - Available governors:
performance,powersave,ondemand,conservative, etc.
- OS: Linux kernel 3.9+ (for intel_pstate) or 2.6+ (for cpufreq)
- CPU: Intel Core processors (Sandy Bridge or newer recommended for HWP)
- Permissions: Root/sudo access to modify CPU governor settings
# Check if intel_pstate is available
ls -la /sys/devices/system/cpu/intel_pstate/
# Check available governors
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors
# Check energy performance preferences (intel_pstate with HWP)
cat /sys/devices/system/cpu/cpu0/cpufreq/energy_performance_available_preferences
# Check current governor
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
# Check current energy preference
cat /sys/devices/system/cpu/cpu0/cpufreq/energy_performance_preferenceImportant: The tool automatically protects interactive user sessions from power management changes.
When entering low power mode, the tool:
- Checks for logged-in users using system utilities (
who,/var/run/utmp) - If users are detected:
- Skips CPU governor changes
- Still closes SSH connections and stops port forwarding
- Logs:
Skipping low power mode: users are logged in to the system
- If no users are logged in:
- Proceeds with full low power mode (including CPU governor change)
- Interactive Performance: Prevents sluggish response during user sessions
- Background Operation: Full power saving when system is unattended
- Automatic Detection: No manual configuration needed
Scenario 1: User Working on System
User logs in via SSH → Bridge sees active session → Skips CPU power change → User experiences normal performance
Scenario 2: Unattended Server
No users logged in → Bridge enters full low power mode → CPU frequency reduced → Power saved
# Run as root to enable CPU power management
sudo ./bridge -config bridge.conf
# Or install as systemd service (runs as root automatically)
sudo systemctl start bridgeThe tool will work without root but will log warnings:
Warning: Failed to set CPU governor to powersave: permission denied
Note: Run with sudo/root privileges to control CPU governor
All other functionality (SSH, port forwarding) works normally.
Enable/disable low power mode in your configuration file:
# Enable automatic CPU power management
LOW_POWER_MODE=true
# Disable automatic CPU power management
LOW_POWER_MODE=falseWhen LOW_POWER_MODE=false, the tool will not attempt to change CPU governors.
Use the included test script to verify CPU governor support:
# Run the test script
./test-cpu-governor.sh
# Run with sudo to test actual governor changes
sudo ./test-cpu-governor.sh-
Start the bridge with a trigger file present:
touch bridge sudo ./bridge -config bridge.conf
-
Monitor CPU governor in another terminal:
watch -n 1 cat /sys/devices/system/cpu/cpu0/cpufreq/energy_performance_preference
-
Remove trigger file to enter low power mode:
rm bridge # Wait for next check interval (default 15 minutes, or set CHECK_INTERVAL=30s for testing) -
Observe the governor change:
- Should switch from
performancetopower
- Should switch from
-
Recreate trigger file to exit low power mode:
touch bridge # Wait for next check interval -
Observe the governor change:
- Should switch back to
performance
- Should switch back to
# If running directly
sudo ./bridge -config bridge.conf
# If running as systemd service
sudo journalctl -u bridge -fYou'll see messages like:
Loading configuration from bridge.conf
Bridge starting with config:
Current CPU Governor: balance_power
...
Entering low power mode...
CPU governor set to powersave mode
Low power mode active - only file checking will continue
...
Exiting low power mode...
CPU governor set to performance mode
Low power mode deactivated - full functionality restored
# Watch CPU frequencies in real-time
watch -n 1 'grep MHz /proc/cpuinfo | head -4'
# Or use cpupower tool
sudo cpupower frequency-info
# Or check sysfs directly
watch -n 1 'cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_cur_freq | head -4'In Low Power Mode:
- CPU frequency reduced to minimum (typically 800-1200 MHz)
- Power consumption reduced by 30-60% (depending on workload)
- Heat generation reduced
- Fan noise reduced (on laptops)
Performance Impact:
- Minimal during idle (file checking only)
- Zero impact on port forwarding (switches to performance mode)
Example: Gateway server that forwards ports to development environment
- Active hours (8 hours/day): Performance mode, full CPU power
- Idle hours (16 hours/day): Powersave mode, ~50% power reduction
- Overall savings: ~30-35% daily power consumption
Check permissions:
# Verify you're running as root
id
# Check file permissions
ls -la /sys/devices/system/cpu/cpu0/cpufreq/scaling_governorCheck if governor is available:
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governorsIf you see "Intel P-State not available", the system is using generic cpufreq. This is normal for:
- Non-Intel CPUs (AMD, ARM, etc.)
- Older Intel CPUs (pre-Sandy Bridge)
- Systems with intel_pstate disabled in BIOS/kernel
The tool will automatically fall back to cpufreq governors.
If you experience performance issues:
-
Check current governor:
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
-
Manually set to performance:
echo performance | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
-
Disable low power mode:
LOW_POWER_MODE=false
To use different governors, modify the code in main.go:
// In enterLowPowerMode()
setCPUGovernor("powersave") // Change to: "conservative" or "ondemand"
// In exitLowPowerMode()
setCPUGovernor("performance") // Keep as performance for best throughputTo set custom frequency limits (requires additional code):
# Manual frequency limits
echo 800000 | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_min_freq
echo 3500000 | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_max_freq- README.md - Main documentation
- QUICKSTART.md - Quick start guide
- SYSTEMD-REFERENCE.md - Systemd service management
test-cpu-governor.sh- CPU governor test script