180 likes | 345 Views
CMT603. Lecture 4 Scheduling-2. Contents. Last Week FCFS SJF Priority scheduling Round Robin Multi Level Queues Real Systems Linux XP. Priority Scheduling.
E N D
CMT603 Lecture 4 Scheduling-2
Contents • Last Week • FCFS • SJF • Priority scheduling • Round Robin • Multi Level Queues • Real Systems • Linux • XP
Priority Scheduling • A priority is associated with each process,and the CPU is allocated to the processwith the highest priority. We assume thatlow numbers represent high priority. • May be preemptive or non-preemptive.
Example: Priority Scheduling • Consider the following set of processes with their arrival times and the length of the CPU-burst time given in milliseconds • The arrival order of the processes is P1, P2, P3, P4, P5
Average wait time= (6+0+16+18+1)/5 = 8.2 Example: Priority Scheduling P2 P5 P1 P3 P4 0 1 6 16 18 19
Average wait time = (1+0+1+6+0)/5 = 1.6 Exercise T=0 T=5 T=6 T=8 T=9 T=16 T=10 T=11 - - - - 8 3 3 1 1 - - - - - - 2 2 1 - - 1 1 1 5 - P1 P2 P1 P3 P5 P4 0 5 6 9 11 16 17
Analysis of Priority Scheduling • May leave some low-priority processes waiting indefinitely for CPU • Starvation. • Aging – a technique of gradually increasing the priority of processes that have waited for a long time.
Round Robin • Similar to FCFS but with preemption. • Have a time quantum (time slice). • Let the first process in the queue run until it exceeds the time quantum, then run the next process. • The arrival order of the processes is P1,P2,P3
Example: Round Robin Time Quantum = 5 milliseconds P1 P2 P3 P1 P3 P1 P1 P1 0 5 8 13 18 22 36 Average waiting Time = (12+5+13)/3 = 10 Time Quantum = 24 milliseconds P1 P2 P3 0 24 27 36 Average waiting Time = (0+24+27)/3 = 17 Turns into FCFS scheduling
Exercise: Round Robin Time quantum = 2 milliseconds P1 P1 P1 P2 P3 P1 P2 P3 P1 P3 P1 P3 P1 P3 P1 P1 P1 P1 P1 8 0 2 4 6 9 11 13 15 17 19 22 23 36 Average waiting Time = (12+6+13)/3 = 10.33 What if context-switch time = 1 millisecond? Total context-switch time =12
Analysis of Round Robin Scheduling • Very small quantum - large context switch overhead. • Very big quantum - turns into FCFS. • The time quantum should be large with respect to the context-switch time. • In most modern OSs • Quantum time range: 10-100 milliseconds • Context-switch time: <10 microseconds
Scheduling algorithms. • FCFS, SJF, Priority, Round Robin. • Preemptive, Non preemptive • All Basic Algorithms • Real life systems have a mix of these approaches
Multi level Queues • Separate scheduling within queues • Scheduling between queues Foreground processes (Round Robin) Queue Scheduler (Priority) Background processes (FCFS)
Linux • Priority Queue • 0-99 real time • 100-140 nice • Higher priority = longer time slice • Once time slice is expired, wait for all other slices to expire
XP • 32 Level Priority Algorithm in two classes • 1-15 Variable • 16-31 Real time • Also 0 for memory management • FIFO queue in each level. • When Quantum runs out in Variable Class priority drops • Limits CPU intensive processes • Foreground windows +3 priority
Summary • Last Week • FCFS • SJF • Priority scheduling • Round Robin • Multi Level Queues • Real Systems • Linux • XP
Group Discussion • For 5-10 minutes, discuss how you would design a scheduling algorithm for a Desktop PC, using multilevel queues.