+ All Categories
Home > Documents > 1 Windows Vista: Developing Power-Aware Applications Pat Stemen FUN319 Program Manager Core Platform...

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

Date post: 29-Mar-2015
Category:
Upload: jonathon-mankins
View: 217 times
Download: 4 times
Share this document with a friend
Popular Tags:
49
1 Windows Vista: Windows Vista: Developing Power-Aware Developing Power-Aware Applications Applications Pat Stemen Pat Stemen FUN319 FUN319 Program Manager Program Manager Core Platform Core Platform Architecture Architecture Microsoft Microsoft Corporation Corporation [email protected] [email protected] Geralyn Miller Geralyn Miller Program Manager Program Manager Windows Laptop PC Windows Laptop PC Microsoft Microsoft Corporation Corporation gemiller@microsoft. gemiller@microsoft. com com
Transcript
Page 1: 1 Windows Vista: Developing Power-Aware Applications Pat Stemen FUN319 Program Manager Core Platform Architecture Microsoft Corporation patste@microsoft.com.

1

Windows Vista: Windows Vista: Developing Power-Aware Developing Power-Aware ApplicationsApplications

Pat StemenPat StemenFUN319FUN319Program ManagerProgram ManagerCore Platform Core Platform ArchitectureArchitectureMicrosoft CorporationMicrosoft [email protected]@microsoft.com

Geralyn MillerGeralyn MillerProgram ManagerProgram ManagerWindows Laptop PCWindows Laptop PCMicrosoft CorporationMicrosoft [email protected]@microsoft.comm

Page 2: 1 Windows Vista: Developing Power-Aware Applications Pat Stemen FUN319 Program Manager Core Platform Architecture Microsoft Corporation patste@microsoft.com.

2

AgendaAgenda

Windows Vista Power Management Windows Vista Power Management GoalsGoals

Power-Aware ApplicationsPower-Aware Applications

Handling Sleep TransitionsHandling Sleep Transitions

Power versus PerformancePower versus Performance

Integrating with Windows Power Integrating with Windows Power PolicyPolicy

Testing for Power ManagementTesting for Power Management

Page 3: 1 Windows Vista: Developing Power-Aware Applications Pat Stemen FUN319 Program Manager Core Platform Architecture Microsoft Corporation patste@microsoft.com.

3

Windows Vista Power Windows Vista Power Management GoalsManagement Goals

Simplify the user experienceSimplify the user experience

Enhance and extend power management Enhance and extend power management usage modelsusage models

Improve the reliability of sleep transitionsImprove the reliability of sleep transitionsPredictable behaviorPredictable behavior

Visibility into power management actionsVisibility into power management actions

Extensive diagnostic tracingExtensive diagnostic tracing

Enable maximum energy savingsEnable maximum energy savingsMobile PC battery lifeMobile PC battery life

Desktop power consumptionDesktop power consumption

Page 4: 1 Windows Vista: Developing Power-Aware Applications Pat Stemen FUN319 Program Manager Core Platform Architecture Microsoft Corporation patste@microsoft.com.

4

Windows VistaWindows VistaMobile PC PillarsMobile PC Pillars

Smooth TransitionsSmooth Transitions

Eliminate Eliminate existing existing

pain pointspain points

More PlacesMore Places

More time More time on Windows on Windows

each dayeach day

More ScenariosMore Scenarios

New mobile New mobile experienceexperience

s, new s, new valuevalue

Fast StartupFast Startup

Power Power ManagementManagement

ConnectivityConnectivity

SynchronizatiSynchronizationon

DisplaysDisplays

Natural Natural Input/OutputInput/Output

Context Context AwarenessAwareness

Auxiliary Auxiliary DisplaysDisplays

SecuritySecurity

Backup & Backup & Recovery Recovery

CollaborationCollaboration

Digital InkDigital Ink

Mobile MediaMobile Media

Page 5: 1 Windows Vista: Developing Power-Aware Applications Pat Stemen FUN319 Program Manager Core Platform Architecture Microsoft Corporation patste@microsoft.com.

5

Power-Aware ApplicationsPower-Aware Applications

To achieve power management To achieve power management goals, applications must be power-goals, applications must be power-awareaware

Designed and tested for power Designed and tested for power managementmanagement

Applications must handle sleep Applications must handle sleep transitions seamlesslytransitions seamlesslyYou can differentiate your application You can differentiate your application with power management featureswith power management features

Handle power management eventsHandle power management eventsScale behavior based on user’s power Scale behavior based on user’s power preference and state of the machinepreference and state of the machineIntegrate with Windows power policyIntegrate with Windows power policy

Page 6: 1 Windows Vista: Developing Power-Aware Applications Pat Stemen FUN319 Program Manager Core Platform Architecture Microsoft Corporation patste@microsoft.com.

6

Enabling Maximum PC Enabling Maximum PC Energy SavingsEnergy Savings

Windows Vista will, by default, enable energy-Windows Vista will, by default, enable energy-saving features on all PCssaving features on all PCs

Sleep is the default “off” behavior on both desktops and Sleep is the default “off” behavior on both desktops and mobilesmobiles

Desktop systems will have monitor blanking and sleep Desktop systems will have monitor blanking and sleep idle timeouts idle timeouts

Aggressive power policy defaults for mobile PCs Aggressive power policy defaults for mobile PCs

Windows Vista addresses the principle power Windows Vista addresses the principle power management adoption blockersmanagement adoption blockers

Removes need to be Administrator to change policy Removes need to be Administrator to change policy settingssettings

Supports Group Policy control of power settingsSupports Group Policy control of power settings

Provides a rich power policy command-line toolProvides a rich power policy command-line tool

Features reliable and deterministic sleep transitionsFeatures reliable and deterministic sleep transitions

Page 7: 1 Windows Vista: Developing Power-Aware Applications Pat Stemen FUN319 Program Manager Core Platform Architecture Microsoft Corporation patste@microsoft.com.

