CS 423: Operating Systems Design
Professor Adam Bates Spring 2017
CS 423 Operating System Design: Scheduling Periodic Tasks In - - PowerPoint PPT Presentation
CS 423 Operating System Design: Scheduling Periodic Tasks In Embedded Systems Professor Adam Bates Spring 2017 CS 423: Operating Systems Design Goals for Today Learning Objective: Conclude discussion inner workings of modern OS
CS 423: Operating Systems Design
Professor Adam Bates Spring 2017
CS 423: Operating Systems Design
the semester now.
2
Reminder: Please put away devices at the start of class
CS 423: Operating Systems Design
3
■ Three tasks A, B, C accumulate virtual time at
■ What is the expected share of the CPU that
Q01: A => {A:1, B:0, C:0} Q02: B => {A:1, B:2, C:0} Q03: C => {A:1, B:2, C:3} Q04: A => {A:2, B:2, C:3} Q05: B => {A:2, B:4, C:3} Q06: A => {A:3, B:4, C:3} Q07: A => {A:4, B:4, C:3} Q08: C => {A:4, B:4, C:6} Q09: A => {A:5, B:4, C:6} Q10: B => {A:5, B:6, C:6} Q11: A => {A:6, B:6, C:6} Strategy: How many quantums required for all clocks to be equal?
CS 423: Operating Systems Design
4
CS 423: Operating Systems Design
5
CS 423: Operating Systems Design
6
CS 423: Operating Systems Design
7
■ What if you want to maximize throughput?
CS 423: Operating Systems Design
8
■ What if you want to maximize throughput?
■ Shortest job first!
CS 423: Operating Systems Design
9
■ What if you want to maximize throughput?
■ Shortest job first!
■ What if you want to meet all deadlines?
CS 423: Operating Systems Design
10
■ What if you want to maximize throughput?
■ Shortest job first!
■ What if you want to meet all deadlines?
■ Earliest deadline first! ■ Problem?
CS 423: Operating Systems Design
11
■ What if you want to maximize throughput?
■ Shortest job first!
■ What if you want to meet all deadlines?
■ Earliest deadline first! ■ Problem? ■ Works only if you are not “overloaded”. If the total
CS 423: Operating Systems Design
12
■ Problem:
■ It is Monday. You have a homework due tomorrow
(Tuesday), a homework due Wednesday, and a homework due Thursday
■ It takes on average 1.5 days to finish a homework.
■ Question: What is your best (scheduling) policy?
CS 423: Operating Systems Design
13
■ Problem:
■ It is Monday. You have a homework due tomorrow
(Tuesday), a homework due Wednesday, and a homework due Thursday
■ It takes on average 1.5 days to finish a homework.
■ Question: What is your best (scheduling) policy?
■ You could instead skip tomorrow’s homework and work on
the next two, finishing them by their deadlines
■ Note that EDF is bad: It always forces you to work on the
next deadline, but you have only one day between deadlines which is not enough to finish a 1.5 day homework – you might not complete any of the three homeworks!
CS 423: Operating Systems Design
14
■ Consider a control system in a autonomous vehicle
■ Steering wheel sampled every 10 ms – wheel positions
adjusted accordingly (computing the adjustment takes 4.5 ms of CPU time)
■ Breaks sampled every 4 ms – break pads adjusted
accordingly (computing the adjustment takes 2ms of CPU time)
■ Velocity is sampled every 15 ms – acceleration is adjusted
accordingly (computing the adjustment takes 0.45 ms)
■ For safe operation, adjustments must always be computed
before the next sample is taken
■ How to assign priorities?
CS 423: Operating Systems Design 15
Steering wheel task (4.5 ms every 10 ms) Breaks task (2 ms every 4 ms) Velocity control task (0.45 ms every 15 ms)
CS 423: Operating Systems Design 16
Sanity check: Is the processor over-utilized?
hours, then you are over utilized (5x6 = 30 > 24).
Steering wheel task (4.5 ms every 10 ms) Breaks task (2 ms every 4 ms) Velocity control task (0.45 ms every 15 ms)
CS 423: Operating Systems Design 17
Sanity check: Is the processor over-utilized?
hours, then you are over utilized (5x6 = 30 > 24).
Steering wheel task (4.5 ms every 10 ms) Breaks task (2 ms every 4 ms) Velocity control task (0.45 ms every 15 ms)
+
+
CS 423: Operating Systems Design 18
Steering wheel task (4.5 ms every 10 ms) Breaks task (2 ms every 4 ms) Velocity control task (0.45 ms every 15 ms)
CS 423: Operating Systems Design 19
■ Rate Monotonic (large rate = higher priority)
Steering wheel task (4.5 ms every 10 ms) Breaks task (2 ms every 4 ms) Velocity control task (0.45 ms every 15 ms) Intuition: Urgent tasks should be higher in priority
CS 423: Operating Systems Design 20
■ Rate Monotonic (large rate = higher priority)
Steering wheel task (4.5 ms every 10 ms) Breaks task (2 ms every 4 ms) Velocity control task (0.45 ms every 15 ms) Intuition: Urgent tasks should be higher in priority
CS 423: Operating Systems Design
■ Deadlines are missed! ■ Average Utilization < 100%
Breaks task (2 ms every 4 ms) Steering wheel task (4.5 ms every 10 ms) Velocity control task (0.45 ms every 15 ms)
CS 423: Operating Systems Design
■ Deadlines are missed! ■ Average Utilization < 100%
Breaks task (2 ms every 4 ms) Steering wheel task (4.5 ms every 10 ms) Velocity control task (0.45 ms every 15 ms)
Fix: Give this task invocation a lower priority (EDF)
CS 423: Operating Systems Design
Breaks task (2 ms every 4 ms) Steering wheel task (4.5 ms every 10 ms) Velocity control task (0.45 ms every 15 ms)
■ Deadlines are missed! ■ Average Utilization < 100%
Fix: Give this task invocation a lower priority (EDF)
CS 423: Operating Systems Design
Breaks task (2 ms every 4 ms) Steering wheel task (4.5 ms every 10 ms) Velocity control task (0.45 ms every 15 ms)
■
Static versus Dynamic priorities?
■
Static: Instances of the same task have the same priority
■
Dynamic: Instances of same task may have different priorities
Intuition: Dynamic priorities offer the designer more flexibility and hence are more capable to meet deadlines
CS 423: Operating Systems Design
25
■ Result #1: Earliest Deadline First (EDF) is the optimal
■ Result #2: Rate Monotonic Scheduling (RM) is the
CS 423: Operating Systems Design
26
■ Result #1: Earliest Deadline First (EDF) is the optimal
■ Result #2: Rate Monotonic Scheduling (RM) is the
CS 423: Operating Systems Design
27
■ What if a higher-priority process needs a
■ How long will the higher priority process have to
CS 423: Operating Systems Design
High-priority task Low-priority task Lock S Preempt.
CS 423: Operating Systems Design
Attempt to lock S results in blocking High-priority task Low-priority task Lock S Preempt. Priority Inversion
CS 423: Operating Systems Design
Attempt to lock S results in blocking
30
High-priority task Low-priority task Lock S Preempt. Unlock S Lock S Unlock S Priority Inversion
CS 423: Operating Systems Design
Attempt to lock S results in blocking
31
High-priority task Low-priority task Lock S Preempt. Intermediate-priority tasks Preempt.
Unbounded Priority Inversion
CS 423: Operating Systems Design
Attempt to lock S results in blocking
32
High-priority task Low-priority task Lock S Preempt. Intermediate-priority tasks Preempt.
Unbounded Priority Inversion
CS 423: Operating Systems Design
Attempt to lock S results in blocking
33
High-priority task Low-priority task Lock S Preempt. Intermediate-priority tasks
Lock S Unlock S Unlock S
CS 423: Operating Systems Design
Priority Inheritance Protocol:
Need Red Need Blue Need Yellow
34
CS 423: Operating Systems Design
■ What is the longest period of time a high priority
Semaphore Queue Resource 1 Semaphore Queue Resource 2 Semaphore Queue Resource M
Two priority inversion scenarios to consider:
(a) Lower priority task holds a resource I need (direct blocking) (b) Lower priority task inherits a higher priority than me because it holds a resource the higher- priority task needs (push-through blocking)
35
CS 423: Operating Systems Design
36
■ Definition: The priority ceiling of a semaphore is the
■ A task that requests a lock Rk is denied if its priority
■ The task is said to be blocked by the task holding lock Rh
■ A task inherits the priority of the top higher-priority
CS 423: Operating Systems Design
Need Yellow but Priority is lower Than Red ceiling Need Blue but Priority is lower Than Red ceiling Needs Red, waits for 1 critical section to complete. Done
37
Priority Ceiling Protocol:
CS 423: Operating Systems Design
Compare to the Priority Inheritance Protocol!!
Need Red Need Blue Need Yellow
38