12.07.2015 Views

Understanding the Latest Open-Source Implementations of Real ...

Understanding the Latest Open-Source Implementations of Real ...

Understanding the Latest Open-Source Implementations of Real ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Technical View<strong>Understanding</strong> <strong>the</strong> <strong>Latest</strong> <strong>Open</strong>-<strong>Source</strong> <strong>Implementations</strong> <strong>of</strong> <strong>Real</strong>-Time Linuxfor Embedded Processors By: Michael Roeder, Field Applications Engineer, Future ElectronicsBy origin GNU/Linux is an Operating System(OS) for desktop computers and servers. Inapplications usually run on those systems,<strong>the</strong> timing determinism <strong>of</strong> operations is not acritical feature. However, GNU/Linux also appealsstrongly to embedded system designers, sovarious efforts to modify or extend Linuxin order to provide time determinism andreal-time capabilities have been made by <strong>the</strong>Linux community.This article provides an insight into three <strong>of</strong> <strong>the</strong>open-source GNU/Linux real-time extensionscurrently available to embedded designers.Of course, when real-time is examined, it isimportant to be clear about what is meant by‘real-time’. In a hard real-time environment, asystem will always meet its deadlines. This meansthat <strong>the</strong> system has to guarantee:• Strict event determinism• Bounded latencies; in o<strong>the</strong>r words, it must<strong>of</strong>fer a guaranteed worst-case latencyHard real-time operation is usually required insafety- or system-critical applications, in forexample <strong>the</strong> automotive, avionics, medical andautomation sectors. A s<strong>of</strong>t real-time environmentis usually optimized for a ‘best effort’. In mostcases, real-time criteria will be met, but <strong>the</strong>re isno guarantee. Common applications include audioand video encoding and broadcast, and VoIP.A s<strong>of</strong>t real-time environment is usually optimizedfor a ‘best effort’. In most cases, real-time criteriawill be met, but <strong>the</strong>re is no guarantee. Commonapplications include audio and video encoding andbroadcast, and VoIP.A concept linked to that <strong>of</strong> real time is preemption:<strong>the</strong> ability <strong>of</strong> a system to interrupt tasks at many‘preemption points’ (Figure 1). The longer <strong>the</strong>non-interruptible program units are, <strong>the</strong> longer is<strong>the</strong> waiting time (‘latency’) <strong>of</strong> a higher priority taskbefore it can be started or resumed. GNU/Linux is‘user-space preemptible’: it allows user tasks tobe interrupted at any point. The job <strong>of</strong> real-timeextensions is to make system calls preemptibleas well.In its current form, GNU/Linux can at best satisfys<strong>of</strong>t real-time conditions, and is not a hard RTOSby design. At <strong>the</strong> same time, plenty <strong>of</strong> commercialTask 2scheduledTask 1Task 2starts executionlatencyLowpriorityTask 2 total response timeTask 2scheduledTask 1Task 2starts executionTask 2Task 2HighpriorityTask 1(cont’ed)Task 2 total response timeFigure 1: The operation <strong>of</strong> non-preemptive (top) andpreemptive (bottom) operating systemstimePreemptionPointstimeRTOSs are available for those with real-time requirements.So why would an engineer bo<strong>the</strong>r tomodify GNU/Linux to meet RTOS requirements?The reasons are usually similar to <strong>the</strong> reasonsthat Linux has been a success in desktop andenterprise computing:• <strong>Open</strong> architecture, open-source licences andno s<strong>of</strong>tware patents• Wide choice <strong>of</strong> application s<strong>of</strong>tware, availablein source code• Total code transparency• Support for wide range <strong>of</strong> processors ando<strong>the</strong>r hardware• Support for <strong>the</strong> latest technology in domainssuch as wireless communications, internetprotocol and security• Community support and community projects• Lower total cost <strong>of</strong> ownership compared to acommercial RTOSCommercial businesses are among those whohave modified GNU/Linux for use in real-timeapplications. But for many embedded developers,<strong>the</strong> appeal <strong>of</strong> Linux is that it is open-source, and<strong>the</strong>y will <strong>the</strong>refore want any real-time modification<strong>of</strong> GNU/Linux to also be open source. Today,<strong>the</strong>re are three mainstream open-source choicesfor implementing real-time applications withGNU/Linux:• Linux with <strong>the</strong> RT_PREEMPT patch(Linux/PREEMPT_RT)• RTAI• XenomaiThe PREEMPT_RT project is a set <strong>of</strong> patches forstandard Linux kernels, aimed at improving <strong>the</strong>native real-time capabilities <strong>of</strong> GNU/Linux. Theproject’s goal is to get all its patches approved foraddition to <strong>the</strong> mainline kernel; for many, this hasalready been achieved.RTAI uses a dual-kernel system: a smalldeterministic real-time kernel with scheduler,and <strong>the</strong> regular Linux kernel. The Linux kernel ismodified to access an interrupt abstraction layer,<strong>the</strong> RTHAL, instead <strong>of</strong> <strong>the</strong> hardware directly. Thisallows <strong>the</strong> real-time kernel to block <strong>the</strong> Linuxkernel while executing real-time functions.Xenomai was launched in 2001 with <strong>the</strong> aim <strong>of</strong>not only providing real-time capabilities to GNU/Linux, but also <strong>of</strong> making it easier to port s<strong>of</strong>twarewritten for o<strong>the</strong>r RTOSs to GNU/Linux. Toachieve this, it provides real-time APIs (for POSIX*1003.1b, VxWorks, pSOS+, VRTX, uITRON, RTAI)*,known as ‘skins’ that can be used to easily portapplications written for those operating systemsto GNU/Linux.Of <strong>the</strong> three products, Xenomai has technicalfeatures which – in this author’s opinion – make it<strong>the</strong> most interesting free hard real-time approachfor GNU/Linux.Originally, Xenomai was solely based on adual-kernel concept using <strong>the</strong> ADEOS (AdaptiveDomain Environment for Operating Systems)I-Pipe as an interrupt abstraction layer. In thiscase, Xenomai provides <strong>the</strong> real-time kernel and<strong>the</strong> Linux kernel is just a special low-priority‘task’ which can be interrupted at any time, quitesimilar to <strong>the</strong> RTAI approach.However, <strong>the</strong> forthcoming Xenomai 3.0 canoperate as a POSIX user thread on any regularLinux kernel (usually with PREEMPT_RT enabled).261.800.FUTURE.1 • www.FutureElectronics.com


