24
1 First Come, First Served First Come, First Served (FCFS) (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 CPU FIFO Ready Queue dispatched

1 First Come, First Served (FCFS) The simplest algorithm –When a process becomes ready, it enters the FIFO queue. –When the currently-running process ceases

Embed Size (px)

Citation preview

Page 1: 1 First Come, First Served (FCFS) The simplest algorithm –When a process becomes ready, it enters the FIFO queue. –When the currently-running process ceases

1

First Come, First Served (FCFS)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

CPU

FIFO Ready Queuedispatched

Page 2: 1 First Come, First Served (FCFS) The simplest algorithm –When a process becomes ready, it enters the FIFO queue. –When the currently-running process ceases

2

• 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

Page 3: 1 First Come, First Served (FCFS) The simplest algorithm –When a process becomes ready, it enters the FIFO queue. –When the currently-running process ceases

3

• The average waiting time is not minimal and varies substantially if the process execution times vary.

• ex 1 Process Arrival Time Process Exec TimeP1 0 24 msecP2 1 3 msecP3 2 3 msec

– Calculate the average waiting time, turnaround time and throughput.

• ex 2 Process Arrival Time Process Exec TimeP2 0 3 msecP3 1 3 msecP1 2 24 msec

– Calculate the average waiting time, turnaround time and throughput.

Page 4: 1 First Come, First Served (FCFS) The simplest algorithm –When a process becomes ready, it enters the FIFO queue. –When the currently-running process ceases

4

ExercisesExercises

Process Arrival T Exec TimeP1 0 24 msecP2 1 3 msecP3 2 3 msec

0 24

P1

P2

P3

Process Arrival T Exec TimeP2 0 3 msecP3 1 3 msecP1 2 24 msec

27 30

Waiting time = (0 + 23 + 25) / 3 = 16 secTurnaround t = (24 + 26 + 28) / 3 = 26 secThroughput = 3/30 = 0.1

0 3

P2

P3

P1

306

Waiting time = (0 + 2 + 4) / 3 = 2 secTurnaround t = (3 + 5 + 28) / 3 = 14.3 secThroughput = 3/30 = 0.1

Page 5: 1 First Come, First Served (FCFS) The simplest algorithm –When a process becomes ready, it enters the FIFO queue. –When the currently-running process ceases

5

• 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 TimeP1 0 24 msecP2 1 3 msecP3 2 3 msec

• ex 2 Process Arrival Time Process Exec TimeP2 0 3 msecP3 1 3 msecP1 2 24 msec

– Calculate the turnaround time and the normalized turnaround time for each process.

Page 6: 1 First Come, First Served (FCFS) The simplest algorithm –When a process becomes ready, it enters the FIFO queue. –When the currently-running process ceases

6

ExercisesExercises

Process Arrival T Exec TimeP1 0 24 msecP2 1 3 msecP3 2 3 msec

0 24

P1

P2

P3

Process Arrival T Exec TimeP2 0 3 msecP3 1 3 msecP1 2 24 msec

27 30

Waiting time = (0 + 23 + 25) / 3 = 16 secTurnaround t = (24 + 26 + 28) / 3 = 26 secNT = 24/24 + 26/3 + 28/3 = 1 + 8.6 + 9.3 = 18.9 secThroughput = 3/30 = 0.1

0 3

P2

P3

P1

306

Waiting time = (0 + 2 + 4) / 3 = 2 secTurnaround t = (3 + 5 + 28) / 3 = 12 secNT = 3/3 + 5/3 + 28/24 = 1 + 1.6 + 1.1 = 3.7 secThroughput = 3/30 = 0.1

Page 7: 1 First Come, First Served (FCFS) The simplest algorithm –When a process becomes ready, it enters the FIFO queue. –When the currently-running process ceases

7

• 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.

Page 8: 1 First Come, First Served (FCFS) The simplest algorithm –When a process becomes ready, it enters the FIFO queue. –When the currently-running process ceases

8

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 NT8.60 2.56

• 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

Page 9: 1 First Come, First Served (FCFS) The simplest algorithm –When a process becomes ready, it enters the FIFO queue. –When the currently-running process ceases

9

Round RobinRound 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

CPU

Ready QueueFIFO and Circular Queue

dispatched

timeout

Page 10: 1 First Come, First Served (FCFS) The simplest algorithm –When a process becomes ready, it enters the FIFO queue. –When the currently-running process ceases

10

A Key Design Issue in RRA 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.

Page 11: 1 First Come, First Served (FCFS) The simplest algorithm –When a process becomes ready, it enters the FIFO queue. –When the currently-running process ceases

11

Exercise 1Exercise 1• Process Arrival Time Process Exec Time

1 0 3 msec2 2 6 msec3 4 4 msec4 6 5 msec5 8 2 msec

0 5 10 15 20

P1P2P3P4P5

RRtq=1

Page 12: 1 First Come, First Served (FCFS) The simplest algorithm –When a process becomes ready, it enters the FIFO queue. –When the currently-running process ceases

12

• 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

P1P2P3P4P5

RRtq=1

Page 13: 1 First Come, First Served (FCFS) The simplest algorithm –When a process becomes ready, it enters the FIFO queue. –When the currently-running process ceases

13

• 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

P1P2P3P4P5

RRtq=1

T NT4-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.5Avg T Avg NT10.8 2.71

Page 14: 1 First Come, First Served (FCFS) The simplest algorithm –When a process becomes ready, it enters the FIFO queue. –When the currently-running process ceases

14

P1P2P3P4P5

0 5 10 15 20

FCFS

• 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

P1P2P3P4P5

RRtq=1

T NT4-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.5Avg T Avg NT10.8 2.71

T NT3-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=6Avg T Avg NT8.60 2.56

17 context switches

Page 15: 1 First Come, First Served (FCFS) The simplest algorithm –When a process becomes ready, it enters the FIFO queue. –When the currently-running process ceases

15

Exercise 2Exercise 2• Process Arrival Time Process Exec Time

1 0 3 msec2 2 6 msec3 4 4 msec4 6 5 msec5 8 2 msec

P1P2P3P4P5

RRtq=4

0 5 10 15 20

Avg process exectime = 4 msec

Page 16: 1 First Come, First Served (FCFS) The simplest algorithm –When a process becomes ready, it enters the FIFO queue. –When the currently-running process ceases

16

• Process Arrival Time Process Exec Time1 0 3 msec2 2 6 msec3 4 4 msec4 6 5 msec5 8 2 msec

P1P2P3P4P5

RRtq=4

0 5 10 15 20

Page 17: 1 First Come, First Served (FCFS) The simplest algorithm –When a process becomes ready, it enters the FIFO queue. –When the currently-running process ceases

17

• 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

P1P2P3P4P5

RRtq=1

P1P2P3P4P5

RRtq=4

0 5 10 15 20

T NT4-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 NT10.8 2.71

T NT3-0 = 3 3/3=117-2=15 15/6=2…11-4=7 7/4=1…20-6=14 14/5=2…19-8=11 11/2=5.5Avg T Avg NT10 2.716 context switches

17 context switches

Page 18: 1 First Come, First Served (FCFS) The simplest algorithm –When a process becomes ready, it enters the FIFO queue. –When the currently-running process ceases

18

Exercise 3Exercise 3• Process Arrival Time Process Exec Time

1 0 3 msec2 2 6 msec3 4 4 msec4 6 5 msec5 8 2 msec

0 5 10 15 20

P1P2P3P4P5

RRtq=6

Page 19: 1 First Come, First Served (FCFS) The simplest algorithm –When a process becomes ready, it enters the FIFO queue. –When the currently-running process ceases

19

• 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

P1P2P3P4P5

RRtq=6

Page 20: 1 First Come, First Served (FCFS) The simplest algorithm –When a process becomes ready, it enters the FIFO queue. –When the currently-running process ceases

20

P1P2P3P4P5

0 5 10 15 20

FCFS

• 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

P1P2P3P4P5

RRtq=6

Page 21: 1 First Come, First Served (FCFS) The simplest algorithm –When a process becomes ready, it enters the FIFO queue. –When the currently-running process ceases

21

Time QuantumTime Quantum

• Should be slightly longer than typical process execution time

• Should be shorter than the longest process exec time.

• Generally 10 to 100 msec

Page 22: 1 First Come, First Served (FCFS) The simplest algorithm –When a process becomes ready, it enters the FIFO queue. –When the currently-running process ceases

22

Another Fairness IssueAnother 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.

Page 23: 1 First Come, First Served (FCFS) The simplest algorithm –When a process becomes ready, it enters the FIFO queue. –When the currently-running process ceases

23

• 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.

CPU

Ready Queue

admitteddispatched exit

interrupted

I/O type 1 wait

I/O 1completed

I/O 1 Blocked Queue

I/O N Blocked QueueI/O type N wait

I/O N completed

CPU-bound processes tend touse more CPU time, whichleads to poor performancein I/O-bound processes.

Page 24: 1 First Come, First Served (FCFS) The simplest algorithm –When a process becomes ready, it enters the FIFO queue. –When the currently-running process ceases

24

HWHW

• 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.