Automatic power saving on a Linux laptop with PowerTOP and systemd

If you have a laptop and want to get more battery life, you may already know about a handy tool from Intel called PowerTOP.

PowerTOP not only monitors your system for interrupts but has a tunable section where you can enable various power saving tweaks. Toggling one such tweak in the PowerTOP interface will show you the specific Linux system command it ran in order to enable or disable it.

PowerTOP Tweaks

Furthermore, it takes an argument ––auto-tune which lets you enable all of the power saving measures it has detected.

The package on Fedora comes with a systemd service, so enabling power saving on boot is simple, just enable the service:
sudo systemctl enable powertop

I noticed, however, that putting some devices into low-power mode on my laptop has unwanted side effects. In my case, the audio system outputs white noise and the USB mouse and keyboard are too slow to wake up (which I find annoying when I want to quickly click on, or type something).

So I took note of the Linux commands that PowerTOP was running for the USB peripherals and the audio device when it disabled power saving. The plan is to use the power of powertop ––auto-tune but I’ll then turn power saving back off for those specific devices.

I created an executable script under /usr/local/sbin/powertop-fixups.sh to disable power saving on those devices:
#!/bin/sh
# Don't do powersave on intel sound, we get static noise
echo '0' > '/sys/module/snd_hda_intel/parameters/power_save'
 
# Don't suspend USB keyboard and mouse
# This takes time to wake up which is annoying
echo 'on' > '/sys/bus/usb/devices/1-2.1.1/power/control'
echo 'on' > '/sys/bus/usb/devices/1-2.2/power/control'

Now, I just needed to tell systemd to start my script on boot, which should require and start after the powertop service.

I created the following service file at /etc/systemd/system/powertop-fixups.service:
[Unit]
Description=PowerTOP fixups
Requires=powertop.service
After=powertop.service
 
[Service]
Type=oneshot
ExecStart=/usr/local/sbin/powertop-fixups.sh
 
[Install]
WantedBy=multi-user.target

Then all I had to do was activate and enable it! Note that I don’t need to enable powertop.service itself, systemd will take care of that for me.

sudo systemctl daemon-reload
sudo systemctl enable powertop-fixups

Now I get the benefit of most of the power savings from PowerTOP, without the settings that were annoying.

4 Responses to “Automatic power saving on a Linux laptop with PowerTOP and systemd”


  • Ernesto ManrĂ­quez

    Why powertop2tuned has to be discarded so quickly? It has proven awesome in my convertible lappy.

  • I don’t think that powertop2tuned has been discarded, it’s still there but requires that you configure and run tuned service. This is just another way do quickly get benefits of powertop using the build in systemd service, but it doesn’t handle other things like tuned does.

  • A suggestion for /usr/local/sbin/powertop-fixups.sh

    Rather than hard-code the USB device path (USB devices may often be changed between ports) search the “product” in each USB device for the specific string of the device you wish to enable.

    For example, my Media PC has a FLIRC remote receiver and a cheap Microsoft wireless keyboard receiver:

    echo ‘on’ > $( grep -l ‘flirc’ /sys/bus/usb/devices/*-*/product | sed ‘s/product/power\/control/’ )
    echo ‘on’ > $( grep -l ‘Microsoft’ /sys/bus/usb/devices/*-*/product | sed ‘s/product/power\/control/’ )

    I guess then the type could be changed from oneshot and a timer added to run once daily?
    (For now I’m lazy and just leaving it as oneshot on boot!)

Leave a Reply