LWN.net Logo

PowerTOP tops up to 2.1

By Nathan Willis
August 30, 2012

You may run free software, but electricity still isn't free. Until it is, monitoring and minimizing power consumption is a necessary evil. Intel released version 2.1 of its power-consumption utility PowerTOP on August 15. PowerTOP has been around since 2007, but the 2.0 release from May 2012 heralded a major rewrite of the code and a shift for the project itself. 2.1 builds on the new design, adding a handful of new features, but if it has been a while since you examined PowerTOP, you may be surprised at how much it has grown.

The new and improved

As the name suggests, PowerTOP monitors system power consumption and reports its statistics to you in a top-like summary. It also makes suggestions for system tweaks that could improve the power usage profile of your system, including everything from peripheral device options down to processor performance states and scheduler settings. In PowerTOP's early days, most of these recommendations were tweaks that the user or system administrator would need to manually apply. Over time, however, the various Linux distributions began to use PowerTOP as a profiling tool to automatically track down optimal settings, which would become the out-of-the-box defaults. This shift in usage patterns was one of the reasons maintainer Arjan van de Ven cited for the rewrite that became 2.0.

Two other factors Van de Ven cited were the unstructured way in which more and more features had been bolted on to the code base, and that PowerTOP is increasingly used as a diagnostic tool to track down specific power consumption problems — such as an errant application or driver — rather than profiling an entire system. As a result, the 2.0 rewrite refactors the code with an eye toward making subsequent extensions easier to add, and it provides a report-generation facility that can output CSV or HTML diagnostic reports suitable for later study.

The 2.x series also utilizes the kernel's perf events subsystem to gather processor-related data, which leads to more accurate numbers. The project has been steadily adding support for additional power-management features in hardware; the supported list includes CPUs, GPUs, storage devices, and an extensive collection of peripherals (network controllers, audio chips, USB adapters, and so on). The 2.1 release itself adds support for monitoring processor cores without performance states (a.k.a. P-states, which correspond to different clock frequencies). This is primarily useful for GPUs, which do have power states (or C-states, which allow the system to put the processor to sleep in stages), allowing inactive cores to be powered-down, but do not have the frequency scaling features now common in CPUs.

In addition to the technical changes, the 2.x series saw the project move away from its original home at lesswatts.org and into Intel's new open source project warehouse at 01.org. The new site hosts news updates, downloads, and a new mailing list. Unfortunately this change meant cutting off the site from several years' worth of mailing list archives and existing online documentation at the old site — although for the time being lesswatts.org remains online. In other changes, the source code is now hosted at GitHub, and the project is using Transifex for UI string translation. The 2.1 announcement advertises nine languages at present, which is not many in the grand scheme of things, but signals an improvement. Compiling PowerTOP is a simple affair; it uses autotools and has few dependencies. The main issue to consider is the kernel version of the machine you wish to profile: 2.6.36 is required for perf support, and newer kernels add additional measurement tools.

Usage

[PowerTOP live monitor]

PowerTOP has two major operating modes: interactive monitoring and report generation. Running powertop (as root) launches the interactive mode, which provides a five-tab ncurses monitor. The overview tab sports a summary line displaying the current number of wakeups-per-second, GPU operations-per-second, virtual filesystem (VFS) operations-per-second, and CPU activity. Beneath this line is a list of power-consumption events of various types (for example, network activity, active processes, and interrupts). CPU information is split into two tabs: Idle Stats and Frequency Stats. The former shows C-state information as an activity percentage for the processor package and for each core; the latter reports the same information labeled with the actual clock frequencies rather than the C-state level.

The fourth tab, Device Stats, contains power usage information from the other hardware devices on the system: the battery (where applicable), screen, GPU(s), networking hardware, and everything else. For laptops, PowerTOP reports the battery's discharge rate, and estimates the discharge rate of the other components. For an accurate report, however, you should first run the calibration routine with powertop --calibrate. This will cycle through the hardware options (e.g., the supported backlight levels) and log the power consumption characteristics. PowerTOP supports even more accurate measurement with a USB-attached power analyzer tool from Extech, although considering the four-digit suggested retail price of said instruments, you would need to tweak quite a few machines to recoup the investment in electricity bills.

The fifth tab, Tunables, lists system settings that can affect power consumption performance. Highlighting an individual entry allows you to toggle the setting on or off with the Return key, so that you can quickly assess its impact. Most of the controls are sysfs parameters (such as SATA link power management or USB device auto-suspend), but others involve separate interfaces (such as wake-on-LAN status for Ethernet adapters). The tab sorts the list into "Good" and "Bad" states, with the Bad listed first, so you can quickly work your way through the list and see if you notice a difference.

[PowerTOP HTML report]

PowerTOP's other mode is report generation, which you can invoke by running either sudo powertop --html or sudo powertop --csv. The CSV output is essentially the same information as that presented in the first four tabs of the interactive mode, with header information demarked by asterisks. The "Tunables" information is listed as well, but the commands required to alter each setting are not supplied. The HTML output presents the same information in a nicely CSS-styled HTML file, complete with element classes on each table cell that might allow further customization or processing.

