Kim Shearer Senior Program Manager Microsoft Corporation SESSION CODE: DPR308.
-
Upload
erik-mosley -
Category
Documents
-
view
217 -
download
2
Transcript of 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
AgendaThe growing importance of IT efficiency initiatives The role of applications in IT efficiencyFirst steps towards Energy Smart Applications
IT, We Have a Problem
Increasing IT Footprint
Decreasing ProductivityRising Costs
Continual Demand for
New Services
Traditional Application Architecture
Typical Operational
Practices
Inefficient IT
And, It Gets Worse
Increasing IT Footprint
Decreasing ProductivityRising Costs
Stressed Power
Systems
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
The Goal
Increasing IT Footprint
Decreasing ProductivityRising Costs
Manageable Service
Demands
Smart Application Resource
Use
New Operational
Practices
Stressed Power
SystemsEfficient IT
The Evolution of IT Fundamentals
Reliable
Reliable & Secure
Reliable, Secure & Efficient
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
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
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
Whose Job is this Anyway?
Hardware
OSApplications
Power EfficientSystem
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
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
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
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.
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
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.
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
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
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…
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
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; }}
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
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 );
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!
}
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
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)
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
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);
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
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
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
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
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
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
Complete an evaluation on CommNet and enter to win!
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
© 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.
JUNE 7-10, 2010 | NEW ORLEANS, LA