Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Windows Vista: Developing Power-Aware Applications Pat Stemen FUN319 Program Manager Core Platform Architecture Microsoft Corporation

Similar presentations

Presentation on theme: "1 Windows Vista: Developing Power-Aware Applications Pat Stemen FUN319 Program Manager Core Platform Architecture Microsoft Corporation"— Presentation transcript:

1 1 Windows Vista: Developing Power-Aware Applications Pat Stemen FUN319 Program Manager Core Platform Architecture Microsoft Corporation Geralyn Miller Program Manager Windows Laptop PC Microsoft Corporation

2 2 Agenda Windows Vista Power Management Goals Power-Aware Applications Handling Sleep Transitions Power versus Performance Integrating with Windows Power Policy Testing for Power Management

3 3 Windows Vista Power Management Goals Simplify the user experience Enhance and extend power management usage models Improve the reliability of sleep transitions Predictable behavior Visibility into power management actions Extensive diagnostic tracing Enable maximum energy savings Mobile PC battery life Desktop power consumption

4 4 Windows Vista Mobile PC Pillars Smooth Transitions Eliminate existing pain points More Places More time on Windows each day More Scenarios New mobile experiences, new value Fast Startup Power Management ConnectivitySynchronizationDisplays Natural Input/Output Context Awareness Auxiliary Displays Security Backup & Recovery Collaboration Digital Ink Mobile Media

5 5 Power-Aware Applications To achieve power management goals, applications must be power-aware Designed and tested for power management Applications must handle sleep transitions seamlessly You can differentiate your application with power management features Handle power management events Scale behavior based on users power preference and state of the machine Integrate with Windows power policy

6 6 Enabling Maximum PC Energy Savings Windows Vista will, by default, enable energy-saving features on all PCs Sleep is the default off behavior on both desktops and mobiles Desktop systems will have monitor blanking and sleep idle timeouts Aggressive power policy defaults for mobile PCs Windows Vista addresses the principle power management adoption blockers Removes need to be Administrator to change policy settings Supports Group Policy control of power settings Provides a rich power policy command-line tool Features reliable and deterministic sleep transitions

7 7 Handling Sleep Transitions Overview Maximizing PC energy savings requires reliable sleep transitions But, failed transitions are the primary sleep adoption blocker Component vetoes are the primary cause Roughly 1/3 of all sleep failures Drivers may veto sleep requests Services may silently fail sleep Some applications display warnings, some do not Some may display warnings – with the laptop lid closed!

8 8 Component vetoes lead to great user frustration and distrust of power management System did not do what the user asked Worst case scenario Laptop in a bag fails to sleep, or wakes and fails to return to sleep Battery drains, system overheats, laptop is unusable when needed, possible data loss Users turn off sleep and use shutdown Handling Sleep Transitions Overview

9 9 Investigations show that applications and services abuse the ability to veto Veto instead of develop and test for power management Veto to prevent potential network connectivity loss Same component may handle network connectivity well outside of sleep / resume

10 10 Handling Sleep Transitions Windows Vista changes Windows Vista will not query user mode components when entering sleep PBT_APMQUERYSUSPEND event will not be sent Windows Vista will continue to notify user mode components when entering sleep PBT_APMSUSPEND event is sent Timeout has been reduced from 20s to 2s Use this event to do limited cleanup before the suspend transition

11 11 Handling Sleep Transitions Applications Do not depend on blocking a sleep state transition An event will always be sent when the system resumes from sleep PBT_APMRESUME, PBT_APMRESUMECRITICAL, PBT_APMRESUMEAUTOMATIC Use this event to automatically restart a task that did not complete because of a sleep state transition PBT_APMxxx events are delivered with the WM_POWERBROADCAST message More information available in the Platform SDK

12 12 Handling Sleep Transitions Idle to Sleep Sleep idle timeout Transitions the system to sleep after period of inactivity Reduces power consumption when the PC is not in use User-configurable, but enabled by default in Windows Vista on both mobiles and desktops Applications may temporarily disable sleep idle timer to ensure system availability e.g., burning a CD, recording a TV show Only disable the timer if absolutely necessary, users expect the system to idle to sleep

13 13 Handling Sleep Transitions Idle to Sleep SetThreadExecutionState API Temporarily disables the sleep idle timer Does not prevent user-initiated sleep transitions Button press, lid switch, Start -> Sleep, etc. Usage of SetThreadExecutionState Disable the sleep idle timer SetThreadExecutionState(ES_SYSTEM_REQUIRED | ES_CONTINUOUS); Process Task When complete, re-enable the sleep idle timer SetThreadExecutionState(ES_CONTINUOUS); If your process is unexpectedly terminated, the power manager will automatically clear the ES_SYSTEM_REQUIRED reference

14 14 Optimizing For Low Power Processor Processor power management is a primary method for the platform to reduce power consumption However, applications can easily prevent processor power management effectiveness When idle, OS directs CPU to a low power sleep state ACPI C-states (C1-C4) Processor is halted and not executing instructions Processor performance states Dynamic voltage and frequency scaling technologies

15 15 Optimizing For Low Power Best Practice: Processor To ensure processor power management effectiveness, applications should avoid Increasing the timer tick frequency If you must increase the timer interval, restore it when work requiring the increase is complete Spinning in tight code loops Use registration / notification APIs, events instead of polling Scheduling frequent periodic timers to poll for work or hardware

16 16 Optimizing For Low Power Best Practice: Processor Applications should Eliminate or reduce polling intervals while on battery power Use Windows Vista asynchronous notifications for power management events instead of polling Use PeekMessage loop for as little time as possible PeekMessage prevents processor idle states Use WaitMessage when not background processing Treat power consumption as a performance metric In general, performance optimizations will often yield CPU power savings

17 17 Optimizing For Low Power Best Practice: Processor Be aware of your apps CPU utilization on both AC and DC power Profile your applications effect on C-state, P-state utilization on laptops running on DC Use Windows Performance Monitor (perfmon.msc)

18 18 Power Versus Performance Display The display backlight represents 33% of a laptops power budget when idle A short display blanking timeout is required to conserve laptop battery power Windows Vista default power plans have short display blanking timeouts Timeout is longer on AC than on DC power

19 19 Power Versus Performance Best Practice: Display Be conscious of your apps use of the display Dont prevent screen blanking when not actively displaying to the user For example (this is incorrect) Application is minimized and has called SetThreadExecutionState(ES_DISPLAY_REQUIRED ) Dont render graphics when display is off 3D graphics and moving visuals use large amounts of CPU/GPU and increase system power consumption Utilize the monitor on/off notification GUID in Windows Vista

20 20 Optimizing For Low Power Hard Disk Drive (HDD) HDD power consumption is 8% of a laptops total power budget Windows power policy will attempt to spin down the HDD when the disk idle timer expires Significant power is consumed by the energy required to spin up the HDD

21 21 Optimizing For Low Power Best Practice: Hard Disk Drive (HDD) Analyze your applications use of the HDD Cache, pre-fetch data where possible Avoid regular, periodic flushes to disk Flushing registry keys E.g. Auto-save less frequently when the system is on battery power Leverage Windows Vista power event notifications to schedule background work Register with GUID_BACKGROUND_TASK_NOTIFICATION Notification indicates that the system is not idle Now is an appropriate time for background work Disk is already spinning

22 22 Windows Power Policy All power plans in Windows Vista have a personality Power Saver Automatic High Performance Windows Vista provides default power plans (instances) of each personality type The identification GUID of the default power plans indicates the personality of all other power plans Power plans may be easily discovered and changed by users Active power scheme personality can be broadcast to interested components Allows applications and devices to understand and respond to users power intent

23 23 Handling Common Power Events Applications may wish to handle common power management events AC / DC power state change Power scheme personality change Monitor on / off Battery capacity remaining Historically, applications need to poll for status change Eg, GetSystemPowerStatus API for battery capacity, AC line status

24 24 Handling Common Power Events Use Windows Vista asynchronous notifications for common power events Eliminates need to poll Register with RegisterPowerSettingNotification API Power event notifications ( PBT_POWERSETTINGCHANGE ) are delivered with the WM_POWERBROADCAST message lParam is a pointer to POWERBROADCAST_SETTING Includes GUID of power setting which changed New value of the power setting Initial notification delivered shortly after registration

25 25 Using Windows Vista Power APIs In a Windows Forms Application Geralyn Miller Program Manager Windows Laptop PC

26 26 Handling Common Power Events AC / DC power state change Register with GUID_ACDC_POWER_SOURCE Callback value is AC (utility power) DC (battery power) Short-term DC (UPS device) Useful for knowing when the system transitions to UPS power

27 27 Handling Common Power Events Power plan personality change Register with GUID_POWER_SCHEME_PERSONALITY Callback value is GUID indicating scheme personality Power Saver Automatic High Performance Can be used to implement simple power saving behavior

28 28 Handling Common Power Events Monitor on / off Register with GUID_MONITOR_POWER_ON Notification value indicates if the primary video device is on or off Useful for media applications Applications may stop rendering video or other content when the display is off to save power

29 29 Integrating With Windows Power Policy Overview Applications have several options for reducing performance to conserve power Scale back the user experience Graphics richness Reduce the frequency of data updates Reduce CPU work loads Number of threads, thread priorities Use hardware (not software) rendering for graphics Turn off or constrain background processing Defer unnecessary tasks

