By default Gutsy/Hardy is reasonable on laptop battery life but, with very little work, it's not difficult to dramatically increase battery life. Some of this information is from lesswatts.org or straight out of the powertop tool however, neither of them (that I've seen) give you a way to automate the switch between AC power and battery.
Essentially the idea is to create a script that plugs into the acpi system that should properly handle events like switching to/from battery as well as resuming from suspend. It's possible to do some of these things via the laptop-mode tool but, I prefer this method because it gives a more fine grained control over what settings you use.
The basic script looks like this:
The commands that will populate the two sections of that script will differ from laptop to laptop but, the information that the powertop tool provides and the tips at http://www.lesswatts.org/tips/ are good places to start. Some of the things are fairly generic however and so a script closer to this is a reasonable starting point:Code:#!/bin/bash if on_ac_power; then # Reset back to normal settings else # Turn on aggressive power savings fi
The first set of settings should be similar to the default Ubuntu settings and are what will be used when on AC power. The second set of settings should help to save power. These settings should work on any modern laptop with a SATA disk but, in practice there are actually many more power saving features that you can use depending on your hardware (sound card, wifi, bluetooth, etc...). The links above to lesswatts.org should get you going in the right direction as far as what more to add.Code:#!/bin/bash if on_ac_power; then # Reset back to normal settings echo 0 > /proc/sys/vm/laptop_mode echo 10 > /proc/sys/vm/dirty_ratio echo 5 > /proc/sys/vm/dirty_background_ratio echo 500 > /proc/sys/vm/dirty_writeback_centisecs echo max_performance > /sys/class/scsi_host/host0/link_power_management_policy else # Turn on aggressive power savings echo 5 > /proc/sys/vm/laptop_mode echo 40 > /proc/sys/vm/dirty_ratio echo 10 > /proc/sys/vm/dirty_background_ratio echo 1500 > /proc/sys/vm/dirty_writeback_centisecs echo min_power > /sys/class/scsi_host/host0/link_power_management_policy fi
For users of nvidia laptop cards, you can also save some power by adding
to /etc/X11/xorg.conf. You'll want to add that to the section in that file that contains 'Driver "nvidia"'. If you are using compiz (Desktop effects) you will either need to disable sync to vblank (not actually enabled by default) or add the following to the script above:Code:Option "OnDemandVBlankInterrupts" "True"
This will toggle compiz sync to vblank depending on whether or not you are on battery power.Code:for x in /tmp/.X11-unix/*; do displaynum=`echo $x | sed s#/tmp/.X11-unix/X##` getXuser; if [ x"$XAUTHORITY" != x"" ]; then export DISPLAY=":$displaynum" if on_ac_power; then su $user -c "gconftool-2 --type boolean --set /apps/compiz/general/screen0/options/sync_to_vblank 1" else su $user -c "gconftool-2 --type boolean --set /apps/compiz/general/screen0/options/sync_to_vblank 0" fi fi done
(Note: The compiz/nvidia solution doesn't work on Hardy. I'm working on a solution for it.)
Finally, you'll need to install the script. You will want to name the script something like 99-save_power.sh and then to install it, you can use a command like this:
For Hardy:
For Gutsy:Code:$ sudo install 99-save_power.sh /etc/pm/power.d $ sudo install 99-save_power.sh /etc/pm/sleep.d
Code:$ sudo install 99-save_power.sh /etc/acpi/ac.d $ sudo install 99-save_power.sh /etc/acpi/battery.d $ sudo install 99-save_power.sh /etc/acpi/resume.d $ sudo install 99-save_power.sh /etc/acpi/start.d
This should make the script run whenever you start the machine, resume it from suspend or plugin/unplug the power cable.
The script(s) as written above may not save you huge amounts of power but, the idea is more to provide a general harness for adding power saving options and reverting those options when on AC power. Once you have the basic scripts in place, things like lesswatts.org or the powertop tool should be able to help guide you in further power savings.
For a machine specific example of how I use this script on a Dell XPS m1330, see: http://ubuntuforums.org/showthread.php?t=847773



Adv Reply



Bookmarks