7

Handling Sleep TransitionsHandling Sleep TransitionsOverviewOverview

Maximizing PC energy savings Maximizing PC energy savings requires reliable sleep transitionsrequires reliable sleep transitionsBut, failed transitions are the primary But, failed transitions are the primary sleep adoption blockersleep adoption blocker

Component vetoes are the primary Component vetoes are the primary causecause

Roughly 1/3 of all sleep failuresRoughly 1/3 of all sleep failuresDrivers may veto sleep requestsDrivers may veto sleep requestsServices may silently fail sleepServices may silently fail sleepSome applications display warnings, some do Some applications display warnings, some do notnotSome may display warnings – with the laptop Some may display warnings – with the laptop

lid closed!lid closed!

Page 8: 1 Windows Vista: Developing Power-Aware Applications Pat Stemen FUN319 Program Manager Core Platform Architecture Microsoft Corporation patste@microsoft.com.

8

Component vetoes lead to great Component vetoes lead to great user frustration and distrust of user frustration and distrust of power managementpower management

System did not do what the user System did not do what the user askedasked

Worst case scenario Worst case scenario Laptop in a bag fails to sleep, or Laptop in a bag fails to sleep, or wakes and fails to return to sleepwakes and fails to return to sleep

Battery drains, system overheats, Battery drains, system overheats, laptop is unusable when needed, laptop is unusable when needed, possible data losspossible data loss

Users turn off sleep and use Users turn off sleep and use shutdownshutdown

Handling Sleep TransitionsHandling Sleep TransitionsOverviewOverviewHandling Sleep TransitionsHandling Sleep TransitionsOverviewOverview

Page 9: 1 Windows Vista: Developing Power-Aware Applications Pat Stemen FUN319 Program Manager Core Platform Architecture Microsoft Corporation patste@microsoft.com.

9

Handling Sleep TransitionsHandling Sleep TransitionsOverviewOverview

Investigations show that applications Investigations show that applications and services abuse the ability to vetoand services abuse the ability to veto

Veto instead of develop and test for Veto instead of develop and test for power managementpower management

Veto to prevent potential network Veto to prevent potential network connectivity lossconnectivity loss

Same component may handle network Same component may handle network connectivity well outside of sleep / resumeconnectivity well outside of sleep / resume

Page 10: 1 Windows Vista: Developing Power-Aware Applications Pat Stemen FUN319 Program Manager Core Platform Architecture Microsoft Corporation patste@microsoft.com.

10

Handling Sleep TransitionsHandling Sleep TransitionsWindows Vista changesWindows Vista changes

Windows Vista will not query user Windows Vista will not query user mode components when entering mode components when entering sleepsleep

PBT_APMQUERYSUSPEND event will not PBT_APMQUERYSUSPEND event will not be sent be sent

Windows Vista will continue to notify Windows Vista will continue to notify user mode components when user mode components when entering sleepentering sleep

PBT_APMSUSPEND event is sentPBT_APMSUSPEND event is sentTimeout has been reduced from 20s to 2sTimeout has been reduced from 20s to 2s

Use this event to do limited cleanup before Use this event to do limited cleanup before the suspend transitionthe suspend transition

Page 11: 1 Windows Vista: Developing Power-Aware Applications Pat Stemen FUN319 Program Manager Core Platform Architecture Microsoft Corporation patste@microsoft.com.

11

Handling Sleep TransitionsHandling Sleep TransitionsApplicationsApplications

Do not depend on blocking a sleep state Do not depend on blocking a sleep state transitiontransition

An event will always be sent when the An event will always be sent when the system resumes from sleepsystem resumes from sleep

PBT_APMRESUME, PBT_APMRESUMECRITICAL, PBT_APMRESUME, PBT_APMRESUMECRITICAL, PBT_APMRESUMEAUTOMATICPBT_APMRESUMEAUTOMATIC

Use this event to automatically restart a task Use this event to automatically restart a task that did not complete because of a sleep state that did not complete because of a sleep state transitiontransition

PBT_APMxxx events are delivered with the PBT_APMxxx events are delivered with the WM_POWERBROADCAST messageWM_POWERBROADCAST message

More information available in the Platform SDKMore information available in the Platform SDK

Page 12: 1 Windows Vista: Developing Power-Aware Applications Pat Stemen FUN319 Program Manager Core Platform Architecture Microsoft Corporation patste@microsoft.com.

12

Handling Sleep TransitionsHandling Sleep TransitionsIdle to SleepIdle to Sleep

Sleep idle timeoutSleep idle timeoutTransitions the system to sleep after period of Transitions the system to sleep after period of inactivityinactivity

Reduces power consumption when the PC is not in useReduces power consumption when the PC is not in use

User-configurable, but enabled by default in User-configurable, but enabled by default in Windows Vista on both mobiles and desktopsWindows Vista on both mobiles and desktops

Applications may temporarily disable sleep Applications may temporarily disable sleep idle timer to ensure system availabilityidle timer to ensure system availability

e.g., burning a CD, recording a TV showe.g., burning a CD, recording a TV show

Only disable the timer if absolutely necessary, Only disable the timer if absolutely necessary, users expect the system to idle to sleepusers expect the system to idle to sleep

Page 13: 1 Windows Vista: Developing Power-Aware Applications Pat Stemen FUN319 Program Manager Core Platform Architecture Microsoft Corporation patste@microsoft.com.

13

Handling Sleep TransitionsHandling Sleep TransitionsIdle to SleepIdle to Sleep

SetThreadExecutionState APISetThreadExecutionState APITemporarily disables the sleep idle timerTemporarily disables the sleep idle timer

Does not prevent user-initiated sleep transitionsDoes not prevent user-initiated sleep transitionsButton press, lid switch, Start -> Sleep, etc.Button press, lid switch, Start -> Sleep, etc.

Usage of SetThreadExecutionStateUsage of SetThreadExecutionStateDisable the sleep idle timerDisable the sleep idle timer

