Documente Academic
Documente Profesional
Documente Cultură
Operating Systems
Lecture 5 - CPU Scheduling
Prof. Nalini Venkatasubramanian
nalini@ics.uci.edu
Note that some slides are adapted from course text slides 2008 Silberschatz.
Some slides also adapted from http://www-inst.eecs.berkeley.edu/~cs162/ Copyright 2010 UCB
Outline
Scheduling Objectives
Levels of Scheduling
Scheduling Criteria
Scheduling Algorithms
Scheduling Objectives
Enforcement of fairness
Enforcement of priorities
Make best use of available system resources
Give preference to processes holding key
resources.
Give preference to processes exhibiting good
behavior.
Degrade gracefully under heavy loads.
I/O boundedness
CPU boundedness
CPU Burst
Distribution.
Levels of Scheduling
Levels of Scheduling(cont.)
CPU Scheduler
Non-preemptive Scheduling
Process exits OR
Process switches to waiting state
Preemptive Scheduling
new
admitted
exit
interrupt
running
ready
I/O or
event
completion
Scheduler
dispatch
waiting
I/O or
event wait
terminated
Dispatcher
switching context
switching to user mode
jumping to the proper location in the user program to restart
that program
Dispatch Latency:
Scheduling Criteria
CPU Utilization
Throughput
Waiting time
Turnaround time
amount of time it takes from when a request was submitted until the
first response is produced, NOT output.
Optimization Criteria
Scheduling Policies
Non-preemptive
Pre-emptive
Priority
Round-Robin
Multilevel Queue
Multilevel Feedback Queue
Real-time Scheduling
First-Come, First-Served(FCFS)
Suppose the arrival
Scheduling
Example
Process
P1
P2
P3
Burst Time
24
3
3
Waiting time
P2
P3
27
30
P1 = 0;
P2 = 24;
P3 = 27;
24
P1, P2, P3
(0+24+27)/3 = 17
(24+27+30)/3 = 27
Example
Process
P1
P2
P3
Burst Time
24
3
3
P3
3
P1
6
(6+0+3)/3 = 3 , better..
30
P1 = 6; P2 = 0; P3 = 3;
P2, P3, P1
Waiting time
P2
(3+6+30)/3 = 13 , better..
Convoy Effect:
Shortest-Job-First(SJF) Scheduling
Scheme 1: Non-preemptive
Scheme 2: Preemptive
P3
7
P2
8
P4
12
P1
16
P2
2
P3 P2
4
P4
7
P1
11
16
SJF/SRTF Discussion
SRTF becomes the same as FCFS (i.e. FCFS is best can do if all jobs
the same length)
SRTF (and RR): short jobs not stuck behind long ones
Starvation
Bottom line, cant really know how long job will take
When you submit a job, have to say how long it will take
To stop cheating, system kills job if takes too long
n+1
= 0, 0 1
Define
n+1 = tn + (1- ) n
Exponential Averaging(cont.)
=0
n+1 = n; Recent history does not count
= 1
n+1 = tn; Only the actual last CPU burst counts.
Similarly, expanding the formula:
j
n+1 = tn + (1-) tn-1 + +
(1-)^j tn-j +
(1-)^(n+1) 0
Priority Scheduling
Cost to user
Importance to user
Aging
%CPU time used in last X hours.
Preemptive
Nonpreemptive
Solution
Example:
Waiting time
P1
Burst Time
53
8
68
24
P2
20
P3
28
P4
48
P1
68
P3
P4
88 108
P1
P3
P3
P1=(68-20)+(112-88)=72
P2=(20-0)=20
P3=(28-0)+(88-48)+(125-108)=85
P4=(48-0)+(108-68)=88
Process
P1
P2
P3
P4
Completion Times:
Job #
1
2
9
10
FIFO
100
200
900
1000
RR
991
992
999
1000
Also: Cache state must be shared between all jobs with RR but can be
devoted to each job with FIFO
Best FCFS:
0
P1
[53]
Quantum
Best FCFS
Q=1
Q=5
Wait
Q=8
Time
Q = 10
Q = 20
Worst FCFS
Best FCFS
Q=1
Q=5
Completion
Q=8
Time
Q = 10
Q = 20
Worst FCFS
32
P1
32
84
82
80
82
72
68
85
137
135
133
135
125
121
P3
[68]
85
P2
0
22
20
8
10
20
145
8
30
28
16
18
28
153
P3
85
85
85
85
85
85
0
153
153
153
153
153
153
68
153
P4
8
57
58
56
68
88
121
32
81
82
80
92
112
145
Average
31
62
61
57
61
66
83
69
100
99
95
99
104
121
P1
P2
P3
P4
P1
P3
P4
P1
P3
P3
0
20 37
57
77
97 117 121 134 154 162
Typically, higher average turnaround time than SRTF,
but better response
Multilevel Queue
Multilevel Queues
Background
number of queues.
scheduling algorithm for each queue.
method used to determine when to upgrade a process.
method used to determine when to demote a process.
method used to determine which queue a process will enter
when that process needs service.
Scheduling
Multiple-Processor Scheduling
Asymmetric multiprocessing
Real-Time Scheduling
Dispatch Latency
Lottery Scheduling
Algorithm Evaluation
Deterministic Modeling