Beruflich Dokumente
Kultur Dokumente
RT Operating System
Features of Real-Time Kernels Most real-time systems do not provide the features found in a standard desktop system Reasons include Real-time systems are typically single-purpose Real-time systems often do not require interfacing with a user Features found in a desktop PC require more substantial hardware that what is typically available in a real-time system
Real-time Programming
2/33
6. RT Operating System
Virtual Memory in Real-Time Systems Address translation may occur via: (1) Real-addressing mode where programs generate actual addresses (2) Relocation register mode (3) Implementing full virtual memory
Real-time Programming
3/33
6. RT Operating System
Page 1
Address Translation
Real-time Programming
4/33
6. RT Operating System
In general, real-time operating systems must provide: (1) Preemptive, priority-based scheduling (2) Preemptive kernels (3) Latency must be minimized
Real-time Programming
5/33
6. RT Operating System
Minimizing Latency Event latency is the amount of time from when an event occurs to when it is serviced.
Real-time Programming
6/33
6. RT Operating System
Page 2
Interrupt Latency Interrupt latency is the period of time from when an interrupt arrives at the CPU to when it is serviced
Real-time Programming
7/33
6. RT Operating System
Dispatch Latency Dispatch latency is the amount of time required for the scheduler to stop one process and start another
Real-time Programming
8/33
6. RT Operating System
Real-Time CPU Scheduling Periodic processes require the CPU at specified intervals (periods) p is the duration of the period d is the deadline by when the process must be serviced t is the processing time
Real-time Programming
9/33
6. RT Operating System
Page 3
Real-time Programming
10/33
6. RT Operating System
A priority is assigned based on the inverse of its period Shorter periods = higher priority; Longer periods = lower priority
Real-time Programming
11/33
6. RT Operating System
Real-time Programming
12/33
6. RT Operating System
Page 4
Priorities are assigned according to deadlines: the earlier the deadline, the higher the priority; the later the deadline, the lower the priority
Real-time Programming
13/33
6. RT Operating System
This ensures each application will receive N / T of the total processor time
Real-time Programming
14/33
6. RT Operating System
Pthread Scheduling
The Pthread API provides functions for managing real-time threads Pthreads defines two scheduling classes for real-time threads: (1) SCHED_FIFO - threads are scheduled using a FCFS strategy with a FIFO queue. There is no time-slicing for threads of equal priority (2) SCHED_RR - similar to SCHED_FIFO except time-slicing occurs for threads of equal priority
Real-time Programming
15/33
6. RT Operating System
Page 5
VxWorks 5.0
Real-time Programming
16/33
6. RT Operating System
Wind Microkernel
(1) Processes and threads (2) preemptive and non-preemptive round-robin scheduling (3) manages interrupts (with bounded interrupt and dispatch latency times) (4) shared memory and message passing interprocess communication facilities
Real-time Programming
17/33
6. RT Operating System
Specifics of RT OS support for real time operations (timers), concurrency (task scheduling), ... deterministic timing behaviour, predictability
Real-time Programming
18/33
6. RT Operating System
Page 6
Obstacles of Predictability direct memory access (DMA) DMA takes control of I/O I/O shares bus with CPU, DMA can block CPU (cycle stealing) caches, memory management (page faults, page replacements) interrupts system calls (what is the worst case execution time?)
Real-time Programming
19/33
6. RT Operating System
Functionality basic services: task management interprocess communication and synchronization timers memory allocation device I/O supervision trade-off: more features, more complex, performance degradation, more dicult to analyze less features, better performance, easier to analyze
Real-time Programming
20/33
6. RT Operating System
Task Scheduling typically based on priority based preemtive scheduling equal priority processes: FIFO, round-robin (time slicing) switch time should be load-independent
Real-time Programming
21/33
6. RT Operating System
Page 7
Standards RT-POSIX OSEK Oene Systeme und deren Schnittstellen fr die Elektronik in Kraftfahrzeugen ("Open Systems and their interfaces for the Electronics in Motor vehicles"), founded in 1993 by a german automotive companies consortium APEX avionics standard ITRON Industrial TRON (The Real-time Operating System Nucleus), started 1984 in Japan, about 50 kernel products
Real-time Programming
22/33
6. RT Operating System
Real-time Programming
23/33
6. RT Operating System
RTLINUX
Real-time Programming
24/33
6. RT Operating System
Page 8
Defects of Linux Linux scheduling algorithms are not designed for real-time tasks. Linux will batch operations to make more efficient use of the hardware. Linux scheduling is unpredictable. Linux processes are heavyweight processes. It can take several hundred microseconds to finish a context switch. Linux Timer resolution is coarse, 10 ms. Linux Kernel is Non-preemptible . Even the lowest priority task is running. Linux will make high priority tasks wait for low priority tasks to release resources. Linux disables interrupts used for coarse-grained synchronization. Coarse grained synchronization means that there are long intervals when one task has exclusive use of some data. Linux uses virtual memory. Linux reorders requests for efficiency (e.g., for disk I/O).
Real-time Programming 25/33 6. RT Operating System
RTLinux RT-Linux is an operating system in which a small real-time kernel coexists with the POSIX-like Linux kernel. RTLinux is module oriented. Scheduler. The earliest deadline first scheduler. Rate-monotonic scheduler. The module that implements RT-FIFOs. RTLinux decouples the mechanisms of the real-time kernel from the mechanisms of the general purpose kernel. Each can be optimized independently. The RT kernel can be kept small and simple.
Real-time Programming
26/33
6. RT Operating System
I/O
Hardware Interrupts
Hardware
Real-time Programming
27/33
6. RT Operating System
Page 9
RTLinux Features
The RTLinux executive is itself non pre-emptible. Its routine are very small and fast, this does not cause big delays. Interrupts from Linux are disabled.
No virtual memory.
Real-time Programming
28/33
6. RT Operating System
RT Tasks
System Libraries Device Drivers Unix/Linux Kernel
I/O
Software Interrupts
RT Scheduler
Direct Hardware Acess I/O Hardware Interrupts
Real-time Programming
29/33
6. RT Operating System
Architecture of RT Application
User Processes
RT FIFO
RT FIFO
Linux Kernel
Real-time processes
Device
Device
RT Device
Real-time Programming
30/33
6. RT Operating System
Page 10
Scheduler RT-Linux contains a dynamic scheduler. RT-Linux has many kinds of Schedulers.
Real-time Programming
31/33
6. RT Operating System
RT FIFO Real-time FIFOs are used to pass information between real-time process and ordinary Linux process. Real-time FIFOs are designed to never block the real-time task. RT-FIFOs are, like real-time tasks, never paged out. This eliminates the problem of unpredictable delays due to paging.
Real-time Programming
32/33
6. RT Operating System
Timer Resolution If the kernel was patched with UTIME, we could schedule processes with microsecond resolution. Running rtlinux-V3.0 Kernel 2.2.19 on the 486 allows stable hard real-time operation. Giving:
15 microseconds worst case jitter. 10 microseconds event resolution. 17 nanoseconds timer resolution. 6 microseconds interrupt response time. (This value was measured on interrupts on the parallel port)
High resolution timing functions give nanosecond resolution (limited by the hardware only.)
Real-time Programming
33/33
6. RT Operating System
Page 11