30 30 Scaling An Avalon Application According To Power Policy Geralyn Miller Program Manager Windows Laptop PC

31 31 Integrating With Windows Power Policy To integrate any component with Windows power policy Define a new power setting Install the new power setting Register for change notification on the new power setting Respond to change notifications

32 32 Scaling Behavior Defining custom power settings Power setting attributes Identification GUID Textual name, description Setting values for AC, DC Range of values List of discrete values Specify default values for each default power plan Correct defaults are critical Assume users will not go to the Power Control Panel to configure the new setting

33 33 Integrating With Windows Power Policy Installing custom power settings INF or API-based installation INF method is the preferred (and easiest) method New INF directives to support power setting installation Use in device installation INF or separate INF executed during application installation Execute separate INF during application installation using InstallHinfSection API rundll32.exe setupapi.dll,InstallHinfSection mySection 128 PathToMyInf.inf Power setting installation requires administrative privileges

34 34 Integrating With Windows Power Policy Installing custom power settings ; Indicate one or more sections for ; new power settings AddPowerPolicy=MyAppPowerSetting ; Section to add the setting [MyAppPowerSetting] Policy =, Friendly Name, Description, Policy =, Friendly Name, Description, SettingRange = 0, 100, % ; Specify default values Default = %MAX_POWERSAVINGS_GUID%, %AC%, 50 Default = %MAX_POWERSAVINGS_GUID%, %DC%, 50 Default = %AUTOMATIC_POWERSAVINGS_GUID%, %AC%, 95 Default = %AUTOMATIC_POWERSAVINGS_GUID%, %DC%, 50 Default = %MAX_PERFORMANCE_GUID%, %AC%, 100 Default = %MAX_PERFORMANCE_GUID%, %DC%, 100

35 35 Integrating With Windows Power Policy Registering for setting notifications Register for change notifications on the new power setting Use the power event/setting notification API: RegisterPowerSettingNotification Register within application initialization code Register for notification with unique GUID Deregister when your application is closed

36 36 Integrating With Windows Power Policy Respond to setting notification Respond to the power setting change notification Change notification will occur when the power setting value changes Active power scheme change AC / DC transition User changes setting value Change notification occurs shortly after registration

37 37 Testing For Power Management Power-aware applications are tested for power management Test your applications behavior for all power management scenarios Sleep / resume Idle to sleep Mobile PC / lid closure AC, DC Use tools available in the WDK to automate sleep transition testing Custom tests can be built using the SetSystemPowerState and SetWaitableTimer APIs

38 38 Summary Windows Vista enables power saving settings (and use of sleep / resume) by default on all PCs Applications must seamlessly handle sleep transitions Applications can use power management best practices to optimize for low power consumption and help extend battery life Windows Vista enables applications to easily integrate with system power policy Applications can scale behavior according to power preference

39 39 Call To Action Design and Test your application for power management! Register for Windows Vista beta program, provide feedback Take advantage of power saving features and opportunities to differentiate your products Use power management best practices when developing your application Integrate your application with system power policy

40 40 Community Resources At PDC Labs: Mobile PC: Building Energy Smart Windows Vista Applications (C#) Lab is on the Tablet PCs in the Presentation Track Area Fundamentals Track Lounge: Friday, 8:30-11:30 AM Get spotted with this button for a chance to win a Tablet PC! After PDC If you missed this related session, watch it on the DVD FUN319: Developing Power-Aware Applications for Windows Vista MSDN Dev Center: MSDN Forums: Mobile PC and Tablet PC category

41 41 Additional Resources White paper detailing Power Policy APIs and power setting installation How to setup a new developer environment on Windows Vista in order to take advantage of the Mobile PC and Tablet PC SDK features, along with Windows Presentation Foundation at Mobile PC and Tablet PC Developer Center: Download SDKs, code samples, articles Fabrikam Fine Furniture Reference Application: End-to-end reference application demonstrating Mobile PC and Tablet PC best practices for business applications. Arcs of Fire: Classic artillery duel game demonstrating how to use gestures, use pressure sensitivity, draw landscapes, and more. This uses the new Tablet PC Game SDK. Tablet PC ISV Partner Program:

42 © 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

43 43 Suspend to RAM (ACPI S3 state) Standby Very fast startup State preserved in RAM (volatile) Suspend to HDD (ACPI S4 state) Hibernate Start up time < boot time State preserved in non-volatile storage Hybrid Sleep Combines Standby and Hibernate Suspend to RAM and HDD at the same time System can wake on: User-initiated action (button press, lid) Wake-capable device Real Time Clock (RTC) - scheduled task Appendix: Windows Power Management Definitions

44 44 System power source AC (utility power) DC (battery power) Long term battery (laptop computer) Short term battery (UPS) Device power states Low power idle or sleep states Appendix: Windows Power Management Definitions

45 45 Appendix: Handling Sleep Transitions EXECUTION_STATE SetThreadExecutionState( EXECUTION_STATE esFlags );FlagValueMeaningES_SYSTEM_REQUIRED0x Informs the system that the state being set should remain in effect until the next call that uses ES_CONTINUOUS and one of the other state flags is cleared. ES_DISPLAY_REQUIRED0x Forces the display to be on by resetting the display idle timer. ES_CONTINUOUS0x Forces the system to be in the working state by resetting the system idle timer. esFlags values

46 46 Appendix: Registering for Windows Power Policy Notifications RegisterPowerSettingNotification USER mode, requires message handler HPOWERNOTIFYRegisterPowerSettingNotification( IN HANDLE hRecipient, IN HANDLE hRecipient, IN LPCGUID PowerSettingGuid, IN LPCGUID PowerSettingGuid, IN DWORD Flags IN DWORD Flags ); );ParameterMeaning Return Value A handle which is used when de-registering for power setting notifications concerning this power setting hRecipient A handle to the window or service where power setting change messages should be delivered. PowerSettingGuid A GUID which indicates the power setting for which change notifications should be delivered. Flags DEVICE_NOTIFY_WINDOW_HANDLE when the registrant wants messages delivered to a window message pump or DEVICE_NOTIFY_SERVICE_HANDLE when the registrant requests notifications to be delivered to a service message handler.

