Embedded Systems Programming: Ver Onica Gaspes
Embedded Systems Programming: Ver Onica Gaspes
Verónica Gaspes
www2.hh.se/staff/vero
Priority assignment
Question
How do we set thread/message priority for the purpose of meeting
deadlines?
:-(
In neither case a method exists that is both predictable and
generally applicable to all programs!
:-)
It is possible to get by if we concentrate on programs of a
restricted form.
Assigning priorities Analysis
Priority assignment
Question
How do we set thread/message priority for the purpose of meeting
deadlines?
:-(
In neither case a method exists that is both predictable and
generally applicable to all programs!
:-)
It is possible to get by if we concentrate on programs of a
restricted form.
Assigning priorities Analysis
Priority assignment
Question
How do we set thread/message priority for the purpose of meeting
deadlines?
:-(
In neither case a method exists that is both predictable and
generally applicable to all programs!
:-)
It is possible to get by if we concentrate on programs of a
restricted form.
Assigning priorities Analysis
Priority assignment
Question
How do we set thread/message priority for the purpose of meeting
deadlines?
:-(
In neither case a method exists that is both predictable and
generally applicable to all programs!
:-)
It is possible to get by if we concentrate on programs of a
restricted form.
Assigning priorities Analysis
Priority assignment
Question
How do we set thread/message priority for the purpose of meeting
deadlines?
:-(
In neither case a method exists that is both predictable and
generally applicable to all programs!
:-)
It is possible to get by if we concentrate on programs of a
restricted form.
Assigning priorities Analysis
Notation
Ti (=Di) Ti (=Di)
Ci Ci
Notation
Ti (=Di) Ti (=Di)
Ci Ci
Notation
Ti (=Di) Ti (=Di)
Ci Ci
Notation
Ti (=Di) Ti (=Di)
Ci Ci
Notation
Ti (=Di) Ti (=Di)
Ci Ci
In concrete code
The application
void ignite(){
BEFORE(D1 , &obj1 , m1 , arg1 );
BEFORE(D2 , &obj2 , m2 , arg2 );
.
.
.
BEFORE(Dn , &objn , mn , argn );
}
STARTUP(ignite());
Assigning priorities Analysis
In concrete code
The objects
Classi obji = initClassi ();
Each Di = Ti
Assigning priorities Analysis
In concrete code
The objects
Classi obji = initClassi ();
Each Di = Ti
Assigning priorities Analysis
Schematically (again)
Obj1 Ports
STARTUP
Objn
Ports
Assigning priorities Analysis
For RM, the actual priority values do not matter, only their relative
order.
For RM, the actual priority values do not matter, only their relative
order.
For RM, the actual priority values do not matter, only their relative
order.
RM example
RM example
RM example
(High) T1
(Low) T2
(Mid) T3
For each task, the period is equal to its deadline. Arrows mark
start of period. Blue when they get to execute. Gray when they
have to wait for higher prio tasks to complete.
Assigning priorities Analysis
RM example
(High) T1
(Low) T2
(Mid) T3
For each task, the period is equal to its deadline. Arrows mark
start of period. Blue when they get to execute. Gray when they
have to wait for higher prio tasks to complete.
Assigning priorities Analysis
EDF example
T1
T2
T3
T1 arrives later, but its deadline is earlier than both T2’s and T3’s
absolute deadlines!
Assigning priorities Analysis
EDF example
T1
T2
T3
T1 arrives later, but its deadline is earlier than both T2’s and T3’s
absolute deadlines!
Assigning priorities Analysis
EDF example
T1
T2
T3
EDF example
T1
T2
T3
Optimality
Clearly, a method that only fails if every other method also fails is
preferred — such a method is called optimal
Optimality
Clearly, a method that only fails if every other method also fails is
preferred — such a method is called optimal
Optimality
Clearly, a method that only fails if every other method also fails is
preferred — such a method is called optimal
Schedulability
Schedulability
Schedulability
Schedulability
Utilization-based analysis
Ti
Ci
Ci
That is, the CPU utilization of a periodic task i is the ratio Ti ,
where Ci is the WCET and Ti is the period.
Note
Any task for which Ci =Ti will effectively need exclusive access to
the CPU!
Assigning priorities Analysis
Utilization-based analysis
Ti
Ci
Ci
That is, the CPU utilization of a periodic task i is the ratio Ti ,
where Ci is the WCET and Ti is the period.
Note
Any task for which Ci =Ti will effectively need exclusive access to
the CPU!
Assigning priorities Analysis
Utilization-based analysis
Ti
Ci
Ci
That is, the CPU utilization of a periodic task i is the ratio Ti ,
where Ci is the WCET and Ti is the period.
Note
Any task for which Ci =Ti will effectively need exclusive access to
the CPU!
Assigning priorities Analysis
That is, the sum of all CPU utilizations must be less than a certain
bound that depends on N.
Assigning priorities Analysis
That is, the sum of all CPU utilizations must be less than a certain
bound that depends on N.
Assigning priorities Analysis
Utilization bounds
N Utilization bound
1 100.0 %
2 82.8 %
3 78.0 %
4 75.7 %
5 74.3 %
10 71.8 %
Example A
+ +
Missed
deadline
0 10 20 30 40 50 60
Assigning priorities Analysis
Example B
7 + 12 + 4 + + 6 7 +
5 5 5
4 4 4 4 4 4 4
0 16 32 48 64 80 96
Assigning priorities Analysis
Example C
5 15 5 15
10 10
5 5 5 5
0 10 20 30 40 50 60 70 80
Assigning priorities Analysis
Characteristics
Characteristics
That is, the sum of all CPU utilizations must be less than 100%,
independent of the number of tasks.
Unlike the case for RM, the utilization-based test for EDF is both
sufficient and necessary (demand more than 100% of the CPU and
you are bound to fail!)
Assigning priorities Analysis
That is, the sum of all CPU utilizations must be less than 100%,
independent of the number of tasks.
Unlike the case for RM, the utilization-based test for EDF is both
sufficient and necessary (demand more than 100% of the CPU and
you are bound to fail!)
Assigning priorities Analysis
That is, the sum of all CPU utilizations must be less than 100%,
independent of the number of tasks.
Unlike the case for RM, the utilization-based test for EDF is both
sufficient and necessary (demand more than 100% of the CPU and
you are bound to fail!)
Assigning priorities Analysis
EDF vs RM
Similarities
Both algorithms are optimal within their class
Both are easy to implement in terms of priority queues
Both have simple utilization-based schedulability tests
Both can be extended in similar ways
Advantages of EDF
Close relation to terminology of real-time specifications
Directly applicable to sporadic, interrupt-driven tasks
superior CPU utilization
Assigning priorities Analysis
EDF vs RM
Similarities
Both algorithms are optimal within their class
Both are easy to implement in terms of priority queues
Both have simple utilization-based schedulability tests
Both can be extended in similar ways
Advantages of EDF
Close relation to terminology of real-time specifications
Directly applicable to sporadic, interrupt-driven tasks
superior CPU utilization
Assigning priorities Analysis
EDF vs RM
Similarities
Both algorithms are optimal within their class
Both are easy to implement in terms of priority queues
Both have simple utilization-based schedulability tests
Both can be extended in similar ways
Advantages of EDF
Close relation to terminology of real-time specifications
Directly applicable to sporadic, interrupt-driven tasks
superior CPU utilization
Assigning priorities Analysis
EDF vs RM
Similarities
Both algorithms are optimal within their class
Both are easy to implement in terms of priority queues
Both have simple utilization-based schedulability tests
Both can be extended in similar ways
Advantages of EDF
Close relation to terminology of real-time specifications
Directly applicable to sporadic, interrupt-driven tasks
superior CPU utilization
Assigning priorities Analysis
EDF vs RM
Similarities
Both algorithms are optimal within their class
Both are easy to implement in terms of priority queues
Both have simple utilization-based schedulability tests
Both can be extended in similar ways
Advantages of EDF
Close relation to terminology of real-time specifications
Directly applicable to sporadic, interrupt-driven tasks
superior CPU utilization
Assigning priorities Analysis
EDF vs RM
Similarities
Both algorithms are optimal within their class
Both are easy to implement in terms of priority queues
Both have simple utilization-based schedulability tests
Both can be extended in similar ways
Advantages of EDF
Close relation to terminology of real-time specifications
Directly applicable to sporadic, interrupt-driven tasks
superior CPU utilization
Assigning priorities Analysis
EDF vs RM
Similarities
Both algorithms are optimal within their class
Both are easy to implement in terms of priority queues
Both have simple utilization-based schedulability tests
Both can be extended in similar ways
Advantages of EDF
Close relation to terminology of real-time specifications
Directly applicable to sporadic, interrupt-driven tasks
superior CPU utilization
Assigning priorities Analysis
EDF vs RM
Similarities
Both algorithms are optimal within their class
Both are easy to implement in terms of priority queues
Both have simple utilization-based schedulability tests
Both can be extended in similar ways
Advantages of EDF
Close relation to terminology of real-time specifications
Directly applicable to sporadic, interrupt-driven tasks
superior CPU utilization
Assigning priorities Analysis
EDF vs RM
Drawbacks of EDF
It exhibits random behaviour under transient overload (but so
does RM, in fact, in a different way)
RM predictably skips low priority tasks under constant
overload (but EDF rescales task periods instead)
Utilization-based test becomes more elaborate for EDF when
Di ≤ Ti (but is still feasible)
Operating systems generally don’t support it (priority scales
lack granularity, no automatic time-stamping)
Few languages allow for natural deadline constraints
EDF vs RM
Drawbacks of EDF
It exhibits random behaviour under transient overload (but so
does RM, in fact, in a different way)
RM predictably skips low priority tasks under constant
overload (but EDF rescales task periods instead)
Utilization-based test becomes more elaborate for EDF when
Di ≤ Ti (but is still feasible)
Operating systems generally don’t support it (priority scales
lack granularity, no automatic time-stamping)
Few languages allow for natural deadline constraints
EDF vs RM
Drawbacks of EDF
It exhibits random behaviour under transient overload (but so
does RM, in fact, in a different way)
RM predictably skips low priority tasks under constant
overload (but EDF rescales task periods instead)
Utilization-based test becomes more elaborate for EDF when
Di ≤ Ti (but is still feasible)
Operating systems generally don’t support it (priority scales
lack granularity, no automatic time-stamping)
Few languages allow for natural deadline constraints
EDF vs RM
Drawbacks of EDF
It exhibits random behaviour under transient overload (but so
does RM, in fact, in a different way)
RM predictably skips low priority tasks under constant
overload (but EDF rescales task periods instead)
Utilization-based test becomes more elaborate for EDF when
Di ≤ Ti (but is still feasible)
Operating systems generally don’t support it (priority scales
lack granularity, no automatic time-stamping)
Few languages allow for natural deadline constraints
EDF vs RM
Drawbacks of EDF
It exhibits random behaviour under transient overload (but so
does RM, in fact, in a different way)
RM predictably skips low priority tasks under constant
overload (but EDF rescales task periods instead)
Utilization-based test becomes more elaborate for EDF when
Di ≤ Ti (but is still feasible)
Operating systems generally don’t support it (priority scales
lack granularity, no automatic time-stamping)
Few languages allow for natural deadline constraints
EDF vs RM
Drawbacks of EDF
It exhibits random behaviour under transient overload (but so
does RM, in fact, in a different way)
RM predictably skips low priority tasks under constant
overload (but EDF rescales task periods instead)
Utilization-based test becomes more elaborate for EDF when
Di ≤ Ti (but is still feasible)
Operating systems generally don’t support it (priority scales
lack granularity, no automatic time-stamping)
Few languages allow for natural deadline constraints
EDF vs RM
Drawbacks of EDF
It exhibits random behaviour under transient overload (but so
does RM, in fact, in a different way)
RM predictably skips low priority tasks under constant
overload (but EDF rescales task periods instead)
Utilization-based test becomes more elaborate for EDF when
Di ≤ Ti (but is still feasible)
Operating systems generally don’t support it (priority scales
lack granularity, no automatic time-stamping)
Few languages allow for natural deadline constraints
Implementation (RM)
In TinyTimber.c
struct msg_block{
...
Time baseline;
Time priority;
...
};
Implementation (EDF)
In TinyTimber.c
struct msg_block{
...
Time baseline;
Time deadline;
...
};
More on real-time
Other analysis
Response-time analysis, a more powerful technique than utilization
based, is needed.
More on real-time
Other analysis
Response-time analysis, a more powerful technique than utilization
based, is needed.
More on real-time
Other analysis
Response-time analysis, a more powerful technique than utilization
based, is needed.