A bit more interesting, however, is the HTML output's Tuning tab, which includes the command necessary to change each "Bad" setting — for example:

    echo 'min_power' > '/sys/class/scsi_host/host0/link_power_management_policy'

This is particularly helpful for bus devices whose specific address would be hard to guess at otherwise, such as /sys/bus/pci/devices/0000:00:1f.2/power/control or /sys/bus/usb/devices/3-2/power/control. One of the lingering gripes many end users have about the program is that the changes they make to device settings do not persist after reboot. PowerTOP's stance is that it does not want to be in the business of writing permanent or semi-permanent changes to the system configuration — for a number of reasons, including the fact that such changes can introduce performance or even stability problems. But having the correct commands at the ready allows the user to assemble a start-up script with little hassle, whether the machine in question is an old netbook with battery trouble or an expensive server.

In addition to the broader changes discussed above, each release of PowerTOP tracks new features available in updated processor and device architectures. The latest releases, for example, have improved support for ARM power management features and for Intel graphics adapters. But even if your processor is already well-supported, the project has made impressive improvements in data collection and in presenting its findings is human-consumable terms. I last looked at PowerTOP in late 2008, so by comparison the advancement of the feature set seems dramatic. But the more important factor is that it has proven itself to be a useful diagnostic tool, and it allows even novice users to instantly apply and test power management options — which could at least de-mystify the world of power-saving, one system at a time.


(Log in to post comments)

PowerTOP tops up to 2.1

Posted Aug 30, 2012 10:49 UTC (Thu) by mina86 (subscriber, #68442) [Link]

Sure electricity is free. I can use it for any purpose, study it, modify it and share it with my friends. ;)

PowerTOP tops up to 2.1

