Laptop computers are great devices — small and portable, yet almost as powerful as a typical desktop system, laptops enable you to work where you want to work. You can take a laptop to the coffee shop to browse the Web while sipping a latte or bring it to the park to edit files in the company of ducks. Once you get to the park, though, you may discover that you aren’t able to do much work, because laptops have a problem: Short battery life. This problem is exacerbated by Linux, which was designed with server and desktop uses in mind. Linux treats its hardware, and runs its software, in ways that aren’t very power-conscious.
Fortunately, this problem is being addressed in various ways. This month I provide a few pointers on reducing your laptop’s power consumption, with particular emphasis on the PowerTOP utility, which will help you track down programs and subsystems that are wasting your power. The PowerTOP Web site includes a “Success Stories” section with claims of 75% increases in battery life. Even if you can’t boost your battery life by that much, an increase of an hour or so would probably be welcome.
Power Consumption Principles
Some power consumption principles are fairly obvious, and Linux has long provided tools to deal with these matters. For instance, you can configure your system to spin down an ATA hard disk when it’s not in use by using the hdparam utility, or set up a screen saver to put the screen into a low-power mode whenever possible. GUI tools to help configure these features are fairly common and well-understood, so I don’t describe them in this column.
More recently, CPUs (particularly those intended for use in laptops) have been designed with power conservation in mind. These CPUs include low-power idle modes and “tickless” operation. The PowerTOP program monitors how programs use (or fail to use) these features, so you can optimize your system to consume less power. For instance, you might find that a program is needlessly accessing your network, with each access attempt draining your battery a bit.
Shutting down or reconfiguring that program will therefore help extend your battery life. In some cases, patching a program can cure it of its power-hungry ways. You might also discover that your kernel is configured sub-optimally for power conservation; recompiling it (or perhaps just adding options to your boot loader) will help extend your battery life.
Note that PowerTOP will be most effective on a modern laptop computer. Desktop computers’ CPUs lack some of the features required for optimal power savings, so although you can run PowerTOP on a desktop system, you probably won’t dramatically reduce a desktop’s or server’s power requirements by running PowerTOP. Likewise, older laptops contain CPUs that lack modern features, so you may not be able to achieve as much savings with them as you would with a modern laptop.
You may be able to obtain PowerTOP as a precompiled package for your distribution, so try using apt-get, yum, emerge, or whatever other tool your distribution provides to install the software. If you can’t find a ready-made package, you can download PowerTOP from its website. The download is available as source code only, so you’ll need to compile and install it:
Unpack the package by typing tar xvfz powertop-1.9.tar.gz. (You may need to adjust the version number.)
Change into the resulting powertop-1.9 directory and type make to compile the package.
As root, type make install to install PowerTop.
If the package won’t compile in step #2, you may need to track down and install appropriate development libraries, such as ncurses. The first error message is likely to contain a clue to what you need to find. Be sure to install the development package, not just the binary package, for the missing library.
In addition to the PowerTOP program itself, you’ll need certain kernel options enabled to make optimum use of the utility. Some of these features (particularly the tickless operation feature, CONFIG_NO_HZ) are available only in 2.6.21 and later kernels (2.6.23 and later for x86_64 CPUs), so you should first be sure you’re running such a recent kernel. Features you should enable are:
In addition, you should ensure that a couple of kernel features are not activated:
These options increase power use unnecessarily. If these features are set inappropriately, PowerTOP will complain, so you may want to delay digging through your kernel configuration until after a first run of PowerTOP.
Before you begin monitoring your system’s power use, you should also upgrade your system to the latest software available. Power-saving fixes are currently being written for many popular programs, so installing the latest versions may fix some problems. You should log out, and perhaps even reboot your computer, to be sure you’re using all the new software.
Monitoring Your System
To obtain the best data, PowerTOP should be run while your laptop is running on battery power, rather than plugged into a wall outlet. It must also be run as root to acquire accurate data, so open a root shell or use sudo to run it:
The program pauses for five seconds while it collects data, then presents a text-mode display summarizing its results. It updates its display every five seconds. Examine its output page for messages relating to incorrect kernel options; for instance:
No detailed statistics available; please enable the CONFIG_TIMER_STATS kernel op
This option is located in the Kernel Debugging section of menuconfig
(which is CONFIG_DEBUG_KERNEL=y in the config file)
Note: this is only available in 2.6.21 and later kernels
This message points you to a missing kernel option. If you see such a message, you may need to recompile your kernel. When you’ve done so, try again. With any luck, you’ll see a more helpful display. Most of the display will be occupied by two types of information: C-states and wakeup causes. You’ll also see a total power use estimate and suggestions to improve power consumption.
C-states are CPU idle states. C0 refers to the CPU running code, while C1 and up refer to power-saving modes, with higher numbers equating to greater power savings but a longer delay to return to C0 state. A typical C-state display in PowerTOP looks something like this:
Ideally, you want your system to be running at the highest C-level possible for the greatest percentage of time possible — preferably 95% or more in the highest C-state with residency times of 50ms or greater. A line just below the C-states display tells you how many times the CPU is being woken up per second. This value should be as low as possible, and can be under 10 (the PowerTOP Web site claims a value of 3 is possible even with a GNOME desktop running).
Be aware that user activity, such as typing in an application, will increase activity, both in terms of wakeups per second and in reduced C-state values. Thus, you should wait a few seconds for your system to settle so you can measure the “resting” state.
The C-state and wakeups-per-second figures give you an idea of whether your system is achieving good CPU power savings, but if the values are poor, you’ll need to look elsewhere for ideas on how to fix the problems. The second half of the PowerTOP output does this; it’s dominated by a summary of the top causes of wakeups. This display summarizes what programs and drivers are causing the CPU to execute code. The display looks something like this:
This example shows the result of a network transfer — 94.6% of wakeups are being caused by the Ethernet device, eth0. This isn’t really a fair or useful test, unless of course the network transfer was something you weren’t aware was happening. Once your system is in a resting state, you can examine the list of wakeup causes to locate possible problem sources.
In the example, kernel core is the second-highest source of wakeups. This could be because of a kernel with sub-optimal configuration — for instance, using a fixed clock rate rather than the tickless operation mentioned earlier. Additional sources of wakeups in the preceding example are the USB device, Firefox, and X. Setting USB options can minimize wakeups from USB devices, although some may be unavoidable. Similar comments apply to other hardware-related wakeups.
Software wakeups, such as those for Firefox and Xorg, can be handled in various ways. One obvious approach is to shut down the offending program; however, if you need to have the program running, that may not be a practical option. You can examine and tweak program options to reduce the program’s CPU demands. For instance, you might change a blinking cursor to a solid cursor in a terminal window, or disable support for animation in a Web browser. Any option that creates changes to the display requires CPU time, and can thus increase power consumption.
X can pose special challenges, since program actions can sometimes cause X to consume CPU time, and therefore show up in PowerTOP’s listing as a cause of wakeups. To fix these problems, though, requires reconfiguration of the programs that are the ultimate cause of the activity. Starting and stopping suspect programs may help you track down wakeups that PowerTOP attributes to X.
The last few lines of PowerTOP’s display are devoted to power-saving tips. Keep your eye on this display, since it changes every few seconds. The tips are generally easy to understand and specify a simple command you can type to achieve power savings, or sometimes a change to a configuration file, such as adding a boot option to your GRUB or LILO configuration. You can test the command by typing it at a command prompt, although some configuration changes may require restarting a process or even rebooting the computer. If you want the changes to remain in effect in the long term, you’ll need to add commands to a local startup script, such as /etc/rc.local.
After you make changes, check the C-state and wakeups-per-second displays to see if the changes have a noticeable effect. Be aware that once you begin actually using the computer — typing in windows, recalculating spreadsheets, and so on — this normal use will drain the battery more than idle time will.
Additional Power-Saving Tips
Some power-hungry programs require patching and recompiling to fix. The PowerTOP Web site includes tips on many specific programs, including pointers to patches. If you’re lucky, your distribution will have incorporated the patches, so you should look for updated software before you try patching programs. If necessary, though, you can download a program’s original source code and recompile it with the patches from the PowerTOP Web site to obtain the fix.
Some common sources of problems include:
GNOME Power Manager Ironically, the gnome-power-manager program seems to cause X wakeups fairly often. Killing it may therefore reduce power consumption.
Pidgin/GAIM Older versions of the Pidgen (a.k.a. GAIM) Internet messaging software causes wakeups that PowerTOP may attribute to X. Version 2.0.1 includes power-saving fixes, so upgrading may improve matters.
Intel i915 video Older versions of the Intel i915 video driver caused unnecessary wakeups in 2D mode. Updating the driver should fix this problem, but 3D mode can cause wakeups that can’t be eliminated (yet). Consider disabling 3D features by adding the Option "NoDRI" line to the Device section of your /etc/X11/xorg.conf file and restarting X.
Web browsers Animated graphics and blinking text can cause any Web browser to chew CPU time, and therefore power, needlessly. Disable animated graphics support or browse away from pages that include these features. The PowerTOP Web page includes a pointer to a Firefox patch to improve its power consumption even when a blank page is being displayed.
Evolution This popular mail client includes a 10Hz timer to manage its event queue, which causes a power drain. The PowerTOP Web page includes a link to a patch to fix this problem.
NTPv The Network Time Protocol (NTP) server is designed to periodically check the time as maintained on a network server, which of course causes some power consumption. A pointer to a patch to minimize this drain is present on the PowerTOP Web site. You might want to consider foregoing use of NTP while your computer is running on battery power, though.
knotify KDE’s knotify applet causes a lot of wakeups. A patch is available via the PowerTOP Web site.
GVIM The GVIM text editor uses a blinking cursor by default. You can switch to a solid cursor by including the line let &guicursor = &guicursor . ",a:blinkon0" in your .gvimrc configuration file.
gksu The GTK+ front-end to su and sudo includes a high-frequency polling loop that’s a real power-hog. As I write, no fix is known.
Media players The Timidity and mpd media players both cause 100 wakeups per second when idle. As I write, no fix is known.
xterm The plain xterm terminal window causes one wakeup per second when idle. Adding the +sm command-line option or setting the sessionMgt resource to false fixes this problem.
The PowerTOP Web site includes information on several hardware-specific issues, such as issues in the forcedeth driver, the tpb ThinkPad laptop utility, and the Apple Macbook TouchPad driver. If PowerTOP shows problems with such hardware, consult the PowerTOP Web site or perform a Web search to try to find a fix. Upgrading to a more recent kernel or driver might also fix the problem; particularly for laptop-specific hardware, developers are becoming more power-conscious, and so are including fixes to power-consumption problems.
In summary, if you’re a laptop user, a survey of your system with PowerTOP will help you track down programs and system settings that are needlessly draining your battery’s power. Spending a while identifying the sources of these problems will help you extend your battery’s life, increasing your independence from the power grid!
Fatal error: Call to undefined function aa_author_bios() in /opt/apache/dms/b2b/linux-mag.com/site/www/htdocs/wp-content/themes/linuxmag/single.php on line 62