RTAI
From wiki.network-crawler.de
Contents |
What is RTAI?
RTAI means Real Time Application Interface. Strictly speaking, it is not a real time operating system, such as VXworks or QNX. It is based on the Linux kernel, providing the ability to make it fully preemptable. Linux is a standard time-sharing operating system which provides good average performance and highly sophisticated services. Like other OS, it offers to the applications at least the following services:
- hardware management layer dealing with event polling or processor/peripheral interrupts
- scheduler classes dealing with process activation, priorities, time slice communications means among applications.
Linux suffers from a lack of real time support. To obtain a timing correctness behaviour, it is necessary to make some changes in the kernel sources, i.e. in the interrupt handling and scheduling policies. In this way, you can have a real time platform, with low latency and high predicatbility requirements, within full non real time Linux environment (access to TCP/IP, graphical display and windowing systems, file and data base systems, etc.).
RTAI offers the same services of the Linux kernel core, adding the features of an industrial real time operating system. It consists basically of an interrupt dispatcher: RTAI mainly traps the peripherals interrupts and if necessary re-routes them to Linux. It is not an intrusive modification of the kernel; it uses the concept of HAL (hardware abstraction layer) to get information from Linux and to trap some fundamental functions. This HAL provides few dependencies to Linux Kernel. This leads to a simple adaptation in the Linux kernel, an easy RTAI port from version to version of Linux and an easier use of other operating systems instead of RTAI. RTAI considers Linux as a background task running when no real time activity occurs.
-- RTAI Development Team
How it works
Linux/RTAI is not a realtime operating system but rather a real-time Linux kernel extension, which allows running real-time tasks seamlessly aside of the hosting GNU/Linux system. The RTAI co-kernel shares hardware interrupts and system-originated events like traps and faults with the Linux kernel using the Adeos [1] virtualization layer, which in turn ensures RTAI low interrupt latencies. The native RTAI API provides the applications a wealth of useful services, including counting semaphores, POSIX 1003.1-1996 facilities such as pthreads, mutexes and condition variables, also adding remote procedure call facility, mailboxes, and precision timers. Most services are symmetrically available from kernel module and user-space programs. -- Xenomai whitepaper
Installation
Dispositions
Download rtai
cd /usr/src wget https://www.rtai.org/RTAI/rtai-3.3.tar.bz2 tar jvxf rtai-3.3.tar.bz2
Download vanilla kernel
I chose the vanilla kernel: linux 2.6.15
Extract the kernel archive
cd /usr/src tar jvxf linux-2.6.15.tar.bz2
Patch your kernel
cd /usr/src/linux-2.6.15 make mrproper patch -p1 < ../rtai-3.3/base/arch/i386/patches/hal-linux-2.6.15-i386-1.2-00.patch
Configure/make your RTAI
cd /usr/src/rtai-3.3 make menuconfig
General --->
(/be/sure/that/i/am/accurate) Installation directory
(/be/sure/that/i/am/accurate) Linux source tree
Machine --->
(1) Number of CPUs (SMP-only)
SLIND
If you try to build a RTAI system for a SLIND target do the following:
mkdir ~/SLIND/installer-image/usr/realtime cd /usr ln -s ~/SLIND/installer_image/usr/realtime/ realtime
and:
General --->
(/usr/realtime) Installation directory
(/be/sure/that/i/am/accurate) Linux source tree
Build your kernel
make menuconfig
Configure your kernel
Code maturity level options --->
[*] Prompt for development and/or incomplete code/drivers
Loadable module support --->
[*] Enable loadable module support
[ ] Module Versioning support (EXPERIMENTAL)
Processor type and features --->
[ ] Use register arguments
[*] Interrupt pipeline
File systems --->
Pseudo filesystems --->
[*] /proc file system support
Note: If your CPU doesn't provide APIC disable it or you will later have the error: RTAI[hal]:ERROR, LOCAL APIC CONFIGURED BUT NOT AVAILABLE/ENABLED and you must compile everything new :(
Processor type and features --->
[ ] Local APIC support on uniprozessors
Build your kernel
make && make install && make modules && make modules_install
For SLIND you should use the Toolchain:
make CC="/usr/bin/i486-linux-uclibc-gcc-3.4" bzImage make CC="/usr/bin/i486-linux-uclibc-gcc-3.4" modules make CC="/usr/bin/i486-linux-uclibc-gcc-3.4" modules install
Build RTAI
In general:
cd ../rtai-3.3/ make && make install
With SLIND:
cd ../rtai-3.3/ ./configure --prefix=/root/SLIND/installer_image/usr/realtime --host=i486-linux-uclibc CC=i486-linux-uclibc-gcc \ --with-linux-dir=/usr/src/linux-2.6.15 make && make install
Uh oh there is a Bug - do the following:
vi base/include/rtai_posix.h
- Replace pthread_yield with sched_yield - then recompile it
- Now copy the newly build modules (in /lib/modules/2.6.15-ipipe/) in your SLIND install image at ~/SLIND/installer_image/lib/modules/2.6.15-ipipe/
- Copy your kernel /usr/src/linux-2.6.15/arch/i386/boot/bzImage to /tftpboot/
Final test with SLIND (in my case)
192.168.1.3 login: root login[732]: root login on `ttyS0' [root@192 ~]# cd /usr/realtime/ bin/ include/ modules/ testsuite/ calibration/ lib/ share/ [root@192 ~]# cd /usr/realtime/testsuite/ kern/ user/ [root@192 ~]# cd /usr/realtime/testsuite/kern/latency/ [root@192 latency]# ls display* latency_rt.ko run* [root@192 latency]# insmod /usr/realtime/modules/rtai_hal.ko Using /usr/realtime/modules/rtai_hal.ko I-pipe: Domain RTAI registered. RTAI[hal]: <3.3> mounted over IPIPE-NOTHREADS 1.2-00. RTAI[hal]: compiled with gcc version 3.3.5 (Debian 1:3.3.5-13). RTAI[hal]: mounted (IPIPE-NOTHREADS, IMMEDIATE (INTERNAL IRQs DISPATCHED), ISOL_CPUS_MASK: 0). PIPELINE layers: c8019e00 9ac15d93 RTAI 200 c02d7580 0 Linux 100 [root@192 latency]# insmod /usr/realtime/modules/rtai_ksched.ko Using /usr/realtime/modules/rtai_ksched.ko RTAI[malloc]: vmalloced extent c8048000, size 2097152. RTAI[malloc]: loaded (global heap size=2097152 bytes). RTAI[sched_lxrt]: loaded (IMMEDIATE, UP, USER/KERNEL SPACE <with RTAI TASKs>). RTAI[sched_lxrt]: hard timer type/freq = 8254-PIT/1193180(Hz); default timing mode is periodic; linear ordering of timed li.RTAI[sched_lxrt]: Linux timer freq = 250 (Hz), CPU freq = 300736000 hz. RTAI[sched_lxrt]: timer setup = 2008 ns, resched latency = 2690 ns. [root@192 latency]# insmod /usr/realtime/modules/rtai_fifos.ko Using /usr/realtime/modules/rtai_fifos.ko [root@192 latency]# insmod .runinfo display latency_rt.ko run [root@192 latency]# insmod latency_rt.ko Using latency_rt.ko [root@192 latency]# mknod -m 666 /dev/rtai_shm c 10 254 [root@192 latency]# mknod -m 666 /dev/rtf1 c 150 1 [root@192 latency]# mknod -m 666 /dev/rtf9 c 150 9 [root@192 latency]# mknod -m 666 /dev/rtf2 c 150 2 [root@192 latency]# mknod -m 666 /dev/rtf3 c 150 3 [root@192 latency]# /usr/realtime/testsuite/kern/latency/display ## RTAI latency calibration tool ## # period = 100000 (ns) # avrgtime = 1 (s) # do not use the FPU # start the timer # timer_mode is oneshot RTAI Testsuite - KERNEL latency (all data in nanoseconds) RTH| lat min| ovl min| lat avg| lat max| ovl max| overruns RTD| -628| -628| 1625| 10933| 10933| 0 RTD| 805| -628| 1609| 13756| 13756| 0 RTD| -781| -781| 1622| 17424| 17424| 0 RTD| 818| -781| 1604| 18082| 18082| 0 RTD| 845| -781| 1613| 12975| 18082| 0 RTD| -585| -781| 1612| 14085| 18082| 0 RTD| 798| -781| 1571| 14338| 18082| 0 RTD| -738| -781| 1576| 8735| 18082| 0 RTD| 851| -781| 1564| 13504| 18082| 0 RTD| -848| -848| 1621| 13188| 18082| 0 RTD| 751| -848| 1601| 14332| 18082| 0 RTD| -1001| -1001| 1628| 12696| 18082| 0 RTD| 881| -1001| 1607| 12313| 18082| 0 RTD| -861| -1001| 1628| 19236| 19236| 0 RTD| 57| -1001| 1610| 12895| 19236| 0 RTD| 788| -1001| 1604| 13813| 19236| 0 RTD| -1014| -1014| 1618| 17580| 19236| 0 RTD| 801| -1014| 1603| 14704| 19236| 0 RTD| -585| -1014| 1599| 12755| 19236| 0 RTD| 811| -1014| 1578| 13284| 19236| 0 RTD| -738| -1014| 1578| 15359| 19236| 0
