This article presents techniques to optimize applications to save power during active use. These techniques include multi-threading, batching of I/0 accesses, and reducing memory bandwidth. Some of the techniques are applicable for general program usage while others may be specific to a certain type of application or platform.
Battery life consumption has become an increasing focus for today’s electronic devices. Many people report frustration when the battery life of small devices (such as Ultrabook™ devices, laptops, cell phones and tablets) are not capable of surviving a typical day, leaving users searching for a charging station at inopportune times. Major contributors to these battery woes are applications which are not optimized to conserve energy. This part of the problem can be solved by improving application battery consumption, both while the program is in an idle state and while it is active. This paper will focus on ways for an application to optimize operations during active use.
The definition of the active period for an application is whenever the program is doing useful work. The term “useful work” is work that is necessary to complete the activity requested directly by the user. Work done in the background wouldn’t be considered “useful work”. An example of an active application period might be calculating results in a spreadsheet program or when a search engine is looking for matches to the user’s input. Both of these examples are initially requested by the user, but then the program is completing the work without user interaction. Other examples include streaming a video or running a virus scan.
It is very easy to understand that conserving battery power during application idle periods makes a lot of sense, but an often overlooked area is the possible power savings that can be achieved during the time when useful work is being performed. Taking your application to the next level in low-power performance can increase the responsiveness of your program, enable a more pleasing user experience (by extending battery life), and keep the user engaged for as long as possible. It’s a win, win result!
Here are some suggestions that you might want to take when looking for ways of saving power during the active periods of your program. You might notice that some of these are the same or very similar to those recommended for idle power savings. That makes sense, since the top energy savers are likely to be contained in the entire program and not just in one particular section. The basic idea behind all of these suggestions is to look for the energy bottlenecks and then see if there is a way to reduce or eliminate them. References on each technique are collected in the References section at the end.
With today’s multiple processor chips becoming more and more prevalent, using all available cores improves performance, and can also improve power usage. Why work one core for a long time at or near 100% performance if you can get the job done faster and with less power by using all available processors? If you can maximize threading concurrency, then your program will run faster and use less energy in the process. The graph below shows the energy consumption results for three different applications when tested on a 2nd Generation Intel® Core™ processor with a Windows* 7 operating system. The media app shows a great improvement on the multi-threaded version over the single threaded version, but all three programs show less energy consumption when the program was multi-threaded.
User to Kernel Transactions
A leading consumer of power during an application’s active state is a high frequency of system calls. When an application has been threaded, contention may be caused between the threads that are interacting with the system kernel. To avoid these problems, use the Windows API call “EnterCriticalSection()” to synchronize inter-process communication between threads in user space rather than the Windows API call “WaitForSingleObject()”, which runs in kernel space. When a 4 thread test application was tested using low lock contention, it showed up to a 60% energy savings on a 2nd Generation Intel Core™ processor Windows 7 platform.
One common source of these kernel-level synchronization calls are transitions between active and idle states. By batching periodic activities and avoiding many transitions between active and idle periods, the concurrency of your threads will be maximized. Together with multi-threading, these changes will help your application do more work with less power.
You have likely noticed how much less work you get done when you are constantly stopping to resolve one issue after the other. The system that your program is running on reacts the same way. So, if you can keep your system timer resolution low and avoid frequent periodic polling, you can reduce the amount of energy lost through waiting for system resources.
This is a pretty fundamental concept. The high-use areas of code will gain the most from optimization, so start with these sections first. One way to optimize this code is to use the latest vectored instructions such as SSE4.x and AVX1 or AVX2. These instructions help perform often used actions faster and with less power requirements.
How many times have you heard that from retail and service companies? It is as true for conserving power usage as it is for money. For power, bundling refers to batching disk I/O accesses. As shown in the table below, power savings can be achieved by increasing the disk idle time between accesses. This also includes any action that will require the application to change its state. If you can bundle calls to resources, then the application can save power.
Achieving memory bandwidth optimization is another way to reduce the overall power usage of your application during its active state. A few suggestions are:
Utilizing less power-hungry methods and being aware of which methods reduce the energy requirements can be of benefit as well. The table below shows several Microsoft DirectX* 9 Present Methods and their accompanying power usages when doing video playback. These figures were collected on a 2nd Generation Intel Core™ processor platform running Windows* 7. In this example, each pixel in a HD video frame occupies either 2 bytes or 4 bytes in memory for the YUY2 and the RGB formats respectively. Hence, the memory footprint of the YUY2 format is smaller and more efficient.
In addition to the recommendations listed above, try reducing time spent in privileged mode and replace Sleep(0) wait-loops with the Pause() function. There are specific recommendations for software designed for specific types of workloads. For instance, there are specific hardware and software suggestions to improve video conferencing power consumption, noted in the References section.
While you are working on saving energy consumption during the active state, keep in mind that those applications which are conscious of environment changes while running can extend the battery life of a device as well. There are a variety of ideas that have been suggested as ways to make your program power aware. The following list of examples is by no means exclusive. Feel free to innovate in order to reduce energy needs. Sometimes it will take several iterations of trying different configurations to achieve a balanced energy performance application model.
Using any or all of the suggestions and including your own will help create a better experience for the user. And in the end, isn’t that a key reason to create the software in the first place?
As we continue to produce devices that are capable of running all day without a recharge and performing more and more work, the demand for power-savvy applications will grow. Developers hold a pivotal role in transforming our old energy wasteful programs into sleek, green versions. Attention paid now to maximizing the ratio of useful work to power consumption will no doubt pay off in multiple ways. Now is the time to shake loose the old conventions and forge good power usage habits. And remember if you don’t innovate your application to take care of active power performance, you know full well that your competition will.
Judy Hartley is a Software Applications Engineer who has been working in the Software and Services Group since 2005. She has contributed to many software products and written about her experiences through blogs and whitepapers. Recently Judy has been working on Graphics and Power tools and training for future Intel processors.
Optimizing Active Power – William Cheung – Presentation: /en-us/videos/channel/power/optimizing-active-power/1532764101001
Whitepaper on Energy Efficient Platforms – Considerations for Application Software & Services: /content/dam/develop/external/us/en/documents/green-hill-sw-20-185393.pdf
Interruptions and Polling:
Bundle and Save:
Power Aware Applications:
Reducing Memory Bandwidth:
Intel® Media SDK 2012: /en-us/articles/vcsource-tools-media-sdk/
CPU Power Utilization on Intel Architectures: /en-us/articles/cpu-power-utilization-on-intel-architectures
Intel's compilers may or may not optimize to the same degree for non-Intel microprocessors for optimizations that are not unique to Intel microprocessors. These optimizations include SSE2, SSE3, and SSSE3 instruction sets and other optimizations. Intel does not guarantee the availability, functionality, or effectiveness of any optimization on microprocessors not manufactured by Intel. Microprocessor-dependent optimizations in this product are intended for use with Intel microprocessors. Certain optimizations not specific to Intel microarchitecture are reserved for Intel microprocessors. Please refer to the applicable product User and Reference Guides for more information regarding the specific instruction sets covered by this notice.
Notice revision #20110804