ESC Brazil - RealTime Linux with RT_PREEMPT

The first Embedded Systems Conference Brazil was held at São Paulo on 24 to May 25 2011 and ProFUSION was there to do a technical talk. Our contributor Lucas De Marchi proposed the talk "Usando Linux como Sistema de Tempo Real" (Using Linux as an Real Time Operating System). He did his master thesis on that topic for 2 years at Politecnico di Milano, so he knows a lot about the topic. Unfortunately Lucas is one of those geeks that try to live a real-world life and plays football (soccer for americans) and in the week before he broke his foot... Ouch! So yours truly was elected to present the talk for him. I already did play with realtime Linux in the past and I knew the concepts from past experiences, thus I accepted the challenge and did the talk. According to the attendees it was a good talk! People got amazed with Linux's Real Time capabilities and the ability to mix it with regular ("fair") tasks, being able to change a process from FAIR to RT during runtime, no recompile was needed! This was demonstrated in a Freescale's i.MX31 running music player running with regular priority and ping flood and a heavy CPU task, the music skipped and it was clear the deadlines were not being met. Running chrt and raising the priority above Kernel Threads that handle interruptions immediately fixed the skips. We also ran a software oscilloscope at desktop that plotted the achieved deadlines and it confirmed what we were listening. If you're not aware, RT_PREEMPT is a patchset (from pre-git days, not a git tree called -rt) that Ingo Molnar and Thomas Gleixner run to improve Real-Time behavior for the Linux kernel. As concepts are tested and patches mature they are moved into mainline tree, benefiting everyone using it, even your desktop running PulseAudio now! The major trick of this work was to handle interruptions in Kernel Threads instead of immediately as it used to be. These threads are RT themselves at priority 50 and if you want you can have a regular user process thread at a higher priority and it will run before the kernel. This was the case with the pingflood, with a regular kernel the music could skip due kernel stopping the playback process to handle the network interruption. Last but not least, if you're not familiar with RT have something clear in your mind. Real Time doesn't mean Real Fast. It just mean you have guarantees to execute things when they should and this is mainly done by means of a preemptive kernel. In some cases RT will turn things slower, as you may switch contexts more often due preemption, but you'll know you'll be on time (as opposed to batch processing). Linux being a General Purpose Operating System (GPOS) was not designed with such thing in mind, but it was successfully converted into one!