Topic: Laptop power saving script for #! & Debian
I was a bit disappointed with the battery life of crunchbang out of the gate. I installed laptop-mode-tools but that did not do much. So I hacked together a little script that will enable some power saving tweaks when on battery power, and default to best performance while on AC. It should work on most setups, but YMMV. It is a good idea to check that the /sys/ entries actually exist on your system, and that the values are sane; Some are hardware specific for instance. We are going to take advantage of a pm-utils feature; any script placed in /etc/pm/power.d/ will automatically run when the AC power is connected or disconnected. Create and open /etc/pm/power.d/powersave, and copy the following script into it. Don't forget to make it executable. Note this part:
# List of modules to unload, space seperated. Edit depending on your hardware and preferences.
modlist="uvcvideo"In modlist you can put a list of modules to automatically load and unload. The uvcvideo entry will disable most webcams. Remove this if you want to use your webcam on battery without having to sudo modprobe uvcvideo first.
"/etc/pm/power.d/powersave"
#!/bin/sh
# A script to enable laptop power saving features for #! & Debian GNU+linux.
# http://crunchbanglinux.org/forums/topic/11954
# List of modules to unload, space seperated. Edit depending on your hardware and preferences.
modlist="uvcvideo"
# Bus list for runtime pm. Probably shouldn't touch this.
buslist="pci spi i2c"
case "$1" in
true)
# Enable some power saving settings while on battery
# Enable laptop mode
echo 5 > /proc/sys/vm/laptop_mode
# Less VM disk activity. Suggested by powertop
echo 1500 > /proc/sys/vm/dirty_writeback_centisecs
# Intel power saving
echo Y > /sys/module/snd_hda_intel/parameters/power_save_controller
echo 1 > /sys/module/snd_hda_intel/parameters/power_save
# Set backlight brightness to 50%
echo 5 > /sys/devices/virtual/backlight/acpi_video0/brightness
# USB powersaving
for i in /sys/bus/usb/devices/*/power/autosuspend; do
echo 1 > $i
done
# SATA power saving
for i in /sys/class/scsi_host/host*/link_power_management_policy; do
echo min_power > $i
done
# Disable hardware modules to save power
for mod in $modlist; do
grep $mod /proc/modules >/dev/null || continue
modprobe -r $mod 2>/dev/null
done
# Enable runtime power management. Suggested by powertop.
for bus in $buslist; do
for i in /sys/bus/$bus/devices/*/power/control; do
echo auto > $i
done
done
;;
false)
#Return settings to default on AC power
echo 0 > /proc/sys/vm/laptop_mode
echo 500 > /proc/sys/vm/dirty_writeback_centisecs
echo N > /sys/module/snd_hda_intel/parameters/power_save_controller
echo 0 > /sys/module/snd_hda_intel/parameters/power_save
echo 10 > /sys/devices/virtual/backlight/acpi_video0/brightness
for i in /sys/bus/usb/devices/*/power/autosuspend; do
echo 2 > $i
done
for i in /sys/class/scsi_host/host*/link_power_management_policy
do echo max_performance > $i
done
for mod in $modlist; do
if ! lsmod | grep $mod; then
modprobe $mod 2>/dev/null
fi
done
for bus in $buslist; do
for i in /sys/bus/$bus/devices/*/power/control; do
echo on > $i
done
done
;;
esac
exit 0To check that the script is running, and to see any errors run cat /var/log/pm-powersave.log
To save even more power check out this thread to enable undervolting. If you have Nvidia graphics check here for xorg.conf settings to save power.
After applying all these tweaks I have seen a healthy increase in battery life. Without the tweaks applied I would get 3:20 of wireless browsing. After applying tweaks I get 4:15.
If you find any hardware specific settings to add please leave a reply, it will help all #! laptop users.
Updated March 4rd, 2011
Running powertop always recommended "Enabling Runtime PM", but I could never find out what that did. Thanks to this thread on the Archlinux forums, I have been able to add it to this script.
Update #2 March 18th, 2011
Thanks to this reply we can save some more power. I simply copied the harddrive, journal_commit, and readahead scripts to my /etc/pm/power.d folder. You can add others if you want, but some duplicate the preceding script. The scripts I added replace laptop-mode-tools, which is deprecated. Thanks Jelloir!
Last edited by hardran3 (2011-03-22 16:21:48)