190 likes | 313 Views
Process Scheduling. Murali P. Dispatch. Admit. Exit. Terminate. New. Ready. Running. Time out. Event Occurs. Event Wait. Blocked. Processor Utilization. How to ensure that some process is always in running state? How are processes selected for execution?
E N D
Process Scheduling Murali P
Dispatch Admit Exit Terminate New Ready Running Time out Event Occurs Event Wait Blocked Processor Utilization • How to ensure that some process is always in running state? • How are processes selected for execution? • What processes are coming for execution? • When processes enter states?
Behavior of processes • CPU bound processes • Having lots of computations • Determine the factorial of a 30-digit number • I/O bound processes • Having a lot of I/O operations • Copying a movie from CD to hard disk • Real world applications have a mix of CPU bursts and I/O operations
Dispatch Admit Exit Terminate New Ready Running Time out Event Occurs Event Wait Blocked CPU Scheduler • Selects from among the processes in memory that are ready to execute, and allocates the CPU to one of them • CPU scheduling decisions : • Scheduling • Non-preemptive • Preemptive
Required Features • CPU is busy full time • Ensure some process is running all time • Or, Squeeze as many processes as possible into CPU • User program gets to execute as soon as it is given • Overall, a process does not run more than what it should have taken • User gets response without too much delay • ???
Scheduling Criteria • CPU utilization • keep the CPU as busy as possible • Throughput • # of processes that complete their execution per time unit • Turnaround time • time to execute a particular process • Waiting time • time that a process has been waiting in the ready queue • Response time • time it takes from when a request was submitted until the first response is produced, not output (for time-sharing environment)
Optimization Criteria • Max CPU utilization • Max throughput • Min turnaround time • Min waiting time • Min response time
Traditional classification of Schedulers • Long-term scheduler • Responsible for ensuring nice mix of CPU bound and I/O bound processes • Choosing New processes • New Ready/Suspended • Medium-term scheduler • Tune degree of multi-programming • Swapping • Short-term scheduler • Improve response time, TAT, WT, …
Dispatcher • Dispatcher module : • switching context • switching to user mode • jumping to the proper location in the user program to restart that program • Dispatch latency • time it takes for the dispatcher to stop one process and start another running • Must be very fast; with very efficient data structures
P1 P2 P3 0 24 27 30 First-Come, First-Served (FCFS) Scheduling ProcessBurst Time Arrival Time P1 24 0 P2 3 1 P3 32 The Gantt Chart for the schedule is: • Waiting time for P1 = 0; P2 = 23; P3 = 25 • Average waiting time: (0 + 23 + 25)/3 = 16
P2 P3 P1 0 3 6 30 FCFS Scheduling ProcessBurst Time Arrival Time P1 24 2 P2 3 0 P3 31 • Suppose the order of arrival : P2 , P3 ,P1The Gantt Chart for the schedule is: • Waiting time for P1 = 4; P2 = 0; P3 = 2 • Average waiting time: (4 + 0 + 2)/3 = 2 • Convoy Effect
Shortest Job First (SJF) • Chooses the job with shortest next CPU burst • Some estimation mechanism used • Eg, tn+1= a bn + (1-a) tn (Exponential Average) • Types • Non-preemptive • Preemptive • Shortest Remaining Time First (SRTF)
P1 P3 P2 P4 0 3 7 8 12 16 Example of Non-Preemptive SJF Process Arrival TimeBurst Time P1 0.0 7 P2 2.0 4 P3 4.0 1 P4 5.0 4 • SJF (non-preemptive) • Average waiting time = (0 + 6 + 3 + 7)/4 = 4
P1 P2 P3 P2 P4 P1 11 16 0 2 4 5 7 Example of Preemptive SJF Process Arrival TimeBurst Time P1 0.0 7 P2 2.0 4 P3 4.0 1 P4 5.0 4 • SJF (preemptive) • Average waiting time = (9 + 1 + 0 +2)/4 = 3
Prediction of the Length of the Next CPU Burst • Prediction not always correct • Better prediction algorithms Slower Dispatcher • What if the big task preempted was important? • Quantify sense of importance
Priority Scheduling • A priority number (integer) is associated with each process • The CPU is allocated to the process with the highest priority (smallest integer highest priority) • Preemptive • nonpreemptive • SJF is a priority scheduling where priority is the predicted next CPU burst time • Problem Starvation – low priority processes may never execute • Solution Aging – as time progresses increase the priority of the process