Real-Time Systems For Embedded Microcontrollers: Software Used in Automotive Systems
Real-Time Systems For Embedded Microcontrollers: Software Used in Automotive Systems
part I
I/O Libraries
completes the OS with the support of the platform HW 10 times bigger than a minimal OS
application
implements only the behavior and not the infrastructures (libraries) independent from the underlying hardware
memory
SRAM / FLASH / ...
the operating system is a key element in the architecture of complex embedded systems
Evidence Srl - [email protected] 2005 Evidence Srl - [email protected] 2005
Tricore
TriCore CPU with 4 stage pipeline 32-bit Peripheral Control Processor (PCP2) 2 MByte embedded program flash with ECC, 128 KByte data flash for scalable 16 KByte EEPROM emulation, 192 KByte on-chip SRAM, 16 KByte instruction cache 16-channel DMA controller Sophisticated interrupt system with 2 x 255 hardware priority arbitration levels serviced by CPU and PCP2 Two general purpose timer array modules plus separate LTC array (GPTA4) Two asynchronous/synchronous serial channels (ASC) Two high speed synchronous serial channels (SSC) Two high-speed Micro Link Interfaces for serial inter-processor communication (MLI) MultiCAN module with four CAN nodes incl. TTCAN functionality 4-channel fast analog-to-digital converter unit (FADC) Two 16-channel analog-to-digital converter units (ADC) with 8/10/12-bit resolution 44 analog input lines for ADC and FADC 123 digital general purpose I/O lines, 4 input lines Evidence Srl - [email protected] 2005
typical footprints
part II
code size 1000kb 100kb 10kb OSEK/VDX 1kb POSIX PSE54 (Linux, FreeBSD) POSIX PSE51/52 ITRON threadX ERIKA tinyOS Linux real-time SHaRK eCOS
VXworks
a good idea would be to try to reduce as much as possible stack usage, sharing the stack stack space among different threads. Now the question is:
an example
suppose to have a system
that schedules tasks using fixed priorities where each task do not block
using resources...
the model where the different tasks do not interact is not realistic we would like to let the different tasks
share some resources still maintaining some timing properties (e.g., meet deadlines) and, if possible, minimize the stack space (RAM) needed
the first problem that must be addressed is the Priority Inversion problem
priority inversion
suppose to have 2 tasks that share a resource the High Priority task can be delayed because of some low priority task
normal execution critical section
priority inheritance
first Solution (Priority Inheritance/Ceiling): the low priority task inherits the priority of T1
note that the execution of T1 and T3 are interleaved!
Deadline miss!!!
S
Push-Through Blocking
S
T1 T2 T3
W
T1 T2 T3
W
yes!
stack can be shared also when mutual exclusion between shared resources have to be guaranteed the idea is that a task can start only when all the resources it needs are free this idea leads to two protocols
Stack Resource Policy (EDF-based) Immediate Priority Ceiling (Fixed Priority-based)
T1 T2 T3
W
Delayed execution
T1 T2 T3
W S
W S
such that the following essential property holds: task i s not allowed to preempt task j, unless i> j under EDF and RateMonotonic, the previous property is verified if periodic task i is assigned the following preemption level:
1 Ti
cei l r k
max i
needs r k
in the case of multi unit resources, the ceiling of each resource is dynamic as it depends on the number of units actually free
a job is not allowed to start executing until its priority is the highest among the active jobs, and its preemption level is greater than the system ceiling
T1 T2 T3
SRP stack usage
without SRP
i ,1 i n ,
k
Ck 1 Tk
Bi 1 Ti
implementation tips
how can two threads share the same stack space?
Task x() { int local; initialization(); for (;;) { do_instance(); end_instance(); } }
the tradictional thread model allows a task to block forces a task structure
a stack is needed for each task that can be preempted the overall requirement for stack space is the sum of all task requirements, plus interrupt frames
Evidence Srl - [email protected] 2005 Evidence Srl - [email protected] 2005
User Stack T1 T2 T3
T1 T2 T3
int local; Task x() { int local; initialization(); for (;;) { do_instance(); end_instance(); } } Task x() { do_instance(); } System_initialization() { initialization(); ... }
the user have to map application tasks into the kernel threads
Task c
Task d
Task f
multistack HAL
support multiple stacks each stack is used by one (or more than one) task kernel must ensure that interleaving can only appear between (top-level) tasks on different stacks
POSIX threads uses a multistack paradigm (they can block)
Task x(void *arg) { int local; initialization(); for (;;) { while (Ihavetodosomework()) { if (Task1_active()) do_Task1(); if (Task2_active()) do_Task2(); ... } end_instance(); } }
stack 1 stack 2 T1 T2 T3
T2 T3
T1
is there a limit?
we are able to let tasks share the same stack space
but only between tasks of the same priority
preemption thresholds
(technique first introduced by Express Logic inside the ThreadX kernel; further studied by Saksena and Wang])
can we do better? the limit for stack reduction is to schedule all the tasks using a non-preemptive algorithm
only one stack is needed not all the systems can afford that
the idea is to limit preemptability without impacting on the schedulability of the system using Preemption Thresholds
disabling preemption
preemption thresholds are used to disable preemption between tasks
Higher priorities
Task B
ready Priority (B)
Task A
ready Priority (A)
task's priority max(ceiling of a pseudo-resource used by the task) preemption thresholds = traditional fixed priorities when ready priority = dispatch priority
Evidence Srl - [email protected] 2005
Why?
reducing the preemption let more tasks share the same stack it is important not to reduce the preemption too much
a non-preemptive system is easily non schedulable
preemption level of each EDF task max(ceiling of a pseudo-resource used by the task) EDF+pr.thresholds has the same behavior of traditional EDF+SRP when dispatch priority = 0
Evidence Srl - [email protected] 2005
enhancing schedulability
premption thresholds have the nice property to enhance schedulability Example [Saksena, Wang,99] :
three periodic tasks with relative deadlines
Task T1 T2 T3 Ci 20 20 35 Ti 70 80 200 Di 50 80 100 ready priority 3 2 1 response time preemptive non-preemptive 20 55 40 75 115 75
1) search for a schedulable solution 2) threshold computation 3) grouping and stack minimization
but is schedulable using preemption thresholds (T1,T2) and (T2,T3) are mutually non preemptive tasks
threshold computation
the schedulable solution found at the previous step consists in a ready and a dispatch priority value for each task observation: raising a dispatch priority
helps stack sharing (tasks easily become mutually non-preemptive) makes feasibility harder (the system tends more to non-preemptive)
this step should produce a feasible priority assignment composed by ready and dispatch priority for each task
fixed priorities
traditional methods
Rate Monotonic Deadline Monotonic
EDF
EDF + SRP assignment is typically a good choice
the objective of this phase is to reduce unnecessary preemptability inserted by the values of the scheduling attributes
algorithm proposed by [Saksena, Wang, 00]
3. 4.
grouping tasks
8 7 Priorities 6 5 4 3 2 1
an example
8 Priorities dispatch priority 7 6 5 4 3 2 1 Stack
1 100 1 3 100 101 1 2 1 2 1 1 1 1
ready priority
Total 102
Task