I have been using powersave until recently, but I have gone from unhappy to fed up. I also have acpi-support and laptop-mode-tools and hell knows how they all interact. To add insult to the injury, powersave loves to crash or get stuck at times and dbus screws up at times too, which in turn screws powersave. Oh dear.

So i have ditched powersave, left laptop-mode-tools and acpi-support around. And i wrote a perl script, i have called it “pm” to handle things i used powersave for. Primarily dpm (device power management) in linux, suspend to ram/disk, battery monitoring and friends. Right now it’s ~250 LOC with comments, and more importantly, i know how it works. And it can do things powersave can’t. So i am basically happy.

It can suspend and resume pci devices (using id<->function mapping) and report their status. It has a very slim suspend wrapper, that just locks screen, syncs drives, remembers power states of pci devices and asks kernel to suspend. After resuming, it restores power states, does chvt voodoo to wake up my intel graphics and sets drive spindown timeout (something, somewhere screws this one up).

I also added a “summary” output, that i run using watch on one of terminals in my screen session, that reports cpu frequency and scaling policy, system temperature, battery state (including charge/discharge rate in watts and remaining capacity in mAh), harddrive state (when spinning, also temperature and number of spinups in the drive’s lifetime… if you know how to get those two without spinning up the drive, tell me). Then power states of devices (usb, ethernet, wlan, sound, modem, pcmcia, smartcard controller and isa bridge). And as a cherry on top, a list of processes and pids that have recently caused block reads from the drive (needs vm/block_dump enabled in kernel), so you can find out what caused drive spinup.

That is about it, now for the catch. It works for me, it probably won’t for you, at least not out of the box, unless you have same laptop as me. The pci ids of devices are hardcoded (although not hard to change near the top of the script), so is the screen lock function and probably a bunch of other things. It shouldn’t be hard to make a similar script for your system using mine as a starting point though. Another thing that is missing is a nice reporter for KDE to be put on the panel or somesuch.

Also, since the script is simplistic in its design, it assumes lots of things about both kernel (tested on 2.6.16 stock debian) and userspace utilities (acpi, hdparm, smartctl) and (oh, coarse-grained evilness), that you have sudo (needed for hdparm at least).

Another assumption is that you have single battery and single cpu. But for all the limitations, it goes that if you are going to use a script like that, you probably know enough to extend it to multi-battery and/or multi-core situations. The script definitely needs a hacker-nature :-).

So for the brave, the script is to be found on the pm page.