What is an operating system ? Eingebettete Systeme Echtzeitverhalten und Betriebssysteme 8. Echtzeitbetriebssysteme Swiss Federal Institute of Technology 1 Computer Engineering and Networks Laboratory Embedded OS Swiss Federal Institute of Technology 2 Computer Engineering and Networks Laboratory Embedded OS Why an OS at all? Why is a desktop OS not suited? Same reasons why we need one for a traditional computer. Not all services are needed for any device. Large variety of requirements and environments: Critical applications with high functionality (medical applications, space shuttle, …). Critical applications with small functionality (ABS, pace maker, …) Not very critical applications with varying functionality (PDA, phone, smart card, microwave ofen, …) Swiss Federal Institute of Technology Piece of software that sits between applications and hardware. Hides hardware details from applications. Provides standard interfaces to hardware and software devices. Provides protection mechanisms. Typical services: Memory management (main memory, secondary memory, virtual memory, paging, file system) Process management (scheduling, task management, synchronization, interrupt and exception handling, inter task communication) Protection Input-Output management (device driver) Support of distributed applications and multiprocessors 3 Computer Engineering and Networks Laboratory Monolithic kernel is too feature reach. Monolithic kernel is not modular, fault-tolerant, configurable, modifiable, … . Takes too much space. Not power optimized. Not designed for mission-critical applications. Known RTOS (real-time operating systems): POSIX, VxWorks, OSOpen, OS-9, pSOSystem, RTEMS, Linux/RT-Linux, Virtuoso, Windows CE, PalmOS, QNX Neutrino, ... Swiss Federal Institute of Technology 4 Computer Engineering and Networks Laboratory Design goals of embedded OS Evolution of embedded OS Small: minimal memory footprint Open: many interfaces and protocols, open system standards Modular: easy to integrate custom components Portable: run on lots of devices Real-time: support of hard deadlines, bounded interrupts, scheduling, synchronization Power consumption: integrated power management Robustness: fault tolerant, halts, guards, exceptions, CRC, … Configurable: adaptable to required functionality Application Browser / GUI Java Advanced Interconnect Advanced Networking Distributed Objects Fault Tolerance Multiprocessing File System Networking Kernel Application X Windows WindNet Memory Management Multiprocessing File System Networking Kernel Application File System Networking Kernel Application Kernel 10%* 1980 1990 30%* 1996 75%* 1998 *Percent of total software supplied by RTOS vendor in a typical embedded device Swiss Federal Institute of Technology Computer Engineering and Networks Laboratory 5 Microkernel-based OS services memory management scheduling appl. 2 Swiss Federal Institute of Technology application 1 scheduling file management I/O management Protection 7 application 2 user kernel user kernel Computer Engineering and Networks Laboratory 6 Conventional OS clients appl. 1 Swiss Federal Institute of Technology memory management Computer Engineering and Networks Laboratory Swiss Federal Institute of Technology 8 Computer Engineering and Networks Laboratory 90%* Example of an embedded OS (conventional) service layer prozessormanagement creation termination communication synchronization scheduling listmanagement machine layer (assemly code) utility services dispatching kernel mechnisms list management context switch interrupt handling Swiss Federal Institute of Technology systemcalls timer handling Computer Engineering and Networks Laboratory 9 Process management services Example structure of an RTOS Machine layer (assembly code): directly interacts with hardware, not visible at the user level primitives mainly deal with context switch, interrupt handling, timer handling List management layer: tasks having the same state are enqueued in lists basic primitives for inserting and removing tasks to an from a list Processor management: scheduling and dispatching operations Service layer: provides all services visible at the user level as a set of system calls task creation, task abortion, suspension of periodic instances, activation and suspension of aperiodic instances, system inquiry operations Swiss Federal Institute of Technology 10 Computer Engineering and Networks Laboratory Process management General goals: generate and terminate processes (and/or threads). process execution context switching External interrupt Interrupt dispatch Interrupt service Timer interrupt Time service & events System calls (trap) Scheduling & dispatcher Task execution Interrupt management: interrupt service (keyboard, AD-converter, sensors, …) driver: transfer of data between periphery and memory in contrary to classical OS, interrupt service is integrated into scheduling to enable hard deadlines Services (create thread, sleep, notify, send,…) kernel Swiss Federal Institute of Technology 11 Computer Engineering and Networks Laboratory Swiss Federal Institute of Technology 12 Computer Engineering and Networks Laboratory Context Switching Process management Interrupt handling hardware (or software) raises interrupt CPU set to privileged mode jumps to specific ISR (interrupt service routine) either using a table or directly save process state perform some action, e.g. move to ready queue of processes (or threads). restore state return to common mode Swiss Federal Institute of Technology 13 Computer Engineering and Networks Laboratory Process management 14 Computer Engineering and Networks Laboratory Process management Scheduling Process synchronization: use of real-time scheduling algorithms schedulability test: can the current tasks perform their functions within the given timing constraints handling of overload conditions, e.g. remove tasks Problems: » Estimating the runtime of tasks; runtime depends on input data, unknown cache and pipeline behavior, unknown interrupt points, garbage collection. » Embedded tasks very often have short runtimes; therefore, the overhead in case of frequent interrupts is prohibitively high. Swiss Federal Institute of Technology Swiss Federal Institute of Technology 15 Computer Engineering and Networks Laboratory In classical operating systems, synchronization and mutual exclusion is performed via semaphores and monitors. In real-time OS, special semaphores and a deep integration into scheduling is necessary (priority inheritance protocols, ….). Further responsibilities: Initializations of internal data structures (tables, queues, task description blocks, semaphores, …) Swiss Federal Institute of Technology 16 Computer Engineering and Networks Laboratory Process states Process states minimal set of process states: terminate run run wait wait wait activate signal Swiss Federal Institute of Technology end_cycle TIMER dispatch preemption ready ready 17 idle idle resume Computer Engineering and Networks Laboratory Data structures Swiss Federal Institute of Technology 18 Computer Engineering and Networks Laboratory Data structures Task Control Block (TCB) contains static and dynamic information, e.g. memory address corresponding to the first instruction of a task task type (periodic, aperiodic, sporadic) task criticalness (hard, soft, non-real time) value which represents the importance of the task current state (ready, running, idle, waiting, ..) worst case execution time relative deadline absolute deadline computed by the kernel at the arrival time pointer to process stack (Process Control Block) , where the context is stored pointer to precedence graph pointer to a list of shared resources … Swiss Federal Institute of Technology Run: A task enters this state as it starts executing on the processor Ready: State of those tasks that are ready to execute but cannot be executed because the processor is assigned to another task. Wait: A task enters this state when it executes a synchronization primitive to wait for an event, e.g. a wait primitive on a semaphore. In this case, the task is inserted in a queue associated with the semaphore. The task at the head is resumed when the semaphore is unlocked by a signal primitive. Idle: A periodic job enters this state when it completes its execution and has to wait for the beginning of the next period. 19 Computer Engineering and Networks Laboratory Lists for task management (queues) Semaphore Control Block (SCB) counter which represents the value of the semaphore semaphore queue for enqueueing the tasks blocked on the semaphore pointer to the next SCB to form a list of semaphores Swiss Federal Institute of Technology 20 Computer Engineering and Networks Laboratory Data structures Communication mechanisms TCB7 TCB3 TCB2 TCB14 Problem: the use of shared resources for implementing message passing schemes may cause priority inversion and blocking. TCB6 TCB5 Swiss Federal Institute of Technology 21 Computer Engineering and Networks Laboratory Communication mechanisms Swiss Federal Institute of Technology Computer Engineering and Networks Laboratory 22 Communication mechanisms Synchronous communication: Whenever two tasks want to communicate they must be synchronized for a message transfer to take place (rendez-vous) They have to wait for each other. Problem in case of dynamic real-time systems: Estimating the maximum blocking time for a process rendez-vous. In a static real-time environment, the problem can be solved off-line by transforming all synchronous interactions into precedence constraints. Swiss Federal Institute of Technology 23 Computer Engineering and Networks Laboratory send send(mes,R) recv(mes,R) recv Swiss Federal Institute of Technology 24 Computer Engineering and Networks Laboratory Communication mechanisms Asynchronous communication: Tasks do not have to wait for each other The sender just deposits its message into a channel and continues its execution; similarly the receiver can directly access the message if at least a message has been deposited into the channel. More suited for real-time systems than synchronous comm. Mailbox: Shared memory buffer, FIFO-queue, basic operations are send and receive, usually has fixed capacity. Problem: Blocking behavior if channel is full or empty; alternative approach is provided by cyclical asynchronous buffers. Sender Empfänger mailbox Swiss Federal Institute of Technology 25 Computer Engineering and Networks Laboratory
© Copyright 2024