Improving power efficiency for applications

AWS

Owner
FPCH Owner
Joined
Nov 19, 2003
Messages
10,976
Location
Florida U.S.A.
Minimizing the power consumption of your PC while maximizing the responsiveness and utility (making it fast and fluid), is a significant engineering challenge. While it starts with the work we do in Windows to provide support for the right level resource usage, this work requires developers to take resource utilization into account as they develop their apps. Power efficiency applies to all form factors and all usage scenariosusing less power is the right thing to do for everyone. This is an area of significant innovation for Windows 8 PCs, and builds on the foundation of the new runtime model in WinRTit is not the sort of thing you can retrofit onto existing desktop applications while still maintaining functionality and compatibility. Much like state migration and setup that we talked about earlier, power consumption is an area of Windows that has been reimagined for new scenarios. With your existing x86-based PC, all of the existing support is still there, and all of the work you do on the desktop continues exactly as it has before (and of course, has been improved, as we have seen). As we see new hardware across all supported SoC hardware (including Intel) this level of power efficiency will be more broadly available. Though we will discuss some of the work weve done to improve the power consumption of desktop apps, to enable the all-day, always-connected scenarios were going to see new apps written to WinRT that run on a new generation of hardware that supports new power management capabilities.
Sharif Farag and Ben Srour, lead program managers on the Fundamentals and User Experience teams respectively, authored this post.
--Steven

<hr />
Weve featured several posts about how were working to improve battery life for Windows 8 PCs. In Pat Stemens
What about background copy jobs. If I put explorer application to background to look [at or] write a word document, do you mean the copy-job is paused until I "fullscreen" the copy-job again? Seriously?
[/quote]
The answer to that question is no, file copy will definitely continue to work exactly as it does today and will not get suspended if you start a copy job and then go do something else while it completes in the background. This works the same whether you are in front of the PC using it or leave the PC long enough for the screen saver or lock screen to kick in. Suspension of inactive apps only applies to Metro style apps, not to basic OS functions like copying files.
Focus on the foreground
For Windows 8, we started off with a rule that would apply to the large majority of Metro style apps: if an app is not on screen, and the screen is not on, it should not impact your battery life. That doesnt mean WinRT and the user model preclude multi-tasking. Theres a new way of thinking about how and when code takes into account modern hardware capabilities, networking demands, form factors, and reliability/security/privacy. There are going to be some exceptions (e.g. background email syncing, desktop tools), but for the majority of cases, we expect the app to do most of its work while you are actively interacting with it. When an app is not in the foreground, we wanted to ensure that it would either suspend completely, or use limited resources based on a set of common background capabilities (like copying files), which the app can access.
So basically, this means that an app can be in one of three possible states:
  • Actively running in the foreground
  • Suspended in the background
  • Performing some defined background activity
<h5>Actively running in the foreground</h5>
The foreground app actively running is pretty easy, as we just let it run and utilize CPU, disk, memory, and other resources as needed. In this way, Metro style apps are essentially the same as Windows applications have always been. This includes both the case where a single app is full screen, as well as when two apps are on screen with one of them snapped to the side. This applies only when the screen is on, since it means the user is interacting with the PC.
There are a lot of new factors to consider in developing fast and responsive apps. Much like the transition from character to GUI programming, where concepts were substantially different, building apps that are respectful of power and resource consumption requires some new approaches. As an example, early Windows programmers were sometimes frustrated by the notion of a WNDPROC and felt that the best way to handle typing was by trapping the interrupt and translating the key pressthe message-based approach inverted this, and Windows handled the translation and let your app know when to worry about the key press, which was quite different from the earlier way of doing things. In a world where 75% or more of the PCs sold are battery powered, programmers are, by definition, being asked to rethink how to get work done again.
Given this, it is important to think about app development in a forward-looking manner that keeps pace with and plans for the evolution of hardware and customer needs. The existing application model needed to evolve in order to yield the power savings and battery life that customers want. Of course, as we keep saying, desktop applications that you currently have will work exactly like they do on Windows 7 today (and were even improved in many dimensions). But over time, were equipping Windows to get more done and use less power, with new applications that help you get that work donefrom entertainment to professional tools and everything in between. The resources available to compute, the resources required, and the types of computation done are changing, and Windows 8 is providing new facilities to tap into this opportunity.
In a foreground-based approach, concurrency becomes a big part of how to develop fast, fluid, and responsive apps. Metro style apps get suspended in the background[/b]
<h5>Performing background activities</h5>
As weve already discussed, developers need to think of how work that was previously done in the background can still be accomplished without impacting battery life. It is easy to ask for multitasking and just enable it, but the downside of this is that if all your apps are always running background tasks then you will never achieve long (or even improved) battery life. In a mobile and constantly connected world of laptops, this is incredibly important. So with Windows 8 and WinRT, we created new APIs to cover
[*]Playing music
[*]Downloading a file from or uploading it to a website
[*]Keeping live tiles alive with fresh content
[*]Printing
[*]Receiving a VoIP call
[*]Receiving an instant message
[*]Receiving an email
[*]Sharing content (like uploading photos to Facebook)
[*]Synchronizing content with a tethered device (like syncing photos)
[/list]
This set of scenarios is based on common patterns used by developers and common patterns we expect to see. Some of these scenarios end up using the same platform affordance, so lets walk through each of them, so you can understand the landscape and power of Windows 8:


