Rensselaer Polytechnic Institute CSC 432 – Operating Systems David Goldschmidt, Ph.D. The short-term scheduler decides which process the CPU executes next The dispatcher gives control of the CPU to the process selected by the CPU scheduler: Performs context switch Switches to user mode Jumps to the proper location in the user program to resume program execution the dispatcher operates here CPU scheduling requires an algorithm to determine which process to dispatch next Scheduling algorithms include: First-Come, First-Served (FCFS) Shortest-Job-First (SJF) Round-Robin (RR) Priority Multilevel Queue (MQ) Preemptive scheduling preempts a running process before its time slice expires process process process process Or it preempts a process because its time slice has expired Non-preemptive scheduling gives a process exclusive uninterrupted access to the CPU for the entirety of its execution Compare scheduling algorithms by measuring CPU utilization – keep CPU as busy as possible Throughput – maximize the number of processes that complete their execution per unit time Turnaround time – minimize the elapsed time to fully execute a particular process Waiting time – minimize the elapsed time a process waits in the ready queue FCFS dispatches processes in the order they enter the ready queue Process CPU Burst Time P1 24 ms P2 3 ms P3 3 ms FCFS is non-preemptive P1 P2 0 24 time P3 27 30 SJF dispatches processes by selecting the process with the lowest CPU burst time Process CPU Burst Time P1 24 ms P2 3 ms P3 3 ms SJF is non-preemptive (and predictive) P2 0 P3 3 P1 6 30 time What happens when processes arrive at different arrival times? Process Arrival Time CPU Burst Time P1 0 7 ms P2 2 ms 4 ms P3 4 ms 1 ms P4 5 ms 4 ms Calculate the turnaround times and wait times for each process Calculate the average turnaround time and average wait time Same as SJF, but a new process may preempt the running process P1 0 P2 2 P3 4 Process Arrival Time CPU Burst Time P1 0 7 ms P2 2 ms 4 ms P3 4 ms 1 ms P4 5 ms 4 ms P2 5 P4 7 time P1 11 16 SJF is the optimal solution The problem with SJF is the inability to know the required CPU burst times Apply a prediction algorithm that uses previous CPU burst times Algorithm uses exponential averaging: ▪ tn = actual length of the nth CPU burst ▪ τn+1 = predicted value for the next CPU burst ▪ τn+1 = α tn + (1 – α) τn , where 0 < α < 1 α is ½ α is ¾ α is ½ α is ¼ Apply the FCFS, SJF, and Preemptive SJF scheduling algorithms to this table: Process Arrival Time CPU Burst Time P1 0 45 ms P2 0 5 ms P3 20 ms 15 ms P4 60 ms 25 ms recalculate using context switch time tcs = 20 μs Calculate the wait and turnaround times of each process, as well as overall averages