Part3 (CPU Scheduling)
Part3 (CPU Scheduling)
• Basic Concepts
• Scheduling Criteria
• Scheduling Algorithms
– Uniprocessor (single-core)
scheduling
– Multiprocessor (multi-core)
scheduling
System-wide Objectives:
1. Max. CPU Utilization: Keep the CPU as
busy as possible
– Percentage of time during which the
CPU cores are busy executing
processes.
– (Sum of execution time on each
core) divided by (total time
multiplied by number of cores)
2. Max. Throughput: Number of processes
that complete their execution per unit
Operating Systems 3.6 Part 3 Process
Scheduling Objectives (Cont.)
Individual Process Objectives:
1. Min. Turnaround Time: Amount of time
to execute a particular process, i.e.,
from the time of creation to the time of
termination
– Time elapsed between “admitted”
and “exit” transitions for a process
– Average over all processes is
denoted as average turnaround time
0 24 27 30
0 3 6 30
• Two schemes:
1. Nonpreemptive: Once core is given to a
process, it cannot be preempted until it
completes its CPU burst
2. Preemptive (also known as Shortest
Remaining-Time First or SRTF): If a newly
created process has CPU burst length less
than the remaining CPU burst of currently
Operating Systems 3.13 Part 3 Process
Example of Nonpreemptive SJF
Process Arrival Time Burst Time
P1 0.0 7
P2 2.0 4
P3 4.0 1
P4 5.0 4
0 3 7 8 12 16
P1 P2 P3 P2 P4 P1
0 2 4 5 7 11 16
P1 P2 P3 P4
• Average waiting time = (9 + 1 + 0 +2)/4 = 3
• Performance:
– n processes in ready queue implies
waiting time is no more than (n-1)q
time units
Operating Systems 3.17 Part 3 Process
Example: RR with Time Quantum
= 20
Process Burst Time
P1 53 33
P2 17 0
P3 68 48
P4 24 4
• No well-
defined
relationship
between
average
Assume arrival turnaround
order is P1, P2, time and
P3, P4 all at quantum size
time 0
• Average
turnaround
time remains
fixed once
quantum size
is larger than
maximum CPU
burst length
Operating Systems 3.20 Part 3 Process
Multilevel Queue Scheduling
Core P1 P3 P1
1
Core P2 P4
2
0 2 4 5 6 8 10
P1 P2 P3 P4
P3 68 48 28 0
P4 24 4 0
• RR0 scheduling
20 40 60 73
dual-core Gantt Chart:
P1 P4 P3 P1
Core
1
Core P2 P3 P1 P4 P3
2
0 17 37 57 61 89
Operating Systems 3.28 Part 3 Process
Global Scheduling: Issues