Optimise Your Laptop’s Battery Life With Linux
All laptop users have something in common: we want our device’s batteries to last longer. Whether it’s for the daily commute or the flight home for Christmas, an extra 30 minutes of power means an extra 30 minutes of entertainment. If you’re running a Linux-based distribution on your netbook, there’s a lot you can do to squeeze every last negatively charged ion from your power source. Here we’re going to cover the best techniques that we’ve discovered. Don’t worry if you’re not a netbook user, as much of this information can be used on Linux laptops too. However, we’ve specifically tailored our advice for netbooks as these seldom include full-blown distros (and hence any easy way of compiling and installing new software). We’re going to focus on Intel’s Moblin and Canonical’s UNR (Ubuntu Netbook Remix), two of the most popular Linux distributions for netbooks, but there’s absolutely no reason why you can’t use a full-fat distribution on your device and make the same changes to its power management.

You deserve to be able to drag every last tiny drop of power out of your laptop’s battery. It’s only fair.
Netbook Linux is still in its infancy. This means that there’s still a great deal that can be done to make these devices more power efficient, and each release of distributions like Moblin or UNR gets better at it. But it also means that hardware compatibility and power saving is experimental for each distribution, especially when you’ve installed it yourself. Until netbook distributions are built for specific netbooks, though, there’s always something you can change in a generic installation to make it work better on your own machine. We’re not talking about massive improvements, but each incremental change may stretch your battery life by around five per cent. Even if just one or two of them work out, you’ll see some extra life from your machine. Like most things to do with Linux, it just takes a little trial and error.
The easy targets
Sometimes it’s the most predictable power saving options that can reap the biggest benefits. Wireless and Bluetooth are our first targets. Even when you’re not using these connections, the radio device tucked away within your machine is still expending energy, either keeping a connection in contention or looking for new networks and devices for you to connect to. Both Moblin and UNR allow you to disable these devices from the desktop, but these options won’t necessarily completely disable the radio. The best option is to use a hotkey combination that’s dedicated to your devices. These are usually labelled in blue across the laptop’s keyboard, and typically involve you having to press the [Fn] key in conjunction with a number. The number key will normally feature a somewhat ambiguous icon that you’ll need to decode in order to figure out which number is the correct one. If you’re lucky, you’ll also see an on-screen message updating you on any progress once you’ve pressed the key.
However, some netbooks don’t have function keys to disable the wireless or Bluetooth radios, and you can’t take any chances with the software disable function. Samsung’s popular NC10 is one example of a machine that doesn’t have a keypress option. In these cases, your only course of action is to change a setting in your netbook’s BIOS – a setting that will stay fixed until you restart your machine and manually undo the change.

