<< Prev | TOC | Front Page | Talkback | FAQ | Next >>
Real time linux
Linux as a RTOS
A real-time operating system (RTOS) [1] is an operating system capable of guaranteeing timing requirements of the processes under its control. While a time-sharing OS like UNIX strives to provide good average performance, for a RTOS, correct timing is the key feature. Throughput [2] is of secondary concern. In order to deliver the tight worst-case timing performance needed by hard real-time, the RTOS needs to be simple, small, predictable, and optimized to minimize the worst-case performance.
Linux operating system which started as a student project by Linus Travaldo gained momentum.in in late 80s is now a complete operating system meeting requirements of nearly all type of users. Further large group of developers are adding features to the core kernel as well as KLM (kernel loadable modules). However indefinite response time, treatment of interrupts, scheduling policy and timer granularity are some of the features of Linux which makes it unsuitable in embedded world where a definite response time is a must. Several techniques and patches are available to customize and modify bare Linux kernel to be acceptable as a hard real time operating system. This article discusses these issues.
1.1 Unsuitability of Linux for Hard Real Time Applications
The following features make Linux infeasible to be used to run hard real-time applications:
1. Unpredictable scheduling - depends on system load;
2. Coarse timer resolution (10 ms);
3. Non-preemptible kernel;
4. Disabling of interrupts used for coarse-grained synchronization;
5. Use of virtual memory;
6. Reordering of requests for efficiency (e.g. for disk I/O).
Moreover, Linux processes are heavyweight processes, and it can take several hundred microseconds to finish a context switch, and thus make it impossible to schedule a task to poll a sensor every 100 microseconds. Another disadvantage of Linux is that it uses process-based model instead of thread model and signals tend to get lost during the execution of processes.
1.2 Basic Real Time Operating System Implementation Approaches
In order to facilitate the implementation of RTOS, POSIX standard has defined RTOS related specifications. POSIX.1b-1993 standard specified some real-time features in UNIX. The standard defined prioritized scheduling, locking of user memory pages in memory, real-time signals, improved IPC and timers, and a number of other features. Linux partially supports the POSIX.1b standard. However, POSIX.1b compatibility only permits certain kinds of soft real-time processing in Linux.
Generally there are three ways to implement a RTOS.
1. Microkernel Approach:
An example is the QNX[4] which only implements process scheduling, interprocess communication, low-level network communication, and interrupt dispatching. All other services, such as device drivers and file systems, are implemented as user processes. So the kernel is very small (7 KB of code) and fast. Comparing with monolithic kernel, it has some advantages. Debugging user processes is easier than debugging kernel components. If user processes are executed in separate address spaces, memory management errors in different modules are isolated. Another advantage is scalability. A QNX system can be scaled down to 100K to fit in the ROM, or expanded to a full-featured multi-machine development environment. Porting and maintenance is also easier. In addition, a real-time user process can preempt a device driver, which is not the case in monolithic kernels.
However, performance becomes a weak point since microkernel architecture places heavy load on interprocess communication and context switching. Microkernels only provide simple services directly. Therefore, more system calls have to be performed in a microkernel system than in a monolithic one to accomplish the same task. it is most likely for performance reasons that monolithic kernels are still prospering.
2. Monolithic Approach: One example of a monolithic system is VxWorks.[7] VxWorks is a proprietary RTOS geared towards host/target approach. A UNIX host is used for software development and for running non-real-time parts of an application. The VxWorks kernel called wind runs real-time tasks on the target computer. The machines communicate using TCP/IP networking. In VxWorks, the kernel and tasks run in one address space. This allows task switching to be very fast and eliminates the need for system call traps. A run-time linker allows dynamic loading of both tasks and system modules. This feature makes for scalability. An interactive shell with C-like syntax can be used to examine and modify variables, evaluate expressions, call functions, and perform simple debugging. These features encourage experimentation and make development somewhat easier. However, they also make the system more fragile as errors in one module can easily affect others.
3. Decoupled Approach: Instead of "making a general purpose operating system kind-of-realtime"(IRIX)[6] and "keeping adding nonreal-time features to a real-time operating system"(VxWorks),[7] the original Real-Time Linux designers took another alternative. RTLinux[5] decouples the real-time and non-real-time systems. This mechanism makes the real-time process simple, fast, predictable and optimized to minimize worst-case performance. In order to support non-real-time applications at the same time, the general purpose Linux is run as the lowest priority thread.
1.4 Conclusions
Linux is easily the fastest growing operating systems in the embedded world. Its low cost, abundant features and openness make Linux a fertile ground for creativity. Many companies have made tailor made modifications to the kernel and or introduced new techniques to give a real time look and feel to Linux. Linux kernel developers have realized this fact that bare Linux kernel cannot give real time performance which is like oxygen to any embedded real life system. Hence in the new release of kernel version 2.6 has enhanced real-time performance, easier porting to new computers, support for large memory models, support for microcontrollers, and an improved I/O system. Linux 2.6 has been enhanced to provide support across the spectrum of needs of embedded systems from small wrist bands to large switches. As its importance grows, we can expect Linux to become the platform where future progress happens first.
1.5 References
[1] Real time systems by KG SHIN and C.M. Krishna, 1st Edition, The McGraw-Hill Companies, Inc., chapter 2.
[2] Operating System Concepts by Avi Silberschatz (Author), Greg Gagne (Author), Peter Baer Galvin (Author)
[3] http://www.embedded-linux.com
[4] QNX company website: http://www.qnx.com
[5] http://www.rtlinux.org
[6] SGI Company website: http://www.sgi.com/software
[7] Wind-River Company website: http://www.windriver.com.
[8] http://www.linuxdevices.com/articles/AT7751365763.html
I am Nikhil Bhargava from Delhi, India. I am a computer engineer and curently working in CDOT, India for past one year.
Copyright © 2003, Nikhil Bhargava.
Copying license http://www.linuxgazette.com/copying.html
Published in Issue 96 of Linux Gazette, November 2003
<< Prev | TOC | Front Page | Talkback | FAQ | Next >>