Technical ViewIt <strong>the</strong>refore allows all applications implementedon Xenomai skins to run directly on a monolithickernel. In o<strong>the</strong>r words, Xenomai 3.0 acts as anabstraction layer over <strong>the</strong> regular Linux kernel,providing this kernel’s real-time capabilities to itsapplications through <strong>the</strong> various skins. Xenomai3.0 only requires <strong>the</strong> standard POSIX API, sothat no patching or porting to particular kernelversions is needed.This gives <strong>the</strong> developer <strong>of</strong> applications for Xenomaia useful choice: to run <strong>the</strong> applications under asmall, lightweight and industry-proven real-timekernel, or under a preemptible Linux monolithickernel. It is important to understand, however,that <strong>the</strong> second choice means that all real-timecapabilities have to come from – and are only asgood as – <strong>the</strong> underlying Linux kernel itself.Dual Kernel Versus Native PreemptionEach method has its own benefits. The co-kernelapproach has <strong>the</strong> advantage that <strong>the</strong> real-timeapplication is totally independent <strong>of</strong> <strong>the</strong> Linuxkernel and only depends on <strong>the</strong> real-time kernel,scheduler and abstraction layers. There is a clearseparation between <strong>the</strong> real-time and non-realtimedomain. This simplifies maintenance, timingand safety certification.Porting to new CPU architectures is also easy,because only <strong>the</strong> abstraction layers have to beadapted. An interrupt abstraction layer patch,however, is always specific to a certain kernelversion, and patches are only available forselected versions <strong>of</strong> <strong>the</strong> <strong>of</strong> <strong>the</strong> mainline kernel.Under <strong>the</strong> single-kernel approach with <strong>the</strong> Linux/PREEMPT_RT patch, a POSIX real-time APIallows real-time applications to be developed in<strong>the</strong> GNU/Linux user-space, and to benefit fromall development, debugging and pr<strong>of</strong>iling toolsavailable <strong>the</strong>re.At some point in <strong>the</strong> future, <strong>the</strong> RT_PREEMPTpatch will be completely merged into <strong>the</strong> mainlinekernel, and <strong>the</strong>n it will be simple to compile areal-time kernel for any supported system. Then,however, every modification to <strong>the</strong> operatingsystem, such as kernel patches or new drivers,might influence <strong>the</strong> system in a perhapsundesired way. Therefore <strong>the</strong> system will haveto be re-qualified and possibly re-certified aftersuch modifications.Ano<strong>the</strong>r drawback is that <strong>the</strong> Linux/PREEMPT_RTentails higher worst-case latencies than adual-kernel system.In <strong>the</strong> author’s opinion, using <strong>the</strong> POSIX real-timeAPI is <strong>the</strong> best answer to <strong>the</strong> problem <strong>of</strong> decidingbetween <strong>the</strong> two approaches. Depending on <strong>the</strong>specific requirements <strong>of</strong> <strong>the</strong> end product, POSIXreal-time applications can ei<strong>the</strong>r run on Xenomai’sdedicated real-time kernel or on a single Linux/PREEMPT_RT kernel.Performance Evaluation in <strong>the</strong> <strong>Real</strong> WorldSo just how ‘real’ is <strong>the</strong> real-time performance<strong>of</strong> Linux? Below is a method to get a quick firstimpression <strong>of</strong> <strong>the</strong> latency <strong>of</strong> any given system.The tool cyclictest is used to schedule a task with<strong>the</strong> highest priority every 10ms. The tool knowswhen this task is expected to run and calculates<strong>the</strong> latency or deviation from this expected time.Table 1 shows <strong>the</strong> results <strong>of</strong> a test run on aFreescale i.MX53 ARM Cortex-A8 processoroperating at 1GHz. It ran Linux kernel 2.6.38 from<strong>the</strong> DENX Linux tree. Two different test systemswere set up.S_CPRE: standard kernel withCONFIG_PREEMPT (“Preemptible Kernel(Low-Latency Desktop)) enabled./cyclictest –m -n -p99 -t1 -i10000 -1360000S_XENO: Kernel + Xenomai 2.6.0-rc4 + I-Pipe1.18-03./cyclictest -n -p99 -t1 -i10000 -1360000SystemLatency/µsS_XENOS_CPRE1st runS_CPRE2nd runMinimum 2 27 13Average 43 88 81Maximum 58 415 1829Table 1: Cyclic test <strong>of</strong> single- and dual-kernel Linux systemsThe average latency shows <strong>the</strong> typical values thatcan be expected from this system. For developers<strong>of</strong> hard real-time applications, however, only <strong>the</strong>maximum latency is <strong>of</strong> interest. The table clearlyshows <strong>the</strong> superior performance <strong>of</strong> a dual-kernelsystem.ConclusionWhen <strong>the</strong> entire PREEMPT_RT patch has goneinto mainline Linux, it will be <strong>the</strong> method <strong>of</strong> choicefor ordinary real-time applications. Xenomai 3.0will <strong>the</strong>n allow easy porting <strong>of</strong> existingapplications to a single, real-time Linux kernel.A dual-kernel approach will continue to be mostappropriate for hard real-time requirements.For developers <strong>of</strong> new applications, <strong>the</strong> use <strong>of</strong> <strong>the</strong>POSIX API is highly recommended whe<strong>the</strong>r <strong>the</strong>yare implementing a single- or dual-kernel system.In <strong>the</strong> near future, <strong>the</strong> trend to use multi-coreprocessors will allow for new solutions to <strong>the</strong>problems discussed in this article. For example,it is already possible in mainline GNU/Linux toassign interrupts to a CPU core and to keep nonreal-timetasks away from this core. Interestingly,<strong>the</strong>refore, a multi-core system nullifies <strong>the</strong>performance advantage <strong>of</strong> <strong>the</strong> dual-kernelapproach. An asymmetric CPU such asFreescale’s Vybrid processor family (using acombination <strong>of</strong> ARM Cortex-A5 and Cortex-M4cores) <strong>of</strong>fers <strong>the</strong> option <strong>of</strong> running multipleoperating systems, each optimised for differentfunctions, to even fur<strong>the</strong>r improve hard or s<strong>of</strong>treal-time performance.* POSIX is a series <strong>of</strong> IEEE standards that helpensure compatibility across operating systems bydefining a series <strong>of</strong> application program interfaces(APIs), functions and command-line shells foruse by <strong>the</strong> OS. Many embedded OSs are POSIXcompliant,including VxWorks, Linux, MQXand QNX.1.800.FUTURE.1 • www.FutureElectronics.com27

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!