Systemd service/timer workflow that switches CPU governors when the user becomes idle or active.
-
Copy the provided
.configand.localfolders into your home directory:cp -rv .config ~/ cp -rv .local ~/ chmod +x ~/.local/bin/idle-cpu-save.sh
-
Confirm
cpupowerbinary location:which cpupower || command -v cpupower
-
Add a sudoers rule (requires root) allowing execution of cpupower:
echo "$(whoami) ALL=(root) NOPASSWD: $(which cpupower)" | sudo tee /etc/sudoers.d/50-idle-cpu-save
Verify produced file syntax with:
sudo visudo -c -f /etc/sudoers.d/50-idle-cpu-save
-
Reload and enable the timer/service (user-level):
systemctl --user daemon-reload systemctl --user enable --now idle-cpu-save.timer
After changing any configuration be sure to reload with systemctl --user daemon-reload
-
Configure desired active and idle governors
Use the
GOV_IDLEandGOV_ACTIVEenvironment variables inidle-cpu-save.service.
Set to correct values likepowersave,performance,schedutil,ondemanddepending on your kernel and cpupower support.
Runcpupower frequency-infoto check. -
Configure idle and active thresholds Use the
IDLE_THRESHOLD_MSenvironment variable inidle-cpu-save.serviceto set the idle detection threshold (default: 120000ms = 2 minutes).
Use theACTIVE_THRESHOLD_MSenvironment variable to set the active detection threshold after coming from idle (default: 20000ms = 20 seconds). This allows faster switch to active state.
-
Test the
cpupowercommand directly:sudo /usr/bin/cpupower frequency-set -g schedutil
-
Check current governor from sysfs (no root usually required for read):
cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor -
Inspect logs:
journalctl --user -u idle-cpu-save.service -u idle-cpu-save.timer --since "5 minutes ago" --follow -
Start the service manually for testing:
systemctl --user start idle-cpu-save.service journalctl --user -u idle-cpu-save.service --since "5 minutes ago" -
Desperate Mode (enabled extra logging):
DEBUG=1 systemctl --user set-environment DEBUG=1 systemctl --user daemon-reload journalctl --user -u idle-cpu-save.service --follow
Cleanup when done:
systemctl --user unset-environment DEBUG
-
Stop and disable the timer (user-level):
systemctl --user disable --now idle-cpu-save.timer
-
Remove the service and timer files:
rm ~/.config/systemd/user/idle-cpu-save.service rm ~/.config/systemd/user/idle-cpu-save.timer systemctl --user daemon-reload
-
Remove the script:
rm ~/.local/bin/idle-cpu-save.sh -
Remove the sudoers rule:
sudo rm /etc/sudoers.d/50-idle-cpu-save
-
(optional) Restore a default CPU governor:
sudo /usr/bin/cpupower frequency-set -g powersave
check available governors with:
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors