Lecture4 Scheduling
Lecture4 Scheduling
Lecture4 Scheduling
Systems
Process Scheduling
and Switching
Introduction
• An important aspect of
multiprogramming is scheduling.
The resources that are scheduled are
IO and processors.
• The goal is to achieve
– High processor utilization
– High throughput
• number of processes completed per unit
time
– Low response time
• time elapse from the submission of a
request to the beginning of the response
Processor Scheduling
Short-
term
Long-
term
Dispatcher (short-term
scheduler)
Medium-
term
Short-
term
Long-
term
SWAPPING
Schematic View of
Swapping
Dynamics of Swapping
A. Frank - P. Weisberg
Context switch between
processes (2)
Steps in Context Switch
device driver {
} scheduler
} schedulerInterrupt
{
device driver
} scheduler
Mode Switch
• Various algorithms
– First-come, first-served
– Priority queues
– Round-robin
Scheduling in Linux
Real-time FIFO
Real-time round robin
Timesharing (for all non real-time processes)
Optimization Criteria
0 24 27 30
Waiting time for P1 = 0; P2 = 24; P3 = 27
• Average waiting time: (0 + 24 + 27)/3 = 17
FCFS Scheduling (Cont.)
P2 P3 P1
0 3 6 30
• Waiting time for P1 = 6; P2 = 0; P3 = 3
• Average waiting time: (6 + 0 + 3)/3 = 3
• Much better than previous case.
• Convoy effect short process behind long process
SHORTEST JOB FIRST
Shortest Job First
(Shortest Process Next)
0 3 7 8 12 16
• Average waiting time = (0 + 6 + 3 + 7)/4 = 4
Example of Preemptive
SJF
P1 P2 P3 P2 P4 P1
0 2 4 5 7 11 16
• Average waiting time = (9 + 1 + 0 +2)/4 = 3
SJF / SPN Critique
# 74
ROUND-ROBIN
Round Robin:
Architecture
Round Robin: scan class queues serving one from
each class that has a non-empty queue
Flow 1 Transmission
link
Flow 2
Round robin
Flow 3
Hardware requirement:
Jump to next non-empty queue
Round Robin
Scheduling
• Characteristics:
– Classify incoming traffic into flows (source-
destination pairs)
– Round-robin among flows
• Problems:
– Ignores packet length (GPS, Fair queuing)
– Inflexible allocation of weights (WRR,WFQ)
• Benefits:
– protection against heavy users (why?)
Round-Robin
• Waiting Time: P1 P2 P3 P1 P1 P1 P1 P1
– P1: (10-4) = 6 0 4 7 10 14 18 22 26 30
– P2: (4-0) = 4
– P3: (7-0) = 7
• Completion Time:
– P1: 30
– P2: 7
– P3: 10
• Average Waiting Time: (6 + 4 + 7)/3= 5.67
• Average Completion Time: (30+7+10)/3=15.67
Turnaround Time Varies
With The Time Quantum
Quantum = 20
A process can finish before the time quantum expires, and release the CPU.
• Waiting Time:
– P1: (68-20)+(112-88) = 72
– P2: (20-0) = 20
– P3: (28-0)+(88-48)+(125-108) = 85
– P4: (48-0)+(108-68) = 88
• Completion Time:
– P1: 125
– P2: 28
– P3: 153
– P4: 112
• Average Waiting Time: (72+20+85+88)/4 = 66.25
• Average Completion Time: (125+28+153+112)/4 = 104.5
Weighted Round-Robin
• Weighted round-robin
– Different weight wi (per flow)
– Flow j can sends wj packets in a period.
– Period of length Σ wj
• Disadvantage
– Variable packet size.
– Fair only over time scales longer than a period time.
• If a connection has a small weight, or the number of connections
is large, this may lead to long periods of unfairness.
DRR (Deficit RR)
algorithm
2nd Round
500 300 B A’s count : 500 (served)
B’s count : 0
1200 C
C’s count : 800 (served)
τ n +1 = α t n + (1 − α )τ n .
Examples of
Exponential Averaging
• α =0
– τn+1 = τn
– Recent history does not count.
• α =1
– τn+1 = tn
– Only the actual last CPU burst counts.
• If we expand the formula, we get:
τn+1 = α tn+(1 - α) α t n -1 + …
+(1 - α ) j α t n -j + …
+(1 - α )n+1 τ1
• Since both α and (1 - α) are less than or equal to 1, each
successive term has less weight than its predecessor.
More on Exponential
Averaging
Tn 6 4 6 4 13 13 13
Sn+1 ɑ=0.8 6.8 4.56 5.71 4.34 11.27 12.49 12.89
Sn+1 ɑ=0.2 8.96 7.808 7.206 6.405 7.204 7.843 8.354