Principles of Operating Systems
Principles of Operating Systems
Operating Systems
Outline
Scheduling Objectives
Levels of Scheduling
Scheduling Criteria
Scheduling Algorithms
FCFS, Shortest Job First, Priority, Round Robin,
Multilevel
Multiple Processor Scheduling
Real-time Scheduling
Algorithm Evaluation
Scheduling Objectives
Enforcement of fairness
in allocating resources to processes
Enforcement of priorities
Make best use of available system resources
Give preference to processes holding key
resources.
Give preference to processes exhibiting good
behavior.
Degrade gracefully under heavy loads.
Program Behavior Issues
I/O boundedness
short burst of CPU before blocking for I/O
CPU boundedness
extensive use of CPU before blocking for I/O
Urgency and Priorities
Frequency of preemption
Process execution time
Time sharing
amount of execution time process has already received.
Basic Concepts
new admitted
exit terminated
interrupt
running
ready
Scheduler
I/O or dispatch
event I/O or
completion event wait
waiting
Dispatcher
CPU Utilization
Keep the CPU and other resources as busy as possible
Throughput
# of processes that complete their execution per time
unit.
Turnaround time
amount of time to execute a particular process from its
entry time.
Scheduling Criteria (cont.)
Waiting time
amount of time a process has been waiting in the ready
queue.
Response Time (in a time-sharing
environment)
amount of time it takes from when a request was
submitted until the first response is produced, NOT
output.
Optimization Criteria
Example
Process Arrival TimeBurst Time
P1 0 7
P2 2 4
P3 4 1
P4 5 4
Gantt Chart for Schedule
P1 P3 P2 P4
0 7 8 12 16
Average waiting time =
(0+6+3+7)/4 = 4
Preemptive SJF Scheduling(SRTF)
Example
Process Arrival TimeBurst Time
P1 0 7
P2 2 4
P3 4 1
P4 5 4
Gantt Chart for Schedule
P1 P2 P3 P2 P4 P1
0 2 4 5 7 11 16
Average waiting time =
(9+1+0+2)/4 = 3
Determining Length of Next CPU
Burst
One can only estimate the length of burst.
Use the length of previous CPU bursts and
perform exponential averaging.
tn = actual length of nth burst
n+1 =predicted value for the next CPU burst
= 0, 0 1
Define
n+1 = tn + (1- ) n
Exponential Averaging(cont.)
=0
n+1 = n; Recent history does not count
= 1
n+1 = tn; Only the actual last CPU burst counts.
(1-)^j tn-j + …
(1-)^(n+1) 0
Each successive term has less weight than its predecessor.
Priority Scheduling
Time Quantum = 20
Process Burst Time
P1 53
P2 17
P3 68
P4 24
Gantt Chart for Schedule
P1 P2 P3 P4 P1 P3 P4 P1 P3 P3
Typically, higher average turnaround time than SRTF, but better response
Multilevel Queue
Scheduling
New job enters Q0 - When it gains CPU, it receives 8
milliseconds. If job does not finish, move it to Q1.
At Q1, when job gains CPU, it receives 16 more
milliseconds. If job does not complete, it is preempted and
moved to queue Q2.
Multilevel Feedback Queues
Multiple-Processor Scheduling
Dispatch Latency
Problem - Need to keep dispatch latency small, OS may
enforce process to wait for system call or I/O to complete.
Solution - Make system calls preemptible, determine safe
criteria such that kernel can be interrupted.
Priority Inversion and Inheritance
Problem: Priority Inversion
Higher Priority Process needs kernel resource currently
being used by another lower priority process..higher
priority process must wait.
Solution: Priority Inheritance
Low priority process now inherits high priority until it has
completed use of the resource in question.
Real-time Scheduling - Dispatch
Latency
Algorithm Evaluation
Deterministic Modeling
Takes a particular predetermined workload and defines the
performance of each algorithm for that workload. Too specific,
requires exact knowledge to be useful.
Queuing Models and Queuing Theory
Use distributions of CPU and I/O bursts. Knowing arrival and
service rates - can compute utilization, average queue length,
average wait time etc…
Little’s formula - n = W where n is the average queue length,
is the avg. arrival rate and W is the avg. waiting time in queue.
Other techniques: Simulations, Implementation