47 47 Appendix: Responding to Windows Power Policy Notifications POWERBROADCAST_SETTING lParam of PBT_POWERSETTINGCHANGE event typedef struct { GUID PowerSetting; DWORD DataLength; UCHAR Data[1]; } POWERBROADCAST_SETTING, *PPOWERBROADCAST_SETTING; ItemMeaningPowerSetting Indicates by GUID the power setting for which this notification is being delivered. DataLength The size of the Data element, which contains the new value of the power setting. Data The buffer containing the new value of the power setting.

48 48 Appendix: Unregistering for Windows Power Policy Notifications UnRegisterPowerSettingNotification USER mode, requires message handler HPOWERNOTIFYUnRegisterPowerSettingNotification( IN HANDLE hRecipient IN HANDLE hRecipient ); );ParameterMeaning Return Value Indicates if the de-registration was successful. Call GetLastError() for more error details hRecipient The handle returned when registering for power setting notifications using RegisterPowerSettingNotification()

49 49 More Available Fast Startup 2-3 second resume from sleep 2-3 second resume from sleep second boot/ disk resume second boot/ disk resume Simplified UX Simplified UX Fast off Fast off Power Mgmt Reliable power state transitions Reliable power state transitions Simplified UX Simplified UX New permissions; Group Policy New permissions; Group Policy Device power management Device power management Hybrid hard drives Hybrid hard drivesConnectivity Wireless performance Wireless performance Wireless security & extensibility Wireless security & extensibility Group policy support Group policy support Network diagnostics Network diagnostics Easy network setup, join and resource discovery Easy network setup, join and resource discovery VPN-less remote access VPN-less remote accessSynchronization PC/PC & PC/server synch PC/PC & PC/server synch Integrated device synch Integrated device synch Performance improvements Performance improvements Sync Center: Consolidated UX Sync Center: Consolidated UXDisplays External display and projector transitions External display and projector transitions Auto-configuration & restore Auto-configuration & restore More Places Natural Input/Output Flicks input gestures Flicks input gestures Pen / shell integration Pen / shell integration TIP auto-complete TIP auto-complete Handwriting personalization Handwriting personalization Ink Watson Ink Watson Touch screen support Touch screen support High DPI support & font scaling High DPI support & font scaling Context Awareness Windows Mobility Center Windows Mobility Center Presentation settings Presentation settings Smart default printer switching Smart default printer switching Auxiliary Displays Quick access to PIM data, system status Quick access to PIM data, system status Audio playback Audio playbackSecurity HW-enabled file & system protection HW-enabled file & system protection Backup & Recovery Easy data backup & restore Easy data backup & restore More Scenarios Collaboration Windows Meeting Space: PC to PC broadcast & file sharing within groups Windows Meeting Space: PC to PC broadcast & file sharing within groups Discovery of nearby people Discovery of nearby people Ad hoc wireless networking Ad hoc wireless networking Networked projection Networked projection Digital Ink Note taking & drawing Note taking & drawing Search ink notes Search ink notes Sticky notes Sticky notes Annotating documents Annotating documents Mobile Media Instant media playback Instant media playback Appendix: Mobile PC Pillar Definitions

Download ppt "1 Windows Vista: Developing Power-Aware Applications Pat Stemen FUN319 Program Manager Core Platform Architecture Microsoft Corporation"

Similar presentations

Ads by Google