RTLinux

From Wikipedia, the free encyclopedia
Jump to: navigation, search
RTLinux
Original author(s) Victor Yodaiken
Developer(s) FSMLabs, Wind River Systems
Written in C
Operating system Linux
Available in English
Type Kernel
License GPL2
Website RTLinuxFree.com

RTLinux is a hard realtime RTOS microkernel that runs the entire Linux operating system as a fully preemptive process. It is the hard realtime variant of Linux that makes it possible to control robots, data acquisition systems, manufacturing plants, and other time-sensitive instruments and machines.

It was developed by Victor Yodaiken (Yodaiken 1999), Michael Barabanov (Barabanov 1996), Cort Dougan and others at the New Mexico Institute of Mining and Technology and then as a commercial product at FSMLabs. Wind River Systems acquired FSMLabs embedded technology in February 2007 and now makes a version available as Wind River Real-Time Core for Wind River Linux.

RTLinux provides the capability of running special realtime tasks and interrupt handlers on the same machine as standard Linux. These tasks and handlers execute when they need to execute no matter what Linux is doing. The worst case time between the moment a hardware interrupt is detected by the processor and the moment an interrupt handler starts to execute is under 15 microseconds on RTLinux running on a generic x86. A RTLinux periodic task runs within 25 microseconds of its scheduled time on the same hardware. These times are hardware limited, and as hardware improves RTLinux will also improve. Standard Linux has excellent average performance and can even provide millisecond level scheduling precision for tasks using the POSIX soft realtime capabilities. Standard Linux is not, however, designed to provide submillisecond precision and reliable timing guarantees. RTLinux was based on a lightweight virtual machine where the Linux "guest" was given a virtualized interrupt controller and timer - and all other hardware access was direct. From the point of view of the real-time "host", the Linux kernel is a thread. Interrupts needed for deterministic processing are processed by the real-time core, while other interrupts are forwarded to Linux, which runs at a lower priority than realtime threads. Linux drivers handle almost all I/O. First-In-First-Out pipes (FIFOs) or shared memory can be used to share data between the operating system and RTLinux.

Contents

[edit] Objective

The key RTLinux design objective is that the system should be transparent, modular, and extensible. Transparency means that there are no unopenable black boxes and the cost of any operation should be determinable. Modularity means that it is possible to omit functionality and the expense of that functionality if it is not needed. The base RTLinux system supports high speed interrupt handling and no more. And extensibility means that programmers should be able to add modules and tailor the system to their requirements. It has simple priority scheduler that can be easily replaced by schedulers more suited to the needs of some specific application. When developing RTLinux, it was designed to maximize the advantage we get from having Linux and its powerful capabilities available.

[edit] Core Components

RTLinux is structured as a small core component and a set of optional components. The core component permits installation of very low latency interrupt handlers that cannot be delayed or preempted by Linux itself and some low level synchronization and interrupt control routines. This core component has been extended to support SMP and at the same time it has been simplified by removing some functionality that can be provided outside the core.

[edit] Functionalities of RTLinux

The majority of RTLinux functionality is in a collection of loadable kernel modules that provide optional services and levels of abstraction. These modules include:

  1. rtl sched a priority scheduler that supports both a “lite POSIX” interface described below and the original V1 RTLinux API.
  2. rtl time which controls the processor clocks and exports an abstract interface for connecting handlers to clocks.
  3. rtl posixio supports POSIX style read/write/open interface to device drivers.
  4. rtl fifo connects RT tasks and interrupt handlers to Linux processes through a device layer so that Linux processes can read/write to RT components.
  5. semaphore is a contributed package by Jerry Epplin which gives RT tasks blocking semaphores.
  6. POSIX mutex support is planned to be available in the next minor version update of RTLinux.
  7. mbuff is a contributed package written by Tomasz Motylewski for providing shared memory between RT components and Linux processes.

[edit] Kernel Modules

RT-Linux application is in fact a Linux kernel module. It is the same type of module, which Linux uses for drivers, file systems and so on. The main difference between RTLinux module and an ordinary Linux module is that RT-Linux module calls functions, which are offered by RT-Linux kernel whereas ordinary module uses only Linux kernel functions. The source code of a simple Linux module is given below. It contains two functions: init_module, which is called when the module is inserted to the kernel by insmod or modprobe command, and cleanup_module, which is called before module is removed by rmmod.

 #include <linux/module.h>
 #include <linux/kernel.h>
 int init_module(void)
 {
   printk("Init\n"); /*Printing "Init" in Kernel*/
   return 0;
 }
 void cleanup_module(void)
 {
   printk("Cleanup\n"); /*Clearing "Init" in Kernel*/
 }

After you insert the module by running insmod threads0.o, you should see a message Init on your console. After running rmmod threads0, you will see a Cleanup message. If you write RT-Linux application you use these functions to initialize and deinitialize your application.

[edit] Threads

RT-Linux implements a POSIX API for a threads manipulation. 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.

[edit] Thread priorities

It is necessary to set thread priorities in RTLinux. 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. This can be guaranteed by assigning a high priority to this thread. The example threads2.c sets different thread priorities. Setting of thread priority is done by code shown below:

 int init_module(void)
 {
   pthread_attr_t attr;
   struct sched_param param;
   pthread_attr_init(&attr);
   param.sched_priority = 1;
   pthread_attr_setschedparam(&attr, &param);
   pthread_create(&t1, &attr, &thread_code, "this is thread 1");
   rtl_printf("Thread 1 started\n");
   ...
 }

The output the program is as follows.

 Thread 1 started
 Thread 2 started
 Thread 3 started
 Message: this is thread 1
 Message: this is thread 2
 Message: this is thread 2
 Message: this is thread 2
 Message: this is thread 1
 Message: this is thread 1
 Message: this is thread 3
 Message: this is thread 3
 Message: this is thread 3

The thread 2 has the highest priority and the thread 3 has the lowest priority. The first message is printed by the middle priority thread 1 because it is started short time before the thread 2.

[edit] See also

  • RTAI - alternative real-time extension for Linux kernel
  • iRMX for Windows - Real-time extension for Windows, somewhat similar architecturally.[citation needed]
  • Xenomai - another alternative real-time extension for Linux kernel

[edit] References

  • Yodaiken, Victor (1999). [1] "The RTLinux Manifesto". Published in the 5th Linux Conference Proceedings.
  • Barabanov, Michael (1996). [2] "A Linux Based Real-Time Operating System".
  • Yodaiken, Victor (1996). [3] "Cheap Operating systems Research" Published in the Proceedings of the First Conference on Freely Redistributable Systems, Cambridge MA, 1996.
  • Dougan, Cort (2004) [4] "Precision and predictability for Linux and RTLinuxPro", Dr. Dobbs Journal, February 1, 2004.
  • Yodaiken,Victor (1997), [5] US Patent 5,995,745

[edit] External links



Personal tools
Namespaces
Variants
Actions
Navigation
Interaction
Toolbox
Print/export
Languages