Anda di halaman 1dari 18

CMT603

Lecture 4 Scheduling-2

Contents
Last Week
FCFS SJF

Priority scheduling Round Robin Multi Level Queues Real Systems


Linux XP

Priority Scheduling
A priority is associated with each process, and the CPU is allocated to the process with the highest priority. We assume that low numbers represent high priority. May be preemptive or non-preemptive.

Example: Priority Scheduling


Consider the following set of processes with their arrival times and the length of the CPU-burst time given in milliseconds
Process P1 P2 P3 Arrival Time 0 0 0 Priority 3 1 4 Burst time 10 1 2

P4
P5

0
0

5
2

1
5

The arrival order of the processes is P1, P2, P3, P4, P5

Example: Priority Scheduling

Proc ess P1 P2 P3 P4 P5

Arrival Time 0 0 0 0 0

Prio rity 3 1 4 5 2

Burst time 10 1 2 1 5

P2
0 1

P5
6

P1
16

P3 P4
18 19

Average wait time= (6+0+16+18+1)/5 = 8.2

Exercise
Process P1 P2 P3 P4 Arrival Time Priority Burst time 0 5 8 10 3 1 4 5 8 1 2 1

T=8 T=6 T=5 T=0

T=16

P5

11

8 3 3 1 - - - 1 - - - - - 2 2 1 - 1 1 1 5 -

T=9

T=10

T=11

P1
0 5

P2 P1
6 9

P3
11

P5

P4
16 17

Average wait time = (1+0+1+6+0)/5 = 1.6

Analysis of Priority Scheduling


May leave some low-priority processes waiting indefinitely for CPU
Starvation.

Aging a technique of gradually increasing the priority of processes that have waited for a long time.

Round Robin
Similar to FCFS but with preemption. Have a time quantum (time slice).
Let the first process in the queue run until it exceeds the time quantum, then run the next process.

Process Arrival Time Burst Time P1 0 24 P2 0 3 P3 0 9


The arrival order of the processes is P1,P2,P3

Process Arrival Time Burst Time

Example: Round Robin


Time Quantum = 5 milliseconds P1 P2 P3
0 5 8 13

P1 P2 P3

0 0 0

24 3 9

P1 P3 P1
18 22

P1

P1
36

Average waiting Time = (12+5+13)/3 = 10 Time Quantum = 24 milliseconds

P1
0

P2
24 27

P3
36

Average waiting Time = (0+24+27)/3 = 17 Turns into FCFS scheduling

Process Arrival Time Burst Time

Exercise: Round Robin

P1
P2 P3

0
0 0

24
3 9

Time quantum = 2 milliseconds


P1 P2 P3 P1 P2 P3 P1 P3 P1 P3 P1 P3 P1 P1 P1 P1 P1 P1 P1
0 2 4 6 8 9 11 13 15 17 19 22 23 36

Average waiting Time = (12+6+13)/3 = 10.33 What if context-switch time = 1 millisecond? Total context-switch time =12

Analysis of Round Robin Scheduling


Very small quantum - large context switch overhead. Very big quantum - turns into FCFS. The time quantum should be large with respect to the context-switch time.
In most modern OSs
Quantum time range: 10-100 milliseconds Context-switch time: <10 microseconds

Scheduling algorithms.
FCFS, SJF, Priority, Round Robin. Preemptive, Non preemptive

All Basic Algorithms


Real life systems have a mix of these approaches

Multi level Queues


Separate scheduling within queues Scheduling between queues
Foreground processes (Round Robin)
Background processes (FCFS)

Queue Scheduler (Priority)

Linux
Priority Queue
0-99 real time 100-140 nice

Higher priority = longer time slice Once time slice is expired, wait for all other slices to expire

XP
32 Level Priority Algorithm in two classes
1-15 Variable 16-31 Real time Also 0 for memory management

FIFO queue in each level. When Quantum runs out in Variable Class priority drops
Limits CPU intensive processes

Foreground windows +3 priority

Summary
Last Week
FCFS SJF

Priority scheduling Round Robin Multi Level Queues Real Systems


Linux XP

Group Discussion
For 5-10 minutes, discuss how you would design a scheduling algorithm for a Desktop PC, using multilevel queues.

Exercise sheet

Anda mungkin juga menyukai