News Archive (1999-2012) | 2013-current at LinuxGizmos | Current Tech News Portal |    About   

Linux gets real (-time)

Jan 8, 2004 — by LinuxDevices Staff — from the LinuxDevices Archive — 2 views

Metrowerks Senior Software Engineer and veteran real-time programmer Bernhard Kuhn has created a Linux kernel patch that he claims enables hard, real-time performance in the Linux kernel by adding priorities to interrupts and spinlocks. Kuhn believes his approach to be more “natural” and akin to traditional real-time operating systems (RTOSs) than the dual-kernel approach taken by real-time projects such… as RTAI and RTLinux, and he is hopeful that his patch might one day win enough interest and support to become part of the official Linux kernel tree.

Kuhn announced the patch today in a post to the Linux kernel mailing list, the rtai-dev mailing list, and the Consumer Electronics Linux Forum's member list, among other places. The patch was completed during several “breakthrough” days over the holiday breaks, according to Kuhn, but represents years of work on Kuhn's part toward a Linux kernel capable of supporting real-time interrupts.

The patch is fairly rudimentary at present, supporting only the x86 architecture and the 2.4.23 kernel. It requires the hardware to have a local APIC (Advanced Programmable Interrupt Controller). Furthermore, it does not support network or block devices (such as hard disk drives) “and it probably never will,” according to Kuhn, who points out that “such devices typically have high latencies, anyway.”

Kuhn says the patch could find traction in data acquisition and real-time (industrial) control, applications that are traditionally the province of RTAI, RTLinux, and the single-kernel, real-time Linux implementation from TimeSys.

“In some cases, a dual kernel approach could actually simplify real-time programming,” notes Kuhn, by compartmentalizing the real-time and non-time-critical parts of an application. “I guess it will be pretty hard to compete with existing and creditable hard-real-time solutions around Linux such as RTAI/Adeos, RTLinux or the mechanisms introduced by TimeSys, since those have a long track record and strong communities. Nevertheless, I hope that some people will at least have a look at the patch and conclude that this is actually the right way of making the linux hard real time aware since this variant is an integration solution rather than “gluing” something to the kernel.”

Kuhn notes that he worked with RTAI/RTLX and other dual-kernel real-time approaches for years before deciding there was a better way.

Real-time performance akin to RTAI, RTLinux

Kuhn is distributing the patch with an example kernel module that can be loaded with or without real-time interrupt priority scheduling. The module outputs a square-wave to a parallel port for display on an oscilloscope. A separate user-space application times the latency of the module's interrupts. A system heavily loaded with interrupts by simultaneous ping floods and 3D modeling with glxgears completed 99.9% of all interrupts within 486.1 microseconds, and a worst case of 500.8 mircoseconds, with normal interrupt priorities. With real-time interrupts enabled, 99.9% of all interrupts were completed within 3.1 microseconds of APIC timer expiration, with a worst case 5.2 microseconds.

“These figures are about the same as what you'd get with RTAI or RTLinux,” notes Kuhn.

Kuhn adds that, “Instead of running Linux as the idle task of the real-time operating system [as with RTAI and RTLinux], it should be possible to modify the RTAI or RTLinux cores in a way that they are simply running as a high priority Linux interrupt, allowing the use of the existing and comfortable APIs of these sub-kernels.”

To-do list

Kuhn says he hopes his patch will generate enough interest among the real-time kernel programming community that others will begin to contribute to it. One important task will involve porting the patch to non-x86 architectures. Because the patch is closely integrated with the kernel, considerable work is required. “But,” notes Kuhn, “X86 was probably the hardest, since it has to support the most legacy structure, so if that's done, it should be possible everywhere.”

Other feature candidates for Kuhn include SMP support, more priority levels (currently limited to “low” and “high”) and, topping the list, the ability to prioritize individual interrupts instead of only the local APIC timer interrupt.

The holy grail — becoming one with Linux

Kuhn's rtirq patch is too new to get a read on the reaction from the kernel developer community, but Kuhn clearly hopes his patch might someday become part of the mainstream Linux kernel source tree. “That's my hope, yes. The patch is very easy, simple to understand, and fits very well into the Linux kernel. For now, the patch is done in such a way that if you don't configure it, it doesn't change the kernel at all.”

Linus has traditionally smiled on interesting experiments when building his development tree, given that, afterall, he started Linux in the first place as an experimental venture.

Dave Beal, of Metrowerks, gives the patch only a fair chance, but says that regardless, Metrowerks intends to support and maintain the work. “Historically, the kernel team has been very cautious, unless contributions can be shown to be worthy enhancements to capabilities, stable, cleanly implemented, and helpful to the fundamental desktop and enterprise uses of Linux,” observes Beal. “One example of this was the the preemptible kernel patch, which, after a period of review by many eyes was accepted into the main tree. Fortunately for us, the preemptible kernel patch also provides advantages in the embedded space. This rtirq patch addresses a lower level of real-time performance that might not meet the last criteria mentioned above.”

“Regardless of whether in the future it will be maintained in the kernel tree or not, Metrowerks will maintain this work in a manner that allows those who focus on embedded Linux to apply and port it cleanly,” adds Beal.

The real-time interrupt patch can be downloaded here. For more technical details about the patch, be sure to read Kuhn's announcement article.


 
This article was originally published on LinuxDevices.com and has been donated to the open source community by QuinStreet Inc. Please visit LinuxToday.com for up-to-date news and articles about Linux and open source.



Comments are closed.