Reducing Power Consumption
Reducing Power Consumption
The Power-Aware Application explains how an application can be aware of power source and power management events. This topic discusses a variety of power-saving practices that you can implement for the processor, display, disk, and external devices. Tuning your code to use resources more efficiently improves both performance and battery life. Most performance tuning also reduces power consumption.
Limiting activities helps power conservation
As with most design questions about user experience, start with the user's tasks when considering power management behavior.
- What are the primary tasks that the user wants to accomplish with your application?
- Do all of these tasks need to be fully supported in all power management states?
- Which activities can be limited or postponed when the computer is in a power-saving state?
Users expect to accomplish work in your application, but they also want to extend the time the mobile PC is available for as long as possible.
Processor
The CPUs on mobile PCs feature power-saving modes, in which the processor can scale back to a lower-frequency and lower-voltage running mode. The processor can scale back to these S1 or S2 processor states if no activity has occurred on the mobile PC for a given time period. You can reduce power consumption by allowing these low-power transitions to occur.
Treat power consumption as a performance metric. In general, performance optimizations, such as using fewer CPU instructions to do the same amount of work, often increase CPU power savings. Follow these guidelines to improve CPU power conservation:
- Enable the processor to scale back to its power-saving states. Batch high processor utilization processes whenever possible.
- Avoid increasing the timer-tick frequency. If you must use a higher frequency, set it back after you finish with it.
- Use asynchronous notifications when possible, such as those provided for power, networking, and display awareness. Avoid polling mechanisms, such as periodic timers or loops in background threads.
- Avoid using PeekMessage because it prevents the processor from going into idle mode.
Use the following tools to analyze how your application uses the processor:
- Performance tools that are integrated in Microsoft Visual Studio 2005 Team System
- Windows Performance Monitor (perfmon.msc)
- Intel VTune Performance Analyzer
For more information about optimization tools, see the following articles:
- Visual Studio 2005 Team System: Building Robust and Reliable Software
- Optimizing Software for Intel Centrino Mobile Technology and Intel NetBurst Microarchitecture
- Optimizing for Intel Pentium M Processor with Intel VTune Performance Analyzer
Display
The LCD display consumes significant power. Windows Vista provides display brightness adjustments as part of its power-saving plans and also during the crucial screen-blanking interval after idle periods. Follow these guidelines to further conserve power:
- When running in a power-saving mode, consider making fewer screen updates and using graphics that are less processor-intensive.
- Regardless of the power state, don't update the application display if your window is minimized or hidden, or if the display is blanked.
- Avoid resetting the display blanking time-out period (the SetThreadExecutionState function).
Disk
Windows Vista can shut down hard disks after a period of inactivity. When a power-saving personality is in use, avoid awakening a disk. Spinning the hard disk back online consumes significant power.
- If the hard disk is shut down, avoid writing to it unless the action is specifically requested by the user. Consider delaying I/O operations that are not explicitly requested.
- In general, avoid periodically writing to disk. Batch your I/O requests. Cache writing to the disk rather than writing continuously, and consider pre-fetching data.
- Avoid flushing registry keys.
- Consider reducing the frequency of background operations, such as indexing, using the spelling checker, and auto-saving. Perform background operations based on a clear user need rather than on timing.
Your application can perform background processing in response to a notification sent when the system returns from an idle state. To register, use the RegisterPowerSettingNotification function.
External devices
Avoid holding open handles to detachable devices that you're not actively using. On a mobile PC, a wide variety of devices can be detached-such as displays, optical drives, and pointing devices. By maintaining an open handle on a device, you can prevent a mobile PC from shutting down the device, and also cause complications when the user tries to undock the mobile PC. You can register to be notified of device removals by using RegisterDeviceNotification. You can also monitor the WM_DEVICECHANGE message for notification of docking and undocking.
Send comments about this topic to Microsoft
Build date: 12/5/2008