Professional Documents
Culture Documents
Operating System Concepts 6.1 Silberschatz and Galvin 2004 revised by Wiseman Operating System Concepts 6.2 Silberschatz and Galvin 2004 revised by Wiseman
Operating System Concepts 6.3 Silberschatz and Galvin 2004 revised by Wiseman Operating System Concepts 6.4 Silberschatz and Galvin 2004 revised by Wiseman
Dispatcher Scheduling Criteria
Operating System Concepts 6.5 Silberschatz and Galvin 2004 revised by Wiseman Operating System Concepts 6.6 Silberschatz and Galvin 2004 revised by Wiseman
• Example: Process Burst Time Suppose that the processes arrive in the order
P1 24 P2 , P3 , P1 .
P3 3
P2 P3 P1
• Suppose that the processes arrive in the order: P1 , P2 , P3
The Gantt Chart for the schedule is:
0 3 6 30
P1 P2 P3 • Waiting time for P1 = 6; P2 = 0; P3 = 3
• Average waiting time: (6 + 0 + 3)/3 = 3
0 24 27 30 • Much better than previous case.
• Waiting time for P1 = 0; P2 = 24; P3 = 27 • Convoy effect short process behind long process
• Average waiting time: (0 + 24 + 27)/3 = 17
Operating System Concepts 6.7 Silberschatz and Galvin 2004 revised by Wiseman Operating System Concepts 6.8 Silberschatz and Galvin 2004 revised by Wiseman
Shortest-Job-First (SJF) Scheduling Example of Non-Preemptive SJF
• Associate with each process the length of its next CPU burst. Process Arrival Time Burst Time
Use these lengths to schedule the process with the shortest time. P1 0.0 7
• Two schemes: P2 2.0 4
– nonpreemptive – once CPU given to the process it cannot P3 4.0 1
be preempted until completes its CPU burst.
P4 5.0 4
– Preemptive – if a new process arrives with CPU burst length
less than remaining time of current executing process, • Gantt Chart of SJF (non-preemptive):
preempt. This scheme is know as the
Shortest-Remaining-Time-First (SRTF).
P1 P3 P2 P4
• SRTF is optimal – gives minimum average waiting time for a
given set of processes.
0 3 7 8 12 16
• Average waiting time = (0 + 6 + 3 + 7)/4 = 4
Operating System Concepts 6.9 Silberschatz and Galvin 2004 revised by Wiseman Operating System Concepts 6.10 Silberschatz and Galvin 2004 revised by Wiseman
Process Arrival Time Burst Time • Can only estimate the length.
P1 0.0 7 • Can be done by using the length of previous CPU bursts, using
P2 2.0 4 exponential averaging.
P3 4.0 1 1. tn = actual lenght of nthCPU burst
P4 5.0 4 2. τ n+1 = predicted value for the next CPU burst
• Gantt Chart of SRTF (preemptive SJF): 3. α , 0 ≤ α ≤ 1
4. Define :
P1 P2 P3 P2 P4 P1 τ n +1 = α t n + (1 − α )τ n
0 2 4 5 7 11 16
• Average waiting time = (9 + 1 + 0 +2)/4 = 3
Operating System Concepts 6.11 Silberschatz and Galvin 2004 revised by Wiseman Operating System Concepts 6.12 Silberschatz and Galvin 2004 revised by Wiseman
Examples of Exponential Averaging Example of Prediction
• α =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
• Since both α and (1 - α) are less than or equal to 1, each
successive term has less weight than its predecessor.
Operating System Concepts 6.13 Silberschatz and Galvin 2004 revised by Wiseman Operating System Concepts 6.14 Silberschatz and Galvin 2004 revised by Wiseman
• A priority number (integer) is associated with each process • Each process gets a small unit of CPU time (time quantum),
usually 10-100 milliseconds. After this time has elapsed, the
• The CPU is allocated to the process with the highest priority
process is preempted and added to the end of the ready queue.
(smallest integer ≡ highest priority).
– Preemptive • If there are n processes in the ready queue and the time
– nonpreemptive 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
• SJF is a priority scheduling where priority is the predicted next than (n-1)q time units.
CPU burst time.
• Performance
• Problem - Starvation – low priority processes may never execute. – q large ⇒ FCFS
• Solution - Aging – as time progresses increase the priority of the – q small ⇒ q must be large with respect to context switch,
process. otherwise overhead is too high.
Operating System Concepts 6.15 Silberschatz and Galvin 2004 revised by Wiseman Operating System Concepts 6.16 Silberschatz and Galvin 2004 revised by Wiseman
Example: RR with Time Quantum = 20 How a Smaller Time Quantum Increases Context Switches
P1 P2 P3 P4 P1 P3 P4 P1 P3 P3
Operating System Concepts 6.17 Silberschatz and Galvin 2004 revised by Wiseman Operating System Concepts 6.18 Silberschatz and Galvin 2004 revised by Wiseman
Operating System Concepts 6.19 Silberschatz and Galvin 2004 revised by Wiseman Operating System Concepts 6.20 Silberschatz and Galvin 2004 revised by Wiseman
Multilevel Feedback Queue Multilevel Feedback Queues
Operating System Concepts 6.21 Silberschatz and Galvin 2004 revised by Wiseman Operating System Concepts 6.22 Silberschatz and Galvin 2004 revised by Wiseman
• Three queues: • CPU scheduling more complex when multiple CPUs are
– Q0 – time quantum 8 milliseconds available.
– Q1 – time quantum 16 milliseconds • Symmetric multiprocessing – all of the processors run an
– Q2 – FCFS identical copy of the same kernel,
• Scheduling – Implemented on Homogeneous processors.
– A new job enters queue Q0 which is served RR. When it – A mechanism for data locking should be implemented.
gains CPU, job receives 8 milliseconds. If it does not finish – All of UNIX versions, WindowsNT and Windows2000 are
in 8 milliseconds, job is moved to queue Q1. Symmetric.
– At Q1 job is again served RR and receives 16 additional • Asymmetric multiprocessing – only one processor running the
milliseconds. If it still does not complete, it is preempted scheduler which accesses the system data structures.
and moved to queue Q2. – Processors can be unequal.
– alleviating the need for data sharing.
– Used on large clusters or Supercomputers.
Operating System Concepts 6.23 Silberschatz and Galvin 2004 revised by Wiseman Operating System Concepts 6.24 Silberschatz and Galvin 2004 revised by Wiseman
Backfilling Gang Scheduling
Operating System Concepts 6.25 Silberschatz and Galvin 2004 revised by Wiseman Operating System Concepts 6.26 Silberschatz and Galvin 2004 revised by Wiseman
Operating System Concepts 6.27 Silberschatz and Galvin 2004 revised by Wiseman Operating System Concepts 6.28 Silberschatz and Galvin 2004 revised by Wiseman
Evaluation of CPU Schedulers by Simulation Linux Scheduling
Operating System Concepts 6.29 Silberschatz and Galvin 2004 revised by Wiseman Operating System Concepts 6.30 Silberschatz and Galvin 2004 revised by Wiseman
Operating System Concepts 6.31 Silberschatz and Galvin 2004 revised by Wiseman Operating System Concepts 6.32 Silberschatz and Galvin 2004 revised by Wiseman