It might sound obvious, but switching off your laptop’s internal radios can give a significant boost to battery life.
Like many desktop machines, you can normally enter your netbook’s BIOS by quickly pressing [F2], although like the hotkeys, this is dependent on your manufacturer (as is what you can and can’t turn off within the BIOS). With the NC10, for instance, you can switch your wireless devices to ‘Always Off’ from the Boot menu within the BIOS. While you’re there, you might also want to disable the ‘Internal LAN’ setting in the Advanced menu, as the Ethernet port can steal power even while not being used. You should also make sure that any power saving modes for your device are enabled.
Screen brightness
Dimming the screen is a great way of saving some power, but this can sometimes be problematic with certain netbooks running a Linux distribution. This is because the hotkey combination may not work from the desktop, and the software isn’t always capable of changing brightness either. The Linux kernel needs to have support for your specific device. If it does, the distribution you use also needs to use the correct version of the kernel and provide a means of changing the brightness. If this isn’t the case, you might still be able to adjust the brightness of your screen from the command line.
The trick is to use a special kind of file that accesses your display hardware. As with most devices, this can be found by typing ls /sys/class/backlight/. If you’ve not encountered the ‘/sys’ series of directories before, it contains dozens of folders and files that refer to each of the devices on your system. Rather than representing the files and folders on a storage device, this structure is a portal for configuring any plug-and-play hardware discovered on your system, and that includes devices like your netbook’s screen, CPU and drive.
To change values in the /sys tree, you will need to switch to the administrator’s account on your machine. Ubuntu users won’t be able to use sudo in the way they might be used to because the command to change values is really two commands, one piping output to another. The sudo privileges will only apply to the first and won’t stretch to allow you to change the parameter in the second. You can get around this by launching a new bash session using sudo, which will start a pseudo-administrator mode where every subsequent command is executed with root privileges. Moblin users just need to type su followed by their root password to get the same thing.
The contents of ‘/sys/class/backlight/’ should look something like ‘acpi_video0’, but this is dependent on the kernel driver for your hardware. Beneath this directory, you’ll find a special type of file called ‘brightness’. If you probe the value of this file by typing cat acpi_video0/brightness, for instance, you’ll see the current brightness setting for your screen. This is usually within the range of 0 to 100, and may jump up in steps that are defined by your hardware’s capabilities. The converse of this probe operation is to pass a value to this special file, hopefully changing your screen brightness in the process. Typing echo 100 > acpi_video0/brightness, for example, will configure maximum brightness, while a value in the region of 15 should be close to your screen’s minimum.
CPU optimisation
We’re going to stick within the /sys subsystem to make a few changes to how the CPU is handled. This can be a rather experimental area to play around with, which may explain why many distributions choose not to enable some of the more optimal modes, but it can be worth the trial and error. It’s also dependent on the features embedded within your CPU. Recent models built around Intel’s newer Atom processors shouldn’t have any problems, but older models may not be so flexible. You should also make sure you’ve got a backup of any critical data on your netbook’s drive before trying things out.
The most important parameter can be discovered by typing cat /proc/sys/vm/laptop_mode. If your machine returns a value of 0, then Laptop mode is currently disabled. You can enable it by typing echo 1 > /proc/sys/vm/laptop_mode. When Laptop mode is enabled, the kernel takes special care only to shuttle data to your storage device when it needs to, saving your battery in the process. You can disable this by swapping the 1 for a 0 in the previous command.
You can get even deeper into how the processor handles tasks by changing how the scheduler works. This is only going to be beneficial if you’ve got a multicore machine, and it changes the way processes are loaded onto each core. Check the contents of the ‘/sys/devices/system/cpu/sched_mc_power_savings’ location. If this is set to 0, your netbook is configured for optimal CPU performance – which is useful for mathematically intensive apps, but not so great if you’re only planning to read a couple of emails. Changing this value to 1 will ask the scheduler to use the threads and processes more efficiently before more are created, effectively saving your other CPU cores from being used and saving energy in the process.
Process pruning
The best thing about a netbook distro is that it is already pruned down to the bare minimum of applications and running processes. There should be very little you can do to improve things here, but there’s never any harm in taking a look. The quickest and easiest way of checking what processes are running is to run the ‘top’ command from the command line. It may look a little perfunctory, but it tells you everything you need to know. It’s called top because it shows you a list of the processes sorted by CPU time, with the highest at the top. This list changes dynamically, and the processes at the top usually include top itself, the Xorg X-Server (which is rendering the graphics on the screen) and maybe the gnome terminal (if this is how you’re running top). You can also remove processes and change their priority, but you need to be careful about this as you could seriously affect the performance of your netbook (and even lose some of your data). The safest option is to look for tasks that are running under your user account: you should be able to see your name in the second column for any tasks falling into that category.
On Moblin 2.0, for instance, we’ve noticed that the Nautilus file manager is used to manage external storage such as USB sticks. Occasionally, especially when you remove a USB stick without first unmounting it, Nautilus is left running, taking up precious CPU cycles. You’ll even be able to see that it’s the process connected to the USB device because this path follows the name of the process. You can remove tasks by pressing [K] to enter Kill mode and then entering the process number. This is listed in the top output below the top line. If you’re running a standard Linux installation, then there are a great number of processes you might want to consider removing. These could include indexing routines, compositing managers, background servers and log file generation. Further information can be found by looking at how the ‘initd’ process works and working out how to disable these services at bootup.
Monitor process power consumption
One of the best tools for monitoring and tweaking your system’s power efficiency is called PowerTop. It’s the electrical power consumption equivalent to the ‘top’ command we used to measure CPU usage, and it should be available through your distribution’s package manager. Moblin users can find it by searching for ‘Power consumption monitor’ in the Add/Remove Software panel. It needs to be run from the command line with system administrator privileges, which means typing sudo powertop for Ubuntu users or su followed by powertop for Moblin.

PowerTop can give you a very accurate indication of how long your netbook will last with its current power usage.
It will take five seconds for the tool to initially monitor your current system, after which it will list the various offending tasks running on your system sorted according to the amount of power they consume. The top section of the tool displays the percentage of time your CPU spends running at a specific speed. More CPU-intensive tasks will switch to a faster power state, which will in turn take more electricity. Ideally, you should expect to spend most of your time in the C4 state (the slowest), with occasional bursts of activity in the fastest state, C1.
PowerTop was originally designed to show which tasks were preventing laptops from entering a sleep state, and it’s still useful for this kind of bug fixing (though hopefully your distro builder has already solved the most serious offenders). This is why you still see the processes listed as ‘Top causes for wakeup’, as these are the events that are interrupting the system.
Unlike nearly every other tool we can think of, PowerTop also displays some useful information that can help you stretch out your netbook’s battery life. If it detects anything that it knows will help, a suggestion will pop up at the bottom of the window. Your adjustment will last for the duration of the current session only, but the tips that PowerTop displays often include instructions on how to make each change more permanent.
Proper sleep function
Suspending your machine by closing the lid and then opening it again seldom has the desired effect with Linux. It’s often easier to just turn the machine off and on again. Things are a lot better than they were, but hibernation is one area of the kernel that remains problematic. The difficulty is that each piece of hardware within your system needs to respond predictably to the sleep call, and this requires well-behaved drivers that have a good understanding of their hardware capabilities.
Unfortunately, this can’t be said for many Linux device drivers – in particular those for graphics cards. The only exception is hardware developed by Intel. Intel has made a big investment in Linux, and it continues to make massive improvements to the drivers for its own hardware. The Moblin distribution is the pinnacle of this work, and you should find that sleep works well with most Atom-based machines, as well as those that use other kinds of Intel processors. If you need to cater for hardware from other manufacturers, the best piece of advice we can give you is to make sure that your kernel is as up to date as possible. Things are changing all the time in the Linux world, and you may find that any problems have already been fixed with a kernel update.



