xtend your battery so y ou can GO ALL NITE

Download this article as an e-bookDownload this article as an e-book

K3ep going all n1te just like all that sp4m c0ming in through your mailbox.10 watts, it's a new record!

10 watts, it's a new record!

From joke to revolver as we say, I’ve noted that many of you find hacking away from power sources quite useful. Here’s how to keep at it longer with low power.

What is killing my battery?

First off, STOP what you’re doing and realize that every single IO op and every second of CPU time is killing your battery. The more you can do without hitting disk, the better – more about disk access later.

Measure your consumption

Use gnome-power-manager’s Power History or powertop to measure your progress towards the Ultimate Battery Life, as measured in watts consumed. You should note the wattage on battery before you start fiddling with settings, and note the impact of every change – in watts and minutes gained – as you make them. I started out with a power consumption of about 42W and managed to shave it down to 10W in special circumstances. Beat that and tell me about it!

Once you’ve followed the tips below you’ll be able to enjoy as much computer time as your battery can possibly produce!

Clamp your clock … or not?

Clamp your CPU down to the minimum possible. 800MHz is plenty, more than you need. Really. You may think that a dynamic clock will get things done faster, but alas you will use more watts total than if you had sticked to the low cpu speed and taken your time. Realize that CPU frequency switching itself costs battery power!

You can save up to *10W* by clamping your CPU clock!

[edit 2009-09-24]: According to mjg59 it’s better to make your cpu clock ondemand so that it can get the work done and go back to idling. This is counter to intuition and my experiences, but the math is sound if the processor does go back into idle fast enough. So, try ondemand and see how it compares to clamping.

On newer laptops, where cpu frequency switching takes less time, ondemand may be a better power saver.

gnome-power-manager and kpowersave are nice apps for adjusting the behaviour of your system on battery.

gnome-power-manager has a pretty Power History grapher

gnome-power-manager has a pretty Power History grapher

However, power-manager doesn’t let you tweak clock speed, and neither app is enough to get the most out of your battery.

powertop is useful

Now, grab Intel’s powertop through apt or yum or whatever godforsaken package manager you are using. Run powertop as root and follow all of its suggestions, which include setting USB autosuspend, SATA link level management and some rather nice sysctl settings.

Powertop shows a respectable 13W power drain.

Powertop shows a respectable 13W power drain.

You can gain 6-8W by following powertop’s tips. That might translate to another half hour or more!

Don’t hit the disk

The idea is to enable power management for all hardware and software that supports it, and to see what programs are causing the CPU to wake up. Apart from power management, the filesystem mount options and harddrive cache strategy can give immeasurable power gains:

$ mount -o remount,noatime /
# or, in /etc/fstab, mount all your filesystems with "noatime":
/dev/sda3       /               ext3    noatime,errors=remount-ro 0       1
/dev/sda5       /var            ext3    noatime        0       2

Thus reading a file will not cause the writing to its access time bits, which is faster and saves power. If you’re a weirdo you should also look at relatime and nodiratime.

Some kernel settings – especially the ones concerning the VM and cache – are really nice to have on a low-powered laptop. I’ll say it again: if you can avoid hitting disk you save gold! So make the lappy cache writes and write out cache together with other disk writes:

# /etc/sysctl.conf - to reload, run $ sysctl -p
# Aye, this be a laptop. Flush dirties after IO.
vm.laptop_mode = 5
# Turn off swapping of this filthy bastard [60]
vm.swappiness = 0
# % of total memory pages when pdflush writes out dirty [5]
vm.dirty_background_ratio = 15
# flush dirty older than.. [3000]
vm.dirty_expire_centisecs = 6000
# % of total memory when writing process will write out dirty [10]
vm.dirty_ratio = 20
# how often to pdflush [1500]
vm.dirty_writeback_centisecs = 0

Agressively power manage your disk. This will suck performance, so turn it on only when you’re on battery:

$ sudo hdparm -B 1 -S 12 /dev/sda

This will turn agressive Advanced Power Management on your disk, and park the disk after 1 minute of idle spinning. The settings are reversed by rebooting, or with the command

$ sudo hdparm -B 255 -S 0 /dev/sda

Save power from the get-go

Make sure the default fallback CPU frequency governor is powersave. Install powersaved and set

CPUFREQ_CONTROL="kernel" # in /etc/powersave/cpufreq

and

CPUFREQUENCY="powersave" # in /etc/powersave/scheme_powersave
$ cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
powersave

If it says “userspace”, either HAL, gnome or kpowersave is what you need to tweak.

Offline unused cores

If you have a multi-core laptop you can disable all cores except for the main core by putting them offline. Just make two scripts cpuoff and cpuon and plod them into /usr/local/bin:

cpuoff:   echo 0 > /sys/devices/system/cpu/cpu1/online
cpuon :   echo 1 > /sys/devices/system/cpu/cpu1/online

