Real Time Operating Systems
Total Page:16
File Type:pdf, Size:1020Kb
School of Electrical and Computer Engineering N.T.U.A. Embedded System Design Real Time Alex Bartzas Operating Systems Microlab/NTUA Άδεια Χρήσης Το παρόν εκπαιδευτικό υλικό υπόκειται σε άδειες χρήσης Creative Commons. Για εκπαιδευτικό υλικό, όπως εικόνες, που υπόκειται σε άδεια χρήσης άλλου τύπου, αυτή πρέπει να αναφέρεται ρητώς. What is an Embedded OS? An "embedded system" is any computer system or computing device that performs a dedicated function or is designed for use with a specific embedded software applica tion. Embedded systems may use a ROM-based operating system or they may use a disk-based system, like a PC. But an embdddbedded sys tem is no t usa ble as a commercillially v ibliable substitute for general purpose computers or devices. 3 Aspects of embedded system design 4 Metrics •Performance can be measured in multiple ways –Latency vs. throughput –Average vs. worst-case vs. best-case –Peak vs. sustained •Power/energy –Power consumption is important for heat generation –Energy consumption is important for battery life –ItIntegra tdted me titrics suc h as Energy-De lay Pro duc t (EDP) •Cost –Des ign time vs. life time •Reliability –Avail a bility, depen da bility, performabilit y 5 Hardware/software codesign •Goals –Optimizing design process –Oppggtimizing design •Tasks –Cospecificationand comodeling –Codesign –Cosynthesis, optimization, interfacing –Verification 6 Codesign flow 7 What makes a good Embedded OS? Modular Scalable Configurable Small footprint CPU support Device drivers etc,,, etc, etc... 8 What is Real Time? “A real time system is one in which the correctness of the computations not only depends upon the logical correctness of the computation but also upon the time at which the result iddIfthtiititfthtis produced. If the timing constraints of the system are no t met, system failure is said to have occurred.” 9 What is Real Time? “Real time in operating systems: The ability of the operating system to provide a required llfiibddlevel of service in a bounded response ti”time.” 10 Hard vs. Soft Real Time Hard guaranteed worst-case response times absol ut el y, positiv el y, fir st tim e ev er y tim e Soft Kinda, sorta, usually 11 What makes a good RTOS? Multi-threaded Thread ppyriority has to exist because no deadline driven OS exists Must support predictable thread synchronization mechanisms A system of priority inheritance must exist 12 Embedded operating systems - Requirement: Configurability - Configurability No single RTOS will fit all needs, no overhead for unused functions tolerated ) configurability needed. simplest form: remove unused functions (by linker ?). Conditional compilation (using #if and #ifdef commands). Dynamic data might be replaced by static data. Advanced compile-time evaluation useful. Object-orientation could lead to a derivation subclasses. Verification a potential problem of systems with a large number of derived OSs: Each derived OS must be tested thoroughly; potential problem for eCos (open source RTOS from Red Hat), inclu ding 100 to 200 configuration points [Takada, 01]. 13 Example: Configuration of VxWorks © Windriver http://www.windriver.com/products/development_tools/ide/tornado2/tornado_2_ds.pdf 14 Embedded operating systems -Requirement: Disc and network handled by tasks - Disc & network handled by tasks instead of integrated drivers Many ES without disc, a keyboard, a screen or a mouse. Effectively no device that needs to be supported by all versions of the OS, except maybe the system timer. Relatively slow discs & networks can be handled by tasks. RTOS Standard OS 15 Example: WindRiver Platform Industrial Automation © Windriver 16 Embedded operating systems - Requirement: Protection is optional- Protection mechanisms not alwayyys necessary: ES typically designed for a single purpose, untested programs rarely loaded, SW considered reliable. (However, protection mechanisms may be needed for safety and security reasons). 17 Embedded operating systems - Requirement: Interrupts not restricted to OS - Interrupts can be employed by any process For standard OS: serious source of unreliability. Since embdddbedded programs can be cons idere d to be teste d, since protection is not necessary and since effi ci ent cont rol over a vari et y of d evi ces i s requi red , it is possible to let interrupts directly start or stop tasks (by storing the tasks start address in the interrupt table). More efficient than going through OS services. However, composability suffers: if a specific task is connected to some interrupt, it may be difficult to add another task which also needs to be started by an event. 18 Embedded operating systems - Requirement: Real -time capability- Many embedded systems are real-time (RT) systems and, hence, the OS used in these systems must be real-time operating systems (RTOSes). 19 Real-time operating systems - Real-time OS (1) - Def.: (A) real-time operating system is an operating system that supports the construction of real-time systems The followinggy are the three key requirements 1. The timing behavior of the OS must be predictable. ∀ services of the OS: Upper bound on the execution time! RTOSs must be deterministic: unlike standard Java, short times during which interrupts are disabled, contiguous files to avoid unpredictable head movements. [Takada, 2001] 20 Real-time operating systems - Real-time OS (2) - 2. OS must managgge the timing and scheduling OS possibly has to be aware of task deadlines; (unless scheduling is done off-line). OS must provide precise time services with high resolution. [Takada, 2001] 21 Time services Time plays a central role in “real-time” systems. Actual time is described by real numbers. Two discrete standards are used in real-time eqqpuipment: • International atomic time TAI (french: temps atomic internationale) Free of any artificial artifacts. • Universal Time Coordinated (UTC) UTC is de fine d by as tronom ica l s tan dar ds UTC and TAI were identical on Jan. 1st, 1958. In the meantime, 30 seconds had to be added. Not without problems: New Year may start twice per night. 22 Internal synchronization Synchronization with one master clock Typically used in startup-phases Distributed synchronization: 1. Collect information from neighbors 2. Compute correction value 3. Set correction value. Precision of steppp 1 depends on how information is collected: Application level: ~500 µs to 5 ms Operation system kernel: 10 µs to 100 µs Communication hardware: < 10 µs 23 Byzantine Error Erroneous local clocks can have an impact on the computed local time. Advanced algorithms are fault-tolerant with respect to Byzantine errors. Excluding k erroneous clocks is possible with 3k+1 clocks (largest and smallest values will be excluded. Many publications in this area. k=1 t 24 External synchronization External synchronization guarantees consistency with actual physical time. Recent trend is to use GPS for ext. synchronization GPS offers TAI and UTC time information. Resolution is about 100 ns. 25 Problems with external synchronization Problematic from the perspective of fault tolerance: Erroneous values are copied to all stations. Consequence: Accepting only small changes to local time. Many time formats too restricted; e.g.: NTP protocol includes only years up to 2036 For time services and global synchronization of clocks synchronization see Kopetz, 1997. 26 Real-time operating systems - Real-time OS (3) - 3. The OS must be fast Practically important. [Takada, 2001] 27 RTOS-Kernels Distinction between • real-time kernels and modified kernels of standard OSes. Distinction between • general RTOSes and RTOSes for specific domains, • standard APIs (e.g. POSIX RT-Extension of Unix, ITRON, OSEK) or proprietary APIs. 28 Functionality of RTOS-Kernels Incl udes • processor management, • memory management, resource management • and timer management; • task management (resume, wait etc), • inter-task communication and synchronization. 29 Classes of RTOSes according to R. Gupta 1. Fast proprietary kernels Fast proprietary kernels For complex systems, these kernels are inadequate, because they are designed to be fast, rather than to be predictable in every respect [R. Gupta, UCI/UCSD] Examples include QNX, PDOS , VCOS, VTRX32, VxWORKS. 30 Classes of RTOSes according to R. Gupta 2. Real-time extensions to standard OSs Real-time extensions to standard OSes: Attempt to exploit comfortable main stream OSes. RT-kernel running all RT-tasks. Stan dar d-OS execu te d as one tas k. + Crash of standard-OS does not affect RT-tasks; - RT-tasks cannot use Standard-OS services; less comfortable than expected 31 Example: RT-Linux RT-tasks cannot use Init BhBash Moz illa standard OS calls. Commercially available from flb(fsmlabs (www. flbfsmlabs.com ) scheduler Linux-Kernel RT-TkTask RT-TkTask driver interrupts RT-Scheduler RT-Linux interrupts I/O interrupts Hardware 32 Example: Posix 1.b RT-extensions to Linux Standard scheduler can be replaced by POSIX scheduler implementing priorities for RT tasks RT-Task RT-Task Init Bash Mozilla Special RT-calls and POSIX 1.b scheduler standard OS calls available. Linux-Kernel Easy programming, driver no guarantee for I/O, i n terrup ts meeting d eadli ne Hardware 33 Evaluation (Gupta) According to Gupta, trying to use a version of a standard OS: nottht the correc t approac hbh because too many bas ic an d inappropriate underlying assumptions still exist such as optimizing for the average case (rather than the worst case), ... ignoring most if not all semantic information, and indeppgendent CPU scheduling and resource allocation. Dependences between tasks not frequent for most applications of std. OSs & therefore frequently ignored. Situation different for ES since dependences between tasks are quite common. 34 Classes of RTOSes according to R. Gupta 3. Research systems trying to avoid limitations Research systems trying to avoid limitations. Include MARS, Spring, MARUTI, Arts, Hartos, DARK, and Melody RhiResearch issues [Ta ka da, 2001]: low overhead memory protection, tlttiftitemporal protection of computing resources RTOSes for on-chip multiprocessors supportft for con tinuous me dia quality of service (QoS) control. CtitibtCompetition between traditional vendors (e.g.