1Real Time in Embedded Linux Systems © Copyright 2004, Michael OpdenackerGNU Free Documentation Licenseelectrons.comReal Time in Linux Embedded SystemsReal Timein Linux Embedded SystemsMichael OpdenackerFree Electronselectrons.comThanks to Nicolas Rougier (Copyright 2003, ~rougier/) for the Tux image2Real Time in Embedded Linux Systems © Copyright 2004, Michael OpdenackerGNU Free Documentation Licenseelectrons.comThanksTo the OpenOffice.org project, for their presentation and word processor tools which satisfied all my needs.To the Handhelds.org community, for giving me so much help and so many opportunities to help.To the members of the whole Free Software and Open Source community, for sharing the best of themselves: their work, their knowledge, their friendship.To people who sent corrections:Matti Aaltonen3Real Time in Embedded Linux Systems © Copyright 2004, Michael OpdenackerGNU Free Documentation Licenseelectrons.comCopying this document© 2004, Michael Opdenackermichael@freeelectrons.comThis document is released under the GNU Free Documentation License, with no invariant sections.Permission is granted to copy and modify this document provided this license is kept.See for detailsDocument updates availableon electrons.com/articles/realtimeCorrections, suggestions and contributions are welcome!4Real Time in Embedded Linux Systems © Copyright 2004, Michael OpdenackerGNU Free Documentation Licenseelectrons.comDocument historyUnless specified, contributions are from Michael OpdenackerSee electrons.com/doc/ChangeLog for detailed changes.Sep 28, 2004. First public releaseSep 2024, 2004. First session for Atmel, Rousset (France)5Real Time in Embedded Linux Systems © Copyright 2004, Michael OpdenackerGNU Free Documentation Licenseelectrons.comAbout this documentThis document is first of all meant to be used as a visual aid by a speaker or a trainer. Hence, this is just a summary or a complement to what is said. Hence, the explanations are not supposed to be exhaustive.However, this document is also meant to become a reference for the audience. It also targets readers interested in selftraining. So, a bit more details are given, making the document a bit less visually attractive.6Real Time in Embedded Linux Systems © Copyright 2004, Michael OpdenackerGNU Free Documentation Licenseelectrons.comContentsIntroductionReducing latency in LinuxLinux hard realtime extensionsCommercial Linux realtime distributionsConclusionReferences7Real Time in Embedded Linux Systems © Copyright 2004, Michael OpdenackerGNU Free Documentation Licenseelectrons.comReal Time in Embedded Linux SystemsIntroduction8Real Time in Embedded Linux Systems © Copyright 2004, Michael OpdenackerGNU Free Documentation Licenseelectrons.comHard Real TimeA system is considered as a hard real time if it can answer to an internal or external stimulus within a given maximum amount of time. “Guaranteed worst case”Hard real time systems are used wherever failing to react in time can cause a system failure or damage, or put its users in danger.Typical examplesIndustrial process controlTransportationMedicine (pacemakers, etc.)9Real Time in Embedded Linux Systems © Copyright 2004, Michael OpdenackerGNU Free Documentation Licenseelectrons.comSoft Real TimeA system is considered as soft real time if it is built to react to stimuli as quickly as it can. “Best effort”However, if the system loses events or fails to process them in time, there is no catastrophic consequence on its operation. There is just a degradation in quality.Typical examplesAudio, videoAirline reservation systems10Real Time in Embedded Linux Systems © Copyright 2004, Michael OpdenackerGNU Free Documentation Licenseelectrons.comLinux and Real TimeLinux cannot be considered as a hard real time systemThere are long sections of code where all interrupts are maskedKernel code (system calls) not preemptible until they complete or decide to release the processor by calling the scheduler.11Real Time in Embedded Linux Systems © Copyright 2004, Michael OpdenackerGNU Free Documentation Licenseelectrons.comTypical response timeA Linux system can be considered as soft real time if it can react within a few hundreds of µs in most cases.A Linux system can be considered as hard real time if it can react within a few tens of µs in all cases.12Real Time in Embedded Linux Systems © Copyright 2004, Michael OpdenackerGNU Free Documentation Licenseelectrons.comLinux 2.6 improvementsLinux 2.6 improves this by offering a preemptible option (CONFIG_PREEMPT)Kernel code can be interrupted at almost any time (except when spinlocks are held)This reduces latency for high priority processesImplications for driver writersAnything can happen between 2 instructionsUniprocessor machines b