Professional Documents
Culture Documents
RTOS
RTOS
RTOS
Operating Systems
Summary
Introduction
Basic concepts
RT Scheduling
Embedded RTOS
Source:
Introduction
Real-time system:
A real-time system is a computer system in which the
correctness of the system behavior depends not only on
the logical results of the computation, but also on the
physical instant at which these results are produced
Introduction (2)
plant control
control of production processes / industrial automation
railway switching systems
automotive applications
flight control systems
environmental acquisition and monitoring
telecommunication systems
robotics
military systems
space missions
household appliances
virtual / augmented reality
4
Introduction (3)
Real-time
Time: main difference to other classes of computation
Real: reaction to external events must occur during
their evolution.
Hard RT task:
Soft RT task:
Areas of application:
Automotive:
Aircraft:
Areas of application:
Communication systems:
RTOS
Multitasking/scheduling
Interrupt management
No concept of RT clock
10
Timeliness
time management
handling tasks with explicit time constraints
Predictability
Fault tolerance
Design for peak load
Maintainability
11
Scheduling latency
(interrupt dispatch latency) (Tsl):
Timeliness
Core of an RTOS!
Predictability
13
In most OS:
14
Problems:
degradation of processor performance (busy wait)
no encapsulation of low level details
15
Problems
degradation of processor performance (still busy waiting
- within I/0 routines)
more inter-process communication than first solution
kernel has to be modified when adding devices
16
17
Advantages
busy wait eliminated
unbounded delays due to unexpected device handling
dramatically reduced (not eliminated !)
remaining unbounded overhead may be estimated
relatively precisely
18
Achieving predictability:
system calls & IPC
19
Example:
H
M
L
20
10
2.
Advantage:
Disadvantage:
Deadlock possible
21
2.
3.
4.
Advantage:
11
Priority inheritance
and priority ceiling
Inheritance
Ceiling
23
Achieving predictability:
architecture
Solutions:
systems without cache (or disabled)
precise estimation of caching behaviour
24
12
Achieving predictability:
memory management
Typically used:
Memory segmentation
Static partitioning
Problems:
flexibility reduced
careful balancing required
25
Achieving predictability:
Applications
Desirable features:
no dynamic data structures
no recursion
only time-bound loops
26
13
What RTOS?
Proprietary:
VxWorks by WindRiver
LynxOS by Lynx
Free/Academical/Open-source:
QNX
RTLinux
Spring
RTX
27
Real-time
Process Management
& Scheduling
28
14
Processes
Called tasks in the RT community
Basic concepts:
Task scheduling
Scheduling problems & anomalies
29
Scheduling: preliminaries
Key fact:
30
15
Scheduling: definition
Given a set of tasks J = {J1 , ...Jn } a schedule is
an assignment of tasks to the processor so that
each task is executed until completion.
Formally:
A schedule is a function : R+ N such that:
Scheduling: example
A schedule is called feasible if all tasks can be
completed according to a set of specified
constraints
A set of tasks is called schedulable if there exist at
least one algorithm that can produce a feasible
schedule
Example:
32
16
Scheduling constraints
Timing constraints
Precedence constraints
Resource constraints
33
Timing constraints
34
17
Task characterization
Arrival time ai :
the time Ji becomes ready for execution
Deadline di :
Start time Si :
Si
fi
di
t
35
Lateness Li:
L i = fi - di
delay of task completion with respect to di
Tardiness Ei:
Ei = max (0, Li)
time a task stays active after its deadline
36
18
38
19
Precedence constraints
39
20
Real-time scheduling
41
Scheduling: formulation
Given:
a set of n tasks J = {J1 , ..., Jn}
a set of m processor P = {P1 , ..., Pm}
a set of s resources R = {R1 , ..., Rs}
Precedences specified using a precedence graph
Timing constraints may be associated to each task.
42
21
Scheduling: classification
Preemptive/non-preemptive
Static
Dynamic
Off-line
On-line
Scheduling: guarantee-based
algorithms
Hard RT systems:
Solutions:
Static RT systems:
Dynamic RT systems:
22
Scheduling metrics
n tasks
Ci
Ji
ai
Si
fi
di
Maximum lateness
tr = i=1N wi fi
Scheduling metrics
Average response time/total completion time not
appropriate for hard real time tasks
Maximum lateness: useful for exploration
Max # of late task more significant
Often conflicting:
Minimizing maximum
lateness does not
minimize number
of tasks that miss
their deadlines:
46
23
47
Classification [Graham]:
Triple (,,)
= the environment on which the task set has to be scheduled
(typically # of processors)
1 | prec | L max
uniprocessor machine
task set with precedence constraints
minimize maximum lateness
2 | sync | i Latei
uniprocessor machine
task set with precedence constraints
minimize # of late tasks
48
24
Jacksons algorithm
[1955]
1 | sync | Lmax
No other constraints are considered:
tasks are independent
no precedence relations
Computation time Ci
Deadline Di
49
50
25
51
Horns algorithm
1 | preem| Lmax
Principle: Earliest Deadline First (EDF)
It can be proved that:
Complexity:
per task: inserting a newly arriving task into an ordered
list properly:
n tasks => total complexity O(n2)
26
Horns algorithm
Example:
53
Two schemes:
Latest Deadline First (LDF)
Modified EDF
54
27
55
56
28
Introduction
57
Assumptions
1.
2.
3.
4.
5.
6.
7.
29
(phase i)
period Ti
worst case computation time Ci
Additional parameters:
Response time Ri = fi ri
Release jitter of a task
U = i=1n Ci/Ti
U can be improved by
30
Schedulability test:
Ulub(A) <= Ulub schedulable.
Ulub(A) > Ulub may be schedulable, if the periods of
the tasks are suitable related.
Ulub(A) > 1 not schedulable.
U ub1
U ub2
2
3
U ub3
4
m
0
U ub4
YES
U lub
U ubm
NO
62
31
63
Static scheduling
With a fixed set of purely periodic tasks it is
possible to layout a schedule such that the
repeated execution of this schedule will cause all
processes to run at their correct rate.
Essentially a table of procedure calls, where each
procedure represents part of a code for a
process.
Cyclic executive approach
64
32
Typically:
Major cycle M = max. period among task set
Minor cycle m = min. period among task set
Must be: M = km
65
Task set
Schedule:
Process
period,T
Computation Time. C
---------------------------------------------------------------A
25
10
B
25
8
C
50
5
D
50
4
E
100
2
Minor cycle
(25)
Major cycle
(100)
Minor cycle
Minor cycle
(25)
(25)
Minor cycle
(25)
23
24
23
22
66
33
loop
wait_for_interrupt
Procedure_For_A
Procedure_For_B
Procedure_For_C
wait_for_interrupt
Procedure_For_A
Procedure_For_B
Procedure_For_D
Procedure_For_E
wait_for_interrupt
Procedure_For_A
Procedure_For_B
Procedure_For_C
wait_for_interrupt
Procedure_For_A
Procedure_For_B
Procedure_For_D
end loop
67
Advantages:
Disadvantages:
34
Process-based scheduling
Fixed-priority scheduling
Rate-monotonic (RM) scheduling
Deadline-monotonic (DM) scheduling
Dynamic-priority scheduling
EDF
69
Intrinsically preemptive:
70
35
RM scheduling
RM is proved to be optimal:
71
RM schedulability test
n (2
Ulub =
i = 1 Ti
1)
U(n) 100.0%
80.0%
60.0%
40.0%
20.0%
0.0%
0
10
15
20
25
30
35
n
72
36
40
30
10
10
Priority, Utilization,
P
U
1
0.24
2
3
0.25
0.33
10
Task_1
Task_2
Task_3
0
10
20
30
40
50
60
Time
74
37
Computation
time, C
32
5
4
Priority, Utilization,
P
U
1
0.400
2
0.125
3
0.250
Task_1
Task_2
Task_3
0
10
20
30
40
50
60
Time
75
Utilization,
U
0.500
0.250
0.250
Task_1
Task_2
Task_3
0
10
20
30
40
50
60
70
80 Time
76
38
EDF algorithm
77
Example
EDF schedule
T1
T2
10
15
Process
Period, T
WCET, C
T1
T2
20
25
14
21
30
28
35
35
RMA schedule
T1
T2
10
3
0
15
Deadline miss
14
20
25
21
30
28
35
35
78
39
Ci
i =1 Ti
n
79
Process
Period, T
WCET, C
T1
T2
U > 69.3%:
U <1:
80
40
Deadline monotonic
(DM) scheduling
Assumption up to now:
relative deadline = period
DM scheduling weakens this assumption
Static algorithm
81
DM scheduling
DM = generalization of RM
Ci
t
Di
Ti
82
41
DM scheduling: example
Period,
T
20
Deadline,
D
5
Computation
time, C
3
Priority,
P
4
Response
time, R
3
Task_2
Task_3
15
10
7
10
3
4
3
2
6
10
Task_4
20
20
20
83
DM schedulability analysis
U = i=1n Ci/Di
Too pessimistic!
Actual guarantee test based on a modified
response time analysis
Ci + Ii Di
i: 1 i n
Ii = (j=1i-1) Ri / Tj Cj
84
42
85
n
L
CP (0, L) = Ci . L
i =1 Ti
In the case D<T
L 0
Number of checkpoints
Is actually limited
Number of completions
Between 0 and L-Di
86
43
Consider:
Task
1
2
T
8
8
D
7
4
C
3
2
15
23
1
4
12
20
L L
((22-7)/8+1) 3 + ((22-4)/8+1) 2 =
6 + 6 = 12 < 22
OK
((24-7)/8+1) 3 + ((24-4)/8+1) 2 =
9 + 6 = 15 < 22
OK
87
88
44
Static
Priority
Dynamic
Priority
Di Ti
RMA
DMA
Processor utilization
approach
1
Ci
n
n (2 1)
T
i =1 i
n
i , Ri = C i +
Ri
C j Di
jhp ( i ) T j
EDF
EDF
Processor utilization
approach
Ci
1
i =1 i
n
L > 0,
n
L Di
L
+ 1 Ci
Ti
i =1
89
Priority servers
90
45
Introduction
Background scheduling
Simplest solution:
Handle soft aperiodic tasks in the background behind
periodic tasks, that is, in the processor time left after
scheduling all periodic tasks.
Aperiodic tasks just get assigned a priority lower than
any periodic one.
Aperiodic tasks
RM
FCFS
CPU
46