180 likes | 264 Views
Rensselaer Polytechnic Institute CSCI-4210 – Operating Systems David Goldschmidt, Ph.D. Operating Systems {week 06b}. Short-term (CPU) scheduling (i). The short-term scheduler decides which process the CPU executes next
E N D
Rensselaer Polytechnic Institute CSCI-4210 – Operating Systems David Goldschmidt, Ph.D. Operating Systems{week 06b}
Short-term (CPU) scheduling (i) • 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
Short-term (CPU) scheduling (ii) the dispatcher operates here
CPU scheduling algorithms (i) • CPU scheduling requires an algorithm todetermine which process to dispatch next • Scheduling algorithms include: • First-Come, First-Served (FCFS) • Shortest-Job-First (SJF) • Round-Robin (RR) • Priority • Multilevel Queue (MQ)
process CPU scheduling algorithms (ii) • Preemptive scheduling preempts a running process before itstime slice expires • Or it preempts a processbecause its time slice has expired • Non-preemptive scheduling gives a process exclusive uninterrupted access to the CPU for the entirety of its execution process process process
CPU scheduling algorithms (iii) • 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
P1 P2 P3 0 24 27 30 First-Come-First-Served (FCFS) • FCFS dispatches processesin the order they enterthe ready queue • FCFS is non-preemptive time
P2 P3 P1 0 3 6 30 Shortest-Job-First (SJF) • SJF dispatches processes byselecting the process withthe lowest CPU burst time • SJF is non-preemptive (and predictive) time
P1 P2 P3 P2 P4 P1 11 16 0 2 4 5 7 Preemptive SJF • Same as SJF, but anew process maypreempt therunning process time
Limitations of SJF (i) • SJF is the optimal solution • The problem with SJF is the inability topredict required CPU burst times • Apply a prediction algorithm that usesprevious 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
P3 P1 P2 P3 P1 P3 P1 0 2 4 6 8 10 12 13 Round-Robin (RR) • RR is a preemptive algorithmthat gives all ready processesa fair time slice of CPU time • Using a time slice of 2 ms.... time
Priority Scheduling (i) • Associate a priority number with each process • The dispatcher selects the processwith the highest priority • For multiple ready processes withidentical priority numbers, use FCFS • Key problem is starvation • Overcome starvation by aging, increasingthe priority of a process as it ages
process Priority Scheduling (ii) • Is priority scheduling preemptiveor non-preemptive? • Non-preemptive priority scheduling places higher-priority processes at the head of the queue • Preemptive priority scheduling requires a running process to be interrupted and preempted upon the arrival of a higher-priority process (use this one for Project #1)
Multiclass systems • Operating systems that support priority schemes are often called multiclass systems use a separate schedulingalgorithm for each queue
Multilevel Queue (MQ) • Assign processes to multiple queues,each with its own scheduling algorithm
Multilevel Feedback Queue (MFQ) • Dynamically assign processes to multiple queues based on actual CPU burst times • i.e. feedback quantum is synonymouswith time slice
Practice! • Apply the FCFS, SJF, RR, and Preemptive Priority scheduling algorithms to this table: • For RR, use a time slice of 10 ms • Calculate the wait and turnaround times ofeach process, as well as overall averages lower number indicates a higher priority recalculate using context switch time tcs = 20 μs