150 likes | 162 Views
Explore CPU scheduling algorithms like SJF, RR, and Proportional-Share Schedulers to enhance system performance. Understand pre-emption benefits and drawbacks, along with a focus on optimizing process turnaround and fairness. Dive into practical examples for better comprehension.
E N D
Operating SystemsCMPSC 473 CPU Scheduling September 07, 2010 - Lecture 5 Instructor: Bhuvan Urgaonkar
From last class • Context switch: why store a subset of registers on process stack rather than on its PCB? • Memory reserved for kernel more precious than that for processes
Choosing the Right Scheduling Algorithm/Scheduling Criteria • Waiting time – amount of time a process has been waiting in the ready queue • Response time – amount of time it takes from when a request was submitted until the first response is produced, not output (for time-sharing environment) • Throughput – # of processes that complete their execution per time unit • Turnaround time – amount of time to execute a particular process • Fairness
Shortest-Job-First (SJF) Scheduling • Associate with each process the length of its next CPU burst. Use these lengths to schedule the process with the shortest time • SJF is optimal for avg. waiting time – gives minimum average waiting time for a given set of processes • In class: Compute average waiting time for the previous example with SJF • Exercise: Prove the optimality claimed above
Why Pre-emption is Necessary • To improve CPU utilization • Most processes are not ready at all times during their lifetimes • E.g., think of a text editor waiting for input from the keyboard • Also improves I/O utilization • To improve responsiveness • Many processes would prefer “slow but steady progress” over “long wait followed by fast process” • Most modern CPU schedulers are pre-emptive
SJF: Variations on the theme • Non-preemptive: once CPU given to the process it cannot be • preempted until completes its CPU burst - the SJF we already saw • Preemptive: if a new process arrives with CPU length less • than remaining time of current executing process, preempt. • This scheme is know as Shortest-Remaining-Time-First (SRTF) • Also called Shortest Remaining Processing Time (SRPT) • Why SJF/SRTF may not be practical • CPU requirement of a process rarely known in advance
Round Robin (RR) • Each process gets a small unit of CPU time (time quantum), usually 10-100 milliseconds. After this time has elapsed, the process is preempted and added to the end of the ready queue. • If there are n processes in the ready queue and the time quantum is q, then each process gets 1/n of the CPU time in chunks of at most q time units at once. No process waits more than (n-1)q time units. • Performance • q large => FCFS • q small => q must be large with respect to context switch, otherwise overhead is too high
P1 P2 P3 P4 P1 P3 P4 P1 P3 P3 0 20 37 57 77 97 117 121 134 154 162 Example of RR with Time Quantum = 20 ProcessCPU Time P1 53 P2 17 P3 68 P4 24 • The Gantt chart is: • Typically, higher average turnaround than SJF, but better response
Proportional-Share Schedulers • A generalization of round robin • Process Pi given a CPU weight wi > 0 • The scheduler needs to ensure the following • forall i, j, |Ti(t1, t2)/Tj(t1,t2) - wi/wj| ≤ e • Given Pi and Pj were backlogged during [t1,t2] • Who chooses the weights and how?
Lottery Scheduling[Carl Waldspurger, MIT, ~1995] • Perhaps the simplest proportional-share scheduler • Create lottery tickets equal to the sum of the weights of all processes • What if the weights are non-integral? • Draw a lottery ticket and schedule the process that owns that ticket • What if the process is not ready? • Draw tickets only for ready processes • Exercise: Calculate the time/space complexity of the operations Lottery scheduling will involve
Lottery Scheduling Example P1=6 P2=9 1 4 7 10 13 2 5 8 11 14 3 6 9 12 15 9 Schedule P2
Lottery Scheduling Example P1=6 P2=9 1 4 7 10 13 2 5 8 11 14 3 6 9 12 15 3 Schedule P1
Lottery Scheduling Example P1=6 P2=9 1 4 7 10 13 • As t ∞, processes will get their share (unless they were blocked a lot) • Problem with Lottery scheduling: Only probabilistic guarantee • What does the scheduler have to do • When a new process arrives? • When a process terminates? 2 5 8 11 14 3 6 9 12 15 11 Schedule P2