You are on page 1of 16

RT Li nux

The Real-time Linux

Click to edit Master subtitle A. Rajesh, style

St. Josephs College of Engg.


E-mail Id:

Real-time Linux!

System that has to perform its functions by responding to synchronous or asynchronous events within a specified amount of time. RT-Linux is an operating system in which a small real-time kernel coexists with the POSIX-like Linux kernel. RT-Linux decouples the mechanisms of the real-time kernel from the mechanisms of the general purpose kernel. The RT kernel can be kept small and simple. Each can be optimised independently. Types of Real-Time systems are: 1. Soft RT (eg. Updating a video display, AT Machine). 2. Hard RT (eg. Rocket controller).

E-mail Id:

Fundamentals of Rt-Linux

RT-Linux will provide facilities to guarantee deadlines will be met. And will provide scheduling algorithms in order to enable deterministic behavior in the system. An RTOS (Includes RT-Linux) is generally valued more for predictability than throughput. Some of the design philosophies of an RTOS (Includes RT-Linux) are with respect to: 1. Scheduling 2. Memory allocation 3. Inter task communication 4. Interrupt handlers

E-mail Id:

Structure of Rt-Linux

A task is the basic unit of execution which has three important properties: 1. Release time: the point in time from which the task can be executed. 2. Deadline: the point in time by which the task must complete. 3. Execution time: the time the task takes to execute. There are two different execution models: 1. In a preemptive model of execution a task may be interrupted (preempted) during its execution and another task run in its place. 2. In a non-preemptive model of execution after a task that starts executing no other task may execute until this task concludes or yields the CPU. RT-Linux runs on the entire Linux operating system as a fully preemptive process by adding as a BSP (Board Support Package).

E-mail Id:

Structural view of Rt-Linux

BSP or Board Support Package makes an RTOS target-specific. Its a processor specific code onto which we like to have our RTOS running. It is commonly built with a bootloader that contains the minimal device support to load the OS and device drivers for all the devices on the board.

E-mail Id:

Rt-Linux And RTAI

RT-Linux and RTAI provide similar mechanism. Both are the variants of Linux with support for real-time applications. They both use a real-time kernel which interacts with the main Kernel. They treat the Linux OS as the lowest running task. RTAI is from Milan Polytech. It supports X86, PowerQUICC architectures. RT-Linux follows the POSIX PE51 1001.13 RT profile ie. The ability of an Operating System to provide a required level of service in a bound response time. It is maintained by FSM labs from New Mexico Technologies. It supports X86, PowerPC, Alpha.

E-mail Id:

Rt-Linux Tasks

Initial Design Each RT task executed in its own address space. High overhead of context switching as TLB had to be invalidated. High overhead of system calls. Now all RT tasks run in the same address space (in the kernel space) and at the highest privilege level. But highly error prone as a bug in a single application can wipe out entire system. RT tasks are run as kernel modules. It can be dynamically added. Tasks have integer context for faster context switching. Task resources should be statically allocated .

E-mail Id:

Rt-Linux scheduling

RT Linux is module based the scheduler is itself a loadable kernel module. Default A simple preemptive priority based scheduler where the tasks are statically assigned priorities. The highest priority task ready to run is scheduled. Alternate scheduling policies 1. Earliest Deadline First (EDF) A dynamic priority scheduler in which the task with the nearest deadline is scheduled. 2. Rate Monotonic (RM) A static priority scheduler for periodic tasks where the task with the smallest period is assigned the highest priority. This is provably the optimal policy.

E-mail Id:

Rt-Linux Timers

Tradeoff between amount of time spent in handling clock interrupts with task release jitter (the difference between the exact time when the task should have been scheduled and the time at which it is actually scheduled). So we program the timer chip to interrupt the CPU exactly when the next event has to be scheduled (one-shot mode). Global time is kept track of by summing up all intervals between interrupts. Time Stamp Counter (TSC) available on Pentiums can also aid in the process. Conventional 10ms interrupts are simulated for Linux. Normal periodic timer mode is also supported to avoid the overhead of reprogramming the clock every time.

E-mail Id:

Inter-Process Communication

Linux kernel may be preempted by an RT task even during a system call, so no Linux routine can be safely called from real-time tasks. RT fifos used for communication between RT tasks and Linux user processes. Its buffers are allocated in kernel address space. It export lock-free functions for reading and writing on RT side and a standard device interface on the user side. Static limit on the number of fifos should be used uni-directionally. A pair can be used for bidirectional transfer. A handler can be associated with a fifo which is called when Linux task accesses it. IPC using shared memory also available.

E-mail Id:

RT Fifo vs Shared Memory IPC

Queue data, no protocol needed to prevent overwrites. Message boundaries not maintained. Support blocking for synchronization, no polling required. Fifos are point-to-point channels. Maximum number of fifos statically defined.

No queuing of data. Need to follow explicit protocol Can write structured data into memory. Need to poll for synchronization. Can have any number of tasks sharing memory. Physical memory is the only limit.

E-mail Id:

Structure Of RT-Application

E-mail Id:

Rt-Linux Interrupts

There are two types of interrupts : Hard and Soft. 1. Hard interrupts are the actual device interrupts and have less latency. First RT handler (if any) is called and if it permits sharing, the hard interrupt is passed on to Linux. Very limited set of kernel functions can be called from hard interrupts . 2. Soft interrupts are at par with normal Linux interrupts and dont provide real time performance. Kernel functions may be called from soft interrupts . It can be delayed for considerable periods of time and are serviced when system switches back to Linux. They are used in implementation of RT fifos.

E-mail Id:

Interrupt Driven Threads

A specific IRQ can be requested with rtl_request_irq(irq, handler, regs). An IRQ can be released using rtl_free_irq(irq). The handler executes with hardware interrupts disabled. If it is necessary to receive further interrupts, re-enabling is done with rtl_hard_enable_irq(irq). An interrupt driven thread is created as usual by calling pthread_create(). The thread calls pthread_suspend_np() and blocks. It is assumed that the interrupt handler will call pthread_wakeup_np() to wakeup this thread.

E-mail Id:

Threads and Priority Threads

RT-Linux implements a POSIX API for a threads manipulation. It is necessary to set thread priorities here. If you are familiar with a POSIX threads library (pthread) used by user-space application, it should not be problem for you to work with threads in RT-Linux. A thread is created by calling the pthread_create() function. The third parameter of pthread_create() is a function which contains the code executed by the thread. Threads with higher priorities can preempt threads with lower priorities. For example, we can have a thread controlling a stepper motor. In order to move the motor fluently, it is necessary to start this thread in strictly regular intervals.

E-mail Id:

Conclusion

RT Linux has achieved hard real-time performance by making minimal changes to a freely available Operating System. Provides an alternative to proprietary real-time systems which may be prohibitively expensive. As Linux develops, RT Linux will also ride the wave of its development. Unlike other RT systems, no separate support for RT Linux is needed since support for Linux is already widely available.

E-mail Id:

You might also like