330 likes | 1.34k Views
First Come, First Served (FCFS). The simplest algorithm When a process becomes ready, it enters the FIFO queue. When the currently-running process ceases to execute, the oldest process in the queue is selected for running. Non-preemptive. FIFO Ready Queue. CPU. dispatched.
E N D
First Come, First Served (FCFS) • The simplest algorithm • When a process becomes ready, it enters the FIFO queue. • When the currently-running process ceases to execute, the oldest process in the queue is selected for running. • Non-preemptive FIFO Ready Queue CPU dispatched
Process Arrival Time Process Exec Time1 0 3 msec2 2 6 msec3 4 4 msec4 6 5 msec5 8 2 msec 0 5 10 15 20 P1 P2 P3 P4 P5
The average waiting time is not minimal and varies substantially if the process execution times vary. • ex 1 Process Arrival Time Process Exec Time P1 0 24 msec P2 1 3 msec P3 2 3 msec • Calculate the average waiting time, turnaround time and throughput. • ex 2 Process Arrival Time Process Exec Time P2 0 3 msec P3 1 3 msec P1 2 24 msec • Calculate the average waiting time, turnaround time and throughput.
Exercises • Process Arrival T Exec TimeP1 0 24 msecP2 1 3 msecP3 2 3 msec • Process Arrival T Exec TimeP2 0 3 msecP3 1 3 msecP1 2 24 msec 6 0 24 27 30 0 3 30 P1 P2 P2 P3 P3 P1 Waiting time = (0 + 23 + 25) / 3 = 16 sec Turnaround t = (24 + 26 + 28) / 3 = 26 sec Throughput = 3/30 = 0.1 Waiting time = (0 + 2 + 4) / 3 = 2 sec Turnaround t = (3 + 5 + 28) / 3 = 14.3 sec Throughput = 3/30 = 0.1
Normalized turnaround time • The ratio of turnaround time to process exec time. • A relative delay experienced by a process • The longer process exec time, the greater absolute amount of tolerable delay. • ex 1 Process Arrival Time Process Exec Time P1 0 24 msec P2 1 3 msec P3 2 3 msec • ex 2 Process Arrival Time Process Exec Time P2 0 3 msec P3 1 3 msec P1 2 24 msec • Calculate the turnaround time and the normalized turnaround time for each process.
Exercises • Process Arrival T Exec TimeP1 0 24 msecP2 1 3 msecP3 2 3 msec • Process Arrival T Exec TimeP2 0 3 msecP3 1 3 msecP1 2 24 msec 6 0 24 27 30 0 3 30 P1 P2 P2 P3 P3 P1 Waiting time = (0 + 23 + 25) / 3 = 16 sec Turnaround t = (24 + 26 + 28) / 3 = 26 sec NT = 24/24 + 26/3 + 28/3 = 1 + 8.6 + 9.3 = 18.9 sec Throughput = 3/30 = 0.1 Waiting time = (0 + 2 + 4) / 3 = 2 sec Turnaround t = (3 + 5 + 28) / 3 = 12 sec NT = 3/3 + 5/3 + 28/24 = 1 + 1.6 + 1.1 = 3.7 sec Throughput = 3/30 = 0.1
The normalized turnaround times for P2 and P3 are intolerable. • This problem occurs whenever a short-lived process arrives right after a long-lived process. • When the variance of process exec time is high, FCFS penalizes short processes. • FCFS is not a fair scheduling algorithm; it does not treat long-lived and short-lived processes equally.
Process Arrival Time Process Exec Time1 0 3 msec2 2 6 msec3 4 4 msec4 6 5 msec5 8 2 msec 0 5 10 15 20 T NT 3-0 = 3 3/3=1… 9-2=7 7/6=1… 13-4=7 7/4=1… 18-6=12 12/5=2… 20-8=12 12/2=6 Avg T Avg NT 8.60 2.56 P1 P2 P3 P4 P5
Round Robin • Clock-based preemption of process (time slicing) • When a clock interrupt occurs, the currently-running process is placed in the end of the Ready queue, and the next ready process is executed. • A straightforward way to reduce the penalty that short-lived processes suffer with FCFS. • A fairer algorithm than FCFS Ready Queue FIFO and Circular Queue CPU dispatched timeout
A Key Design Issue in RR • How to determine the length of time quantum (time slice)? • If it’s too short, • Processing overhead becomes high to handle clock interrupts and perform context switches. • (the time to handle a clock interrupt and perform a context switch) / (time quantum) should be small enough. • If it’s too long, • RR degenerates to FCFS.
Exercise 1 • Process Arrival Time Process Exec Time1 0 3 msec2 2 6 msec3 4 4 msec4 6 5 msec5 8 2 msec 0 5 10 15 20 P1 P2 RRtq=1 P3 P4 P5
Process Arrival Time Process Exec Time1 0 3 msec2 2 6 msec3 4 4 msec4 6 5 msec5 8 2 msec 0 5 10 15 20 P1 P2 RRtq=1 P3 P4 P5
Process Arrival Time Process Exec Time1 0 3 msec2 2 6 msec3 4 4 msec4 6 5 msec5 8 2 msec 0 5 10 15 20 T NT 4-0 = 4 4/3=1… 18-2=16 16/6=2… 17-4=13 13/4=3… 20-6=14 14/5=2… 15-8=7 7/2=3.5 Avg T Avg NT 10.8 2.71 P1 P2 RRtq=1 P3 P4 P5
Process Arrival Time Process Exec Time1 0 3 msec2 2 6 msec3 4 4 msec4 6 5 msec5 8 2 msec 0 5 10 15 20 T NT 4-0 = 4 4/3=1… 18-2=16 16/6=2… 17-4=13 13/4=3… 20-6=14 14/5=2… 15-8=7 7/2=3.5 Avg T Avg NT 10.8 2.71 P1 P2 RRtq=1 P3 P4 P5 17 context switches 0 5 10 15 20 T NT 3-0 = 3 3/3=1… 9-2=7 7/6=1… 13-4=7 7/4=1… 18-6=12 12/5=2… 20-8=12 12/2=6 Avg T Avg NT 8.60 2.56 P1 P2 FCFS P3 P4 P5
Exercise 2 • Process Arrival Time Process Exec Time1 0 3 msec2 2 6 msec3 4 4 msec4 6 5 msec5 8 2 msec Avg process exec time = 4 msec 0 5 10 15 20 P1 P2 RRtq=4 P3 P4 P5
Process Arrival Time Process Exec Time1 0 3 msec2 2 6 msec3 4 4 msec4 6 5 msec5 8 2 msec 0 5 10 15 20 P1 P2 RRtq=4 P3 P4 P5
Process Arrival Time Process Exec Time1 0 3 msec2 2 6 msec3 4 4 msec4 6 5 msec5 8 2 msec 0 5 10 15 20 T NT 4-0 = 4 4/3=1… 18-2=16 16/6=2… 17-4=13 13/4=3… 20-6=14 14/5=2… 15-8=7 7/2=3… Avg T Avg NT 10.8 2.71 P1 P2 RRtq=1 P3 P4 P5 17 context switches 0 5 10 15 20 T NT 3-0 = 3 3/3=1 17-2=15 15/6=2… 11-4=7 7/4=1… 20-6=14 14/5=2… 19-8=11 11/2=5.5 Avg T Avg NT 10 2.71 P1 P2 RRtq=4 P3 P4 P5 6 context switches
Exercise 3 • Process Arrival Time Process Exec Time1 0 3 msec2 2 6 msec3 4 4 msec4 6 5 msec5 8 2 msec 0 5 10 15 20 P1 P2 RRtq=6 P3 P4 P5
Process Arrival Time Process Exec Time1 0 3 msec2 2 6 msec3 4 4 msec4 6 5 msec5 8 2 msec 0 5 10 15 20 P1 P2 RRtq=6 P3 P4 P5
Process Arrival Time Process Exec Time1 0 3 msec2 2 6 msec3 4 4 msec4 6 5 msec5 8 2 msec 0 5 10 15 20 P1 P2 RRtq=6 P3 P4 P5 0 5 10 15 20 P1 P2 FCFS P3 P4 P5
Time Quantum • Should be slightly longer than typical process execution time • Should be shorter than the longest process exec time. • Generally 10 to 100 msec
Another Fairness Issue • RR treats long-lived and short-lived processes equally. • However, it does not treat CPU-bound and I/O-bound processes equally. • CPU-bound process • Mainly performs computational work and occasionally uses I/O devises • I/O-bound process • spends more time using I/O devises than using the CPU.
I/O-bound processes use less CPU time than CPU-bound processes. • An I/O-bound process uses for a short period and then is blocked for an I/O operation. It returns to the Ready queue when the I/O operation is completed. • A CPU-bound process uses a complete time quantum and returns to the Ready queue. Ready Queue CPU exit dispatched admitted interrupted CPU-bound processes tend touse more CPU time, whichleads to poor performancein I/O-bound processes. I/O 1completed I/O 1 Blocked Queue I/O type 1 wait I/O N completed I/O N Blocked Queue I/O type N wait
HW • Read Paper #1 (see the course web site), and summarize how the proposed scheduling algorithm addresses this fairness issue. • Use a queuing diagram in your explanation.