windows 7 designing efficient background processes l.
Skip this Video
Loading SlideShow in 5 Seconds..
Windows 7: Designing Efficient Background Processes PowerPoint Presentation
Download Presentation
Windows 7: Designing Efficient Background Processes

Loading in 2 Seconds...

play fullscreen
1 / 27

Windows 7: Designing Efficient Background Processes - PowerPoint PPT Presentation

  • Uploaded on

PC 19. Windows 7: Designing Efficient Background Processes. Vikram Singh Program Manager Microsoft Corporation. Agenda. Introduction Choosing the Right Model Windows 7 Trigger-Start Services Task Scheduler Conditions and Triggers Security and Performance Recommendations.

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
Download Presentation

PowerPoint Slideshow about 'Windows 7: Designing Efficient Background Processes' - daniel_millan

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
windows 7 designing efficient background processes


Windows 7: Designing Efficient Background Processes

Vikram Singh

Program Manager

Microsoft Corporation

  • Introduction
  • Choosing the Right Model
  • Windows 7 Trigger-Start Services
  • Task Scheduler Conditions and Triggers
  • Security and Performance Recommendations
what is background activity
What Is Background Activity?
  • System activity that is not directly initiated by user
    • Services, Scheduled tasks, some COM processes such as a COM service, WMI providers, etc.
  • Part of nearly every usage scenario:
    • Search indexing
    • System security and maintenance
    • Network management
    • Device management
    • System configuration
impact of background activity


    • Responsiveness to the user
    • Consumes resources from foreground applications
    • Boot, Shutdown, Logoff, etc.
  • Reliability
    • Memory leaks
    • System crashes, hangs
    • Dependent application crashes
Impact Of Background Activity
  • Security
    • Activity may require system privileges
    • Successful attack may compromise entire system
  • Power Consumption
    • Extra disk, CPU utilization
    • Decrease in battery life
    • Prevents idle efficiencies
impact of background activity5
Impact Of Background Activity
  • Internal evaluation of 49 Windows services
    • Not critical for boot and login
    • Critical and required for their individual scenarios
background activity performance impact
Background Activity Performance Impact
  • Compared IT image to clean Windows Vista installation:
    • 10 additional 3rd-party services
designing for efficiency
Designing For Efficiency
  • Choose the right model
    • Windows Service or Scheduled Task?
  • Leverage the latest Windows infrastructure
    • Trigger-Start Services for Windows 7
  • Make performance optimizations
  • Eliminate unnecessary privileges
  • Evaluate and measure
  • Iterate (step 1)
services and scheduled tasks
Services And Scheduled Tasks
  • Continuous activity from boot to shutdown
  • Service Control Manager (SCM) programming model
  • Can specify dependency
  • Short duration action
  • Idle activity
  • Take action on user login
  • Standalone executable or out-of-process COM server
  • Generally execute in user session
  • Windows Service
  • Scheduled Task
windows services auto start
Windows Services: Auto_Start
  • Auto_Startstart type enables the service to launch at boot and never terminate
  • Most common service start type
    • Easy for developers—service is always running!
  • Problems
    • Startup time adds to boot time
    • Adds to system base “footprint”
    • Many Auto_Start services wait for rare events
w i ndows 7 trigger start services
Windows 7: Trigger-Start Services
  • Trigger-Start centralizes environmental detection logic
    • SCM registers for system events via interesting providers:
      • Device arrival
      • IP address
      • Domain join and leave
      • Group policy updates
      • Custom ETW (Event Tracing for Windows) events
    • SCM starts or stops registered services:
      • Examples:
        • TabletInputService started only if digitizer is present
        • StorSvc starts when group policy updates are applied, automatically stops
service shutdown
Service Shutdown
  • Self-stop the service
    • Immediately or after pre-determined idle time when task is complete if Trigger-StartorDemand_Start
  • System shutdown
    • Do not set SERVICE_ACCEPT_SHUTDOWN unless required
    • No need to free memory if the service is in a standalone process
    • Target less than 200ms for completing shutdown notification
service control handler
Service Control Handler
  • No blocking calls!
    • WaitForSingleObject, CreateFile, RPCs, etc.
    • Strive for lock-free code
  • Execute work items in a thread pool
  • Follow the MSDN guidelines for specific return codes
    • Call SetServiceStatus(SERVICE_STOP_PENDING)
    • Post stop work to a thread pool
    • Order is key!
service security
Service Security
  • [DllImport(“advapi32.dll”, SetLastError=true)]
  • Public static extern bool ChangeServiceConfig2(
  • IntPtrhService,
  • uint32dwInfoLevel,
  • IntPtrlpInfo
  • );
  • // Example UPS Service
  • protected override void OnStart (string[] args)
  • {
  • IntPtrServiceHandle;
  • IntPtrRequiredPrivilegesString;
  • // set required privileges
  • string RequiredPrivileges = “SeShutdownPrivilege\0\0”;
  • RequiredPrivilegesString = Marshal.StringToHGlobalAuto(RequiredPrivileges);
  • ChangeServiceConfig2(
  • this.ServiceHandle,
  • RequiredPrivilegesString
  • );
  • }
  • Run in the least privilege required
    • LocalService/NetworkService
    • Avoid LocalSystem
  • Remove unneeded privileges
    • E.g., SeImpersonatePrivilege
  • Express required privileges
    • SCM automatically removes all others
scheduled task example
Scheduled Task Example
  • Power Efficiency Diagnostics
    • Windows 7 power problem analysis
    • Executes every 2 weeks when the system is idle
    • Requires SYSTEM privilege to access NT Kernel Logger
    • Saves report data for user
    • Uploads CEIP data to Microsoft


Detects Idle Condition

Task Scheduler


Launches Task

Power Efficiency Diagnostics


task triggers
Task Triggers
  • Calendar
  • Boot
  • Logon
  • Idle
  • Event log based entry
  • Workstation lock
  • Workstation unlock
task conditions
Task Conditions
  • Idle condition
  • Stop when not idle
  • AC power only
  • Stop on battery
  • Wake computer from sleep
  • Specific or any network connection
task recommendations
Task Recommendations
  • Use the idle condition to prevent background activity from interrupting the user
  • Enable the Power condition—do not run when the system is on battery
  • Enable the Network condition if the task requires network connectivity
    • E.g., download software update
performance and power
Performance And Power
  • Performance is critical for background activity
    • Adds to the base footprint of the system
    • Interferes with foreground user activity
    • Resource utilization directly tied to Power Consumption
  • Target:
    • Less than 2% CPU activity when the system is idle
    • No disk activity when the system is idle
  • Evaluate and Measure:
    • Use XPerf (Windows Performance Tools Kit)
call to action
Call To Action
  • Understand that background activity has tangible impact on system quality
  • Select the right model: service or task
  • Use Windows 7 Trigger-Start instead of Auto_Start
  • Configure your service to use the smallest set of security privileges
  • Leverage scheduled task idle, power and network conditions
  • Use Windows Performance Tools Kit (XPerf) to measure
additional resources
Additional Resources
  • Developing Efficient Background Processes for Windows
  • Services in Windows Vista
  • Service Control Manager [MSDN]
  • Task Scheduler
  • Windows Performance Tools Kit
evals recordings
Evals & Recordings

Please fill out your evaluation for this session at:

This session will be available as a recording at:


© 2008 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.