Posted Aug 30, 2012 13:23 UTC (Thu) by rahulsundaram (subscriber, #21946) [Link]

Yes but the results may shock you

PowerTOP tops up to 2.1

Posted Aug 30, 2012 15:55 UTC (Thu) by hp (subscriber, #5220) [Link]

I have a lot of "Bad" on my Tunable tab, but they just make me wonder why it's like that by default.

If I change from "Bad" to "Good" does that mean the default system configuration was broken and I should file a Fedora bug report, or does it mean that there's some downside (like it's going to slow down or break)?

If all this stuff is Bad by default it really has to be a distribution bug on some level, right?

PowerTOP tops up to 2.1

Posted Aug 30, 2012 17:28 UTC (Thu) by mjg59 (subscriber, #23239) [Link]

Some of the bad things are stuff the distribution should be setting. Some of them are things that break other things if you change them.

PowerTOP tops up to 2.1

Posted Aug 30, 2012 17:38 UTC (Thu) by hp (subscriber, #5220) [Link]

sort of what I expected :-/ so in practice I just leave them all set to Bad, there's no way to know.

PowerTOP tops up to 2.1

Posted Aug 30, 2012 22:04 UTC (Thu) by dlang (✭ supporter ✭, #313) [Link]

some of them are probably "bad" from a power usage point of view, but "good" from a responsiveness or performance point of view.

which is "correct" for you?

which is "correct" for me?

since the changes don't persist across reboots, you can try them and if you don't notice any downside, set something up to change them for you permanently.

PowerTOP tops up to 2.1

Posted Aug 30, 2012 22:29 UTC (Thu) by hp (subscriber, #5220) [Link]

I'm worried some are bad from a crash/break point of view ... if they are all just perf tradeoffs then a big "fast or battery" button (slider perhaps) could cover it. And save the settings separately according to whether I'm on AC.

Powertop mostly just makes me feel that my OS could have had good battery life but doesn't.

A doc blurb about the tradeoff for each toggle might go a long way though. Or if all of them have a "slowdown" worst case, one global blurb explaining that they're all safe but may cause performance decrease.

PowerTOP tops up to 2.1

Posted Aug 30, 2012 23:00 UTC (Thu) by dlang (✭ supporter ✭, #313) [Link]

the problem is that in theory these are all safe, but in practice there is buggy hardware and so they are not safe.

So you need to take a risk at some point, and if the system crashes, don't use that option any longer.

These are the sorts of possible problems (along with the performance issues) that make it so that Fedora doesn't default all these things to the most power saving mode.

Some people seem to forget that the best way to have a computer save power is to never buy it in the first place. Computers are purchased to get things done, and that requires using power. How much power should be used depends on how valuable the result is to the person paying for it.

PowerTOP tops up to 2.1

Posted Aug 30, 2012 23:07 UTC (Thu) by hp (subscriber, #5220) [Link]

yeah, that's what I expected :-) thanks for reply.

no way I'm getting near that, basically. would rather just have bad battery life.

PowerTOP tops up to 2.1

Posted Aug 30, 2012 23:21 UTC (Thu) by dlang (✭ supporter ✭, #313) [Link]

remember, this doesn't last past a reboot, so at most it will result in ONE crash, and it's not very likely to do even that.

PowerTOP tops up to 2.1

Posted Sep 11, 2012 12:15 UTC (Tue) by Jannes (subscriber, #80396) [Link]

I don't think I ever had a crash, but I have had situations where audio stopped working or it wouldn't come out of suspend cleanly anymore. I'm guessing such subtleties are more common than straight out crashes.

PowerTOP tops up to 2.1

Posted Aug 31, 2012 12:34 UTC (Fri) by wookey (subscriber, #5501) [Link]

New powertop is nice, but it seems to have lost my favourite feature which was the reading of current power consumption in Watts. Is there a good reason why that is no longer printed?

Currently I can twiddle params between 'good' and 'bad', and I can see how that changes the fraction of time in various states, but not the _actual power consumption_ which is what I am trying to optimise.

I can sort of guess by wiating a while and looking at the 'time left' pop-up in xfce4-power-manager, but that's still not actual current average consumption, although I naively hope it's linearly related to it.

And more help on the what the various params actually _do_ would be really nice. For the non kernel-power-management guru most of it is highly cryptic. Some idea of each tradeoff and associated risks would be very nice.

In practice I've found that turning everything to 'good' still leaves my machine working, and this article has allowed me to discover there there is an easy way to put all that lot in my 'onbatt' script, which is great. Some of them should perhaps be on for mains use too though - and I have no idea how to work out which.

But what does BAD->GOOD do?

Posted Aug 31, 2012 15:06 UTC (Fri) by spaetz (subscriber, #32870) [Link]

My biggest gripe (I am sure I have overseen it), is that while I can make myself happy by transitioning everything from BAD to GOOD until the next reboot, I have no way to find out what this actually does.

E.g. how would you learn that "Turn off NMI watchdog" translates into

"echo 0 > /proc/sys/kernel/nmi_watchdog" (this took me quite some googling and one one of the easier things to find out).

I would appreciate if powertop could tell me what tweak it actually applies when hitting <ENTER>. Teach me to fish, don't just hand me one :-).

But what does BAD->GOOD do?

Posted Aug 31, 2012 17:14 UTC (Fri) by hummassa (subscriber, #307) [Link]

Version 2.1 does just that.
But I didn't like the system after I transitioned (ok, I did everything together and shouldn't have done that...), it became strange and unresponsive.

But what does BAD->GOOD do?

Posted Sep 1, 2012 2:15 UTC (Sat) by spaetz (subscriber, #32870) [Link]

Thanks that is good to hear. But I just opened Powertop 2.1 and could not find anything like that. Can you enlighten me?

But what does BAD->GOOD do?

Posted Sep 2, 2012 21:09 UTC (Sun) by drago01 (subscriber, #50715) [Link]

From the article:
PowerTOP's other mode is report generation, which you can invoke by running either sudo powertop --html or sudo powertop --csv. [...] A bit more interesting, however, is the HTML output's Tuning tab, which includes the command necessary to change each "Bad" setting

But what does BAD->GOOD do?

Posted Sep 3, 2012 8:42 UTC (Mon) by spaetz (subscriber, #32870) [Link]

DOH, thanks for that! Clearly, I need to brush up my reading capabilities.

PowerTOP tops up to 2.1

Posted Sep 3, 2012 23:33 UTC (Mon) by Baylink (subscriber, #755) [Link]

Well, wookey, thank you for saving me a lot of time and trouble. I've got enough info out of powertop 1.13, and if 2.x doesn't show me watts anymore, I'm not sure I'm going to bother...

Showing watts

Posted Sep 3, 2012 23:45 UTC (Mon) by corbet (editor, #1) [Link]

It shows power consumption just fine on my machine. Like 1.x, you likely need to be off AC power before ACPI will tell powertop what the current usage is.

Showing watts

Posted Sep 4, 2012 0:33 UTC (Tue) by wookey (subscriber, #5501) [Link]

Aha. That is indeed the secret. Unplug the power, get power consumption stats, plug it back in and they disappear. I suppose this is a feature of ACPI and/or what the hardware can measure. I'd have been much less confused if there was some kind of clue that this info would be displayed when off mains, such as a placeholder.

Showing watts

Posted Sep 4, 2012 0:40 UTC (Tue) by Baylink (subscriber, #755) [Link]

Oh, that.

Silly me. Hadn't even thought about that. Thanks.

Showing watts

Posted Sep 4, 2012 0:45 UTC (Tue) by mjg59 (subscriber, #23239) [Link]

ACPI doesn't report power consumption, it reports change in battery state. So if you're on AC, the interface that would tell you power consumption is instead telling you how fast your battery is charging…

Showing watts

Posted Sep 4, 2012 23:15 UTC (Tue) by zlynx (subscriber, #2285) [Link]

And you should note that in most cases, the reported watt usage is correct because the battery hardware is working properly.

In some cases the watt usage will be incorrect because your battery is borked. I've seen this happen.

If your battery drops from 100% to 60% within 15 minutes, there is almost certainly something wrong with the battery. Or you are running an Alienware. :-)

Showing watts

Posted Sep 5, 2012 23:25 UTC (Wed) by nix (subscriber, #2304) [Link]

... or it's an old battery with correspondingly high internal resistance due to oxidation. (This generally exhibits itself as a battery with 'high' capacity that drops fast, in my experience.)

Copyright © 2012, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds