Kim Shearer Senior Program Manager Microsoft Corporation SESSION CODE: DPR308.

39
The Efficiency Imperative: The Importance of Making Your Applications “Energy Smart” Kim Shearer Senior Program Manager Microsoft Corporation SESSION CODE: DPR308

Transcript of Kim Shearer Senior Program Manager Microsoft Corporation SESSION CODE: DPR308.

Page 1: Kim Shearer Senior Program Manager Microsoft Corporation SESSION CODE: DPR308.

The Efficiency Imperative: The Importance of Making Your Applications “Energy Smart”Kim ShearerSenior Program ManagerMicrosoft Corporation

SESSION CODE: DPR308

Page 2: Kim Shearer Senior Program Manager Microsoft Corporation SESSION CODE: DPR308.

AgendaThe growing importance of IT efficiency initiatives The role of applications in IT efficiencyFirst steps towards Energy Smart Applications

Page 3: Kim Shearer Senior Program Manager Microsoft Corporation SESSION CODE: DPR308.

IT, We Have a Problem

Increasing IT Footprint

Decreasing ProductivityRising Costs

Continual Demand for

New Services

Traditional Application Architecture

Typical Operational

Practices

Inefficient IT

Page 4: Kim Shearer Senior Program Manager Microsoft Corporation SESSION CODE: DPR308.

And, It Gets Worse

Increasing IT Footprint

Decreasing ProductivityRising Costs

Stressed Power

Systems

Page 5: Kim Shearer Senior Program Manager Microsoft Corporation SESSION CODE: DPR308.

And Worse Still…

Increasing IT Footprint

Decreasing ProductivityRising Costs

Increasing IT Power• Increasing Regulatory

attention• Shareholder & NGO Scrutiny• Power Constraints & Outages

• Grid• Local

Stressed Power

Systems

Page 6: Kim Shearer Senior Program Manager Microsoft Corporation SESSION CODE: DPR308.

The Goal

Increasing IT Footprint

Decreasing ProductivityRising Costs

Manageable Service

Demands

Smart Application Resource

Use

New Operational

Practices

Stressed Power

SystemsEfficient IT

Page 7: Kim Shearer Senior Program Manager Microsoft Corporation SESSION CODE: DPR308.

The Evolution of IT Fundamentals

Reliable

Reliable & Secure

Reliable, Secure & Efficient

Page 8: Kim Shearer Senior Program Manager Microsoft Corporation SESSION CODE: DPR308.

IT Power Reduction Opportunities

Increase Server UtilizationCentralized PC Power Management

RightsizingEfficient Power SupplyRemove Unnecessary Components

Energy Efficient & Aware Applications

Platform Power Management

Low-power components

Building

Management Infrastructure

Hardware Package

Applications

Operating System

Silicon

Improve Data Center PUEIncrease Facility Utilization

Energy Efficient & Aware Applications

Page 9: Kim Shearer Senior Program Manager Microsoft Corporation SESSION CODE: DPR308.

Impacts of software-related inefficiencies

Client• Reduced battery life – important user feature• Cost of system insomnia (additional cost to enterprises)• Poor user experience (laptop as bag warmer)

Cloud• Less effective virtualization/consolidation• More servers - Increased Capex/Opex/disposal• Stressed power and cooling systems

Page 10: Kim Shearer Senior Program Manager Microsoft Corporation SESSION CODE: DPR308.

Platform Power Management

Enables transition to a low power mode while saving OS and application state

Allows active system to reduce power needs without negatively impacting user productivity

Provides users and administrators with controls to save energy

Page 11: Kim Shearer Senior Program Manager Microsoft Corporation SESSION CODE: DPR308.

Whose Job is this Anyway?

Hardware

OSApplications

Power EfficientSystem

Page 12: Kim Shearer Senior Program Manager Microsoft Corporation SESSION CODE: DPR308.

Welcome to the Party, Applications!

“Energy Smart” Application

Allows the system to reduce

power when possible

Respects user preferences to

save energy

Responds to system state and

power source changes

Page 13: Kim Shearer Senior Program Manager Microsoft Corporation SESSION CODE: DPR308.

The first steps

Client Code

• Verify system sleep and display power management behavior

Server Code

• Measure application energy consumption• Establish goals and a schedule for improvement

All Code

• Detect and analyze timer resolution changes• Encourage use of timer coalesce

Page 14: Kim Shearer Senior Program Manager Microsoft Corporation SESSION CODE: DPR308.

System sleep & display power management Sleep uses 1/10 or less power of active idleGetting better each generation of hardwareSignificant cost savings - http://www.energystar.gov/index.cfm?c=power_mgt.pr_power_mgt_low_carbon

SoDon’t cause insomniaDo use availability requests intelligentlyBehave well around sleep transitions

Verizon 185,000 PCs $7 million savings

FedEx 20,000 PCs $1 million savings

Page 15: Kim Shearer Senior Program Manager Microsoft Corporation SESSION CODE: DPR308.

Availability request APIsAvailability request API methods

These can be used to:Prevent display power management dimming the screenPrevent display power management turning off the screenPrevent the system entering automatic sleepEnable away mode (intended for media systems)

Function name DescriptionPowerCreateRequest Creates a power context object and returns a handle to it.PowerClearRequest Removes an outstanding availability request on a particular request context objectPowerSetRequest Activates a power availability request and indicates the type of request.

Page 16: Kim Shearer Senior Program Manager Microsoft Corporation SESSION CODE: DPR308.

Accidental insomniaLook carefully at any availability requests you raise

Don’t prevent sleep unless it is criticalDon’t prevent sleep for a system on battery unless it is really critical

If a task will require preventing sleep, but was not user initiated, should you start it on battery?Be aware of indirect PA requests you may cause

Open file shares?Audio stack open?Other libraries

Page 17: Kim Shearer Senior Program Manager Microsoft Corporation SESSION CODE: DPR308.

Debugging insomniaPowercfg /requests

Additional energy efficiency information with Powercfg /energy

C:\Windows\system32>powercfg /requestsDISPLAY:None.

SYSTEM:[SERVICE] \Device\HarddiskVolume2\Windows\System32\svchost.exe (RasMan)Active RAS connection

AWAYMODE:None.

Page 18: Kim Shearer Senior Program Manager Microsoft Corporation SESSION CODE: DPR308.

Passive Interaction ScenariosDo use an availability request in passive viewing or listening scenariosIf rendering user-initiated video in foreground keep screen awakeIf not actively rendering to the screen or in the background, clear the availability request e.g.

Played to end of videoPausedHidden tab in browserInactive/hidden window

Page 19: Kim Shearer Senior Program Manager Microsoft Corporation SESSION CODE: DPR308.

Sleep/Resume Transition BehaviorDo return from sleep in a “reasonable” mannerAllow system to be responsive – don’t hog resources on wakeMake sure application is responsiveForced sleep has no veto, make sure you handle thisPwrTest tool helps in testing these scenarios

http://msdn.microsoft.com/en-us/library/ff550682(VS.85).aspx

Many parameters including – cycles, duration, sleep state, critical…PwrTest /sleep /c:10 /s:rnd /d:180 /p:600

Page 20: Kim Shearer Senior Program Manager Microsoft Corporation SESSION CODE: DPR308.

Timer resolutionDefault resolution is 15.6msMaximum resolution is 1ms1ms can increase power consumption by 20%!Which decreases battery run time by 20%!1. Try to be event or interrupt driven2. Use least resolution that is good enough3. Set high resolution only when you need itAggressively reset resolution to default

Play back is pausedTab is not active in browserScreen is dimmed or sleeping…

Page 21: Kim Shearer Senior Program Manager Microsoft Corporation SESSION CODE: DPR308.

Application Design PrinciplesOptimize Resource Consumption

WaitForSingleObjectEx() or SleepEx() APIsAllows you to wait for many different types of objects, I/O Completions, or APCs

void EatBatteryLife(){

HANDLE sharedResource = NULL;

//spawn multiple threads, one of which does this:while (sharedResource == NULL){

waitTime++;Sleep(1);//or just keep spinning on a lock or mutex

}}

DO NOT DO THIS

Page 22: Kim Shearer Senior Program Manager Microsoft Corporation SESSION CODE: DPR308.

Application Design PrinciplesEvent Driven Example

//thread 1’s codevoid UpdateSharedResource() { //set sharedResource sharedResource = UpdateResource();

//Set sharedResourceIsReadyEvent to signaled SetEvent(sharedResourceIsReadyEvent);}

/thread 2's codevoid ConsumeSharedResource() {

DWORD dwWaitResult;

dwWaitResult = WaitForSingleObject( sharedResourceIsReadyEvent, INFINITE); // indefinite wait

switch (dwWaitResult) { case WAIT_OBJECT_0: // // TODO: use sharedResource // break;

default: return 0; }}

Page 23: Kim Shearer Senior Program Manager Microsoft Corporation SESSION CODE: DPR308.

Timer Coalesce - Increasing idle periods

Allows grouping of scheduled timer eventsLonger idle periodsExtending Idle periods will be more critical to energy efficiency on future platforms

Windows 7

VistaTimer tick15.6 ms

Periodic Timer Events

Windows 7

Windows Vista

Page 24: Kim Shearer Senior Program Manager Microsoft Corporation SESSION CODE: DPR308.

Application Design PrinciplesCoalesce Activity

SetWaitableTimerEx() APIYou should replace calls to SetWaitableTimer() with calls to this APIMore efficient than a purely periodic timerHas a tolerance parameter that should scale with the timer period

BOOL WINAPI SetWaitableTimerEx( __in HANDLE hTimer, __in const LARGE_INTEGER *lpDueTime, __in LONG lPeriod, __in_opt PTIMERAPCROUTINE pfnCompletionRoutine, __in_opt LPVOID lpArgToCompletionRoutine, __in_opt PREASON_CONTEXT WakeContext, __in ULONG TolerableDelay );

Page 25: Kim Shearer Senior Program Manager Microsoft Corporation SESSION CODE: DPR308.

Application Design PrinciplesCoalesce Activity

void CreateAndSetPeriodicTimer(){

myTimer = CreateWaitableTimerEx(NULL,TimerName, //string with chosen timer nameNULL,TIMER_MODIFY_STATE); //required security attribute to call

//SetWaitableTimerEx

bError = SetWaitableTimerEx(myTimer,DueTime, //UTC due time10000, //periodic timer duration is ten secondsCompletionRoutinePointer, //APC completion routineArgsToCompletionRoutine, //completion routine argumentsWakeContext, //only if waking the machine1000); //tolerable delay is one second

//DO WORKbError = CancelWaitableTimer(myTimer); //be sure to cancel periodic timers!

}

Page 26: Kim Shearer Senior Program Manager Microsoft Corporation SESSION CODE: DPR308.

Measuring power consumptionPerformance tests are usually about extreme loadMost opportunities for PPM energy savings are at low to medium loadHow efficient is your product at low load levels?Measure increase in idle power for install of your productMeasure at multiple load levels: idle, 25%, 50%, 100% back to idleTrend these over timeSet a goal for increased efficiency

Page 27: Kim Shearer Senior Program Manager Microsoft Corporation SESSION CODE: DPR308.

Effect of Timer Resolution (end of 08)

0.00% 10.00% 20.00% 30.00% 40.00% 50.00% 60.00% 70.00% 80.00% 90.00% 100.00%40.00%

50.00%

60.00%

70.00%

80.00%

90.00%

100.00%

Scaled Power vs. Throughput (Run1)

OOB1ms

Throughput (% of max SSJ_Ops)

Pow

er (%

of M

ax W

atts)

Page 28: Kim Shearer Senior Program Manager Microsoft Corporation SESSION CODE: DPR308.

Register for Power EventsUse RegisterPowerSettingNotification to register for power eventsReceive PBT_POWERSETTINGCHANGE notifications with

WM_POWERBROADCAST messages for interactive applicationsThrough the HandleEX callback registered with RegisterServiceCtrlHanderEx for service applications

PowerEvent monitoring tool provides example code

Page 29: Kim Shearer Senior Program Manager Microsoft Corporation SESSION CODE: DPR308.

Register for Power Events

//// Register for Power Setting Notifications. //// The RegisterPowerSettingNotification API returns a handle to the // registration which we cache in a local variable so that we can // unregister when the window is closed. We also do the registration here// because it is explicitly obvious that the dialog is initialized and the // handle to the window is valid. //hPowerPersonality = RegisterPowerSettingNotification(m_hWnd,

&GUID_POWERSCHEME_PERSONALITY, DEVICE_NOTIFY_WINDOW_HANDLE);

hBatteryPercentage = RegisterPowerSettingNotification(m_hWnd, &GUID_BATTERY_PERCENTAGE_REMAINING, DEVICE_NOTIFY_WINDOW_HANDLE);

hACDCSource = RegisterPowerSettingNotification(m_hWnd, &GUID_ACDC_POWER_SOURCE, DEVICE_NOTIFY_WINDOW_HANDLE);

Page 30: Kim Shearer Senior Program Manager Microsoft Corporation SESSION CODE: DPR308.

Listen and Take Action

//Custom handler for processing WM_POWERBROADCAST messagesLRESULT CPowerMonDlg::OnWMPowerBroadcast(WPARAM wParam, LPARAM lParam){

… switch(LOWORD(wParam)) {

case PBT_POWERSETTINGCHANGE:// // This is the type of message sent by the power manager when a// power event such as a power plan personality or a system power source// change event occurs. We need to take the // POWERBROADCAST_SETTING struct pointed to by the lParam and // analyze it to determine what setting changed.//

PowerMessageSetting = (PPOWERBROADCAST_SETTING)lParam;

if (IsEqualGUID(PowerMessageSetting->PowerSetting, GUID_POWERSCHEME_PERSONALITY) && PowerMessageSetting->DataLength == sizeof(GUID)) {

// // This is a powerscheme personality change. // Determine power scheme, then take appropriate actions // PowerMessageGUID = *(GUID*)PowerMessageSetting->Data; if (IsEqualGUID(PowerMessageGUID, GUID_TYPICAL_POWER_SAVINGS)){ // Balanced

Page 31: Kim Shearer Senior Program Manager Microsoft Corporation SESSION CODE: DPR308.

Success Stories

SQL Server 2008 R2

• Avoided use of 1ms timer resolution

Adobe Flash 10.1 Release Candidate

• Power Availability Requests• Indirect (close audio channel on multi-media pause)• Direct (prevent display dimming when playing video in visible window)

• Contextual timer resolution changes• Default when loaded doing nothing or paused• 1ms only when rendering video

• Frame-rate throttling• Drop video to 2fps when rendering video in hidden window

Page 32: Kim Shearer Senior Program Manager Microsoft Corporation SESSION CODE: DPR308.

ToolsPowercfg – detect many power efficiency issues and modify power plans

http://www.microsoft.com/whdc/system/pnppwr/mobile_bat_Win7.mspxPwrtest – test sleep and resume behavior

http://msdn.microsoft.com/en-us/library/ff550682(VS.85).aspxPowerEvent monitoring tool – example app

http://www.microsoft.com/whdc/system/pnppwr/powermgmt/PM-apps_samp.mspx

Page 33: Kim Shearer Senior Program Manager Microsoft Corporation SESSION CODE: DPR308.

Future considerationsBe more aware of conserving power on batteryOn Power Saver think about saving power at the cost of performanceCore parking – avoid core affinityThe better processors get at saving power at idle, the more you have to lose by not getting to and staying at idle

Page 34: Kim Shearer Senior Program Manager Microsoft Corporation SESSION CODE: DPR308.

Call to ActionDownload and read the guidanceExplore the toolsTest your applications for appropriate use of:

Timer resolution changes (client and server apps)Direct and Indirect Power availability requests (client apps)

For client apps, ensure:Good behavior after sleep/resume transition

For client and server apps, plan for:Mobile power source changes or server power cappingIncreasing power savings at idle – get to idle and stay at idleWorking effectively with PPM

Page 35: Kim Shearer Senior Program Manager Microsoft Corporation SESSION CODE: DPR308.

Resources

www.microsoft.com/teched

Sessions On-Demand & Community Microsoft Certification & Training Resources

Resources for IT Professionals Resources for Developers

www.microsoft.com/learning

http://microsoft.com/technet http://microsoft.com/msdn

Learning

Page 36: Kim Shearer Senior Program Manager Microsoft Corporation SESSION CODE: DPR308.

Complete an evaluation on CommNet and enter to win!

Page 37: Kim Shearer Senior Program Manager Microsoft Corporation SESSION CODE: DPR308.

Sign up for Tech·Ed 2011 and save $500 starting June 8 – June 31st

http://northamerica.msteched.com/registration

You can also register at the

North America 2011 kiosk located at registrationJoin us in Atlanta next year

Page 38: Kim Shearer Senior Program Manager Microsoft Corporation SESSION CODE: DPR308.

© 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to

be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Page 39: Kim Shearer Senior Program Manager Microsoft Corporation SESSION CODE: DPR308.

JUNE 7-10, 2010 | NEW ORLEANS, LA