Reservation-based scheduling€¦ · Weakly-hard systems A task with 𝑚,𝑘weakly-hard timing...
Transcript of Reservation-based scheduling€¦ · Weakly-hard systems A task with 𝑚,𝑘weakly-hard timing...
1 | 57Embedded and Networked Systems
[email protected](appointment by email)
IN4343 Real-Time Systems, Lecture 11
Reservation-based scheduling
2 | 57Embedded and Networked Systems
Sources
Some slides have been taken from Giorgio Buttazzo’s website:
http://retis.sssup.it/~giorgio/rts-MECS.html
Thank you Giorgio :)
Giorgio Buttazzo’s book, chapter 9
3 | 57Embedded and Networked Systems
MPEG decoding
Frame execution
times distributionfor “Star Wars”
Note: it is a soft real-time system
4 | 57Embedded and Networked Systems
Varying workload
Video playingMPEG standard encodes frames in "Group of Pictures" (GOP), consisting into 3 types of frames:• I frames (Inter-frames) include the entire content of a picture;• B frames, (Backwards predictive) look backwards at the I frames and P frames;• P frames (Predictive) looks forward at the frame, constantly comparing frame content.
PAL standard:
• frame rate = 25 fps
• decoding time: 2-20 ms
I-frames can take 10 timesmore than B-frames
5 | 57Embedded and Networked Systems
What to do with varying workloads?
1. Calculate and use the worst-case execution time
Advantages• It is safe• Necessary for hard real-time systems
Disadvantages• It results in pessimistic analysis which is
far from reality• It leads to overprovisioning the system
6 | 57Embedded and Networked Systems
What to do with varying workloads?
2. Model it using more expressive task models
Advantages• It is safe but not pessimistic: you can use it
to obtain the WCRT of the task• Necessary for hard real-time systems
Disadvantages • It is too complex to derive such a model from a
general application• Some systems do not have such a regular pattern• It is hard to analyze such a complex workload
20 2 2 8
I frame B frame B frame P frame
𝑎𝑖,𝑗 𝑎𝑖,𝑗 + 𝛿𝑖,1 𝑎𝑖,𝑗 + 𝛿𝑖,2 𝑎𝑖,𝑗 + 𝛿𝑖,3 𝑎𝑖,𝑗 + 𝑇𝑖
𝑐𝑖,1 𝑐𝑖,2 𝑐𝑖,3 𝑐𝑖,4
𝜏𝑖 = 𝑐𝑖,1, 𝛿𝑖,1 , 𝑐𝑖,2, 𝛿𝑖,2 , 𝑐𝑖,𝑘𝑖 , 𝛿𝑖,𝑘𝑖 , 𝑇𝑖 , 𝐷𝑖
• Each pair 𝑐𝑖,𝑗 , 𝛿𝑖,𝑗 represents the workload of a frame
• 𝛿 is the intra-arrival-time of the frames
Multi-frame task model
7 | 57Embedded and Networked Systems
What to do with varying workloads?
3. Just use a smaller value than the WCET, but then handle task overruns!
Advantages• It is efficient since it allows having an analysis that is
closer to the average case performance of the system
• Allows using the existing analyses techniques
Disadvantages• It is unsafe: we may have deadline misses• If the value we assign is too small, many
“overruns” may happen. • Handling overruns increases the overheads
overruns
Overrun: happens when a task exceeds its expected utilization.
8 | 57Embedded and Networked Systems
Load and design assumptions
System designed under worst-case assumptions
System designed under average-case assumptions
9 | 57Embedded and Networked Systems
Consequences of overruns
A task overrun may not cause a deadline miss:
But in general, it may delay the execution of other tasks, causing a deadline miss:
10 | 57Embedded and Networked Systems
What can go wrong if overruns are not controlled?
EDF may have domino effect:
one (or more) overrun(s) may result in a series of deadline misses
(exam example): Build an example of an EDF schedule with three jobs such that two jobs miss their deadline because of an overrun in the first job
(exam example): Consider the following task set scheduled by EDF. 1. How much overrun in 𝝉𝟏 will cause one deadline miss?2. How much overrun in 𝝉𝟏 will cause two deadline misses?
1 unit
0 5
15 17
25
10 0
16 17
25
6 10 0
17
25
8 10
3 units
12 | 57Embedded and Networked Systems
What can go wrong if overruns are not controlled?
In FP, low-priority tasks may starve due to an overrun in high-priority tasks
13 | 57Embedded and Networked Systems
Handling overruns: not-so-good solutions
• Terminate the execution of the task that overruns• It may cause data inconsistency
• Use fixed-priority scheduling and “pray”! • If a high-priority task overruns, lower-priority tasks may starve
• Exception handling mechanisms• These mechanisms have runtime overhead. Hence, they reduce
timing predictability
14 | 57Embedded and Networked Systems
Handling overruns: better solutions
It is a mechanism to bound the resource consumption of a task
(and limit the interference to other tasks).
1. Performance degradation (also known as graceful degradation)• Execute a shorter version of the program
2. Resource reservation• Allows analyzing the WCRT despite possible
transient overruns• Isolates task’s overrun from each other
Fast and low qualityExample: a PID controller
Example: implement multiple versions:
Slow but high qualityExample: a model predictive controller is slow but can optimize control decisions
Middle ground Example: an LQG controller
15 | 57Embedded and Networked Systems
Performance degradation
• Degrading functionality (reducing task execution time)
• Skipping specific jobs
• Increasing periods
The load can be decreased not only by rejecting tasks, but also by reducing their performance requirements.
16 | 57Embedded and Networked Systems
Functional degradation
• In some applications, computation can be performed at different level of accuracy or quality of service (QoS):
“the higher the QoS, the longer the computation”
Examples:• Binary search algorithms• Image processing and computer graphics• Neural learning• Anytime control
Imprecise computation Multiple version
17 | 57Embedded and Networked Systems
Imprecise computation
• In this model, each task 𝜏𝑖 = 𝐶𝑖 , 𝑇𝑖 , 𝐷𝑖 , 𝑀𝑖 , 𝑂𝑖 , 𝑤𝑖 is divided in two parts:
• a mandatory part with the worst-case execution time 𝑀𝑖
• an optional part: with the worst-case execution time 𝑂𝑖• 𝐶𝑖 = 𝑀𝑖 + 𝑂𝑖• 𝑤𝑖 is the importance weight of the optional part
18 | 57Embedded and Networked Systems
Imprecise computation
• In this model, a schedule is said to be:• feasible, if all mandatory parts complete within 𝐷𝑖• precise, if also the optional parts are completed.
GOAL: minimize the average error
19 | 57Embedded and Networked Systems
Multiple versions
• If a task does not comply with the imprecise computational model, another option is to implement a function in multiple versions (operational modes):
Decreasing quality of
service
20 | 57Embedded and Networked Systems
Example: engine control task (in cars)
• In engine control, some tasks are activated at specific angles of the crankshaft.
• The activation rate of these tasks is proportional to the angular velocity 𝜔 of the engine:
21 | 57Embedded and Networked Systems
Example: engine control task (in cars)
break
22 | 57Embedded and Networked Systems
A solution for engine control tasks
rpm = rotation per minute.
Small period: 10mslarge period ~ 100ms
Reducing the number of functions
23 | 57Embedded and Networked Systems
Job skipping
Periodic load can also be reduced by skipping some jobs, once in a while.
Many systems tolerate skips, if they do not occur too often:• multimedia systems (video reproduction)• inertial systems (robots)• Control systems • monitoring systems (sporadic data loss)
24 | 57Embedded and Networked Systems
Example
• The system is overloaded, but tasks can be EDF-schedulable if 𝜏1 skips one instance every 3:
25 | 57Embedded and Networked Systems
Weakly-hard systems
A task with 𝑚, 𝑘 weakly-hard timing constraint is feasible if and only if in every
window of k consecutive jobs of that task, at least m jobs meet their deadlines.
What is an (m, k) for 𝝉𝟏? (assume that the following pattern repeats forever)
𝜏20 100
Miss Miss Miss
0 10 20 30 40 50 60 70 80 90 100𝜏1
Miss
110 120
Miss
How about (3, 4)? No, because of 𝑱𝟏,𝟗 and 𝑱𝟏,𝟏𝟎
Can (6, 10) be an answer? Yes.
What is the smallest k if m = 2? 5
How about (2, 4)? No, because of 𝑱𝟏,𝟗 and 𝑱𝟏,𝟏𝟎 and 𝑱𝟏,𝟏𝟏
26 | 57Embedded and Networked Systems
Weakly-hard systems
A task with 𝑚, 𝑘 weakly-hard timing constraint is feasible if and only if in every
window of k consecutive jobs of that task, at least m jobs meet their deadlines.
What is an (m, k) for 𝝉𝟏? (assume that the following pattern repeats forever)
𝜏20 100
Miss Miss Miss
0 10 20 30 40 50 60 70 80 90 100𝜏1
Miss
110 120
Miss
What is the largest m if k = 6? 3
27 | 57Embedded and Networked Systems
Weakly-hard systems
A task with 𝑚, 𝑘 weakly-hard timing constraint is feasible if and only if in every
window of k consecutive jobs of that task, at least m jobs meet their deadlines.
What is an (m, k) for 𝝉𝟏? (assume that the following pattern repeats forever)
𝜏20 100
Miss Miss Miss
0 10 20 30 40 50 60 70 80 90 100𝜏1
Miss
What is the largest m if k = 8? 4
110 120
Miss
28 | 57Embedded and Networked Systems
Weakly-hard systems
A task with 𝑚, 𝑘 weakly-hard timing constraint is feasible if and only if in every
window of k consecutive jobs of that task, at least m jobs meet their deadlines.
What is an (m, k) for 𝝉𝟏? (assume that the following pattern repeats forever)
𝜏20 100
Miss Miss Miss
0 10 20 30 40 50 60 70 80 90 100𝜏1
Miss
What is the smallest non-zero m for any k > 1? 1 as in (1, 5)
What is the smallest k (with a non-zero m)? 4 as in (1, 4). Note that any k smaller than 3 will have m = 0
110 120
Miss
29 | 57Embedded and Networked Systems
Weakly-hard systems
A task with 𝑚, 𝑘 weakly-hard timing constraint is feasible if and only if in every
window of k consecutive jobs of that task, at least m jobs meet their deadlines.
In general, can we say if a task set is (m, k) feasible, it will be (m-1, k) feasible too?
Yes. Just by definition: there must be “at least” m successful jobs in every window of k jobs.
In general, can we say if a task set is (m, k) feasible, it will be (m, k-1) feasible too?
No. The following task set is (1, 4) feasible but not (1, 3) feasible.
𝜏20 100
Miss Miss Miss
0 10 20 30 40 50 60 70 80 90 100𝜏1
Miss
110 120
Miss
30 | 57Embedded and Networked Systems
Weakly-hard systems
A task with 𝑚, 𝑘 weakly-hard timing constraint is feasible if and only if in every
window of k consecutive jobs of that task, at least m jobs meet their deadlines.
In general, if a task set is (m, k) feasible, as long as we increase k or decrease m, it stays feasible
What (m, k) constraint represents a hard real-time system?
m must be equal with k, for example (1, 1) or (2, 2) or (100, 100)
New research directions: combining multiple (m, k) constraints:Example: At least 80% of the jobs must meet their deadlines in the long run, while the system cannot tolerate more than 3 misses in every 5 jobs:
(800, 1000) ∧ (2, 5)
31 | 57Embedded and Networked Systems
Reservation-based scheduling
Resource reservation is a mechanism to bound the resource consumption of a task or a group of tasks
(and limit their interference on the other tasks).
32 | 57Embedded and Networked Systems
Example: reservation-based scheduling
Reservation server 𝑺
𝜏1𝐶1 = 6𝑇1 = 30
Assume this is the pattern of available budget from a reservation server:
How is task 𝝉𝟏 scheduled within server 𝑺?
0 22 28 45 48 57 60
8 6 2 3 3
8 36 38
2 3 16
6 45 48 57 5836 380 30 60
More reservation is available than needed
The task is released but there is no budget to start its execution
What is the response time of 𝑱𝟏,𝟏? What is the WCRT of 𝝉𝟏?
6
28 A reservation shows when the processor can be assigned to a task
33 | 57Embedded and Networked Systems
𝜏2: 𝐶1 = 16𝑇1 = 30
Assume this is the pattern of available budget from a reservation server:
How are tasks 𝝉𝟏 and 𝝉𝟐 scheduled in server 𝑺 when Rate Monotonic is used to schedule them inside the server?
Reservation server 𝑺
0 24 28 45 48 50 60
22 4 8 3 10
22 30 38
What is the WCRT of 𝝉𝟏? What is the WCRT of 𝝉𝟐?
12
30
𝜏1: 𝐶1 = 5𝑇1 = 20
3 25
5 45 48 50 52
2
22 24 27
3
0 20 6040
0 30 6038
815
20 5228
81
Example: reservation-based scheduling
A reservation shows when the processor can be assigned to a task
34 | 57Embedded and Networked Systems
Hierarchical scheduling
Resource reservation can be used to develop hierarchical systems, where each component is implemented within a reservation
35 | 57Embedded and Networked Systems
Xen Project https://xenproject.org/
Hierarchical scheduling: hypervisor implementations
This is the most practical aspect of real-time systems course in your engineering life!
Familiarize with hypervisors
36 | 57Embedded and Networked Systems
Hierarchical scheduling: hypervisor implementations
XtratuM hypervisorhttps://fentiss.com/products/hypervisor/
PikeOShttps://www.sysgo.com/products/pikeos-hypervisor/Uses offline scheduling for reservation servers.
Linux: Preempt-RThttps://www.linux.org/(implements constant-bandwidth server)
37 | 57Embedded and Networked Systems
Analyzing reservation-based scheduling
• To describe the time available in a reservation, we need to identify, for any interval [0, t], the minimum time allocated in the worst-case situation.
Supply bound function sbf(t):
minimum amount of time available in the reservation 𝑺 in every time interval of length t.
38 | 57Embedded and Networked Systems
Example: static time partition
• Example of reservation providing 4 units every 10 (bandwidth = 0.4).
• Assume that the server is scheduled as the highest-priority entity in the system.
sbf(t)
4
8
6 10 16 20
sbf(t) shows the minimum amount of time available in the reservation 𝑺 in every time interval of length t.
Periodic reservation server 𝑆:
budget 𝑄𝑠 = 4Period 𝑃𝑠 = 10
39 | 57Embedded and Networked Systems
Periodic reservation server 𝑆:
budget 𝑄𝑠 = 4Period 𝑃𝑠 = 10
Example: static time partition
• Example of reservation providing 4 units every 10 (bandwidth = 0.4).
sbf(t)
4
8
6 10 16 20
sbf(t) shows the minimum amount of time available in the reservation 𝑺 in every time interval of length t.
The minimum amount of time available every time interval of length 10 is 4.
40 | 57Embedded and Networked Systems
Example: static time partition
• Example of reservation providing 4 units every 10 (bandwidth = 0.4).
sbf(t)
4
8
6 10 16 20
sbf(t) shows the minimum amount of time available in the reservation 𝑺 in every time interval of length t.
The minimum amount of time available every time interval of length 18 is 6.
18
6
Periodic reservation server 𝑆:
budget 𝑄𝑠 = 4Period 𝑃𝑠 = 10
41 | 57Embedded and Networked Systems
Example: static time partition
• Example of reservation providing 4 units every 10 (bandwidth = 0.4).
sbf(t)
4
8
6 10 16 20
sbf(t) shows the minimum amount of time available in the reservation 𝑺 in every time interval of length t.
The minimum amount of time available every time interval of length 20 is 8.
Periodic reservation server 𝑆:
budget 𝑄𝑠 = 4Period 𝑃𝑠 = 10
42 | 57Embedded and Networked Systems
Analysis under resource reservation + EDF
• Assume that tasks inside the server are scheduled by EDF.
We can use the Processor Demand Criterion as follows:
For each point in time where either the value of sbf(t) or dbf (t) changes, check if dbf(t) is smaller than sbf(t).
43 | 57Embedded and Networked Systems
Faster test
• Assume that tasks inside the server are scheduled by EDF.
Design a faster sufficient schedulability test!
Replace sbf(t) with a lower bound, called
supply lower-bound function slbf(t):
44 | 57Embedded and Networked Systems
Faster test: approximating supply lower-bound function with a line
• A simple supply bound function can have the form of a linear function (of time).
In other words, we want to approximate the sbf(t) with a linear equation:
Slope of this line is 𝛼
It cuts the horizontal axis at time Δ
45 | 57Embedded and Networked Systems
Given a generic supply function sbf(t), the bandwidth 𝛼 is the equivalent to the slope computed for long intervals:
Faster test: approximating supply lower-bound function with a line
46 | 57Embedded and Networked Systems
• For a periodic server with budget 𝑄𝑠 and period 𝑃𝑠 running at the highest priority (among other servers), we have:
Example: Periodic Server
Why did we need this assumption?
𝑄𝑠
𝑃𝑠is the utilization
of the server
47 | 57Embedded and Networked Systems
Example: Periodic Server
• For a periodic server with budget 𝑄𝑠 and period 𝑃𝑠 running at an unknown priority, we have:
48 | 57Embedded and Networked Systems
Observations about periodic servers
In a periodic server with bandwidth 𝛼, we have that:
49 | 57Embedded and Networked Systems
Observations about periodic servers
A reservation can be wasted because of
• occasional load reduction due to early terminations
• wrong bandwidth allocation at design time
• application changes due to environmental changes
50 | 57Embedded and Networked Systems
Next lecture introduces other type of servers
51 | 57Embedded and Networked Systems
Step 1: open www.kahoot.it in your browser (phone or laptop)Step 2: enter the pin code and then a nickname
52 | 57Embedded and Networked Systems
Which partitioning solution results in a feasible RM-schedulable?
𝝉𝒊 𝑻𝒊 𝑼𝒊
1 5 0.2
2 10 0.1
3 20 0.69
4 25 0.3
A: Core 1: {𝜏1, 𝜏2} , Core 2: {𝜏3, 𝜏4}
B: Core 1: {𝜏1, 𝜏2, 𝜏3} , Core 2: {𝜏4}
C: Core 1: {𝜏1, 𝜏3} , Core 2: {𝜏2, 𝜏4}
D: Core 1: {𝜏1, 𝜏2, 𝜏4} , Core 2: {𝜏3}
Answer: D
53 | 57Embedded and Networked Systems
What is the smallest k for Task 1 when m = 3?
𝜏20 100
Miss
0 10 20 30 40 50 60 70 80 90 100𝜏1
Miss
Weakly hard system (m = 3, k = ?)
Miss Miss
Answer: k = 7
𝜏20 100
Miss
0 10 20 30 40 50 60 70 80 90 100𝜏1
Miss Miss Miss
54 | 57Embedded and Networked Systems
If this was a repeatable pattern of a periodic server, what could be its possible period and budget?
Reservation server 𝑺
0 22 28 45 48 55 60
8 6 2 3 5
8 36 38
Period is 20Budget is 8
Reservation server 𝑺𝑷𝒔 = 𝟐𝟎𝑸𝒔 = 𝟖
0 22 28 45 48
8 6 2 3
8 36 38
20 40 600
55 60
5
What are the parameters of this periodic server?
55 | 57Embedded and Networked Systems
5
5 20 40 600 55
Which sbf(t) represents this server?
35
sbf(t)
5
10
30 35 55 7050
sbf(t)
10
20
25 40 604520
Reservation server 𝑺Period 𝑷𝒔 = 𝟐𝟎Budget 𝑸𝒔 = 𝟓The server has an unknown priority
A: B:
56 | 57Embedded and Networked Systems
1 2
3
4
1
5
2
5
2
Label shows WCET
57 | 57Embedded and Networked Systems