Page 1 of 8 123 ... LastLast
Results 1 to 10 of 73

Thread: HOWTO: Improve battery life on a laptop

  1. #1
    Join Date
    Jan 2007
    Location
    $here ? $here : $there
    Beans
    3,717
    Distro
    Ubuntu 8.04 Hardy Heron

    HOWTO: Improve battery life on a laptop

    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:

    Code:
    #!/bin/bash
    if on_ac_power; then
    # Reset back to normal settings
    else
    # Turn on aggressive power savings
    fi
    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
      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
    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.

    For users of nvidia laptop cards, you can also save some power by adding

    Code:
        Option      "OnDemandVBlankInterrupts" "True"
    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:
    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
    This will toggle compiz sync to vblank depending on whether or not you are on battery power.

    (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:
    Code:
    $ sudo install 99-save_power.sh /etc/pm/power.d
    $ sudo install 99-save_power.sh /etc/pm/sleep.d
    For Gutsy:
    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
    Last edited by sdennie; July 8th, 2008 at 09:58 AM. Reason: More Hardy updates

  2. #2
    Join Date
    Feb 2007
    Location
    Gray, TN, USA
    Beans
    155
    Distro
    Xubuntu 10.10 Maverick Meerkat

    Re: HOWTO: Improve battery life on a laptop

    I've got a riddle for you -- a conundrum, if you will. What do you do when "on_ac_power" returns true no matter whether the laptop is plugged in or not? How does gnome-power-manager know whether the laptop is on battery or on AC? In other words, is there some sort of something in /proc or /dev that gnome-power-manager reads to know whether to display a battery or a plug in the tray? Is there something I could grep to determine whether my script should call either the fullBlast or the powerSave function, rather than calling on_ac_power, which is apparently lying?
    Q: How many ADD kids does it take to screw in a lightbulb?
    A: Hey! Let's go ride bikes!

  3. #3
    Join Date
    Jan 2007
    Location
    $here ? $here : $there
    Beans
    3,717
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: HOWTO: Improve battery life on a laptop

    Actually, on_ac_power is just a script in /usr/bin that checks /proc/acpi/ac_adapter/state (or status). You could look at that as a start or you could probably do something like:

    Code:
    grep discharging /proc/acpi/battery/BAT0/state
    If neither of those things properly display ac/battery changes, it's possible that it's a BIOS problem and you may want to check if your laptop/motherboard has any BIOS updates.

  4. #4
    Join Date
    Dec 2007
    Location
    pacific northwest
    Beans
    244
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: HOWTO: Improve battery life on a laptop

    how would you install the above script for use by pm-utils in 8.04 hardy?

  5. #5
    Join Date
    Jan 2007
    Location
    $here ? $here : $there
    Beans
    3,717
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: HOWTO: Improve battery life on a laptop

    Updated first post for pm-utils in Hardy.
    Don't try to make something "fast" until you are able to quantify "slow".

  6. #6
    Join Date
    Dec 2007
    Location
    pacific northwest
    Beans
    244
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: HOWTO: Improve battery life on a laptop

    another question: how do these settings relate to/interact with what exists in /usr/lib/pm-utils/power.d/laptop-tools ? and also the ones in laptop-mode-tools if laptop-mode is enabled? it is all very confusing to have so many different places where a single parameter can be set, or perhaps be in conflict or be overridden...

  7. #7
    Join Date
    Jan 2007
    Location
    $here ? $here : $there
    Beans
    3,717
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: HOWTO: Improve battery life on a laptop

    Yes, it's quite confusing and worse in Hardy with the inclusion of /usr/lib/pm-utils. However, one nice things is that all these ".d" directories should be looking at the numbers at the beginning of the filename and executing them in order so, "99-foo.sh" will get executed after "50-bar.sh". I think if you name your personal settings "99-whatever.sh", you can essentially override any other setting that has come before it.
    Don't try to make something "fast" until you are able to quantify "slow".

  8. #8
    Join Date
    Nov 2005
    Location
    USA
    Beans
    38
    Distro
    Ubuntu 14.04 Trusty Tahr

    Question Re: HOWTO: Improve battery life on a laptop

    I am using 8.04 x86-64 on a HP6715b with a Turion TL60. I know the processor supports C1E but I never see the processor in any state but C0.
    Does anyone else see the "power management: yes"
    in the processor info?
    I would like to enable C1E in linux to improve battery life.



    :/proc/acpi/processor/C000$ more info
    processor id: 0
    acpi id: 1
    bus mastering control: yes
    power management: no
    throttling control: yes
    limit interface: yes

    :/proc/acpi/processor/C000$ more power
    active state: C0
    max_cstate: C8
    bus master activity: 00000000
    maximum allowed latency: 8000 usec
    states:
    C1: type[C1] promotion[--] demotion[--] latency[000] usage[00000000] duration[00000000000000000000]

    thanks
    Computer
    CPU i5-4460 , Motherboard GA-B85M-DS3H-A
    8GB Memory, 1TB /Home, 128GB SSD /
    Samsung 19" DVI, Acer 19" VGA

  9. #9
    Join Date
    Jan 2007
    Location
    $here ? $here : $there
    Beans
    3,717
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: HOWTO: Improve battery life on a laptop

    smsmith050, I've never used an AMD CPU before. Have you used powertop to check the C and P states of the CPU? I'm not sure if it works with AMD CPUs but, it's possible that /proc/acpi is simply wrong and that powertop can give you more accurate information.
    Don't try to make something "fast" until you are able to quantify "slow".

  10. #10
    Join Date
    Nov 2005
    Location
    USA
    Beans
    38
    Distro
    Ubuntu 14.04 Trusty Tahr

    Question Re: HOWTO: Improve battery life on a laptop

    The Intel powertop app is not able to identify the AMD Turion.

    For C1E not working I suspect something is wrong with the BIOS. C1E does work with windows.... I have the latest BIOS

    During C1E the hyper-transport link is stopped, the memory is in self-refresh, and the processor clocks are divided down. It saves a good amount of power.

    S

    PowerTOP version 1.9 (C) 2007 Intel Corporation

    P-states (frequencies)
    2.00 Ghz 0.0%
    1.80 Ghz 0.0%
    1.60 Ghz 0.0%
    800 Mhz 100.0%
    < Detailed C-state information is only available on Mobile CPUs (laptops) >
    Computer
    CPU i5-4460 , Motherboard GA-B85M-DS3H-A
    8GB Memory, 1TB /Home, 128GB SSD /
    Samsung 19" DVI, Acer 19" VGA

Page 1 of 8 123 ... LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •