CPU Scheduling
CPU Scheduling
CPU Scheduling
Presented
by
Soma Hazra
Outline…
Basic Concepts
Scheduling Criteria
Scheduling Algorithms
First-Come-First-Serve (FCFS) Scheduling
Shortest Job First (SJF) Scheduling
Priority Scheduling
Round-Robin (RR) Scheduling
Multilevel Queue Scheduling
Multilevel Feedback Queue Scheduling
Basic Concepts
Scheduling is a fundamental operating-system
function.
Almost all computer resources are scheduled before
use.
CPU scheduling is the basis of multi-programmed
operating system.
The objective of multiprogramming is to Maximize
the CPU utilization.
As CPU is one of the primary resources, its scheduling
is central to the operating-system design.
The success of CPU scheduling depends on the
process execution cycle.
The execution cycles of process are called as CPU
burst and I/O burst cycle.
CPU - I/O Bursts Cycle
Processes alternate between
these two states.
Process execution begins with
a CPU burst.
That is followed by an I/O
burst then another CPU burst,
then another I/O burst, and so
on.
The last CPU burst will end up
with a system request to
terminate execution, rather
than with another I/O burst.
CPU Scheduler
Selects from among the processes in memory that are
ready to execute, and allocates the CPU to one of them.
CPU scheduling decisions may take place when a process:
1. Switches from running to waiting state.
2. Switches from running to ready state.
3. Switches from waiting to ready.
4. Terminates.
Scheduling under 1 and 4 is nonpreemptive.
All other scheduling is preemptive.
Under nonpreemptive scheduling, once the CPU has been
allocated to a process, the process keeps the CPU until it
releases the CPU either by terminating or by switching to
the waiting state.
Dispatcher
Dispatcher module gives control of the CPU to the
process selected by the short-term scheduler. This
involves:
switching context
switching to user mode
jumping to the proper location in the user program to
restart that program
Dispatch latency – time it takes for the dispatcher to
stop one process and start another running.
Scheduling Criteria
CPU utilization – keep the CPU as busy as possible.
Throughput – the number of processes that complete their
execution per time unit.
Turnaround time – the interval from the time of submission
to the time of completion of a process. [OR]
Turnaround time (TAT) = Finishing time – Arrival time
Waiting time – the sum of the time periods spends waiting
in the ready queue. [OR]
Waiting time (WT) = Starting time – Arrival time
Response time – amount of time it takes from when a
request was submitted until the first response is produced.
[OR]
Response time (RT) = First response – Arrival time
Optimization Criteria
Maximum CPU utilization
Maximum throughput
Minimum turnaround time
Minimum waiting time
Minimum response time
P1 P2 P3
0 24 27 30
Turnaround time for P1 = 24; P2 = 27; P3 = 30
Average TAT time : (24 + 27 + 30 )/3 = 27 ms
Waiting time for P1 = 0; P2 = 24; P3 = 27
Average WT: (0 + 24 + 27)/3 = 17 ms
Response time for P1 = 0; P2 = 24; P3 = 27 (Same as WT in Case Non-PS)
FCFS Scheduling contd…
Suppose that the processes arrive in the order P2 , P3 , P1 .
The Gantt chart for the schedule is:
P2 P3 P1
0 3 6 30
P1 P3 P2 P4
0 3 7 8 12 16
P1 P2 P3 P2 P4 P1
0 2 4 5 7 11 16
P1 P2 P3 P1 P2 P3 P1 P1 P1 P1
0 5 10 15 20 21 24 29 34 39 44