SetThreadExecutionState(ES_SYSTEM_REQUIRED | ES_CONTINUOUS);SetThreadExecutionState(ES_SYSTEM_REQUIRED | ES_CONTINUOUS);

Process TaskProcess Task

When complete, When complete, re-enable the sleep idle timerre-enable the sleep idle timer

SetThreadExecutionState(ES_CONTINUOUS);SetThreadExecutionState(ES_CONTINUOUS);

If your process is unexpectedly terminated, the power manager If your process is unexpectedly terminated, the power manager will automatically clear the ES_SYSTEM_REQUIRED referencewill automatically clear the ES_SYSTEM_REQUIRED reference

Page 14: 1 Windows Vista: Developing Power-Aware Applications Pat Stemen FUN319 Program Manager Core Platform Architecture Microsoft Corporation patste@microsoft.com.

14

Optimizing For Low Power Optimizing For Low Power ProcessorProcessor

Processor power management is a primary Processor power management is a primary method for the platform to reduce power method for the platform to reduce power consumptionconsumption

However, applications can easily prevent However, applications can easily prevent processor power management effectivenessprocessor power management effectiveness

When idle, OS directs CPU to a low power When idle, OS directs CPU to a low power sleep statesleep state

ACPI C-states (C1-C4)ACPI C-states (C1-C4)Processor is halted and not executing instructionsProcessor is halted and not executing instructions

Processor performance statesProcessor performance statesDynamic voltage and frequency scaling technologiesDynamic voltage and frequency scaling technologies

Page 15: 1 Windows Vista: Developing Power-Aware Applications Pat Stemen FUN319 Program Manager Core Platform Architecture Microsoft Corporation patste@microsoft.com.

15

Optimizing For Low Power Optimizing For Low Power Best Practice: ProcessorBest Practice: Processor

To ensure processor power To ensure processor power management effectiveness, management effectiveness, applications should avoidapplications should avoid

Increasing the timer tick frequencyIncreasing the timer tick frequencyIf you must increase the timer interval, If you must increase the timer interval, restore it when work requiring the increase is restore it when work requiring the increase is complete complete

Spinning in tight code loopsSpinning in tight code loopsUse registration / notification APIs, events Use registration / notification APIs, events instead instead of pollingof polling

Scheduling frequent periodic timers to Scheduling frequent periodic timers to poll for work or hardwarepoll for work or hardware

Page 16: 1 Windows Vista: Developing Power-Aware Applications Pat Stemen FUN319 Program Manager Core Platform Architecture Microsoft Corporation patste@microsoft.com.

16

Optimizing For Low Power Optimizing For Low Power Best Practice: ProcessorBest Practice: Processor

Applications shouldApplications shouldEliminate or reduce polling intervals while on Eliminate or reduce polling intervals while on battery powerbattery power

Use Windows Vista asynchronous notifications for Use Windows Vista asynchronous notifications for power management events instead of pollingpower management events instead of polling

Use PeekMessage loop for as little time as Use PeekMessage loop for as little time as possiblepossible

PeekMessage prevents processor idle statesPeekMessage prevents processor idle states

Use WaitMessage when not background processingUse WaitMessage when not background processing

Treat power consumption as a performance Treat power consumption as a performance metricmetric

In general, performance optimizations will often yield In general, performance optimizations will often yield CPU power savingsCPU power savings

Page 17: 1 Windows Vista: Developing Power-Aware Applications Pat Stemen FUN319 Program Manager Core Platform Architecture Microsoft Corporation patste@microsoft.com.

17

Optimizing For Low Power Optimizing For Low Power Best Practice: ProcessorBest Practice: Processor

Be aware of your Be aware of your app’s CPU utilization app’s CPU utilization on both AC and DC on both AC and DC powerpower

Profile your Profile your application’s effect application’s effect on C-state, P-state on C-state, P-state utilization on laptops utilization on laptops running on DCrunning on DC

Use Windows Use Windows Performance Monitor Performance Monitor (perfmon.msc)(perfmon.msc)

Page 18: 1 Windows Vista: Developing Power-Aware Applications Pat Stemen FUN319 Program Manager Core Platform Architecture Microsoft Corporation patste@microsoft.com.

18

Power Versus Power Versus PerformancePerformanceDisplayDisplay

The display backlight represents ≈ The display backlight represents ≈ 33% of a laptop’s power budget when 33% of a laptop’s power budget when idleidle

A short display blanking timeout is A short display blanking timeout is required to conserve laptop battery required to conserve laptop battery powerpower

Windows Vista default power plans Windows Vista default power plans have short display blanking timeoutshave short display blanking timeouts

Timeout is longer on AC than on DC Timeout is longer on AC than on DC powerpower

Page 19: 1 Windows Vista: Developing Power-Aware Applications Pat Stemen FUN319 Program Manager Core Platform Architecture Microsoft Corporation patste@microsoft.com.

19

Power Versus Power Versus PerformancePerformanceBest Practice: DisplayBest Practice: Display

Be conscious of your app’s use of the Be conscious of your app’s use of the displaydisplay

Don’t prevent screen blanking when not Don’t prevent screen blanking when not actively displaying to the useractively displaying to the user

For example (this is incorrect)For example (this is incorrect)

Application is minimized and has calledApplication is minimized and has called

SetThreadExecutionState(ES_DISPLAY_REQUIRESetThreadExecutionState(ES_DISPLAY_REQUIRED) D)

Don’t render graphics when display is offDon’t render graphics when display is off3D graphics and moving visuals use large 3D graphics and moving visuals use large amounts of CPU/GPU and increase system amounts of CPU/GPU and increase system power consumptionpower consumption

Utilize the monitor on/off notification GUID in Utilize the monitor on/off notification GUID in Windows VistaWindows Vista

