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.
Multi-Threading and Concurrency Maximizations
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.
Minimize Interruptions and Avoid Frequent Polling
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.
Optimize Frequently Used Code
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.
Bundle and Save
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.
Reducing Memory Bandwidth
Achieving memory bandwidth optimization is another way to reduce the overall power usage of your application during its active state. A few suggestions are:
- Avoid unneeded format conversions between different graphics formats (such as YUV and RGB) for accesses by the GPU and the CPU
- Cache frequently accessed data structures
- Limit kernel/user space data moves
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.
Power Aware Applications Rock
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.
- 3D Games: When a system indicates it is running in battery mode, cap the rendering frame to a lower rate
- Video Player: When the battery level is getting low, reduce or disable filters for image and color enhancement during video playback
- Any Program:
- Don’t update the display when the application is minimized
- Choose good power aware defaults
- Delay non-critical tasks when in battery mode
- Suggest to user additional ways to reduce power consumption in the form of optional settings
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.
About the Author
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: /sites/default/files/m/d/4/1/d/8/Green_Hill_SW_20.pdf
Interruptions and Polling:
Bundle and Save:
Power Aware Applications:
- Power-Aware Mobilized Windows Applications
- Creating Power Aware Applications on Linux using Qt4
- Developing Power Aware Apps
Reducing Memory Bandwidth:
- Reducing the Impact of Misaligned Memory Accesses
- Detecting Memory Bandwidth Saturation in Threaded Applications
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