Professional Documents
Culture Documents
CPU Scheduling
CPU Scheduling
CPU Scheduling
CPU Scheduling
• Basic Concepts
• Scheduling Criteria
• Scheduling Algorithms
• Algorithm Evaluation
Basic Concepts
• Maximum CPU
utilization obtained :
multiprogramming
• Priority Scheduling
• Commonly, α set to ½
Prediction of the Length of the Next CPU Burst
Shortest-remaining-time-first
• Preemptive version of SJF is called
shortest-remaining-time-first
• Example illustrating the concepts of varying arrival times
and preemption.
ProcessA arri Arrival TimeT Burst Time
P1 0 8
P2 1 4
P3 2 9
P4 3 5
• Preemptive SJF Gantt Chart
Answer 5ms
??
• Consider the following set of processes, with the
arrival times and the CPU-burst times given in
milliseconds
Process Arrival Time Burst Time
P1 0 5
P2 1 3
P3 2 3
P4 4 1
• What is the average turnaround time for these
processes with the preemptive shortest remaining
processing time first (SRPT) algorithm ?
Answer 5.5
*??*
Consider the following table (Assume Non Preemptive scheduling):
Process Arrival Time Burst Time
P1 0.0 8
P2 0.4 4
P3 1.0 1
a. Give the Gantt Chart & Calculate average turnaround time using
i) FCFS scheduling
ii) SJF scheduling
b. Give the Gantt Chart & Compute average turnaround time if the
CPU is left idle for the first 1 unit
and then SJF scheduling is used. (Remember that processes P1 and
P2 are waiting during this idle time, so their waiting time may
increase.)
Round Robin (RR)
• Designed for time-sharing systems
• Each process gets a small unit of CPU time (time
quantum q).
• 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 (hardware support) interrupts every quantum
to schedule next process
Round Robin (RR)
• Performance
– q large ⇒ FIFO
– q small ⇒ q must be large with respect to context
switch, otherwise overhead is too high
Round Robin (RR) algorithm
Example of RR with Time Quantum = 4
■ System executes the highest priority process; processes with the same
priority will be run using round-robin.
• 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
Logical Questions
What scheduling policy will you use for each of
the following cases? Explain your reasons for
choosing them.
a. The processes arrive at large time intervals:
b. The system’s efficiency is measured by the
percentage of jobs completed.
c. All the processes take almost equal amounts
of time to complete.
a. FCFS
b. STF
c. FCFS or RR
• What happens if the time allocated in a
Round Robin Scheduling is very large? And
what happens if the time allocated is very
low?