














Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!















t^
S h d li
Lecture 17 – Process Scheduling
In discussing processes and threads, we talked about
g p
context switching– an interrupt occurs (device completion, timer, …)– a thread causes an exception (a
trap
or a
fault
We glossed over the choice of which thread ischosen to be run nextchosen to be run next– “some thread from the ready queue”
-^
This decision is called scheduling
g
3
-^
Batch
Throughput / utilization oriented
-^
Throughput / utilization oriented
-^
Example: audit inter-bank funds transfers each night, Pixar rendering
-^
Interactive–
Response time oriented
-^
Hard Real Time–
Deadline driven– Example: embedded systems (cars, airplanes, etc.)
-^
Soft Real Time–
Video, TIVO, etc.
-^
Parallel–
Speedup driven– Example: “space-shared” use of a 1000-processor machine for largeExample:
space shared
use of a 1000 processor machine for large
simulations
-^
Others…
-^
We’ll be talking primarily about interactive schedulers (as does the text)We ll be talking primarily about interactive schedulers (as does the text).
5
-^
Long term
Sh
ld^
“j b” b
“i iti t d ”
h^
ld it b
h ld?
t
-^
Medium term– Should a running program be temporarily marked as non-
runnable (e.g., swapped out)? Short term
-^
Short term– Which thread should get the CPU next? For how long?– Which I/O operation should be sent to the disk next?
O^
lti
6
No single, compelling definition of “fair”
g^
p^
g
bound?
-^
Sometimes the goal is to be unfair:– Explicitly favor some particular class of requests– Explicitly favor some particular class of requests
(priority system), but…
i^
some service)
8
Scheduling:- Who to assign each resource to
h^
l
•••
•••
Schedulable units
Resources
9
-^
First-come first-served / First-in first-out (FCFS/FIFO)
h d l
i^
th
d^
th t th
i
j^
q^
y,
Sounds perfect!– in the real world, when does FCFS/FIFO work well?
11
Job A
B^
C time
1
C B^
Job A
2
-^
Suppose the duration of A is 5, and the durations of B and Care each 1– average response time for schedule 1 (assuming A, B,
and C all arrive at about time 0) is (5+6+7)/3 = 18/3 = 6and C all arrive at about time 0) is (5+6+7)/
18/
6
10/3 = 3.
measure:measure:• Schedule 1: A is 5/5, B is 6/1, C is 7/1 (worst is 7,
ave is 4.7)
12
Shortest processing time first / Shortest job first
p^
g^
j
(SPT/SJF)– choose the request with the smallest service
i^
t
requirement
-^
Provably optimal
with respect to average response
timetime
14
s f^
s g
t k^
t+s k
f^
t+s k
+s f g
In any schedule that is not SPT/SJF, there is somedj
t^
i^
f^
t^
f^
d^
h^
th
i^
ti
adjacent pair of requests f and g where the service time(duration) of f, s
, exceeds that of g, sf
g
The total contribution to average response time of f andThe total contribution to average response time of f andg is 2t
+2sk^
+sgf
If you interchange f and g, their total contribution will be2t
+2sk
+sfg
, which is smaller because s
< sg^
f
15
-^
Round Robin scheduling (RR)
d^
i^
d^
i^
l^
FIFO
Sounds perfect!
C^
S?
what are the warts?
17
What if all jobs are exactly the same length?
j^
y^
g
What do you set the quantum to be?– no value is “correct”
if small then context switch often incurring
g ,
p^
g
18
-^
How are you going to assign priorities?
y^
g^
g^
g^
p
-^
Starvation
if th
i^
dl^
l^
f hi h
i^
it^
j b
low-priority job will ever run
-^
Solution: “age” threads over time– increase priority as a function of accumulated wait time
d^
i^
it^
f^
ti^
f^
l t d
processing time
20
-^
In practice, any real system uses some sort of hybrid
p^
y^
y^
y
approach, with elements of FCFS, SPT, RR, and Priority
-^
Example: multi level feedback queues (MLFQ)
-^
Example: multi-level feedback queues (MLFQ)– there is a hierarchy of queues– there is a priority ordering among the queues
p^
y^
g^
g^
q
h^
diff
t^
t
history
21