Beruflich Dokumente
Kultur Dokumente
Ludovic Apvrille
Telecom ParisTech Eurecom, Oce 470 ludovic.apvrille@telecom-paristech.fr
Fall 2012
Outline
Embedded Systems in a Nutshell Introduction Architecture Real-time Systems in a Nutshell Denition Examples of real-time and embedded systems Real-Time Operating Systems Basics Advanced concepts Exceptions and interrupts Timers Real-Time UNIX Towards real-time Unix Scheduling issues Linux for real-time systems
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
Introduction Architecture
Outline
Embedded Systems in a Nutshell Introduction Architecture Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
Ludovic Apvrille
3 of 75
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
Introduction Architecture
Embedded system
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
Introduction Architecture
The system evolves in an environment that must be taken into account: Temperature, vibration, impacts, variable power supply, interferences, corrosion, re, water, radiations, etc.
Criticality
Failures may have major consequences The system should always perform correctly!
Hardware level: for example, a specication could be that the system should continue to work even if an electronic component fails (redundancy) Safety at software level: e.g., handling of possible bugs and crash
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
Introduction Architecture
Source: Providing Open Architecture High Availability solutions, Revision 1.0, Published by HA Forum, Feb. 2001
Ludovic Apvrille
6 of 75
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
Introduction Architecture
Example: smartphones
Various techniques
Mix of analog, digital, software functions Hardware / software co-design System on a Chip (SoC)
Ludovic Apvrille
7 of 75
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
Introduction Architecture
High-level Architecture
Embedded system = controlling system + controlled system + environment
Ludovic Apvrille
8 of 75
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
Introduction Architecture
Ludovic Apvrille
9 of 75
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
Introduction Architecture
Ludovic Apvrille
10 of 75
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
Introduction Architecture
Ludovic Apvrille
11 of 75
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
Introduction Architecture
Ludovic Apvrille
12 of 75
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
Introduction Architecture
Ludovic Apvrille
13 of 75
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
Introduction Architecture
Disabling interrupts and cache memories Initializing memory controller, memory chips, and cache units
Getting the start address for memory Getting the size of memory Performing preliminary memory tests, if required
Ludovic Apvrille
14 of 75
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
Introduction Architecture
Setting up execution and interrupt handlers Initializing bus interfaces such as VME, PCI and USB Initializing board peripherals such as serial, LAN and SCSI
Ludovic Apvrille
15 of 75
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
Introduction Architecture
Debugging
ROM Monitor
BDM - Background Debug Mode JTAG - Joint Test Action Group No need for underlying software support on chip Content of processor registers System memory dump Instruction under execution
Ludovic Apvrille
16 of 75
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
Outline
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Denition Examples of real-time and embedded systems Real-Time Operating Systems Real-Time UNIX
Ludovic Apvrille
17 of 75
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
Those systems in which the correctness of the system depends not only on the logical results of the computation, but also on the time at which the results are produced
(J. Stankovic, Misconceptions About Real-Time Computing, IEEE Computer, 21(10), October 1988)
Ludovic Apvrille
18 of 75
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
It reacts to these stimuli within a limit of time, regardless of the load of the system
Best eort
Ludovic Apvrille Real-Time Operating Systems - Fall 2012 19 of 75
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
Ludovic Apvrille
20 of 75
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
A task is a set of related jobs joined to provide functions A job is a unit of work executed by the system
Parameters
Temporal behavior
E.g., a job lasting less than 20ms, a periodic task with period = 30ms
Functional: intrinsic properties of the job (e.g., taps of lter) Resource requirements (e.g., 10kb of memory) Interconnection: its communication with other jobs
E.g., a decoding job must send its result to a displaying job Relies on shared memory, message queues, etc.
Ludovic Apvrille Real-Time Operating Systems - Fall 2012 21 of 75
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
Time Constraints
Release time
Deadline
Instant of time at which a job is required to be completed Absolute deadline = release time + relative deadline
Response Time
Dierence between the completion time and the release time of a job
Ludovic Apvrille Real-Time Operating Systems - Fall 2012 22 of 75
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
System Latency
System latency = End-to-end delay between a change of state in the environment, and the corresponding output reaction produced by the system Latency involves: delay for scanning the environment, delay due to the OS, delay for executing calculations, delay for producing output results (communication delay)
Load of the system, etc. Should be low with regards to the latency
Ludovic Apvrille Real-Time Operating Systems - Fall 2012 23 of 75
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
Determinism Issue
Computing time
Each activity can use various execution branches Status of messages queues, delay of signals, etc.
Communication time
Ludovic Apvrille
24 of 75
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
1 2 3
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
Software is in charge
Of some operations performed at physical level (receiving, sending, measuring the level of the electromagnetic eld, etc.) Of logical operations such as scanning for incoming calls, maintaining connections when changing of beams, etc. 577s of voice data are transmitted every 4.6ms 577s of voice data are received every 4.6ms If the distance to the relay is increasing, data should be emitted earlier to remain synchronized with the relay (Doppler eect)
Ludovic Apvrille
26 of 75
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
Constraints
Local (temporal) constraints on sending and receiving Global constraints: audio quality
Ludovic Apvrille Real-Time Operating Systems - Fall 2012 27 of 75
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
Discrete media (=static): media characterized by their spatial dimension: text, images Continuous media (=dynamic or isochrones): media with a temporal dimension: sound, video and animations
Ludovic Apvrille
28 of 75
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
Ludovic Apvrille
29 of 75
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
True or False?
A real-time system runs faster than usual systems? An elevator controlling system is a real-time system? A real-time application can be executed on every operating systems?
Ludovic Apvrille
30 of 75
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
Outline
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Basics Advanced concepts Exceptions and interrupts Timers Real-Time UNIX
Ludovic Apvrille
31 of 75
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
Scheduling policies share CPUs in fair way They dont take into account temporal constraints Communication mechanisms introduce non-deterministic temporal behavior Time is wasted at input / output management level Memory management (MMU, cache, dynamic allocation) introduces non-deterministic execution time Software timers used for managing time are not ne-grained enough
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
Key Characteristics
Reliability
Need to operate for a long period of time System reliability depends on all system elements
Predictability
To a certain degree, and at least better than in GPOS Completion of system calls occurs within known frames
Benchmark on the variance of the response times for each system calls WCET
Ludovic Apvrille
33 of 75
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
CPU performance: MIPS Throughput performance: bps Performance should be measured as a whole
Compactness
Scalability
Meet application-specic requirements Modular components File systems, protocol stacks, etc.
Ludovic Apvrille Real-Time Operating Systems - Fall 2012 34 of 75
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
Ludovic Apvrille
35 of 75
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
Examples of RTOS
VxWorks LynuxWorks QNX Windows Phone, iOS, Symbian Linux for RT and embedded systems
Ludovic Apvrille
36 of 75
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
Ludovic Apvrille
37 of 75
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
Ludovic Apvrille
38 of 75
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
Scheduling
Limitations of schedulers in general-purpose OS
Temporal constraints are not taken into account Schedulability analysis cannot be performed
Ludovic Apvrille
39 of 75
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
Memory Management
Dynamic allocations
Should be avoided at run-time Algorithms are based on xed-size blocks Pools of objects
No memory compaction
And sometimes even not implemented in RTOS! Page fault introduces non-determinism
Ludovic Apvrille Real-Time Operating Systems - Fall 2012 40 of 75
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
Solutions
Drivers working closely with the kernel Deterministic delay in all inter-process communications
Ludovic Apvrille
41 of 75
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
A Few Solutions
Example: RT-FIFO
RT-FIFO: FIFO with predened maximum size and with pre-allocated messages
Ludovic Apvrille
42 of 75
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
Events that disrupt the normal execution ow of the processor and force the processor to execute special instructions in a privileged state Synchronous exceptions
Asynchronous exceptions
Interrupts
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
Hardware-implemented Prioritizing multiple interrupt sources so that at any time the highest priority interrupt is presented to the core CPU for processing PICs have a set of Interrupt Request Lines
Interrupt = physical signal on a given line ESR = Exception Service Routine ISR = Interrupt Service Routine
Ludovic Apvrille
44 of 75
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
Ludovic Apvrille
45 of 75
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
High
18h
N/A
Med
1Bh
20Hz
Low
1Dh
100Hz
Ludovic Apvrille
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
Masking Interrupts
Why masking?
Disable the device so that it cannot assert additional interrupts Mask the interrupts of equal or lower priority levels Disable the line between the PIC and the core processor
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
Classication of Exceptions
Asynchronous Non-maskable
Cannot be blocked or enabled by software
Maskable
Can be blocked or enabled by software
Synchronous Precise
Program counter points to
Non-precise
Because of prefetching and pipelining techniques, no knowledge about the exact instruction that caused the exception
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
Ludovic Apvrille
49 of 75
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
Nested Interrupts
Ludovic Apvrille
50 of 75
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
Exceptions Timing
Should avoid situations where interrupts could be missed Should be aware of interrupt frequency of each device
Should take into account the fact that real-time tasks cannot execute when interrupts are being processed
Ludovic Apvrille
51 of 75
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
Ludovic Apvrille
52 of 75
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
Ludovic Apvrille
53 of 75
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
Conclusion on ISRs
Benets about cutting ISRs in two parts
Lower priority interrupts can be handled Reduces the chance of missing interrupts Increase concurrency because devices can start working on next operations earlier
An ISR should disable interrupts of the same level An ISR should mask all interrupts if it needs to execute a sequence of code as one atomic operation An ISR should avoid calling non-reentrant functions and blocking system calls
Ludovic Apvrille Real-Time Operating Systems - Fall 2012 54 of 75
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
Ludovic Apvrille
55 of 75
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
Ludovic Apvrille
56 of 75
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
Acknowledging the interrupt, reinitializing the necessary timer control register and returning from interrupt
Ludovic Apvrille
57 of 75
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
Ludovic Apvrille
58 of 75
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
Allowing applications to start a timer Allowing applications to stop or cancel a previously installed timer Internally maintaining the application timers
Ludovic Apvrille
59 of 75
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
ISR triggers asynchronous events to signal a task of the expiration of its timer
Task scheduling delay, context switch Higher priority task may be running
Ludovic Apvrille
60 of 75
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
Soft-Timer Services
timer create ()
Allocates a new structure for a timer Inputs: expiration time, function to be called at timer expiration Returns: id of the timer
timer delete ()
Ludovic Apvrille
61 of 75
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
Starts a previously created timer: a timer structure is installed into the timer-handling facility Input: id of the timer
timer cancel ()
Cancels a timer by removing the currently running timer from the timer-handling facility Input: id of the timer
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
Outline
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX Towards real-time Unix Scheduling issues Linux for real-time systems
Ludovic Apvrille
63 of 75
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
Time-sharing based scheduling Services are not always reentrant Blocking input / output operations Timing issues
Heavy management of IPC induces non-determinism in computing time Large memory footprint Reduced set of booting devices
Ludovic Apvrille
64 of 75
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
Real-time classes Faster switching Increased modularity (Micro-kernels) Support of the POSIX interface
Introduction of threads
Ludovic Apvrille
65 of 75
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
Ludovic Apvrille
66 of 75
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
Preemption Points
Adding preemption points in the kernel
Dene a slice of time during which no preemption is allowed (e.g., 2,000 instructions) Rewrite all kernel primitives:
The duration during which no preemption is allowed must always be shorter than the dened slice of instructions After each slice, call the scheduler (just in case) Fully preemptive kernel (see next slides)
Too long average preemption latency is higher Too short important overhead
Ludovic Apvrille Real-Time Operating Systems - Fall 2012 67 of 75
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
Libraries oer services such as: Input / Output operations, dynamic memory allocations, etc. Services may have an internal state: buer (I/O), pointer to the next chunk of free memory, etc. If preemption occurs when a service is being called, internal state of the service may be corrupted
Solutions
Safe, but costly Safe, less costly (but more costly than non-reentrant librairies)
Ludovic Apvrille Real-Time Operating Systems - Fall 2012 68 of 75
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
Maintenance can be performed for as long as desired Systems can be built from this source code
Ludovic Apvrille
69 of 75
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
Time-sharing system
Interactivity-based scheduling: strict priority-based approach is needed in real-time systems! Preemption is not possible When executing a system call (so, interrupts may be missed!) When executing an ISR
Ludovic Apvrille
70 of 75
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
Patch Modules
Ludovic Apvrille
71 of 75
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
Preempt Kernel
Low Latency
Based on call to the scheduler whenever possible Kernels data are protected with mutex
Adds preemption points at carefully chosen places in the code Approach is less systematic Performance study demonstrates its eciency with regards to the Preempt kernel patch
Real-Time Operating Systems - Fall 2012 72 of 75
Ludovic Apvrille
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
Priority-based scheduling policy Non real-time tasks are scheduled by the default Linux scheduler Real-time tasks are programmed as linux kernel modules
Ludovic Apvrille
73 of 75
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
Ludovic Apvrille
74 of 75
Embedded Systems in a Nutshell Real-time Systems in a Nutshell Real-Time Operating Systems Real-Time UNIX
Architecture of RTAI
Ludovic Apvrille
75 of 75