Lecture 5
Lecture 5
Mechanisms and
Performance Evaluation
CPU Scheduling
• Basic Concepts
• Scheduling Criteria
• Scheduling Algorithms
• Thread Scheduling
• Multiple-Processor Scheduling
• Real-Time CPU Scheduling
• Operating Systems Examples
• Algorithm Evaluation/Performance Evaluation
Objectives
P1 P2 P3
0 24 27 30
P2 P3 P1
0 3 6 30
• Associate with each process the length of its next CPU burst
• Use these lengths to schedule the process with the shortest time
• SJF is optimal – gives minimum average waiting time for a
given set of processes
• The difficulty is knowing the length of the next CPU request
• Could ask the user
Example of SJF
P1 P2 P4 P1 P3
0 1 5 10 17 26
• Each process gets a small unit of CPU time (time quantum q),
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.
• Timer interrupts every quantum to schedule next process
• Performance
• q large FIFO
• q small q must be large with respect to context switch, otherwise
overhead is too high
Example of RR with Time Quantum
=4
Process Burst Time
P1 24
P2 3
P3 3
• The Gantt chart is:
P1 P2 P3 P1 P1 P1 P1 P1
0 4 7 10 14 18 22 26 30
• 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
Multiple-Processor Scheduling
• CPU scheduling more complex when multiple CPUs are
available
• Homogeneous processors within a multiprocessor
• Asymmetric multiprocessing – only one processor accesses
the system data structures, alleviating the need for data
sharing
• Symmetric multiprocessing (SMP) – each processor is self-
scheduling, all processes in common ready queue, or each
has its own private queue of ready processes
• Currently, most common
• Processor affinity – process has affinity for processor on
which it is currently running
• soft affinity
• hard affinity
• Variations including processor sets
Algorithm Evaluation
• How to select CPU-scheduling algorithm for an OS?
• Determine criteria, then evaluate algorithms
• Deterministic modeling
• Type of analytic evaluation
• Takes a particular predetermined workload and defines the performance
of each algorithm for that workload
• Consider 5 processes arriving at time 0:
Deterministic Evaluation
RR is 23ms:
Queueing Models
• Describes the arrival of processes, and CPU and I/O bursts
probabilistically
• Commonly exponential, and described by mean
• Computes average throughput, utilization, waiting time, etc
• Computer system described as network of servers, each with
queue of waiting processes
• Knowing arrival rates and service rates
• Computes utilization, average queue length, average wait time, etc
Little’s Formula
• n = average queue length
• W = average waiting time in queue
• λ = average arrival rate into queue
• Little’s law – in steady state, processes leaving queue must
equal processes arriving, thus:
n=λxW
• Valid for any scheduling algorithm and arrival distribution
• For example, if on average 7 processes arrive per second, and
normally 14 processes in queue, then average wait time per
process = 2 seconds
Simulations