Page 20: 1 Windows Vista: Developing Power-Aware Applications Pat Stemen FUN319 Program Manager Core Platform Architecture Microsoft Corporation patste@microsoft.com.

20

Optimizing For Low Power Optimizing For Low Power Hard Disk Drive (HDD)Hard Disk Drive (HDD)

HDD power consumption is ≈ 8% of a HDD power consumption is ≈ 8% of a laptop’s total power budgetlaptop’s total power budget

Windows power policy will attempt to Windows power policy will attempt to spin down the HDD when the disk idle spin down the HDD when the disk idle timer expirestimer expires

Significant power is consumed by the Significant power is consumed by the energy required to spin up the HDDenergy required to spin up the HDD

Page 21: 1 Windows Vista: Developing Power-Aware Applications Pat Stemen FUN319 Program Manager Core Platform Architecture Microsoft Corporation patste@microsoft.com.

21

Optimizing For Low Power Optimizing For Low Power Best Practice: Hard Disk Drive Best Practice: Hard Disk Drive (HDD)(HDD)

Analyze your application’s use of the HDDAnalyze your application’s use of the HDD

Cache, pre-fetch data where possibleCache, pre-fetch data where possible

Avoid regular, periodic flushes to diskAvoid regular, periodic flushes to diskFlushing registry keysFlushing registry keys

E.g. Auto-save less frequently when the system is on E.g. Auto-save less frequently when the system is on battery powerbattery power

Leverage Windows Vista power event notifications Leverage Windows Vista power event notifications to schedule background workto schedule background work

Register with GUID_BACKGROUND_TASK_NOTIFICATIONRegister with GUID_BACKGROUND_TASK_NOTIFICATION

Notification indicates that the system is not idleNotification indicates that the system is not idleNow is an appropriate time for background workNow is an appropriate time for background work

Disk is already spinningDisk is already spinning

Page 22: 1 Windows Vista: Developing Power-Aware Applications Pat Stemen FUN319 Program Manager Core Platform Architecture Microsoft Corporation patste@microsoft.com.

22

Windows Power PolicyWindows Power Policy

All power plans in Windows Vista have a All power plans in Windows Vista have a personalitypersonality

Power SaverPower Saver

AutomaticAutomatic

High PerformanceHigh Performance

Windows Vista provides default power plans Windows Vista provides default power plans (instances) of each personality type(instances) of each personality type

The identification GUID of the default power plans The identification GUID of the default power plans indicates the personality of all other power plansindicates the personality of all other power plans

Power plans may be easily discovered and Power plans may be easily discovered and changed changed by usersby users

Active power scheme personality can be broadcast Active power scheme personality can be broadcast to interested componentsto interested components

Allows applications and devices to understand and Allows applications and devices to understand and respond to user’s power intentrespond to user’s power intent

Page 23: 1 Windows Vista: Developing Power-Aware Applications Pat Stemen FUN319 Program Manager Core Platform Architecture Microsoft Corporation patste@microsoft.com.

23

Handling Common Power Handling Common Power EventsEvents

Applications may wish to handle Applications may wish to handle common power management eventscommon power management events

AC / DC power state changeAC / DC power state changePower scheme personality changePower scheme personality changeMonitor on / offMonitor on / offBattery capacity remainingBattery capacity remaining

Historically, applications need to poll Historically, applications need to poll for status changefor status change

Eg, GetSystemPowerStatus API for Eg, GetSystemPowerStatus API for battery capacity, AC line statusbattery capacity, AC line status

Page 24: 1 Windows Vista: Developing Power-Aware Applications Pat Stemen FUN319 Program Manager Core Platform Architecture Microsoft Corporation patste@microsoft.com.

24

Handling Common Power Handling Common Power EventsEvents

Use Windows Vista asynchronous Use Windows Vista asynchronous notifications for common power events notifications for common power events

Eliminates need to pollEliminates need to pollRegister with Register with RegisterPowerSettingNotification RegisterPowerSettingNotification APIAPIPower event notifications Power event notifications ((PBT_POWERSETTINGCHANGEPBT_POWERSETTINGCHANGE) are delivered with ) are delivered with the the WM_POWERBROADCASTWM_POWERBROADCAST message message

lParamlParam is a pointer to is a pointer to POWERBROADCAST_SETTINGPOWERBROADCAST_SETTING Includes GUID of power setting which changedIncludes GUID of power setting which changedNew value of the power settingNew value of the power setting

Initial notification delivered shortly after Initial notification delivered shortly after registrationregistration

Page 25: 1 Windows Vista: Developing Power-Aware Applications Pat Stemen FUN319 Program Manager Core Platform Architecture Microsoft Corporation patste@microsoft.com.

25

Using Windows Vista Power Using Windows Vista Power APIs APIs In a Windows Forms ApplicationIn a Windows Forms Application

Geralyn MillerGeralyn MillerProgram ManagerProgram ManagerWindows Laptop PCWindows Laptop PC

Page 26: 1 Windows Vista: Developing Power-Aware Applications Pat Stemen FUN319 Program Manager Core Platform Architecture Microsoft Corporation patste@microsoft.com.

26

Handling Common Power Handling Common Power EventsEvents

AC / DC power state changeAC / DC power state changeRegister with Register with GUID_ACDC_POWER_SOURCEGUID_ACDC_POWER_SOURCE

Callback value isCallback value isAC (utility power)AC (utility power)

DC (battery power)DC (battery power)

Short-term DC (UPS device)Short-term DC (UPS device)Useful for knowing when the system transitions to Useful for knowing when the system transitions to UPS powerUPS power

Page 27: 1 Windows Vista: Developing Power-Aware Applications Pat Stemen FUN319 Program Manager Core Platform Architecture Microsoft Corporation patste@microsoft.com.

27

Handling Common Power Handling Common Power EventsEvents

Power plan personality changePower plan personality changeRegister with Register with GUID_POWER_SCHEME_PERSONALITYGUID_POWER_SCHEME_PERSONALITY

Callback value is GUID indicating scheme Callback value is GUID indicating scheme personalitypersonality

Power SaverPower Saver

AutomaticAutomatic

High PerformanceHigh Performance

Can be used to implement simple power Can be used to implement simple power saving behavior saving behavior

Page 28: 1 Windows Vista: Developing Power-Aware Applications Pat Stemen FUN319 Program Manager Core Platform Architecture Microsoft Corporation patste@microsoft.com.

28

Handling Common Power Handling Common Power EventsEvents

Monitor on / offMonitor on / offRegister with Register with GUID_MONITOR_POWER_ONGUID_MONITOR_POWER_ON

Notification value indicates if the primary Notification value indicates if the primary video device is on or offvideo device is on or off

Useful for media applicationsUseful for media applicationsApplications may stop rendering video or Applications may stop rendering video or other content when the display is off to save other content when the display is off to save powerpower

Page 29: 1 Windows Vista: Developing Power-Aware Applications Pat Stemen FUN319 Program Manager Core Platform Architecture Microsoft Corporation patste@microsoft.com.

29

Integrating With Windows Power Integrating With Windows Power PolicyPolicyOverviewOverview

Applications have several options for Applications have several options for reducing performance to conserve reducing performance to conserve powerpower

Scale back the user experienceScale back the user experienceGraphics richnessGraphics richness

Reduce the frequency of data updatesReduce the frequency of data updates

Reduce CPU work loadsReduce CPU work loadsNumber of threads, thread prioritiesNumber of threads, thread priorities

Use hardware (not software) rendering for Use hardware (not software) rendering for graphicsgraphics

Turn off or constrain background Turn off or constrain background processingprocessing

Defer unnecessary tasksDefer unnecessary tasks

Page 30: 1 Windows Vista: Developing Power-Aware Applications Pat Stemen FUN319 Program Manager Core Platform Architecture Microsoft Corporation patste@microsoft.com.

30

Scaling An Avalon Scaling An Avalon Application According To Application According To Power PolicyPower Policy

Geralyn MillerGeralyn MillerProgram ManagerProgram ManagerWindows Laptop PCWindows Laptop PC

Page 31: 1 Windows Vista: Developing Power-Aware Applications Pat Stemen FUN319 Program Manager Core Platform Architecture Microsoft Corporation patste@microsoft.com.

31

Integrating With Windows Integrating With Windows Power PolicyPower Policy

To integrate any component with To integrate any component with Windows power policyWindows power policy

Define a new power settingDefine a new power setting

Install the new power settingInstall the new power setting

Register for change notification on the Register for change notification on the new power setting new power setting

Respond to change notificationsRespond to change notifications

Page 32: 1 Windows Vista: Developing Power-Aware Applications Pat Stemen FUN319 Program Manager Core Platform Architecture Microsoft Corporation patste@microsoft.com.

32

Scaling BehaviorScaling BehaviorDefining custom power settingsDefining custom power settings

Power setting attributesPower setting attributesIdentification GUIDIdentification GUID

Textual name, descriptionTextual name, description

Setting values for AC, DCSetting values for AC, DCRange of valuesRange of values

List of discrete valuesList of discrete values

Specify default values for each default Specify default values for each default power planpower plan

Correct defaults are criticalCorrect defaults are critical

Assume users will not go to the Power Control Assume users will not go to the Power Control Panel to configure the new settingPanel to configure the new setting

Page 33: 1 Windows Vista: Developing Power-Aware Applications Pat Stemen FUN319 Program Manager Core Platform Architecture Microsoft Corporation patste@microsoft.com.

33

Integrating With Windows Power Integrating With Windows Power PolicyPolicyInstalling custom power settingsInstalling custom power settings

INF or API-based installationINF or API-based installationINF method is the preferred (and easiest) INF method is the preferred (and easiest) methodmethod

New INF directives to support power setting New INF directives to support power setting installationinstallation

Use in device installation INF or separate INF Use in device installation INF or separate INF executed during application installationexecuted during application installation

Execute separate INF during application Execute separate INF during application installation using InstallHinfSection APIinstallation using InstallHinfSection APIrundll32.exe setupapi.dll,InstallHinfSection mySection 128 PathToMyInf.inf

Power setting installation requires Power setting installation requires administrative privilegesadministrative privileges

Page 34: 1 Windows Vista: Developing Power-Aware Applications Pat Stemen FUN319 Program Manager Core Platform Architecture Microsoft Corporation patste@microsoft.com.

34

Integrating With Windows Power Integrating With Windows Power PolicyPolicyInstalling custom power settingsInstalling custom power settings; Indicate one or more sections for ; Indicate one or more sections for

; new power settings; new power settingsAddPowerPolicy=MyAppPowerSettingAddPowerPolicy=MyAppPowerSetting

; Section to add the setting; Section to add the setting[MyAppPowerSetting][MyAppPowerSetting]Policy = <Power Setting GUID>, “Friendly Name”, Policy = <Power Setting GUID>, “Friendly Name”,

“Description”, <reference to icon>“Description”, <reference to icon>SettingRange = 0, 100, “%”SettingRange = 0, 100, “%”

; Specify default values; Specify default valuesDefault = %MAX_POWERSAVINGS_GUID%, %AC%, 50Default = %MAX_POWERSAVINGS_GUID%, %AC%, 50Default = %MAX_POWERSAVINGS_GUID%, %DC%, 50Default = %MAX_POWERSAVINGS_GUID%, %DC%, 50Default = %AUTOMATIC_POWERSAVINGS_GUID%, %AC%, 95Default = %AUTOMATIC_POWERSAVINGS_GUID%, %AC%, 95Default = %AUTOMATIC_POWERSAVINGS_GUID%, %DC%, 50Default = %AUTOMATIC_POWERSAVINGS_GUID%, %DC%, 50Default = %MAX_PERFORMANCE_GUID%, %AC%, 100Default = %MAX_PERFORMANCE_GUID%, %AC%, 100Default = %MAX_PERFORMANCE_GUID%, %DC%, 100Default = %MAX_PERFORMANCE_GUID%, %DC%, 100

Page 35: 1 Windows Vista: Developing Power-Aware Applications Pat Stemen FUN319 Program Manager Core Platform Architecture Microsoft Corporation patste@microsoft.com.

35

Integrating With Windows Power Integrating With Windows Power PolicyPolicyRegistering for setting notificationsRegistering for setting notifications

Register for change notifications on Register for change notifications on the new power settingthe new power setting

Use the power event/setting notification Use the power event/setting notification API: RegisterPowerSettingNotificationAPI: RegisterPowerSettingNotification

Register within application initialization Register within application initialization codecode

Register for notification with unique GUIDRegister for notification with unique GUID

Deregister when your application is Deregister when your application is closedclosed

Page 36: 1 Windows Vista: Developing Power-Aware Applications Pat Stemen FUN319 Program Manager Core Platform Architecture Microsoft Corporation patste@microsoft.com.

36

Integrating With Windows Power Integrating With Windows Power PolicyPolicyRespond to setting notificationRespond to setting notification

Respond to the power setting change Respond to the power setting change notificationnotification

Change notification will occur when the Change notification will occur when the power setting value changespower setting value changes

Active power scheme changeActive power scheme change

AC / DC transitionAC / DC transition

User changes setting valueUser changes setting value

Change notification occurs shortly after Change notification occurs shortly after registrationregistration

Page 37: 1 Windows Vista: Developing Power-Aware Applications Pat Stemen FUN319 Program Manager Core Platform Architecture Microsoft Corporation patste@microsoft.com.

37

Testing For Power Testing For Power ManagementManagement

Power-aware applications are Power-aware applications are testedtested for for power managementpower management

Test your application’s behavior for all power Test your application’s behavior for all power management scenariosmanagement scenarios

Sleep / resumeSleep / resume

Idle to sleepIdle to sleep

Mobile PC / lid closureMobile PC / lid closure

AC, DCAC, DC

Use tools available in the WDK to automate Use tools available in the WDK to automate sleep transition testingsleep transition testing

Custom tests can be built using the Custom tests can be built using the SetSystemPowerStateSetSystemPowerState and and SetWaitableTimer APIsSetWaitableTimer APIs

Page 38: 1 Windows Vista: Developing Power-Aware Applications Pat Stemen FUN319 Program Manager Core Platform Architecture Microsoft Corporation patste@microsoft.com.

38

SummarySummary

Windows Vista enables power saving Windows Vista enables power saving settings (and use of sleep / resume) by settings (and use of sleep / resume) by default on all PCsdefault on all PCs

Applications must seamlessly handle sleep Applications must seamlessly handle sleep transitionstransitions

Applications can use power management Applications can use power management best practices to optimize for low power best practices to optimize for low power consumption and help extend battery lifeconsumption and help extend battery life

Windows Vista enables applications to Windows Vista enables applications to easily integrate with system power policy easily integrate with system power policy

Applications can scale behavior according toApplications can scale behavior according topower preferencepower preference

Page 39: 1 Windows Vista: Developing Power-Aware Applications Pat Stemen FUN319 Program Manager Core Platform Architecture Microsoft Corporation patste@microsoft.com.

39

Call To ActionCall To Action

DesignDesign and and TestTest your application for your application for power management!power management!

Register for Windows Vista beta Register for Windows Vista beta program, provide feedbackprogram, provide feedback

Take advantage of power saving Take advantage of power saving features and opportunities to features and opportunities to differentiate your productsdifferentiate your productsUse power management best Use power management best practices when developing your practices when developing your application application Integrate your application with Integrate your application with system power policysystem power policy

Page 40: 1 Windows Vista: Developing Power-Aware Applications Pat Stemen FUN319 Program Manager Core Platform Architecture Microsoft Corporation patste@microsoft.com.

40

Community ResourcesCommunity Resources

