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.
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'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.
to post comments)