Tools for optimizing Linux power management

The Frugal Penguin

Article from Issue 202/2017
Author(s): , Author(s):

Linux offers several tools that help users analyze the power consumption of hardware components.

A computer consists of many electronic components. In addition to the motherboard with the processor (CPU) and the graphic chip (GPU), the list includes random access memory (RAM), drives and storage media, card readers, a hard disk controller, sensors, and network interfaces. In the case of mobile devices, the display, keyboard, and touchpad all run on the same battery.

All these components need power. Modern CPUs have different power-saving mechanisms that significantly affect the power consumption and thus the battery life. This article studies some tools that monitor and manage power usage for the system. These tools will give you the information you need to adjust the necessary settings for optimal power usage.

Power Consumption

Power consumption depends on the electronic components enabled and installed in the device and on the programs running on the computer [1]. A small tool by the name of Lstopo [2] visualizes the information on electronic components running on the system (Figure 1). Lstopo is part of the hwloc package of hardware tools that is pre-installed or available in package form for many Linux systems. Communication between the individual components is via the internal I2C bus (see the box entitled "I2C").

Figure 1: Lstopo shows the components within a laptop.

I2C

The components of an electronic system need a reliable shared communication channel. On many systems, that communication channel is the I2C or I2C bus (also known as the Inter-IC bus). Raspberry Pi DIY aficionados may already have worked with the I2C bus directly. The bus itself dates back to the 1980s and was originally invented by Philips engineers to support communication between individual components.

The I2C bus only uses two conductors, not including ground and the supply voltage. The two lines are SDA (data) and SCL (clock). The SDA conductor is used to transfer the data, and clock pulses are sent on the SCL conductor. All devices in the system are attached to these two lines. Each connected device has its own address, by which it can be addressed during communication (Figure 2).

Figure 2: Circuit and devices on the I2C bus.

The bus distinguishes between master and slave devices. The master/slave setting defines the right to communicate on the bus: The master can initiate communication, and slaves can only respond. The master sends a byte address to the I2C system and states whether it wants read or write access to it. The connected devices check the start condition sent with the address to see if the master is talking to them. Then the corresponding component responds and the actual data exchange occurs. At the end of communication, a stop condition releases the line [16].

Tasks such as image and video processing, cryptography, data exchange, synchronization, and data transfer (I/O) are often computationally expensive and therefore expensive for power consumption. Also, kernel bugs can have a massive effect on power usage, as dealing with the leap second showed in 2012.

Laptops are typically more efficient than desktop PCs: The components installed in these devices take a more frugal approach. For example, a 2.5-inch SATA hard disk for a laptop will consume between 3 and 5W, whereas a 3.5-inch desktop HDD will need 10 to 20W of power. A modern SSD, however, is content with just 0.2 to 2W. The values depend on the activity: When idle, the disk requires less power than when reading or writing data.

The processor is one of the biggest power hogs. Tuning the settings can quickly achieve up to 30 percent savings. The Cpufrequtils [3] command-line tool lets you conserve power by controlling the CPU frequency scaling daemon. Cpufrequtils comes with plugins for desktop environments, such as XFCE [4]. You also need to look at the power consumption in idle mode. The system, including all active applications, wakes up quickly from the suspend to disk (STD) or suspend to RAM (STR) modes (see the box entitled "Suspend Modes").

Suspend Modes

The purpose of a suspend mode is to back up the computer's current execution state and reduce power consumption by hardware components you do not currently need. When the system wakes up, the state is reloaded, so that the system can proceed with the next instruction. Three modes available in Linux are:

  • Suspend to RAM (STR for short, or stand-by suspend) keeps the RAM active
  • Suspend to Disk (STD, or hibernate) swaps out the RAM content to the hard disk
  • Suspend to Both (STB) saves the machine to swap space then invokes a STR

During STR, the CPU runs in the internal S2 mode, and the system's power consumption drops to the extent that it can sleep for several days in this state. Only the RAM retains power. You can wake the computer from this mode very quickly, because it does not need to read any data from the hard disk. You only need to make sure the device does not entirely run out of power, in which case you would lose your unsaved changes.

In STD (mode S3), all data is dumped on the swap partition or swap file of the hard disk. The system then shuts off completely. The next time the system is powered up, it does not completely reboot but loads the saved state.

STB, which became available in kernel 3.6, uses the in-memory copy of the state upon awakening, provided that the battery is not completely discharged. If the battery is discharged and the copy of the state in RAM is lost, the system reverts to the state saved on the swap partition.

To enable this function on Debian and Ubuntu, access the pm-utils [17] or uswsusp [18] packages. uswsusp includes the s2disk, s2ram, and s2both tools.

An external graphics card that only computes when needed consumes about 10 percent less. Test measurements show that the choice of graphics driver can also save about 5W.

Directly managing the display brightness, so you don't use more energy than you need for the display, can quickly add another 20 percent to your power savings account. If you do not need WiFi and switch the chip off, you'll save another 10 percent. Bluetooth helps you realize at least 2 percent savings, and a properly controlled fan can save up to 4 percent.

The Powerstat tool [5] will help you determine the power consumption for a laptop. The program output in Figure 3 shows an average power consumption of just under 10W for the test computer.

Figure 3: Power consumption measured while writing this article.

CPU Performance States

The original x86 processors always ran at full power. As of the 486 generation, with the Intel 486DX4 from 1994, various power-saving mechanisms were introduced to let the system reduce the consumption in an idle state. Other chip manufacturers introduced similar features, such as ARM with the ARMv4, StrongARM, and ARMv5 and Sun with the microSPARC in the mid-1990s.

Within these idle states was a gradual division of several C-States [6]. C0 always means full activity and is the same for all manufacturers; higher C-states – C1 to C7 [7] – correspond to sleep state levels. The supported modes depend on the CPU manufacturer and the specific processor model [8]. Measurements show that a processor in the C-States C6 and C7 does not need more than 0.5W.

You can read the maximum usable C-State for Intel CPUs from the /sys/modules/intel_idle/max_cstate/ file (Listing 1). You can set a maximum C-State as an additional parameter in the Grub configuration. The entry intel_idle.max_cstate=1 defines a maximum of C1 (Listing 2).

Listing 1

Reading the Max C-State

 

Listing 2

Setting the Max C-State

 

C-State and Power Consumption

The power consumption depends on the current power saver mode, the clock frequency, and the number of currently active CPU cores. The system dynamically adjusts depending on the situation and requirements.

The faster the processor is clocked, and the more cores it uses at the same time, the higher the power consumption will be. The Turbostat tool from the Debian linux-cpupower package shows you exactly what is going on. Get the details about power consumption by setting the -S and --debug options (Listing 3). The three last columns of the output are of interest for power consumption – these settings represent the consumption per CPU (PkgWatt), consumption per core (CorWatt), and the GPU share (GFXWatt). In the case of server processors, instead of GFXWatt, you can specify RAMWatt, which returns the power consumption of the RAM modules (DIMMs).

Listing 3

Turbostat Details

 

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • PowerTOP 2.0

    The PowerTOP tool developed by Intel helps you save power. In version 2.0, it can also handle GPUs and offers advanced tracking features.

  • Saving Power

    Save power by choosing the right system and software configuration.

  • Free Software Projects

    A new status report on suspend and hibernate discusses the workings of, issues with, and future plans for power-saving modes in Linux.

  • Ask_Klaus!
  • PowerTOP

    Intel’s PowerTOP analysis tool helps optimize power usage and shows you the power guzzlers hiding out on your operating system.

comments powered by Disqus
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters

Support Our Work

Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.

Learn More

News