Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Inside the Windows NT Scheduler, Part 1 Assigning CPU time in a uniprocessor environment by Mark Russinovich Windows NT Magazine - July 1997 Inside the.

Similar presentations


Presentation on theme: "1 Inside the Windows NT Scheduler, Part 1 Assigning CPU time in a uniprocessor environment by Mark Russinovich Windows NT Magazine - July 1997 Inside the."— Presentation transcript:

1 1 Inside the Windows NT Scheduler, Part 1 Assigning CPU time in a uniprocessor environment by Mark Russinovich Windows NT Magazine - July 1997 Inside the Windows NT Scheduler, Part 2 Multiprocessor scheduling decisions can affect NT’s scalability by Mark Russinovich Windows NT Magazine - August 1997 Presented by: Jack McCrorey

2 2 Main Topics Windows NT Scheduler on Uniprocessor system Windows NT Scheduler on Multiprocessor systems Options, Tradeoffs, and techniques Unusual Consequences Final thoughts

3 3 Windows NT Scheduling Basic scheduling unit is a Thread A thread is an executable entity that runs in the address space of a process Priority based scheduling Preemptive operating system No shortest job first, no quotas

4 4 Priority Levels Priorities are assigned to Threads Priorities are from 0 to 31 –31 is the highest; 0 is system idle thread –Realtime priorities: 16 - 31 –Dynamic priorities: 1 - 15

5 5 Priority Assignment NT kernel uses 31 priority levels Users specify a priority class: –realtime (24), high (13), normal (8) and idle (4) –and a relative priority: –highest (+2), above normal (+1), normal (0), below normal (-1), and lowest (-2) –to establish the Starting priority Threads also have a current priority

6 6 Priorities

7 7 Quantum Determines how long a Thread runs once selected Varies based on: NT Workstation or NT Server Intel or Alpha hardware Foreground/Background application threads –NOTE: NT 4.0 increases quantum for foreground threads while NT 3.5 increased priorities

8 8 Thread States WaitingRunningReady New Dispatch Interrupt I/O Wait I/O Complete Exit Slide “borrowed” from CS502 Class Slides - Mark Claypool

9 9 Scheduling Decision 1A running thread’s quantum expires 2A running thread waits for an event to occur 3A thread becomes ready to execute FindReadyThread ReadyThread

10 10 Dispatcher Ready List Keeps track of all Ready-to-execute threads 31 entries for each priority level queue of threads assigned to each level Dispatcher Ready List 11 10 9 8 7 Ready Threads

11 11 FindReadyThread Locates the highest priority thread that is ready to execute Scans dispatcher ready list Picks front thread in highest priority nonempty queue –How is this different from SelectProcessToRun (last weeks code sample)? How is it the same?

12 12 ReadyThread Places threads in Dispatcher Ready List If (ready-thread-priority > executing-thread-priority) Preempt executing-thread Put executing-thread back in DRL at front of queue (this thread has some remaining quantum to run) Else Put ready-thread in DRL at back of queue

13 13 Boosting and Decay Priority of Dynamic range threads are boosted in some situations –Usually when an event happens that a blocked thread is waiting on –Realtime priorities are not boosted –Boosts never exceed priority 15 Boost decreases by one for each quantum Decays to starting priority (no lower)

14 14 Starvation Prevention Low priority threads may never execute NT has an “anti-CPU starvation policy” for threads that have not executed for 3 seconds –boosts priority to 15 –doubles quantum –calls ReadyThread Decay is swift not gradual after this boost

15 15 Multiprocessor Systems Scheduler can choose among several CPUs NT supports symmetric multiprocessing OS kernel can run on any CPU –Simultaneously on several CPUs!! CPUs have own cache Equal access to main memory and I/O

16 16 SMP

17 17 Protecting Data NT kernel protects shared data structures with locks The DRL is a core data structure that NT protects with a lock If lock is not available, the CPU waits Scheduler will never run simultaneously

18 18 SMP Scheduling Situations requiring scheduling are the same One new Ready-to-execute situation –One CPU pulls thread off before quantum is exhausted –Thread is still eligible to execute (on another CPU) –Call ReadyThread

19 19 Affinity and Ideal Processor Soft Affinity - Scheduler tries to run thread on CPU it last executed on Hard Affinity - thread is assigned a list of CPUs that in can run on Ideal Processor - every thread is assigned an ideal CPU Scheduler tries to run thread on Ideal CPU Preferred choice from Hard affinity list

20 20 FindReadyThread -SMP Acquire DRL Lock Find highest priority non-empty queue Mark first thread with Hard Affinity = CPU as Primary candidate If Primary-Soft-affinity = CPU OR Ideal-Processor = CPU OR Time-since-last-execute > 20 ms Choose Primary as next thread to execute Else Look down queue for 1st thread that satisfies above If new-thread is found Choose it Else Choose Primary Release DRL Lock

21 21 Skipping a thread

22 22 ReadyThread - SMP Acquire DRL lock If Idle-CPU = ready-thread-Hard-Affinity-List signal Idle-CPU to execute thread Else Examine executing-thread-priority on ready-thread-IdealCPU If ready-thread-priority > execute-thread-priority signal CPU to stop current and execute this thread Else place ready-thread on DRL Release DRL lock

23 23 High priority thread must wait

24 24 Thread Migration

25 25 Alternative Approach Soft - AffinityPriority Based

26 26 Final Thoughts Microsoft claims high SQL Srv. throughput Author claims NT scheduling tuned for this Theoretical problem shown No measurements, proofs, scenarios What is a “good” scheduler? –Fair, Efficient, Responsive, Turnaround Time, and Throughput


Download ppt "1 Inside the Windows NT Scheduler, Part 1 Assigning CPU time in a uniprocessor environment by Mark Russinovich Windows NT Magazine - July 1997 Inside the."

Similar presentations


Ads by Google