dcsimg

PowerTOP: Saving Power in Linux

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

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.

PowerTOP Requirements

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:

  1. Unpack the package by typing tar xvfz powertop-1.9.tar.gz. (You may need to adjust the version number.)
  2. Change into the resulting powertop-1.9 directory and type make to compile the package.
  3. 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:

CONFIG_NO_HZ
CONFIG_HPET_TIMER
CONFIG_CPU_FREQ_GOV_ONDEMAND
CONFIG_USB_SUSPEND
CONFIG_SND_AC97_POWER_SAVE
CONFIG_TIMER_STATS

In addition, you should ensure that a couple of kernel features are not activated:

CONFIG_IRQBALANCE
CONFIG_ACPI_DEBUG

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:

powertop

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:

C<
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:

Cn          Avg residency (5s)  Long term residency avg
C0 (cpu running)        ( 3.8%)
C1                0.0ms ( 0.0%)                   0.0ms
C2                4.4ms (57.3%)                   4.4ms
C3               10.0ms (31.1%)                  10.0ms
C4                2.3ms ( 7.7%)                   2.3ms

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:

  94.6% (4480.0)      <interrupt> : eth0
   2.3% (111.1)     <kernel core> : <ffffffff8024954a> (<ffffffff80249280>)
   0.6% ( 28.4)       <interrupt> : uhci_hcd:usb1, uhci_hcd:usb2, ehci_hcd:usb3
   0.5% ( 24.7)     <kernel core> : <ffffffff80249869> (<ffffffff80249280>)
   0.4% ( 20.0)       firefox-bin : <ffffffff8024a696> (<ffffffff80243aa0>)
   0.2% ( 10.8)              Xorg : <ffffffff80232137> (<ffffffff80232280>)

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!

Comments on "PowerTOP: Saving Power in Linux"

poyayan

Nice tips, Thanks!

dxdkfc

A lot of issues are solved by patching applications. That is IMHO a hard way to do it as the patch either will go away next time I update my system or my system will never be updated and thus volonurable for hacker attacks.

justinlawrence

great article, thanks

pachequin

Great article, I would like to know if there exist any similar application for AMD turion. Thank you

bsdlinux

nically, the gnome-power-manager program…

But then killing it may cause you to use more power. Sounds like a catch 22.

Hi there, I discovered your website via Google whilst looking for a comparable matter, your site came up, it appears to be like great. I’ve added to my favourites|added to bookmarks.

Marvelous, what a web site it is! This web site presents useful facts to us, keep it up.

It’s a pity you don’t have a donate button! I’d definitely donate to this fantastic blog! I suppose for now i’ll settle for book-marking and adding your RSS feed to my Google account. I look forward to fresh updates and will talk about this website with my Facebook group. Chat soon!

I together with my buddies have been digesting the best tips and tricks from the website and then all of a sudden I got a terrible suspicion I had not thanked the site owner for those techniques. These women ended up for this reason happy to read them and now have sincerely been enjoying them. We appreciate you really being so helpful and also for picking this sort of notable information most people are really eager to discover. My personal honest apologies for not saying thanks to you sooner.

There as certainly a great deal to know about this subject. I like all the points you ave made.

VHohT8 I truly appreciate this article post.Much thanks again. Want more.

Please visit the websites we follow, which includes this one, as it represents our picks from the web.

Thanks a lot for sharing this with all of us you really know what you’re talking about! Bookmarked. Kindly also visit my web site =). We could have a link exchange contract between us!

That is the end of this post. Right here you will discover some sites that we think you?ll enjoy, just click the links.

“Hello my family member! I wish to say that this article is awesome, nice written and come with almost all vital infos. I’d like to see more posts like this .”

“I am regular visitor, how are you everybody? This post posted aat this website is genujnely good.”

We came across a cool web page which you may take pleasure in. Take a look when you want.

Here are some links to internet sites that we link to simply because we consider they’re worth visiting.

Here are some hyperlinks to web pages that we link to since we assume they’re worth visiting.

Below you will obtain the link to some web pages that we believe you need to visit.

Wonderful story, reckoned we could combine several unrelated information, nevertheless actually really worth taking a look, whoa did one particular discover about Mid East has got additional problerms at the same time.

Great site. A great deal of useful info here.
I’m sending it to several pals ans additionally sharing in delicious.
And needless to say, thanks a lot with your sweat!

My web site :: MicaLTydings

Today, I went to the beach front with my children. I found a
sea shell and gave it to my 4 year old daughter and
said “You can hear the ocean if you put this to your ear.” She placed the shell to her ear and screamed.
There was a hermit crab inside and it pinched her ear.

She never wants to go back! LoL I know this is totally off topic
but I had to tell someone!

Stop by my blog :: ClydeSGodina

naturally like your web-site but you should test the spelling on quite a few of the posts.

Many turn out to be rife with spelling issues and i also to
discover it very bothersome to inform the truth on the
other hand I am going to surely come again again.

my web-site … EllisPSauers

Very couple of internet websites that take place to be comprehensive below, from our point of view are undoubtedly properly really worth checking out.

We like to honor a lot of other online web-sites around the web, even if they aren?t linked to us, by linking to them. Below are some webpages worth checking out.

It’s will be end of mine day, except before
ending I am looking over this great piece of writing to increase my experience.

My blog – WillisLAjose

Should you want to improve your experience just keep visiting
this site and become updated together with the newest news update posted here.

Here is my homepage CesarLEnders

Usually posts some quite intriguing stuff like this. If you are new to this site.

XXPbDu msnbcbyovxhx, [url=http://mkxdmauqgagw.com/]mkxdmauqgagw[/url], [link=http://ewovfaikbdjh.com/]ewovfaikbdjh[/link], http://pnpeguhbwnso.com/

We prefer to honor lots of other net web sites around the net, even when they aren?t linked to us, by linking to them. Underneath are some webpages worth checking out.

Leave a Reply