cmt603 lecture 3 scheduling. contents intro to scheduling preemption scheduling algorithms –?–?...

22
CMT603 Lecture 3 Scheduling

Upload: kian-peeke

Post on 02-Apr-2015

229 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: CMT603 Lecture 3 Scheduling. Contents Intro to scheduling Preemption Scheduling Algorithms –?–? –?–? –?–?

CMT603

Lecture 3

Scheduling

Page 2: CMT603 Lecture 3 Scheduling. Contents Intro to scheduling Preemption Scheduling Algorithms –?–? –?–? –?–?

Contents

• Intro to scheduling

• Preemption

• Scheduling Algorithms– ?– ?– ?

Page 3: CMT603 Lecture 3 Scheduling. Contents Intro to scheduling Preemption Scheduling Algorithms –?–? –?–? –?–?

Three Types of Scheduling

• Job scheduling– Selects processes from the process pool

(usually on disk) and loads them into memory• Also known as long-term scheduler

• Process scheduling– Selects processes from the ready queue.

• Short term scheduler

• Thread scheduling– Schedules threads from within a process

Page 4: CMT603 Lecture 3 Scheduling. Contents Intro to scheduling Preemption Scheduling Algorithms –?–? –?–? –?–?

Why schedule processes? - Increase Efficiency

• The reason scheduling works is because of the CPU-I/O burst cycle.

• When processes run, it has been observed that:– CPU has a burst of activity– Then it waits for I/O

• The Durations of the CPU burst have been measured extensively

Page 5: CMT603 Lecture 3 Scheduling. Contents Intro to scheduling Preemption Scheduling Algorithms –?–? –?–? –?–?

CPU Burst Durations

80 2416 32 40

140

120

110

100

80

60

40

20

160

Fre

quen

cy

Burst Duration (ms)[Silberschatz2005]

Page 6: CMT603 Lecture 3 Scheduling. Contents Intro to scheduling Preemption Scheduling Algorithms –?–? –?–? –?–?

Reminder- How Operating Systems work

• Interrupts

• Dual Mode.

• Timers

Page 7: CMT603 Lecture 3 Scheduling. Contents Intro to scheduling Preemption Scheduling Algorithms –?–? –?–? –?–?

Preemption

• Non-preemptive Scheduling: Once thesystem has assigned a CPU to aprocess, the system cannot removethat CPU from that process

• Preemptive Scheduling: The systemcan remove the running process from the CPU

Page 8: CMT603 Lecture 3 Scheduling. Contents Intro to scheduling Preemption Scheduling Algorithms –?–? –?–? –?–?

Scheduling Criteria

• What do we want from a scheduling algorithm?

Page 9: CMT603 Lecture 3 Scheduling. Contents Intro to scheduling Preemption Scheduling Algorithms –?–? –?–? –?–?

Scheduling Criteria

• It is desirable to maximize CPUutilization and throughput, and tominimize turnaround time, waiting timeand response time.

• CPU Utilization – use of the CPU.

• Throughput – number of processescompleted per time unit.

Page 10: CMT603 Lecture 3 Scheduling. Contents Intro to scheduling Preemption Scheduling Algorithms –?–? –?–? –?–?

Scheduling Criteria

• Turnaround time – interval from submission to completion of a process.

• Waiting time – time spent ready to run but not running.

• Response time – the time from submission of a request until the first response is produced.– normally used for measuring an interactive

system.

Page 11: CMT603 Lecture 3 Scheduling. Contents Intro to scheduling Preemption Scheduling Algorithms –?–? –?–? –?–?

Scheduling Algorithms

• Question…..

– Think of some different ways in which we could chose which process to execute next?

Page 12: CMT603 Lecture 3 Scheduling. Contents Intro to scheduling Preemption Scheduling Algorithms –?–? –?–? –?–?

Scheduling Algorithms

• First come First Served

• SJF non preemptive / preemptive

• Priority

• Round robin

Page 13: CMT603 Lecture 3 Scheduling. Contents Intro to scheduling Preemption Scheduling Algorithms –?–? –?–? –?–?

First come First Served

Process Burst Time (ms)

P1 30

P2 4

P3 2

Processes arrive at time 0In the order P1, P2, P3

• Uses a FIFO queue

• Non preemptive

• An Example FCFS

Page 14: CMT603 Lecture 3 Scheduling. Contents Intro to scheduling Preemption Scheduling Algorithms –?–? –?–? –?–?

Process Burst Time (ms)

P1 30

P2 4

P3 2

P1

0

P3P2

363430

Average wait time = (0+30+34)/3 = 21.33

Turnaround time = (30+34+36)/3 = 33.33

Gant chart

Example FCFS

Page 15: CMT603 Lecture 3 Scheduling. Contents Intro to scheduling Preemption Scheduling Algorithms –?–? –?–? –?–?

Exercise (5 minutes)

Process Burst Time (ms)

P3 2

P2 4

P1 30

P1P3 P2

0 362 6

Average wait time = (0+2+6)/3 = 2.67

Turnaround time = (2+6+36)/3 = 14.67

Page 16: CMT603 Lecture 3 Scheduling. Contents Intro to scheduling Preemption Scheduling Algorithms –?–? –?–? –?–?

Analysis of FCFS

• Average wait time is very variable– If the burst times vary greatly

• Convoy effect

• Low device utilisation– If a CPU bound process is active for long

periods, other devices are not being used

Page 17: CMT603 Lecture 3 Scheduling. Contents Intro to scheduling Preemption Scheduling Algorithms –?–? –?–? –?–?

Shortest job first

• Assign CPU to the process that has the smallest next CPU-burst time

• Non Preemptive or Preemptive

Process Arrival Time (ms)

Burst Time (ms)

P1 0 8

P2 0 5

P3 2 7

P4 2 2

Page 18: CMT603 Lecture 3 Scheduling. Contents Intro to scheduling Preemption Scheduling Algorithms –?–? –?–? –?–?

Process Arrival Time (ms)

Burst Time (ms)

P1 0 8

P2 0 5

P3 2 7

P4 2 2

Example: SJF Non Preemptive

P2 P4

50 7 2214

P1P3

• Average Wait Time = (14+0+5+3)/4 = 5.5

Page 19: CMT603 Lecture 3 Scheduling. Contents Intro to scheduling Preemption Scheduling Algorithms –?–? –?–? –?–?

Exercise

Process Arrival Time (ms)

Burst Time (ms)

P1 0 8

P2 0 5

P3 2 7

P4 2 2

Using SJF Preemptive

What is the averagewait time?

P2 P4

40 7 2214

P1P3

2

P2

• Average wait time = (14+2+5+0)/3 = 5.25

Page 20: CMT603 Lecture 3 Scheduling. Contents Intro to scheduling Preemption Scheduling Algorithms –?–? –?–? –?–?

Analysis of SJF

• Optimal with respect to average waiting time

• How does scheduler know the length of the next CPU-burst time?

Page 21: CMT603 Lecture 3 Scheduling. Contents Intro to scheduling Preemption Scheduling Algorithms –?–? –?–? –?–?

Summary (2)

• Intro to scheduling

• Preemption

• Scheduling Algorithms– FCFS– SJF

Page 22: CMT603 Lecture 3 Scheduling. Contents Intro to scheduling Preemption Scheduling Algorithms –?–? –?–? –?–?

Exercise sheets