RTOS Real-Time Operating Systems Chenyang Lu
OS Support for Real-Time Ø Real-Time OS Ø Real-time extensions to general-purpose OS Chenyang Lu 19
RTOS: Features for Efficiency Ø Small Ø Minimal set of functionality Ø Fast context switch Ø Fast and time bounded response to interrupts Ø Fixed or variable partitions of memory q May not support paging or virtual memory q May support locking code and data in memory Ø Sequential file that can accumulate data at fast rate q May be memory-based Chenyang Lu 20
Code Size Name Code Size Target CPU posek 2K Microcontrollers psosystem PII->ARM Thumb VxWorks 286K Pentium -> Strong ARM QNX Nutrino >100K Pentium II -> NEC QNX RealTime 100K Pentium II -> SH4 OS-9 Pentium -> SH4 Chorus OS 10K Pentium -> Strong ARM ARIEL 19K SH2, ARM Thumb Creem 560 bytes ATMEL 8051 Chenyang Lu 21
RTOS: Features for Real-Time Ø Preemptive priority scheduling q At least 32 priority levels, commonly 128-256 priority levels q Priority inheritance/ceiling protocol Ø System calls q Bounded execution times q Short non-preemptable code Ø High-resolution system clock q Resolution down to nanoseconds q But it takes about a microsecond to process a timer interrupt Chenyang Lu 22
Other Important Features Ø Conformance to standards q Real-Time POSIX API q TCP/IP Ø Modularity and configurability q Small kernel q Pluggable modules Chenyang Lu 23
Example: VRTX Ø VRTXsa q RT-POSIX compliant q Full real-time support Ø VRTXmc q Optimized for power and footprint Ø First RTOS certified by FAA q 100% code coverage in testing Ø Runs the Hubble Space Telescope Chenyang Lu 24
Real-Time Extensions to General OS Ø Generally slower and less predictable than RTOS Ø More functionality and development support Ø Standard interfaces Ø Suitable for soft real-time applications Chenyang Lu 25
How Real-Time Is Linux? Ø I believe that Linux is ready to handle applications requiring submillisecond process-scheduling and interrupt latencies with 99.99+ percent probabilities of success. No, that does not cover every imaginable real-time application, but it does cover a very large and important subset. Ø The Linux 2.6 kernel, if configured carefully and run on fast hardware, can provide sub-millisecond interrupt and process scheduling latencies with extremely high probabilities of success. There are patches out there that are expected to provide latencies in the tens of microseconds. These patches need some work, but are maturing quickly. Paul McKenney, IBM Linux Technology Center Shrinking slices: Looking at real time for Linux, PowerPC, and Cell Chenyang Lu 26
Why isn t Linux real-kme? Ø The Linux kernel only allows a process to preempt another under certain circumstances: q when the CPU is running user-mode code; q when kernel code returns from a system call or an interrupt to user space; q when kernel code blocks on a mutex, or explicitly yields control to another process. Ø If kernel code is executing, a high priority thread cannot preempt the kernel until the kernel code explicitly yields control. Ø In the worst case, the latency could potentially be hundreds milliseconds or more. Source: h*ps://rt.wiki.kernel.org/ Chenyang Lu 27
Linux Scheduling Ø Real-time scheduling class q Fixed priority q SCHED_FIFO: First-In-First-Out q SCHED_RR: Round-Robin Ø Non-real-time scheduling class (SCHED_NORMAL) Ø Default q Real-time: 0 99 q Non-real-time: 100 139 Chenyang Lu 28
Real-Kme Linux Ø Core kernel modifications: patches q Require modifications to Linux kernel q Example: CONFIG_PREEMPT_RT patch Ø Compliant kernels: modified native RTOS q Linux binaries can run without modifications q Example: LynxOS Ø Dual kernels: real-time kernel sits below Linux q Real-time kernel traps all interrupts and schedules all processes q Linux runs as a low-priority process q Example: RT-Linux (FSLabs) Chenyang Lu 29
CONFIG_PREEMPT_RT Patch Ø Convert Linux into a fully preemptible kernel. Ø Locks q Making in-kernel locking-primitives preemptible through reimplementation with rtmutexes. q Critical sections protected by spinlock_t and rwlock_t are preemptible. q Priority inheritance for in-kernel spinlocks and semaphores. Ø Convert interrupt handlers into preemptible kernel threads. Ø Convert timer API into separate infrastructures for high resolution kernel timers plus one for timeouts, leading to user space POSIX timers with high resolution. Source: h*ps://rt.wiki.kernel.org/ Chenyang Lu 30
MulK-core Real-Time Scheduler Ø Push-pull scheduler schedules tasks across CPUs. Ø Every CPU has a runqueue. Ø Push: considers all the runqueues within its root domain to find the one of a lower priority than the task being pushed. q Push a task when it wakes up on a runqueue running a task of higher priority q Push a task when a higher-priority task on the same runqueue wakes up and preempts it Ø Pull: whenever a runqueue is about to schedule a task that is lower in priority than the previous one, it checks whether it can pull tasks of a higher priority from other runqueues. Chenyang Lu 31
RT-Linux Real-time kernel traps all interrupts and schedules all processes Linux runs as a low-priority process Real-time applications cannot take advantage of Linux calls Linux Process Linux Process Linux Kernel Software Interrupts RT Process Scheduling Real-Time Kernel Hardware Interrupts Chenyang Lu 32
More InformaKon Ø Real-Time Linux Wiki: https://rt.wiki.kernel.org/index.php/frequently_asked_questions Ø Real-Time Linux Kernel Scheduler: http://www.linuxjournal.com/magazine/real-time-linux-kernel-scheduler Chenyang Lu 33