Document 6517939

Transcription

Document 6517939
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