They need to be executed as root. Just because you disabled the cpu core doesn’t mean your system is using less power. Mine will use about 1.3W *more* if I disable the sec0nd core. YMMV. I’d love to hear about your experience.

Dim your panel

Every brightness level on your display costs you (at least) 1 Watt of power, or maybe 15 minutes more hacking! Set your panel brightness to the lowest level you can go while still being able to read text. Use gnome-power-manager or kpowersave to dim the backlight or even turn off the screen after 2 minutes of idleness.

kpowersave is a flexible power manager if you're sick of the old gnome

kpowersave is a flexible power manager if you're sick of the old gnome

Make the display more readable with a dim backlight: use large equal width white fonts on black background. Don’t strain your eyes! Small black serif fonts on white backgrounds are bad for the eyes as well as the battery! (my wordpress blog theme nonwithstanding)

Engage radio silence

Disable bluetooth and WAN if you’re not using them. On the ThinkPad, that’s done as root in the following way:

echo 0 > /sys/devices/platform/thinkpad_acpi/bluetooth_enable
echo 0 > /sys/devices/platform/thinkpad_acpi/wwan_enable

If you’re not using the nets, disconnect and turn off the radio with your KILL switch.

If you need to stay connected and you’re on your own wifi, there are things you can tweak in your access point to save battery. Go to your wireless settings and increase the DTIM interval (try doubling or tripling the default) and set your beacon interval to once every few seconds. What it saves in CPU power it costs in latency.

You can also try upping the power saving features of your wireless card:

iwpriv wlan0 set_power 5

or

echo 5 > /sys/bus/pci/drivers/iwlagn/*/power_level

Kill power hogs

Every single running application, every single background daemon and every active driver takes a continuous charge off your battery and eventually depletes it. So turn off everything but what you are working with right now. Remove beagle and updatedb to avoid those nasty cron jobs scanning your whole system.

Firefox is a particular power hog, especially with flash and java plugins running. Kill it, use opera or chromium instead. Use only a few tabs and close them when you are done!

Go through the scripts in /etc/rc3.d (or chkconfig –) and disable all the services you might as well start manually when you need them. Create a short script that stops all non-essential services, one by one.

That blinking cursor

One usually has a blinking cursor in the text editor, document writing application or text terminal. Turn of the blink and your CPU won’t have to wake up every second to draw it. Here’s how to do so in the fabulous VIM (put this in your ~/.vimrc):

" don't wake up cpu by blinking
let &guicursor = &guicursor . ",a:blinkon0"

Set a new record

I mentioned that I’ve managed to trim down to a total power usage of 8.1W – this translates into 14 hours of mp3 play time with a 9 cell + 3 cell expansion battery when my laptop is in “heavy iPod mode” – lights out, lid closed, display off and only audacious2 piping some of the breakest beats and dubbest steps into my headphones straight out of my backpack.

Record-breaking 8W power consumption

Record-breaking 8W power consumption

lesswatts.org is a cool place to continue from here.

Who’s to say these tips only apply to laptops? Recently companies have been looking for ways to save the environment – and save money on their electricity bills. Easy peasy with these steps.

Did you like this article? Post a comment & tell us how much power you’re saving, or how much I suck or rule :-)

Download this article as an e-bookDownload this article as an e-book

Tags: , , , , , ,

6 Responses to “xtend your battery so y ou can GO ALL NITE”

  1. kristian says:

    Nice one, finally had a chance to tickle with this.

    I found the “laptop_mode” / laptop-mode script quite useful, which essentially does most of the kernel/disk stuff for you. On my Ubuntu it was installed but disabled by default.

    I found that kjournald would keep waking up the disk even with noatime, which I suspect was caused by relatime, but was also solved with the laptop-mode script. An other annoyance is logs.

    I decided to just use a ramfs. Since this is a laptop, I don’t really need old logs, but I often use logs for debugging. This helped alot, since stupid things like wicd insisted on waking up writing a log-entry every few seconds.

    Anyway, very nice post Kacper :D

  2. Kacper says:

    Thanks Kristian laptop_mode is indeed useful and coprehensive :-) Putting stuff on ramfs / tmpfs is an interesting approach and would be the recommended way to do it, except the difficulties it causes with debugging. Would be cool to make a system log critical info only to disk, and noncrit info to ram :-)

    Hey wait… you could do that with syslog

  3. motorola akku says:

    I’ve found the same about mac PC. There is a certain procedure to follow to get maximum from the battery using mac os. I’ll post it soon here after some testing.

  4. kacper says:

    you have a battery saving script for the mac? I’d love to look at it

  5. Jones says:

    Awesome. You can Google in black on your phone at http://bGoog.com to extend you battery life and to use less bandwidth! The black background definitely saves power on my phone and it looks sweet too.

Leave a Reply