Académique Documents
Professionnel Documents
Culture Documents
CPU Scheduling
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
2 / 22
Process states
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
2 / 22
Process states
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
2 / 22
Scheduling policies
the scheduling policy: how does the OS select a process from the
ready queue to execute?
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
3 / 22
Scheduling policies
the scheduling policy: how does the OS select a process from the
ready queue to execute?
CPU scheduler invoked to carry out scheduling policies during
hardware interrupts and also system calls
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
3 / 22
Scheduling metrics
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
4 / 22
Workload assumptions
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
5 / 22
First Cum First Served (FCFS)
Example:
A arrived just before B which arrived just before C.
Each job runs for 10 seconds.
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
6 / 22
First Cum First Served (FCFS)
Example:
A arrived just before B which arrived just before C.
Each job runs for 10 seconds.
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
6 / 22
First Cum First Served
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
7 / 22
First Cum First Served
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
7 / 22
First Cum First Served
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
7 / 22
First Cum First Served
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
7 / 22
First Cum First Served
Run the shortest job first, then the next shortest, and so on
Non-preemptive = scheduler not allowed to interrupt a running process
Example:
A arrived just before B which arrived just before C.
A runs for 100 seconds, B and C run for 10 each.
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
8 / 22
Shortest Job First (SJF)
Run the shortest job first, then the next shortest, and so on
Non-preemptive = scheduler not allowed to interrupt a running process
Example:
A arrived just before B which arrived just before C.
A runs for 100 seconds, B and C run for 10 each.
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
8 / 22
SJF with late arrivals from B and C
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
9 / 22
SJF with late arrivals from B and C
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
9 / 22
Shortest Time-to-Completion First (STCF)
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
10 / 22
Shortest Time-to-Completion First (STCF)
Example:
A arrives at t=0 and needs to run for 100 seconds.
B and C arrive at t=10 and each need to run for 10 seconds
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
11 / 22
Shortest Time-to-Completion First (STCF)
Example:
A arrives at t=0 and needs to run for 100 seconds.
B and C arrive at t=10 and each need to run for 10 seconds
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
11 / 22
New scheduling metric: Response time
The time from when the job arrives to the first time it is scheduled.
SJF (and STCF) are not particularly good for response time.
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
12 / 22
Why SJF is not that great for response time?
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
13 / 22
Why SJF is not that great for response time?
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
13 / 22
Round Robin (RR) Scheduling
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
14 / 22
Round Robin (RR) Scheduling
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
14 / 22
RR Scheduling Example
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
15 / 22
RR Scheduling Example
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
15 / 22
The length of the time slice is critical
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
16 / 22
The length of the time slice is critical
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
16 / 22
So Far
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
17 / 22
Incorporating I/O
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
18 / 22
Incorporating I/O (contd.)
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
19 / 22
Incorporating I/O (contd.)
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
20 / 22
Problems
we would like to
optimize turnaround time
minimize response time (for interactive users)
Two types of schedulers
SJF and STCF: optimize turnaround time, but are bad for response
time
RR: optimize response time, but is bad for turnaround time
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
21 / 22
Lecture reading
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
22 / 22