lightweight powersave on linux with udev and cpufreq-set

by Martin Monperrus

There is a number of tools to save power on Linux by throttling the CPU(s). Some are daemon based for example cpufreqd, powernowd, powersaved, cpudyn. Some are desktop based for example kpowersave or gnome-power-manager. These tools require configuration, and heavyweight system services like hal or d-bus.

This page describes a simple and lightweight solution to enable powersave on Linux with udev. It only requires udev (no hal, no dbus). The idea in to use udev events to trigger ‘’cpufreq-set’’.

  1. Check if the modules related to cpu frequency scaling are loaded, i.e. if you have these files or similar ones ’‘/etc/rc5.d/S05loadcpufreq’’ and ’‘/etc/rc5.d/S19cpufrequtils’’

  2. In a new udev rule file, for example ’‘/etc/udev/rules.d/cpufreq.rules’’, add: # the powersave kernel module (cpufreq_powersave) simply selects the minimum frequency SUBSYSTEM==“power_supply”, ENV{POWER_SUPPLY_ONLINE}==“0”, RUN+=“/usr/bin/cpufreq-set -g powersave” # the powersave kernel module (cpufreq_performance) simply selects the maximum frequency SUBSYSTEM==“power_supply”, ENV{POWER_SUPPLY_ONLINE}==“1”, RUN+=“/usr/bin/cpufreq-set -g performance”

  3. Finally, to set the correct governor at startup, add to ’‘/etc/rc.local’’ (and be sure ’‘/etc/rc.local’’ is used at startup) if grep on-line /proc/acpi/ac_adapter/AC/state; then cpufreq-set -g performance; else cpufreq-set -g powersave; fi

Tagged as: