cpu scheduling
Download
Report
Transcript cpu scheduling
CH 5. CPU Scheduling
2015-11-02
5.1 Basic Concepts
CPU Scheduling
context switching
CPU switching for another process
saving old PCB and loading new PCB
dispatcher
give control of the CPU to the process selected by the CPU
scheduler
CPU-I/O Burst Cycle
Process execution begins with a CPU burst
5.1 Basic Concepts
Load store
add store
read from file
Wait for I/O
CPU burst
160
I/O burst
140
Wait for I/O
CPU burst
I/O burst
frequency
Store increment
index
write to file
120
100
80
60
40
Load store
add store
read from file
20
CPU burst
0
8
16
24
32
40
burst duration (milliseconds)
Wait for I/O
I/O burst
Alternating sequence of CPU and I/O bursts
Histogram of CPU-burst times
5.2 Scheduling Criteria
Performance comparison criteria of CPU scheduling
algorithm
CPU utilization : 40% ~ 90%
throughput : finished job # per time unit
turnaround time : waiting time in the Ready Queue
response time : interactive system
preemptive & nonpreemptive Scheduling
context switching : pure overhead (PCB save, load)
Interval timer & interrupting clocking
prevent a monopoly of system
Deadline Scheduling
pay remnant cost for processing in explicit time
5.3 Scheduling Algorithms
1. FIFO(FCFS)
Finish
C
B
A
CPU
Nonpreemptive
Ex) Job
1
2
3
Burst Time
24
3
3
If arriving order 1, 2, 3
Job1
Job2 Job3
24
27
30
Average Turnaround Time = (24 + 27 + 30)/3 = 27
Average Waiting Time = (0 + 24 + 27)/3 = 17 ms
If arriving order is 2, 3, 1
A.T.T = (3 + 6 + 30) / 3 = 13
A.W.T = (0 + 3 + 6) / 3 = 3
5.3 Scheduling Algorithms
2. Round Robin Scheduling for Timesharing System
Time Quantum of Time Slice (10 ~ 100 msec)
Preemptive
New job
Finish
Ex) In the case of jobs in previous example, if time quantum is 4,
Average turnaround time is -J1
J2
4
J3
7
J1
10
J1
14
·····
J1
47 / 3 16
30
Average Waiting Time = (4 + 7 + (10 - 4)) / 3 = 17 / 3 = 5.66 ms
R.R Scheduling = Preemptive Scheduling
Time Quantum : if large
FCFS
short
like processor sharing
context switching overhead
5.3 Scheduling Algorithms
Process time = 10
Quantum
0
12
0
6
1
1
9
10
0
0
Context switches
6
1
2
3
4
5
6 7
10
8
9
10
Showing how a smaller time quantum increases context switching
Average turnaround time
5.3 Scheduling Algorithms
12.5
Process time
12.0
11.5
11.0
10.5
10.0
P1
6
P2
3
P3
1
P4
7
9.5
9.0
1
2
3
4
5
6
7
Time quantum
Showing how turnaround time varies with the time quantum
5.3 Scheduling Algorithms
3. Shortest - Job - First (SJF)
Non preemptive Scheduling
Long - Term Scheduling in Batch system : good.
Short-Term Scheduling : impossible
Job
1
2
3
4
Burst Time
6
8
7
3
J4
0
J1
3
J3
9
J2
16
24
A.W.T = (3 + 16 + 9 + 0)/4 = 7 ms.
– FCFS A.W.T = (0 + 6 + 14 + 21)/4 = 41/4 = 10.25 ms.
– AVG Turnaround Time = (3 + 9 + 16 + 24)/4 = 52/4 = 13 ms.
5.3 Scheduling Algorithms
4. Shortest-Remaining-Time-First(SRT)
Transformation of Shortest-Job-First
Preemptive SJF
Ex)
Job
1
2
3
4
Arrive Time
0
1
2
3
J1 J2
0
1
J4
5
Burst Time
8
4
9
5
J1
10
* Assign the Thrasholded Value
J3
17
26
A.W.T = ((10-1) + (1-1) + (17 -2) + (5-3))/4 = 26/4 = 6.5 ms.
– A.T.T = 17 + (5-1) + (26-2) + (10-3) =52/4 = 13 ms.
– SJF A.T.T = 14.25 ms.
– SJF A.W.T = 5.75 ms.
5.3 Scheduling Algorithms
5. Priority Scheduling
SJF : Special case of the general priority scheduling.
FCFS : Equal priority.
Ex)
Job
1
2
3
4
5
J2
0
Burst Time
10
1
2
1
5
J5
1
Priority
3
1
3
4
2
J1
6
J3
16
J4
18
19
A.W.T = 8.2 ms
A.T.T = 12 ms
Major problem : indefinite blocking or starvation.
Solution HRN
5.3 Scheduling Algorithms
6. HRN(Highest-Response-ratio-Next) : Brinch Hansen
priority = (Waiting Time + Service Time) / Service Time
Nonpreemptive method that apply process service time and
total time to wait service
5.3 Scheduling Algorithms
7. Multilevel Queue
processes each job classified into queues
ex) classify into Foreground and Background (80% : 20%)
F.G is scheduled by Round Robin algorithm
B.G is scheduled by an FCFS algorithm
highest priority
system processes
Interactive processes
Interactive editing processes
batch processes
lowest priority
student processes
Multilevel Queue scheduling
5.3 Scheduling Algorithms
8. Multilevel Feedback Queue
allow a process to move between queues
quantum = 8
quantum = 16
FCFS
Fig 5.7 Multilevel feedback queues
5.5 Real-Time Scheduling
Hard real-time
within a guaranteed time
soft real-time
less restrictive
5.6 Algorithm Evaluation
Deterministic modeling
Process
Burst Time
P1
10
P2
1
P3
2
P4
1
P5
5
maximize CPU utilization
maximize throughput)
Queueing Models
result mathematical formula that estimate the distribution of
CPU and I/O bursts.
Simulations
5.6 Algorithm Evaluation
FCFS
R•R (Quantum=1)
S.J.F
Evaluation method
Analytical evaluation
use mathematical analysis by predetermined workload, …
ex) Deterministic modeling
Queuing Model
mathematical formula, arrival rate, service rate
utilization, queue length, wait time
Simulation