Laptop Power Saving

Today I had an issue updating the kernel on my company's laptop. I ended up reconfiguring it from strach istead of doing the oldconfig option (make oldconfig didn't ask anything but the kernel hard locked on boot). I took the oportunity to try to get a more duration out of the battery. How? By consuming less power.

PowerTop came in and lend a helping hand but it was not sufficient. When I enabled USB Suspend (CONFIG_USB_SUSPEND) the keyboard didn't work well. I have a keyboard, mouse and webcam connected to a hub that I use when I'm on my desk. Everything was working, power was being saving, even for the keyboard. The problem was that when the keyboard entered power saving mode and I pressed a key the first key that I pressed would be lost. The documentation talks about this issue but I didn't want to loose on the opportunity to increase my laptop's autonomy. Solution: udev to the rescue.

I created a udev rule that detects the USB Keyboard (by vendor and product id, maybe someday I'll connect to a keyboard without a problem). When the keyboard is connect it disables auto suspend just for the keyboard. Here is how I've done it (Note:I'm using Gentoo, but this should work on any linux, with more or less salt).

I created a udev rule in "/etc/udev/rules.d/92-usb-autosuspendfix.rules" with the following contents:
SUBSYSTEMS=="usb", ATTRS{idVendor}=="04f2", ATTRS{idProduct}=="0403",
RUN+="/etc/fixes/disableKeyBoardAutoSuspend.sh 04f2 0403"
The "/etc/fixes/disableKeyBoardAutoSuspend.sh" script does the whole magic. It search for the usb device in the sysfs and toggles the power control to on (it defaults to auto if the device supports power control).
#!/bin/bash

cd /sys/bus/usb/devices/
for device in `ls`; do
if [ -f $device/idVendor ]; then
if [ -f $device/idProduct ]; then
vendor=`cat $device/idVendor`
product=`cat $device/idProduct`
if [ "$1 $2" == "$vendor $product" ]; then
echo "Disable power for device $vendor:$product."
cd $device/power
echo on > level
fi
fi
fi
done
Hope this helps you. Maybe we should start a blacklist of USB devices that don't work well with power control.

Comments

Popular posts from this blog

Back to C: CMake and CUnit

OpenClock and Gentoo

Gentoo with LUKS and LVM