At PDCAt PDCLabs: “Mobile PC: Building Energy Smart Windows Vista Labs: “Mobile PC: Building Energy Smart Windows Vista Applications (C#)”Applications (C#)”

Lab is on the Tablet PCs in the Presentation Track AreaLab is on the Tablet PCs in the Presentation Track Area

Fundamentals Track Lounge: Friday, 8:30-11:30 AMFundamentals Track Lounge: Friday, 8:30-11:30 AM

Get spotted with this button for a chance to win a Tablet Get spotted with this button for a chance to win a Tablet PC!PC!

After PDCAfter PDCIf you missed this related session, watch it on the DVDIf you missed this related session, watch it on the DVD

FUN319: “Developing Power-Aware Applications for FUN319: “Developing Power-Aware Applications for Windows Vista”Windows Vista”

MSDN Dev Center: MSDN Dev Center: http://http://msdn.microsoft.com/windowsvistamsdn.microsoft.com/windowsvista

MSDN Forums: MSDN Forums: http://forums.microsoft.com/msdnhttp://forums.microsoft.com/msdn““Mobile PC and Tablet PC” categoryMobile PC and Tablet PC” category

Page 41: 1 Windows Vista: Developing Power-Aware Applications Pat Stemen FUN319 Program Manager Core Platform Architecture Microsoft Corporation patste@microsoft.com.

41

Additional ResourcesAdditional Resources

White paper detailing Power Policy APIs and power setting White paper detailing Power Policy APIs and power setting installationinstallation

http://http://go.microsoft.com/fwlink/?LinkIdgo.microsoft.com/fwlink/?LinkId=51286=51286

How to setup a new developer environment on Windows How to setup a new developer environment on Windows Vista in order to take advantage of the Mobile PC and Tablet Vista in order to take advantage of the Mobile PC and Tablet PC SDK features, along with Windows Presentation PC SDK features, along with Windows Presentation Foundation at Foundation at msdn.microsoft.com/mobilepc/pdc05msdn.microsoft.com/mobilepc/pdc05

Mobile PC and Tablet PC Developer Center: Mobile PC and Tablet PC Developer Center: msdn.microsoft.com/MobilePCmsdn.microsoft.com/MobilePC

Download SDKs, code samples, articlesDownload SDKs, code samples, articles

Fabrikam Fine Furniture Reference Application: End-to-end Fabrikam Fine Furniture Reference Application: End-to-end reference application demonstrating Mobile PC and Tablet PC reference application demonstrating Mobile PC and Tablet PC best practices for business applications.best practices for business applications.

Arcs of Fire: Classic artillery duel game demonstrating how to Arcs of Fire: Classic artillery duel game demonstrating how to use gestures, use pressure sensitivity, draw landscapes, and use gestures, use pressure sensitivity, draw landscapes, and more. This uses the new Tablet PC Game SDK. more. This uses the new Tablet PC Game SDK.

Tablet PC ISV Partner Program: Tablet PC ISV Partner Program: TabletPCPartners.comTabletPCPartners.com

Page 42: 1 Windows Vista: Developing Power-Aware Applications Pat Stemen FUN319 Program Manager Core Platform Architecture Microsoft Corporation patste@microsoft.com.

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

Page 43: 1 Windows Vista: Developing Power-Aware Applications Pat Stemen FUN319 Program Manager Core Platform Architecture Microsoft Corporation patste@microsoft.com.

43

Suspend to RAM (ACPI S3 state)Suspend to RAM (ACPI S3 state)““Standby”Standby”Very fast startupVery fast startupState preserved in RAM (volatile)State preserved in RAM (volatile)

Suspend to HDD (ACPI S4 state)Suspend to HDD (ACPI S4 state)““Hibernate”Hibernate”Start up time < boot timeStart up time < boot timeState preserved in non-volatile storageState preserved in non-volatile storage

Hybrid SleepHybrid SleepCombines Standby and HibernateCombines Standby and HibernateSuspend to RAM and HDD at the same timeSuspend to RAM and HDD at the same time

System can wake on:System can wake on:User-initiated action (button press, lid)User-initiated action (button press, lid)Wake-capable deviceWake-capable deviceReal Time Clock (RTC) - scheduled taskReal Time Clock (RTC) - scheduled task

Appendix: Windows Power Appendix: Windows Power Management DefinitionsManagement DefinitionsAppendix: Windows Power Appendix: Windows Power Management DefinitionsManagement Definitions

Page 44: 1 Windows Vista: Developing Power-Aware Applications Pat Stemen FUN319 Program Manager Core Platform Architecture Microsoft Corporation patste@microsoft.com.

44

System power sourceSystem power sourceAC (utility power)AC (utility power)

DC (battery power)DC (battery power)Long term battery (laptop computer)Long term battery (laptop computer)

Short term battery (UPS)Short term battery (UPS)

Device power statesDevice power statesLow power idle or sleep statesLow power idle or sleep states

Appendix: Windows Power Appendix: Windows Power Management DefinitionsManagement DefinitionsAppendix: Windows Power Appendix: Windows Power Management DefinitionsManagement Definitions

Page 45: 1 Windows Vista: Developing Power-Aware Applications Pat Stemen FUN319 Program Manager Core Platform Architecture Microsoft Corporation patste@microsoft.com.

45

Appendix: Handling Sleep Appendix: Handling Sleep TransitionsTransitionsAppendix: Handling Sleep Appendix: Handling Sleep TransitionsTransitions

EXECUTION_STATEEXECUTION_STATE SetThreadExecutionState(SetThreadExecutionState( EXECUTION_STATEEXECUTION_STATE esFlagsesFlags ););

FlagFlag ValueValue MeaningMeaningES_SYSTEM_REQUIREDES_SYSTEM_REQUIRED 0x800000000x80000000 Informs the system that the Informs the system that the

state being set should remain in state being set should remain in effect until the next call that effect until the next call that uses ES_CONTINUOUS and one of uses ES_CONTINUOUS and one of the other state flags is cleared.the other state flags is cleared.

ES_DISPLAY_REQUIREDES_DISPLAY_REQUIRED 0x000000020x00000002 Forces the display to be on by Forces the display to be on by resetting the display idle timer.resetting the display idle timer.

ES_CONTINUOUSES_CONTINUOUS 0x000000010x00000001 Forces the system to be in the Forces the system to be in the working state by resetting the working state by resetting the system idle timer.system idle timer.

esFlags valuesesFlags values

Page 46: 1 Windows Vista: Developing Power-Aware Applications Pat Stemen FUN319 Program Manager Core Platform Architecture Microsoft Corporation patste@microsoft.com.

46

Appendix: Registering for Windows Appendix: Registering for Windows Power Policy NotificationsPower Policy NotificationsAppendix: Registering for Windows Appendix: Registering for Windows Power Policy NotificationsPower Policy Notifications

RegisterPowerSettingNotificationRegisterPowerSettingNotificationUSER mode, requires message handlerUSER mode, requires message handlerHPOWERNOTIFYHPOWERNOTIFYRegisterPowerSettingNotification(RegisterPowerSettingNotification( IN HANDLE hRecipient,IN HANDLE hRecipient, IN LPCGUID PowerSettingGuid,IN LPCGUID PowerSettingGuid, IN DWORD FlagsIN DWORD Flags ););

ParameterParameter MeaningMeaningReturn ValueReturn Value A handle which is used when de-registering for power setting A handle which is used when de-registering for power setting

notifications concerning this power settingnotifications concerning this power setting

hRecipienthRecipient A handle to the window or service where power setting change A handle to the window or service where power setting change messages should be delivered.messages should be delivered.

PowerSettingGuidPowerSettingGuid A GUID which indicates the power setting for which change notifications A GUID which indicates the power setting for which change notifications should be delivered.should be delivered.

FlagsFlags DEVICE_NOTIFY_WINDOW_HANDLE when the registrant wants messages DEVICE_NOTIFY_WINDOW_HANDLE when the registrant wants messages delivered to a window message pump or delivered to a window message pump or DEVICE_NOTIFY_SERVICE_HANDLE when the registrant requests DEVICE_NOTIFY_SERVICE_HANDLE when the registrant requests notifications to be delivered to a service message handler.notifications to be delivered to a service message handler.

Page 47: 1 Windows Vista: Developing Power-Aware Applications Pat Stemen FUN319 Program Manager Core Platform Architecture Microsoft Corporation patste@microsoft.com.

47

Appendix: Responding to Windows Appendix: Responding to Windows Power Policy NotificationsPower Policy NotificationsAppendix: Responding to Windows Appendix: Responding to Windows Power Policy NotificationsPower Policy Notifications

POWERBROADCAST_SETTINGPOWERBROADCAST_SETTINGlParam of PBT_POWERSETTINGCHANGE lParam of PBT_POWERSETTINGCHANGE eventeventtypedef struct {typedef struct {

GUID PowerSetting;GUID PowerSetting;DWORD DataLength;DWORD DataLength;UCHAR Data[1];UCHAR Data[1];

} POWERBROADCAST_SETTING, *PPOWERBROADCAST_SETTING;} POWERBROADCAST_SETTING, *PPOWERBROADCAST_SETTING;

ItemItem MeaningMeaning

PowerSettingPowerSetting Indicates by GUID the power setting for which this Indicates by GUID the power setting for which this notification is being delivered.notification is being delivered.

DataLengthDataLength The size of the Data element, which contains the new value The size of the Data element, which contains the new value of the power setting.of the power setting.

DataData The buffer containing the new value of the power setting.The buffer containing the new value of the power setting.

Page 48: 1 Windows Vista: Developing Power-Aware Applications Pat Stemen FUN319 Program Manager Core Platform Architecture Microsoft Corporation patste@microsoft.com.

48

Appendix: Unregistering for Appendix: Unregistering for Windows Power Policy NotificationsWindows Power Policy NotificationsAppendix: Unregistering for Appendix: Unregistering for Windows Power Policy NotificationsWindows Power Policy Notifications

UnRegisterPowerSettingNotificationUnRegisterPowerSettingNotificationUSER mode, requires message handlerUSER mode, requires message handler

HPOWERNOTIFYHPOWERNOTIFYUnRegisterPowerSettingNotification(UnRegisterPowerSettingNotification( IN HANDLE hRecipientIN HANDLE hRecipient ););

ParameterParameter MeaningMeaning

Return ValueReturn Value Indicates if the de-registration was successful. Call Indicates if the de-registration was successful. Call GetLastError() for more error detailsGetLastError() for more error details

hRecipienthRecipient The handle returned when registering for power setting The handle returned when registering for power setting notifications using RegisterPowerSettingNotification()notifications using RegisterPowerSettingNotification()

Page 49: 1 Windows Vista: Developing Power-Aware Applications Pat Stemen FUN319 Program Manager Core Platform Architecture Microsoft Corporation patste@microsoft.com.

49

More AvailableFast StartupFast Startup

• 2-3 second resume from 2-3 second resume from ‘sleep’‘sleep’• 10-15 second boot/ disk 10-15 second boot/ disk resumeresume• Simplified UXSimplified UX• Fast offFast off

Power MgmtPower Mgmt• Reliable power state Reliable power state transitionstransitions• Simplified UXSimplified UX• New permissions; Group New permissions; Group PolicyPolicy• Device power managementDevice power management• Hybrid hard drivesHybrid hard drives

ConnectivityConnectivity• Wireless performanceWireless performance• Wireless security & Wireless security & extensibilityextensibility• Group policy supportGroup policy support• Network diagnosticsNetwork diagnostics• Easy network setup, join Easy network setup, join and resource discoveryand resource discovery• VPN-less remote accessVPN-less remote access

SynchronizationSynchronization• PC/PC & PC/server synch PC/PC & PC/server synch • Integrated device synchIntegrated device synch• Performance improvementsPerformance improvements• Sync Center: Consolidated Sync Center: Consolidated UXUX

DisplaysDisplays• External display and External display and projector transitionsprojector transitions• Auto-configuration & restoreAuto-configuration & restore

More Places

Natural Input/OutputNatural Input/Output• ‘ ‘Flicks’ input gesturesFlicks’ input gestures• Pen / shell integrationPen / shell integration• TIP auto-completeTIP auto-complete• Handwriting Handwriting personalizationpersonalization• Ink WatsonInk Watson• Touch screen supportTouch screen support• High DPI support & font High DPI support & font scalingscaling

Context AwarenessContext Awareness• Windows Mobility CenterWindows Mobility Center• Presentation settingsPresentation settings• Smart default printer Smart default printer switchingswitching

Auxiliary DisplaysAuxiliary Displays• Quick access to PIM data, Quick access to PIM data, system statussystem status• Audio playbackAudio playback

SecuritySecurity • HW-enabled file & system HW-enabled file & system protectionprotection

Backup & RecoveryBackup & Recovery• Easy data backup & Easy data backup & restorerestore

More Scenarios

CollaborationCollaboration• Windows Meeting Space: Windows Meeting Space: PC to PC broadcast & file PC to PC broadcast & file sharing within groupssharing within groups• Discovery of nearby Discovery of nearby peoplepeople• Ad hoc wireless Ad hoc wireless networkingnetworking• Networked projectionNetworked projection

Digital InkDigital Ink• Note taking & drawingNote taking & drawing• Search ink notes Search ink notes • Sticky notesSticky notes• Annotating documentsAnnotating documents

Mobile MediaMobile Media• Instant media playbackInstant media playback

Appendix: Mobile PC Pillar Appendix: Mobile PC Pillar DefinitionsDefinitions


Recommended