Your SlideShare is downloading. ×
The Windows Scheduler
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Saving this for later?

Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime - even offline.

Text the download link to your phone

Standard text messaging rates apply

The Windows Scheduler

6,427
views

Published on

An introduction to the Windows Scheduling algorithms with a discussion of its relevance to software developers.

An introduction to the Windows Scheduling algorithms with a discussion of its relevance to software developers.

Published in: Technology

0 Comments
6 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
6,427
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
0
Comments
0
Likes
6
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide
  • Transcript

    • 1. The Windows Scheduler Peter Shirley-Quirk
    • 2. The Windows Scheduler
      • In this presentation we will look at:
        • What the scheduler is
        • How it works
        • Tips for developers
    • 3. What is a scheduler?
      • A scheduler shares out the computer system’s processing resource fairly between all the processes it has to run
      • Types of scheduler
        • Long-term decides whether the system can run any additional jobs/processes
        • Mid-term used to swap out a process
        • Short-term decides which thread is to be executed
    • 4. How does Windows Scheduler work?
      • Scheduling algorithm
        • Managing a queue of threads that are ready to execute
        • Performing context switches and allocating time slices to respond to interrupts that affect which threads are able to run
        • Ensuring that threads get a chance to run
    • 5. When is a thread Ready to run? Figure 3-19, Inside Microsoft Windows 2000, Third Edition by David A. Solomon and Mark E. Russinovich
    • 6. Context switching (1)
      • Context switching happens:
        • At the end of a time slice
        • When a higher priority thread becomes ready e.g. garbage collection thread starts
        • When the currently running thread goes into a wait state
      • To run a thread the processor needs the full context
        • registers
        • stack (user and kernel)
        • environment
    • 7. Context switching (2)
      • To switch context the scheduler:
        • Saves the context for the executing thread
        • Places that thread at the end of the queue for its priority
        • Finds the highest priority queue that contains ready threads
        • Removes the thread at the head of the queue, loads its context, and executes it
    • 8. Process Priority Classes The Process Priority Class is under the designer’s control Can be read or set using System.Diagnostics.Process.PriorityClass AboveNormal Time-critical tasks that must be executed immediately e.g. the Task List dialog High BelowNormal E.g. multimedia applications RealTime E.g. screen saver, indexer etc. Idle No special scheduling needs. Normal
    • 9. Where does the priority come from?
      • The thread’s base priority is based on several factors
        • Process Priority Class
        • Thread Priority Level
        • Foreground / background
      • These combine to give the Thread’s Base Priority
      • The dynamic priority can be boosted by the scheduler
    • 10. When does the scheduler boost the priority?
      • Avoiding starvation
        • To prevent a high priority task from completely blocking a lower priority task the latter will be given a priority boost
      • Avoiding choking
        • CPU bound vs. IO bound – burst characteristics
        • A CPU bound thread can choke resources from an IO bound thread – perceived as poor responsiveness from mouse or keyboard
    • 11. Resolving priority inversion
      • Thread A, a low-priority thread, is executing code in a critical section (lock).
      • Thread B, the high-priority thread, begins waiting for a shared resource (e.g. the lock) from thread A.
      • Thread C has medium priority. Thread C receives all the processor time
      • Scheduler boosts priority of A so that it can exit the lock
      A B C Wait Ready Time Priority A
    • 12. What if there’s more than one processor?
      • The system uses a SMP model to schedule threads on multiple processors
        • Any thread can be assigned to any processor
        • The system schedules threads to run concurrently
        • You can influence the scheduler
          • Thread Affinity
          • Thread Ideal Processor
    • 13. Multi-Processor Architecture
      • Hyperthreading
        • 2 virtual processors but sharing some processor resources – consider using thread affinity
      • Intel Dual-core
        • Sharing onboard cache – thread affinity
      • AMD dual core
        • Treat as independent processors
      • The future: 4-way, 8-way
        • Design for parallel processing
    • 14. Some final thoughts
      • Designing for concurrency
        • Take advantage of multiple processors
        • Aim to blend CPU and IO work
      • Know your synchronization mechanisms
        • Design to avoid deadlock
        • Keep locks private and short
      • Be aware of Garbage Collection in .NET
        • Usually quick, occasionally quite slow
    • 15. More information
      • http://msdnwiki.microsoft.com
        • Managing Processes Sample 
        • System.Diagnostics namespace 
          • Process
          • ProcessThread
        • System.Threading namespace 
          • Thread