Scheduling Policies: COMP 530 Introduction To Operating Systems

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

COMP 530

Introduction to Operating Systems

Scheduling Policies

Kevin Jeffay
Department of Computer Science
University of North Carolina at Chapel Hill
jeffay@cs.unc.edu
September 15, 2010

http://www.cs.unc.edu/~jeffay/courses/comp530
©2010 by Kevin Jeffay 1

Lecture 4: Scheduling Policies


Outline and key concepts

 FCFS
 Short Job First
 Priority Scheduling
 Round-Robin Scheduling
 Multi-level Feedback Queues
 Real-time Scheduling

 Readings:
» Chapter 19 (Real-time Systems)
» Chapter 21 (Linux, sec. 21.5 on Scheduling)

©2010 by Kevin Jeffay 2


Scheduling Policies
Evaluation metrics

 CPU/device utilization
Ready Running
 System throughput
ready Waiting running
 Waiting time queue

 Turnaround time synchronization queues

 Response time

©2010 by Kevin Jeffay 3

Scheduling Policies
First-Come-First-Served (FCFS)

 The discipline corresponding to FIFO queuing

 Example — 3 processes with compute times 12, 3, and 3


» Job arrival order P1, P2, P3
Execution P1 P2 P3
Time 0 12 15 18
Average response time = ( 12 + 15 + 18 )/3 = 15

» Job arrival order P2, P3, P1


Execution P2 P3 P1
Time 0 3 6 18

Average response time = ( 3 + 6 + 18 ) /3 = 9


©2010 by Kevin Jeffay 4
Scheduling Policies
Shortest-Job-First (SJF)

 Select the job that is closest to finishing


» Enqueue jobs in the ready queue in order of estimated
completion time

Head Pw, c = 9
Px, c = 12
Ready Running
Py, c = 34
Tail Pz, c = 62 ready Waiting running
queue

synchronization queues

©2010 by Kevin Jeffay 5

Shortest-Job-First Scheduling
An optimal policy for minimizing response times

 Proof sketch: Consider an SJF execution of a set of


processes
» Average response time = (r1 + r2 + r3 + r4 + r5 + r6)/6
SJF: P1 P2 P3 P4 P5 P6
0 r1 r2 r3 r4 r5 r6

 Can switching the execution order reduce response time?


XYZ: P1 P2 P4 P5 P3 P6
0 r1 r2 r4 – c3 r5 – c3 r3+c4+c5 r6
Average response
time = (r1 + r2 + (r4–c3) + (r5–c3) + (r3+c4+c5) + r6)/6
= (r1 + r2 + r3 + r4 + r5 + r6 + (c4+c5–2c3))/6
©2010 by Kevin Jeffay 6
Short-Job-First Scheduling
Estimating execution time

process P
begin
loop
<read input from user>
<process input>
end loop
end P

tn — duration of the nth CPU burst


n+1 — predicted duration of the n+1st CPU burst
n+1 = tn + (1–)n, for 0    1

 Jobs are enqueued in order of estimated completion time


» “Recent history is a good indicator of the near future”
©2010 by Kevin Jeffay 7

Scheduling Policies
Priority Scheduling (PS)
High Priority
(small number)

Head Pw, p = 9
Ready Running
Px, p = 12
Py, p = 34 ready Waiting running
queue
Tail Pz, p = 62
Low Priority
(large number)
synchronization queues

 Assign a priority (a number)  Issues:


to each job and schedule jobs » Static versus dynamic
in order of priority priority assignment
» Typically low priority values » Preemptive versus non-
equal “high priority” preemptive
©2010 by Kevin Jeffay
» Starvation 8
Priority Scheduling
Avoiding starvation

 Employ aging: Priority


» Gradually increase a Value
process’s priority
(decrease it’s priority
value) over time Time

Head Pw, p = 9
Px, p = 12 Age low Ready Running
priority
Py, p = 34 processes
Waiting
Tail Pz, p = 62 ready
queue

©2010 by Kevin Jeffay 9

Scheduling Policies
Round-Robin Scheduling (RR)

Ready Queue Running


Process
<q Completion
Px Pc Pb Pa CPU or
I/O Request
=q
Timer Interrupt

 Allocate the processor in discrete units called quantums


(or time-slices)
 Switch to the next ready process at the end of each
quantum
» Processes execute every (n – 1)q time units
 Critical issue: How big is q?
©2010 by Kevin Jeffay 10
Scheduling Policies
Multi-level feedback queues (MLF)
Level 1
q = t0
High
Priority Pa

Level 2 Running
n q = 2t0
Ready P3 P2 P1
Queues CPU
...

...
Level n
Low
Priority Py Px q = 2n-1 t
0

 Combining priority and round-robin scheduling


» n priority levels — priority scheduling between levels, round-robin within
a level
» Quantum size decreases with priority level
» Jobs are demoted to lower priority levels if they’re still executing when a
quantum expires
©2010 by Kevin Jeffay 11

Scheduling Policies
Real-time scheduling
Example: Digital video playout

/* Main processing loop */


loop
data = read( network)
video_frame = decompress(data)
write( frame_buffer, video_frame)
end loop

Timing constraint: Execute loop once every 33 ms.

 Real-time processes have timing constraints


»Timing constraints are translated into deadlines or rate
requirements
 Two dominant real-time scheduling policies:
»“Rate-Monotonic” scheduling »“Deadline” scheduling
 Priority = 1/rate (the “period”)  Priority = release time + period
©2010 by Kevin Jeffay 12
Scheduling Policies
Real-time scheduling example

Video
Process
Audio
Process

0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100

deadline scheduling: priority = release time + period


(priority = processs next “deadline” )

 Consider scheduling audio and video playout processes


»The audio process processes 1 audio sample every 20 ms
»The video process processes 1 video frame every 33 ms
©2010 by Kevin Jeffay 13

Scheduling Policies
Real-time scheduling example

Video
Process
Audio
Process

0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100

rate-monotonic scheduling: priority = 1 / rate = period

 Consider scheduling audio and video playout processes


»The audio process processes 1 audio sample every 20 ms
»The video process processes 1 video frame every 33 ms
©2010 by Kevin Jeffay 14
Lecture 4 Gut Check
Is this soaking in??

 If you’ve been studying then you should be


able to tell me the difference between…
» Starvation and throughput
» Static priority and dynamic priority scheduling
» Round-robin and multi-level feedback queues
» Scheduling policy/mechanism separation
» …

©2010 by Kevin Jeffay 15

You might also like