scheduling algorithms

22
Scheduling Algorithms 1 Julian Ilham Dept. of Electronic Engineering Pukyong National University Email: [email protected] Nov 2 nd 2012

Upload: pt-mecoindo-itron

Post on 12-Dec-2014

346 views

Category:

Technology


0 download

DESCRIPTION

Scheduling algorithms for embedded system

TRANSCRIPT

Page 1: Scheduling Algorithms

Scheduling Algorithms

1

Julian IlhamDept. of Electronic Engineering

Pukyong National UniversityEmail: [email protected]

Nov 2nd 2012

Page 2: Scheduling Algorithms

2

Content

Introduction Preemptive vs Non-Preemptive

First Come First Served (FCFS) Shortest Job First (SJF) Priority Based Scheduling Round Robin (RR)

Page 3: Scheduling Algorithms

3

Introduction

Choosing which task to run and for how long

What is scheduling?

- Improve the system performance- Support multitasking

Why do we need it?

Page 4: Scheduling Algorithms

4

Preemptive vs Non-Preemptive

Running task can be forced to release even though it is neither completed

Preemptive

Each running task keeps processing until it completed

Non - Preemptive

Page 5: Scheduling Algorithms

5

First Come First Served (FCFS)

Only available in Non-Preemptive mode Example:

Gantt chart

Tasks Arrival Times (ms) Burst Time (ms)

P2 0.0 12

P3 3.0 8

P4 5.0 4

P1 10.0 10

P5 12.0 6

P2 P3 P4 P1 P5

012

20 24 34 40 (ms)3 5 10

Page 6: Scheduling Algorithms

6

First Come First Served (FCFS)

Time CalculationP1 : 24 – 10 = 12 msP2 : 0 msP3 : 12 – 3 = 9 msP4 : 20 – 5 = 15 msP5 : 34 – 12 = 22 ms

Total waiting time : P1 + P2 + P3 + P4 + P5 = 58 msAverage waiting time : 58 ms / 5 = 11.6 ms

Page 7: Scheduling Algorithms

7

First Come First Served (FCFS)

Advantage: Very simple code and structure

Disadvantage: Large average waiting time

Page 8: Scheduling Algorithms

8

Shortest Job First (SJF)

Available in Preemptive and Non-Preemptive mode Example (Preemptive)

Gantt chart

Tasks Arrival Times (ms) Burst Time (ms)

P2 0.0 12

P3 3.0 8

P4 5.0 4

P1 10.0 10

P5 12.0 6

P2 P3 P4 P1P5

30

59 15

P3

21

P2

30 4010 12

(ms)

Page 9: Scheduling Algorithms

9

Shortest Job First (SJF)

Time Calculation (Preemptive)P1 : 30 – 10 = 20 msP2 : 0 + (21 – 3) = 18 msP3 : (3 – 3) + (9 – 5) = 4 msP4 : 5 – 5 = 0 msP5 : 15 – 12 = 3 ms

Total waiting time : P1 + P2 + P3 + P4 + P5 = 45 msAverage waiting time : 45 ms / 5 = 9 ms

Page 10: Scheduling Algorithms

10

Shortest Job First (SJF)

Example (Non-Preemptive)

Gantt chart

Tasks Arrival Times (ms) Burst Time (ms)

P2 0.0 12

P3 3.0 8

P4 5.0 4

P1 10.0 10

P5 12.0 6

P2 P4 P1P5

30

516

P3

22 30 4010 12

(ms)

Page 11: Scheduling Algorithms

11

Shortest Job First (SJF)

Time Calculation (Non-Preemptive)P1 : 30 – 10 = 20 msP2 : 0 msP3 : 22 – 3 = 19 msP4 : 12 – 5 = 7 msP5 : 16 – 12 = 4 ms

Total waiting time : P1 + P2 + P3 + P4 + P5 = 50 msAverage waiting time : 50 ms / 5 = 10 ms

Page 12: Scheduling Algorithms

12

Shortest Job First (SJF)

Advantage: Minimum average waiting time for a given set of process

Disadvantage: Difficult to estimate burst time, starvation (indefinite blocking)

Page 13: Scheduling Algorithms

13

Priority Based Scheduling

Available in Preemptive and Non-Preemptive mode Example (Preemptive)

Gantt chart

Tasks Arrival Times (ms) Burst Time (ms) Priority

P2 0.0 12 2

P3 3.0 8 5

P4 5.0 4 1

P1 10.0 10 4

P5 12.0 6 3

P2 P4 P1P5

30

516

P3

22 32 4010 12

9

P2

(ms)

Page 14: Scheduling Algorithms

14

Priority Based Scheduling

Time Calculation (Preemptive)P1 : 22 – 10 = 12 msP2 : 9 – 5 = 4 msP3 : 32 – 3 = 29 msP4 : 5 – 5 = 0 msP5 : 16 – 12 = 4 ms

Total waiting time : P1 + P2 + P3 + P4 + P5 = 49 msAverage waiting time : 49 ms / 5 = 9.8 ms

Page 15: Scheduling Algorithms

15

Priority Based Scheduling

Example (Non-Preemptive)

Gantt chart

Tasks Arrival Times (ms) Burst Time (ms) Priority

P2 0.0 12 2

P3 3.0 8 5

P4 5.0 4 1

P1 10.0 10 4

P5 12.0 6 3

P2 P4 P1P5

3 516

P3

22 32 4010 12

(ms)

Page 16: Scheduling Algorithms

16

Priority Based Scheduling

Time Calculation (Non-Preemptive)P1 : 22 – 10 = 12 msP2 : 0 msP3 : 32 – 3 = 29 msP4 : 12 – 5 = 7 msP5 : 16 – 12 = 4 ms

Total waiting time : P1 + P2 + P3 + P4 + P5 = 52 msAverage waiting time : 52 ms / 5 = 10.4 ms

Page 17: Scheduling Algorithms

17

Priority Based Scheduling

Advantage: Easier than SJF

Disadvantage: Can cause indefinite blocking

Page 18: Scheduling Algorithms

18

Round Robin (RR)

Only available in Non-Preemptive mode FCFS is used in sequencing policy Need to determine time slice/ quantum as a unit of time for

each process Then continue to the next process after reaching maximum of

quantum

- Too small time quantum -> too many tasks switched- Too large time quantum -> inherits the problem of FCFS

Page 19: Scheduling Algorithms

19

Round Robin (RR)

Example (assuming quantum is 5 ms):

Gantt chart

Tasks Arrival Times (ms) Burst Time (ms)

P2 0.0 12

P3 3.0 8

P4 5.0 4

P1 10.0 10

P5 12.0 6

P2

53

24 29

10 12

P3 P414

P1 P519

P5P2 P3 P1 P20 105 32 37 38 40

Page 20: Scheduling Algorithms

20

Round Robin (RR)

Time CalculationP1 : (14 – 10) + (32 – 19) = 17 msP2 : 0 + (24 – 5) + (38 – 29) = 28 msP3 : (5 – 3) + (29 – 10) = 21 msP4 : 10 – 5 = 5 msP5 : (19 – 12) + (37 – 24) = 20 ms

Total waiting time : P1 + P2 + P3 + P4 + P5 = 91 msAverage waiting time : 91 ms / 5 = 18.2 ms

Page 21: Scheduling Algorithms

21

Round Robin (RR)

Advantage: Guarantee fairness (bounded waiting time and no starvation)

Disadvantage: Average waiting time is long

Page 22: Scheduling Algorithms

22

End

Q n A