Comp2240 Os W04
Comp2240 Os W04
Week 4
Much of the material on these slides comes from the recommended textbook by William Stallings
2
Lecture
DetailedPlan
content
Weekly program
Weekly program
Week 1 – Operating System Overview
Week 2 – Processes and Threads
Week 3 – Scheduling
Week 4 – Real-time System Scheduling and Multiprocessor Scheduling
16/08/2017
16/08/2017
Round
FCFS SPN SRT HRRN Feedback
robin 4
Selection æ w + sö
max[w] constant min[s] min[s – e] maxç ÷ (see text)
function è s ø
Preemptive Preemptive
Decision Non- Non- Preemptive Non-
(at time (at time
mode preemptive preemptive (at arrival) preemptive
quantum) quantum)
May be
Through- Not low if Not
quantum High High High
Put emphasized
is too
emphasized
small
May be
high,
Provides Provides
especially if
good good Provides
there is a
Response response response good Provides good Not
large
time time for time for response response time emphasized
variance in time
short short
process
processes processes
execution
times
Overhead Minimum Minimum Can be high Can be high Can be high Can be high
Penalizes
short
Penalizes Penalizes May favor
Effect on processes; Fair
long long Good balance I/O bound
processes penalizes treatment
processes processes processes
I/O bound
processes
Starvation No No Possible Possible No Possible
16/08/2017
A
First-Come-First B
Served (FCFS) C
D
5
E
A
Round-Robin B
(RR), q = 1 C
D
E
A
Round-Robin B
(RR), q = 4 C
D
E
A
Shortest Process B
Next (SPN) C
D
E
A
Shortest Remaining B
Time (SRT) C
D
E
A
Highest Response B
Ratio Next (HRRN) C
D
E
A
Feedback B
q=1 C
D
E
A
Feedback B
i
q=2 C
D
E
16/08/2017
0 5 10 15 20
COMP2240 - Semester 2 - 2017 | www.newcastle.edu.au
Figure 9.5 A Comparison of Scheduling Policies
A Comparison of Scheduling Policies
Process A B C D E
Arrival Time 0 2 4 6 8 6
Service Time (Ts) 3 6 4 5 2 Mean
FCFS
Finish Time 3 9 13 18 20
Turnaround Time (Tr) 3 7 9 12 12 8.60
Tr/Ts 1.00 1.17 2.25 2.40 6.00 2.56
RR q = 1
Finish Time 4 18 17 20 15
Turnaround Time (Tr) 4 16 13 14 7 10.80
Tr/Ts 1.33 2.67 3.25 2.80 3.50 2.71
RR q = 4
Finish Time 3 17 11 20 19
Turnaround Time (Tr) 3 15 7 14 11 10.00
Tr/Ts 1.00 2.5 1.75 2.80 5.50 2.71
SPN
Finish Time 3 9 15 20 11
Turnaround Time (Tr) 3 7 11 14 3 7.60
Tr/Ts 1.00 1.17 2.75 2.80 1.50 1.84
SRT
Finish Time 3 15 8 20 10
Turnaround Time (Tr) 3 13 4 14 2 7.20
Tr/Ts 1.00 2.17 1.00 2.80 1.00 1.59
HRRN
Finish Time 3 9 13 20 15
Turnaround Time (Tr) 3 7 9 14 7 8.00
Tr/Ts 1.00 1.17 2.25 2.80 3.5 2.14
FB q = 1
Finish Time 4 20 16 19 11
Turnaround Time (Tr) 4 18 12 13 3 10.00
Tr/Ts 1.33 3.00 3.00 2.60 1.5 2.29
FB q = 2i
Finish Time 4 17 18 20 14
Turnaround Time (Tr) 4 15 14 14 6 10.60
16/08/2017 Tr/Ts 1.33 2.50 3.50 2.80 3.00 2.63
COMP2240 - Semester 2 - 2017 | www.newcastle.edu.au
7
16/08/2017
16/08/2017
16/08/2017
16/08/2017
16/08/2017
16/08/2017
16/08/2017
Scheduling on a
multiprocessor involves
three interrelated
issues:
assignment of actual
processes to use of dispatching of a
processors multiprogramming on process
individual processors
16/08/2017
16/08/2017
• Process Dispatching
– the complex selection procedure involved in uniprocessors may not be necessary
and could even be detrimental; a simple FIFO strategy may be best - less
overhead.
16/08/2017
16/08/2017
16/08/2017
• Threads are different from processes in ways that are important for
scheduling:
– the overhead of thread switching is smaller than for process switching
– threads share resources (including memory) and there is some principle
of locality.
16/08/2017
Load Sharing/
Self Scheduling Gang Scheduling
Four approaches for
multiprocessor thread
scheduling and
processor assignment
are:
Dynamic Scheduling
Dedicated Processor Assignment
16/08/2017
16/08/2017
16/08/2017
• Some research suggests that FCFS is better than the other two
(more complicated) policies.
16/08/2017
16/08/2017
16/08/2017
16/08/2017
16/08/2017
• For some applications it is possible to provide language and system tools that
permit the number of threads in the process to be altered dynamically
– this would allow the operating system to adjust the load to improve utilization
• Both the operating system and the application are involved in making scheduling
decisions
16/08/2017
• When a job requests processors (either when the job arrives or when it
creates new threads), the OS acts as follows:
– if there are idle processors, then the request is satisfied.
– otherwise, if the job is new then it is allocated a single processor by
pre-empting a job which has more than one processor.
– if the request cannot be satisfied, the request waits in a queue for a
processor to become available, or until the job rescinds the request
(because it's not needed any more).
– when processors are released, scan queue of unsatisfied requests.
Assign one processor per new process, then allocate to existing
requesting processes on a FCFS basis.
• For instance
– the question of how many processors to allocate to a job is
analogous to the question of how many pages to allocate to a job.
16/08/2017
Cache Sharing 32 kB 32 kB
L1-I L1-D
32 kB 32 kB
L1-I L1-D
32 kB 32 kB
L1-I L1-D
32 kB 32 kB
L1-I L1-D
32 kB 32 kB
L1-I L1-D
32 kB 32 kB
L1-I L1-D
34
12 MB
L3 Cache
2 MB 2 MB
L2 Cache L2 Cache
8 MB
L3 Cache
DDR3 Memory
Hypertransport 3.1
Controllers
16/08/2017
16/08/2017
• Correctness of the system may depend not only on the logical result of
the computation but also on the time when these results are produced
• e.g.
– Tasks attempt to control events or to react to events that take place
in the outside world
– These external events occur in real time and processing must be
able to keep up
– Processing must happen in a timely fashion
• Neither too late, nor too early
16/08/2017
• Requirements:
– Must always meet all deadlines (time guarantees)
– You have to guarantee that in any situation these applications are
done in time,
– otherwise it will cause unacceptable damage or a fatal error to the
system
• Examples:
1. If the landing of a fly-by-wire jet cannot react to sudden side-winds
within some milliseconds, an accident might occur.
2. An airbag system or the ABS has to react within milliseconds
16/08/2017
• Requirements:
– Must mostly meet all deadlines
– An associated deadline that is desirable but not mandatory
– it still makes sense to schedule and complete the task even if it has
passed its deadline
• Examples:
1. Multimedia: 100 frames per day might be dropped (late)
2. Car navigation: 5 late announcements per week are acceptable
3. Washing machine: washing 10 sec over time might occur once in
10 runs, 50 sec once in 100 runs.
16/08/2017
16/08/2017
• Periodic
– Each task is repeated at a regular interval
– Max execution time is the same each period
– Arrival time is usually the start of the period
– Deadline is usually the end
• Aperiodic (sporadic)
– Each task can arrive at any time
16/08/2017
– Determinism
– Responsiveness
– User Control
– Reliability
– Fail-safe operation
16/08/2017
16/08/2017
Responsiveness includes:
• User should be able to distinguish between hard and soft tasks and to
specify relative priorities within each class
16/08/2017
16/08/2017
• Determinism
– how long an OS delay before acknowledging an interrupt
• Responsiveness
– After acknowledgment, how long does it take to service the interrupt.
• User Control
– Fine-grained control over task priority
• Reliability
• Fail-safe operation
– Preserve as much capability and data as possible when system fail
– Attempt to correct the problem or minimize its effects while continuing to run
• Stability
– at least meet all task deadlines of most critical, high-priority tasks even if some less critical
task deadlines are not always met.
16/08/2017
Request from a
real-time process Real-time process added
to head of run queue
Real-time scheduling of process Real-time
50
Current process process
Current process
Scheduling time blocked or completed
Request from a
real-time process Wait for next
preemption point
Real-time
Current process process
Preemption
Scheduling time
point
Request from a
real-time process
Real-time process preempts current
process and executes immediately
Real-time
Current process process
Scheduling time
16/08/2017
16/08/2017
16/08/2017
16/08/2017
16/08/2017
16/08/2017
Starting
• time task must begin
deadline
• measures relative
Priority
importance of the task
Completion • time task must be
deadline completed
• a task may be
Subtask decomposed into a
Processing • time required to execute scheduler mandatory subtask and
time the task to completion an optional subtask
16/08/2017
16/08/2017
𝐶1 𝐶2 𝐶𝑛
+ + ⋯+ ≤1
𝑇1 𝑇2 𝑇𝑛
16/08/2017
16/08/2017
Fixed-priority scheduling; A1 B1 A2 B1 A3 B2 A4 B2 A5 B2
A has priority
A1 A2 B1 A3 A4 A5, B2
(missed)
Fixed-priority scheduling; B1 A2 A3 B2 A5
B has priority
A1 A2 B1 A3 A4 A5, B2
(missed) (missed)
Figure 10.5 Scheduling of Periodic Real-time Tasks with Completion Deadlines (based on Table 10.2)
16/08/2017
Table 10.4
Execution Profile of Five Aperiodic Tasks
16/08/2017
64
Arrival times A B C D E
Requirements
Starting deadline B C E D A
Arrival times A B C D E
Earliest Service A C E D
deadline
Starting deadline B (missed) C E D A
Arrival times A B C D E
Earliest
deadline Service B C E D A
with unforced
idle times
Starting deadline B C E D A
Arrival times A B C D E
First-come Service
first-served A C D
(FCFS)
Starting deadline B (missed) C E (missed) D A
16/08/2017
66
P Processing Idle Processing
Time
task P execution time C
task P period T
Low
Rate (Hz)
16/08/2017
16/08/2017
16/08/2017
16/08/2017
16/08/2017
16/08/2017
• It has been proven that RMS is only guaranteed to work if the CPU
utilisation is not too high
– For three tasks, CPU utilisation must be less than 0.780
16/08/2017
1
𝐶1 𝐶2 𝐶𝑛 𝐶 𝐶 𝐶
• For RMS: + + ⋯+ ≤ 𝑛 2 − 1 For EDFS: 𝑇1 + 𝑇2 + ⋯ + 𝑇𝑛 ≤ 1
𝑛
𝑇1 𝑇2 𝑇𝑛 1 2 𝑛
16/08/2017
16/08/2017
T1
T2
preempted preempted
by T1 s unlocked
s locked by T2
T3
t1 t2 t3 t4 t5 t6 t7 t8
time
(a) Unbounded priority inversion
16/08/2017
time
76
(a) Unbounded priority inversion
Priority Inheritance
s locked
blocked by T3 by T1
(attempt to lock s) s unlocked
T1
T2
s locked preempted
by T1 s unlocked
by T3
T3
t1 t2 t3 t4 t5 t6 t7
16/08/2017
(b) Use of priority inheritance
COMP2240 - Semester 2 - 2017 | www.newcastle.edu.au
Priority Ceiling 77
16/08/2017
16/08/2017
16/08/2017
16/08/2017