L3 ASR2 07 Scheduling
L3 ASR2 07 Scheduling
Basic Concepts
Scheduling Criteria
Scheduling Algorithms
Multiple-Processor Scheduling
Real-Time Scheduling
Thread Scheduling
Operating Systems Examples
Java Thread Scheduling
Algorithm Evaluation
Operating System Concepts – 7th Edition, Feb 2, 2005 5.2 Silberschatz, Galvin and Gagne ©2005
1
Basic Concepts
Operating System Concepts – 7th Edition, Feb 2, 2005 5.3 Silberschatz, Galvin and Gagne ©2005
Operating System Concepts – 7th Edition, Feb 2, 2005 5.4 Silberschatz, Galvin and Gagne ©2005
2
Histogram of CPU-burst Times
Operating System Concepts – 7th Edition, Feb 2, 2005 5.5 Silberschatz, Galvin and Gagne ©2005
CPU Scheduler
Operating System Concepts – 7th Edition, Feb 2, 2005 5.6 Silberschatz, Galvin and Gagne ©2005
3
Dispatcher
Operating System Concepts – 7th Edition, Feb 2, 2005 5.7 Silberschatz, Galvin and Gagne ©2005
Scheduling Criteria
Operating System Concepts – 7th Edition, Feb 2, 2005 5.8 Silberschatz, Galvin and Gagne ©2005
4
Optimization Criteria
Operating System Concepts – 7th Edition, Feb 2, 2005 5.9 Silberschatz, Galvin and Gagne ©2005
First-
First-Come, First-
First-Served (FCFS) Scheduling
P1 P2 P3
0 24 27 30
Waiting time for P1 = 0; P2 = 24; P3 = 27
Average waiting time: (0 + 24 + 27)/3 = 17
Operating System Concepts – 7th Edition, Feb 2, 2005 5.10 Silberschatz, Galvin and Gagne ©2005
5
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
Operating System Concepts – 7th Edition, Feb 2, 2005 5.11 Silberschatz, Galvin and Gagne ©2005
Associate with each process the length of its next CPU burst. Use
these lengths to schedule the process with the shortest time
shortest next CPU burst algorithm
Two schemes:
nonpreemptive – once CPU given to the process it cannot be
preempted until completes its CPU burst
preemptive – if a new process arrives with CPU burst length
less than remaining time of current executing process,
preempt. This scheme is know as the
Shortest-Remaining-Time-First (SRTF)
Operating System Concepts – 7th Edition, Feb 2, 2005 5.12 Silberschatz, Galvin and Gagne ©2005
6
Example of Non-Preemptive SJF
P1 P3 P2 P4
0 3 7 8 12 16
Operating System Concepts – 7th Edition, Feb 2, 2005 5.13 Silberschatz, Galvin and Gagne ©2005
P1 P2 P3 P2 P4 P1
0 2 4 5 7 11 16
Operating System Concepts – 7th Edition, Feb 2, 2005 5.14 Silberschatz, Galvin and Gagne ©2005
7
Determining Length of Next CPU Burst
Operating System Concepts – 7th Edition, Feb 2, 2005 5.15 Silberschatz, Galvin and Gagne ©2005
τ0 = 10
α=½
Operating System Concepts – 7th Edition, Feb 2, 2005 5.16 Silberschatz, Galvin and Gagne ©2005
8
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 - α)α tn -1 + …
+(1 - α )j α tn -j + …
+(1 - α )n +1 τ0
Operating System Concepts – 7th Edition, Feb 2, 2005 5.17 Silberschatz, Galvin and Gagne ©2005
Priority Scheduling
Operating System Concepts – 7th Edition, Feb 2, 2005 5.18 Silberschatz, Galvin and Gagne ©2005
9
Round Robin (RR)
Each process gets a small unit of CPU time (time quantum), usually 10-
100 milliseconds. After this time has elapsed, the process is preempted
and added to the end of the ready queue.
If there are n processes in the ready queue and the time quantum is q,
then each process gets 1/n of the CPU time in chunks of at most q time
units at once. No process waits more than (n-1)q time units.
Performance
q large ⇒ FIFO
q small ⇒ q must be large with respect to context switch, otherwise
overhead is too high
Time quanta: 10 to 100 milliseconds
Context switch time: less than 10 microseconds
Operating System Concepts – 7th Edition, Feb 2, 2005 5.19 Silberschatz, Galvin and Gagne ©2005
P1 P2 P3 P4 P1 P3 P4 P1 P3 P3
Operating System Concepts – 7th Edition, Feb 2, 2005 5.20 Silberschatz, Galvin and Gagne ©2005
10
Time Quantum and Context Switch Time
Operating System Concepts – 7th Edition, Feb 2, 2005 5.21 Silberschatz, Galvin and Gagne ©2005
Average turnararound time can be improved if most processes finish their next CPU
burst in one time quantum
80% of the CPU burst should be shorter than the time quantum
Operating System Concepts – 7th Edition, Feb 2, 2005 5.22 Silberschatz, Galvin and Gagne ©2005
11
Multilevel Queue
Operating System Concepts – 7th Edition, Feb 2, 2005 5.23 Silberschatz, Galvin and Gagne ©2005
Operating System Concepts – 7th Edition, Feb 2, 2005 5.24 Silberschatz, Galvin and Gagne ©2005
12
Multilevel Feedback Queue
Operating System Concepts – 7th Edition, Feb 2, 2005 5.25 Silberschatz, Galvin and Gagne ©2005
Three queues:
Q0 – RR with time quantum 8 milliseconds
Q1 – RR time quantum 16 milliseconds
Q2 – FCFS
Scheduling
A new job enters queue Q0 which is served FCFS. When it
gains CPU, job receives 8 milliseconds. If it does not finish in 8
milliseconds, job is moved to queue Q1.
At Q1 job is again served FCFS and receives 16 additional
milliseconds. If it still does not complete, it is preempted and
moved to queue Q2.
Operating System Concepts – 7th Edition, Feb 2, 2005 5.26 Silberschatz, Galvin and Gagne ©2005
13
Multilevel Feedback Queues
Operating System Concepts – 7th Edition, Feb 2, 2005 5.27 Silberschatz, Galvin and Gagne ©2005
Multiple-Processor Scheduling
Operating System Concepts – 7th Edition, Feb 2, 2005 5.28 Silberschatz, Galvin and Gagne ©2005
14
Real-Time Scheduling
Operating System Concepts – 7th Edition, Feb 2, 2005 5.29 Silberschatz, Galvin and Gagne ©2005
15