<tbody>


Scenario


Description




Background download or upload


Accessing and storing content on the Internet is a pretty common scenario for apps. We want you to always have the freshest content already loaded as soon as you switch back to your app. This will be particularly helpful with magazine or news-based apps. Apps can use the new Connected standby and sleep-capable machines[/size]
By the time Windows 8 is released, there will be a broader range of PCs available than ever before. Many of these will have similar power options to those running Windows 7 today. Besides turning off completely, they will be able to go into a sleep state, either on demand, or after a period of inactivity. During sleep, all system activity is completely suspended.
Application execution on PCs that are sleep-capable (default settings)[/b]
The chart above shows how, as the PC idles just prior to sleep, desktop apps continue to run in the same way as they have in prior versions of Windows, while Metro style apps run in the managed way I described earlier. When the PC goes to sleep, both desktop apps and Metro style apps are fully suspended. This is great for battery lifewhen the machine is asleep, it consumes very little power. Its not as great for a data-freshness though, since when the machine is asleep, it isnt getting live tile updates, downloading new mail, or getting ready to alert you with alarms or other notifications.
As Pat covered in his post, weve enabled a new smartphone-like power state for a new class of PCs that rarely get turned off completely. Typically based on System on Chip (SoC) architectures, these PCs are interesting because instead of turning off during periods of inactivity they go into a very low power state while still running. This new state is referred to as connected standby. This enables some great connected scenarios, such as always having email up-to-date, and being able to receive instant messages or phone calls, while still delivering amazing battery life. The chart below shows behavior for both desktop and Metro style apps during connected standby. For this to really work effectively though, we had to consider both Metro style apps (which, as you saw earlier, we can very effectively ensure are conservative with system resources), as well as desktop applications, which presented a tougher challenge because they have been designed over the years to expect either full access to system resources (when running in the fore or background) or no access (when the PC is asleep.)
Application execution on PCs that have connected standby[/b]
To this end, we have added a new component to Windows 8 called the Desktop Activity Moderator, which only runs on these new connected standby-capable platforms. This component is designed to help reduce the resource utilization of desktop apps when the device goes into connected standby. If we allowed apps to continue running unchecked in this low-power mode, the PC would run down the battery more quickly. Instead, we suspend desktop applications, stopping their resource use and maximizing battery life. From the applications perspective, it will appear as if the PC has simply been put to sleep. When the PC is woken from connected standby, the app will resume as if the PC had been woken from a sleep state.
However, there are actually several components on the system that are required for connected standby, which we cannot suspend. These include drivers, some inbox and 3<sup>rd</sup> party services, and of course, the Metro style apps that use the background features mentioned earlier. Many of these provide functionality such as responding to user input when you return to your device, or providing network functionality. We enable these to run in connected standby after careful evaluation to ensure they do not have a significant impact on battery life. In addition, there are a set of processes that need to run in response to activity on the system. These processes are throttled to only run for short periods of time until a background activity is initiated, at which point they are allowed to run unimpeded. A great example of this is an antivirus product, which is often scanning in response to activity on the system. When there is background activity occurring such as receiving an incoming email via the background affordances, antivirus can run unimpeded during this time. But during the majority of the time when incoming network activity is not occurring, there is very minimal activity and therefore these components will be throttled to minimize their impact on battery life.
Summary
As you can see, we have made significant investments in engineering Windows 8 to be great for battery life. We engineered the new application model to deliver consistently long battery life while enabling connected experiences. Applications that were designed for Windows 7 will continue to work as they have before with no change in behavior, and new Metro style apps can be developed to enable new connected experiences that work in a more power-efficient manner, by taking advantage of the background infrastructure that the operating system provides.
-- Sharif Farag and Ben Srour
108621b6fde7e64e5a40feaa079a0b15._.gif


Source: Windows 8 Blog
 
Last edited:
Back
Top