Escolar Documentos
Profissional Documentos
Cultura Documentos
Review: Deadlock
Starvation vs. Deadlock
No preemption
Circular wait
10/04/10
Lec 10.2
R1
T1
R2
T2
R3
R1
T3
R4
Simple Resource
Allocation Graph
10/04/10
T1
R2
T2
R3
R1
T3
R4
Allocation Graph
With Deadlock
Kubiatowicz CS162 UCB Fall 2010
T1
T2
T3
R2
T4
Allocation Graph
With Cycle, but
No Deadlock
Lec 10.3
10/04/10
Lec 10.4
Preventing Deadlock
Scheduling Policy goals
Policy Options
Implementation Considerations
Lec 10.5
R1
T1
10/04/10
T2
T3
R2
T4
Lec 10.6
Lec 10.7
10/04/10
Lec 10.8
Lec 10.9
d
we
lo le
al u
is R
D By
10/04/10
Lec 10.10
10/04/10
Lec 10.11
10/04/10
Lec 10.12
Administrivia
Officially Project 1 code due tomorrow (10/5)
However, autograder not up until Friday, so will let you turn in
code on Wednesday. However, Doc still due Wednesday
Conserve your slip days!!! Its not worth it yet.
Group Evaluation: Required! (Due Wednesday 10/6)
Group eval (with TA oversight) used in computing grades
Zero-sum game!
Must do a group evaluation after you finish project
Midterm I coming up in two weeks
Monday, 10/18, 6:00-9:00 (Location: 155 Dwinelle)
Should be 2 hour exam with extra time
Closed book, one page of hand-written notes (both sides)
Conflict with exam? Let me know (send me email)
No class on day of Midterm
I will post extra office hours for people who have questions
about the material (or life, whatever)
Midterm Topics
Everything up to previous Wednesday, 10/13
History, Concurrency, Multithreading, Synchronization,
Spaces
10/04/10 Protection/Address
Kubiatowicz
CS162 UCB Fall 2010
Lec 10.13
CPU Scheduling
Lec 10.14
Scheduling Assumptions
CPU scheduling big area of research in early 70s
Many implicit assumptions for CPU scheduling:
One program per user
One thread per program
Programs are independent
If I run one compilation job and you run five, you get five
times as much CPU on many operating systems
USER2
USER3
USER1 USER2
Time
10/04/10
Lec 10.15
10/04/10
Lec 10.16
Maximize Throughput
Fairness
10/04/10
Lec 10.17
P2
24
P3
27
30
10/04/10
Lec 10.18
P3
P1
30
In second case:
Simple (+)
Short jobs get stuck behind long ones (-)
10/04/10
10.19
Performance
q large FCFS
q small Interleaved (really small hyperthreading?)
q must be large with respect to context switch, otherwise
overhead is too high (all overhead)
10/04/10
Lec 10.20
Process
P1
P2
P3
P4
Burst Time
53
8
68
24
P2
20
28
P3
P4
48
P1
68
P3
P4
P1
P3
P3
P1=(68-20)+(112-88)=72 P2=(20-0)=20
Waiting time for
P3=(28-0)+(88-48)+(125-108)=85
P4=(48-0)+(108-68)=88
Average waiting time = (72+20+85+88)/4=66
Average completion time = (125+28+153+112)/4 = 104
10/04/10
Lec 10.21
Round-Robin Discussion
How do you choose time slice?
What if too big?
10/04/10
Lec 10.22
RR scheduler quantum of 1s
All jobs start at the same time
Job #
FIFO
RR
100
991
200
992
900
999
10
1000
1000
Best FCFS:
0
P4
[24]
8
32
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
10/04/10
P1
[53]
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
Lec 10.24
10/04/10
Lec 10.25
Discussion
SJF/SRTF are the best you can do at minimizing
average response time
Provably optimal (SJF among non-preemptive, SRTF
among preemptive)
Since SRTF is always at least as good as SJF, focus on
SRTF
10/04/10
Lec 10.26
A or B
Cs
I/O
Three jobs:
Cs
I/O
Cs
I/O
With FIFO:
Once A or B get in, keep CPU for two weeks
Lec 10.27
Cs
I/O
CABAB
Cs
I/O
C
Cs
I/O
10/04/10
Cs
I/O
Disk
CsUtilization:
~90%
I/O but lots
of wakeups!
Cs
I/O
A
Disk
Utilization:
C
9/201
~ 4.5%
Disk
Utilization:
90%
SRTF
Kubiatowicz CS162 UCB Fall 2010
Lec 10.28
Starvation
When you submit a job, have to say how long it will take
To stop cheating, system kills job if takes too long
Bottom line, cant really know how long job will take
However, can use SRTF as a yardstick
for measuring other policies
Optimal, so cant do any better
10/04/10
Lec 10.29
Summary (Deadlock)
Four conditions required for deadlocks
Mutual exclusion
No preemption
Circular wait
Deadlock detection
Deadlock prevention
10/04/10
Lec 10.30
Summary (Scheduling)
Scheduling: selecting a waiting process from the ready
queue and allocating the CPU to it
FCFS Scheduling:
Run threads to completion in order of submission
Pros: Simple
Cons: Short jobs get stuck behind long ones
Round-Robin Scheduling:
10/04/10
Lec 10.31