A dynamic CPU frequency governor manager for Linux systems that automatically adjusts CPU scaling governors based on real-time CPU load. powergov implements an intelligent state machine with implicit hysteresis to optimize power consumption while maintaining system responsiveness.
powergov is a lightweight daemon that monitors CPU utilization and dynamically switches between CPU frequency governors (powersave, schedutil, and performance) to balance power efficiency and performance. The system operates as a background service that continuously evaluates CPU load and makes governor transitions according to a state machine with built-in hysteresis to prevent rapid oscillations.
powergov operates through a continuous monitoring loop that:
- Monitors CPU Load: Samples CPU utilization by reading
/proc/statand calculating usage over a 200ms measurement window - State Management: Maintains a three-state system (POWERSAVE, BALANCED, PERFORMANCE) representing different power/performance profiles
- Governor Switching: Dynamically sets the appropriate CPU frequency governor for all CPU cores via
/sys/devices/system/cpu/cpu*/cpufreq/scaling_governor - Battery Monitoring: When battery-safe mode is enabled, monitors battery level and prevents performance mode when battery is low
- Dynamic Configuration: Supports runtime configuration changes via Unix domain socket, allowing threshold adjustments without service restart
- Background Operation: Runs as a daemon process, operating independently as a system service
The system implements the following state machine:
- POWERSAVE → BALANCED: Triggered when CPU load exceeds 25%
- BALANCED → PERFORMANCE: Triggered when CPU load exceeds 75%
- PERFORMANCE → BALANCED: Triggered when CPU load falls below 60%
- BALANCED → POWERSAVE: Triggered when CPU load falls below 25%
powergov implements implicit hysteresis through asymmetric transition thresholds. This design prevents rapid governor switching (thrashing) that would occur with symmetric thresholds.
The hysteresis mechanism is implicit in the state transition logic:
-
Performance threshold asymmetry: To enter PERFORMANCE state, load must exceed 75%, but to exit it, load must drop below 60%. This creates a 15% dead zone (60-75%) that prevents oscillation when load fluctuates around a single threshold.
-
State-dependent behavior: The transition conditions depend on the current state, not just the absolute load value. This ensures that once a state is entered, it requires a different load level to exit, naturally creating hysteresis.
- Stability: Prevents rapid switching between governors when CPU load hovers around transition points
- Reduced overhead: Minimizes the computational cost and system disruption from frequent governor changes
- Predictable behavior: Provides consistent system response characteristics
- Battery optimization: Allows the system to remain in power-saving states longer, as it requires sustained higher load to transition upward
powergov can significantly improve battery life on laptops and mobile devices through several mechanisms:
-
Aggressive Power Saving: When CPU load is below 25%, the system uses the
powersavegovernor, which keeps CPU frequencies at minimum levels, reducing power consumption. -
Dynamic Scaling: Instead of running at fixed high frequencies (as with
performancegovernor) or always using balanced scaling, powergov adapts to actual workload demands, scaling up only when necessary. -
Reduced CPU Voltage: Lower CPU frequencies require lower operating voltages. Since power consumption scales quadratically with voltage (P ∝ V²f), even small frequency reductions yield substantial power savings.
-
Thermal Efficiency: Lower power consumption reduces heat generation, which can allow the system to maintain lower fan speeds or passive cooling, further reducing overall system power draw.
-
Idle Optimization: During periods of low activity, the system remains in POWERSAVE state, allowing the CPU to spend more time in deeper idle states (C-states), which consume minimal power.
The actual battery savings depend on workload characteristics, but typical improvements range from 10-30% for mixed usage patterns, with higher gains during light workloads.
This project is licensed under the GNU General Public License version 3 (GPL-3.0).
The GNU General Public License version 3 is a copyleft license that ensures software remains free and open. Key provisions include:
- Freedom to use: Anyone can run the software for any purpose
- Freedom to study: Source code must be available, allowing users to understand how the software works
- Freedom to modify: Users can change the software to suit their needs
- Freedom to distribute: Users can share the software, including modified versions
Copyleft requirement: If you distribute modified versions of GPL-3 licensed software, you must also license your modifications under GPL-3, ensuring the software and its derivatives remain free and open.
This license ensures that powergov and any improvements to it remain available to the community under the same terms.
- GCC compiler
- Linux kernel with CPU frequency scaling support
- Root/sudo access (required for governor switching)
makesudo make installsudo make install-service
sudo systemctl enable powergov.service
sudo systemctl start powergov.serviceStart powergov:
sudo powergov onStop powergov:
sudo powergov offDisplay help:
powergov --helppowergov supports dynamic battery-aware configuration to prevent the system from using performance mode when battery is low.
Enable battery-safe mode with threshold:
sudo powergov --battery-safe <percent>This command configures powergov to disable the performance governor when battery level falls below the specified threshold. The configuration is applied immediately to the running process without requiring a restart.
Examples:
sudo powergov --battery-safe 50 # Disable performance mode when battery <= 50%
sudo powergov --battery-safe 20 # Disable performance mode when battery <= 20%
sudo powergov --battery-safe 0 # Disable battery-safe mode (allow performance at any battery level)When battery-safe mode is enabled:
- If battery level is above the threshold: normal operation, performance mode can be used
- If battery level is at or below the threshold: performance governor is blocked, system stays in
schedutilorpowersave - Configuration can be changed on-the-fly while powergov is running
- Battery level is checked every ~10 seconds
If installed as a systemd service:
sudo systemctl start powergov # Start the service
sudo systemctl stop powergov # Stop the service
sudo systemctl status powergov # Check service status
sudo systemctl restart powergov # Restart the service- Sampling interval: 2 seconds
- CPU load measurement window: 200ms
- Transition thresholds:
- Low: 25% (0.25)
- Medium: 60% (0.60)
- High: 75% (0.75)
- Supported governors: powersave, schedutil, performance
- CPU detection: Automatically detects and manages all available CPU cores
- Linux operating system
- Kernel with CPU frequency scaling subsystem (
CONFIG_CPU_FREQ) /sys/devices/system/cpu/cpu*/cpufreq/scaling_governorinterface/proc/statfor CPU load monitoring- Root privileges for governor switching
powergov/
├── main.c # CLI entry point and daemon management
├── governor/
│ ├── governor.c # CPU governor switching implementation
│ ├── governor.h
│ ├── loop.c # Main state machine and monitoring loop
│ └── loop.h
├── cpu/
│ ├── cpu_load.c # CPU utilization measurement
│ └── cpu_load.h
├── Battery/
│ ├── battery.c # Battery level detection
│ └── battery.h
└── service/
└── powergov.service # systemd service file
Contributions are welcome. Please ensure that any modifications maintain compatibility with the GPL-3 license and include appropriate documentation.
This software modifies system-level CPU frequency scaling behavior. While designed to be safe, users should understand that incorrect governor settings or system misconfiguration could affect system performance. Use at your own risk.