RTLinux
RTLinux
Linux
Defects of Linux
• Linux scheduling algorithms are not designed for real-time tasks.
– Linux will “batch” operations to make more efficient use of the hardware.
• Linux scheduling is unpredictable.
– Linux processes are heavyweight processes.
– It can take several hundred microseconds to finish a context switch.
• Linux Timer resolution is coarse, 10 ms.
• Linux Kernel is Non-preemptible .
– Even the lowest priority task is running.
– Linux will make high priority tasks wait for low priority tasks to release resources.
• Linux disables interrupts used for coarse-grained synchronization.
– “Coarse grained” synchronization means that there are long intervals when one
task has exclusive use of some data.
• Linux uses virtual memory.
• Linux reorders requests for efficiency (e.g., for disk I/O).
RTLinux
RT-Linux is an operating system in which a small
real-time kernel coexists with the POSIX-like Linux
kernel.
RTLinux is module oriented.
Scheduler.
The “earliest deadline first” scheduler.
Rate-monotonic scheduler.
The module that implements RT-FIFOs.
RTLinux decouples the mechanisms of the real-time
kernel from the mechanisms of the general purpose
kernel.
Each can be optimized independently.
The RT kernel can be kept small and simple.
RTLinux Features
Real-time scheduling algorithm.
Predictable delays.
By its small size and limited operations.
Finer timer resolution.
Preemptible kernel.
The RTLinux executive is itself nonpreemptible.
Its routine are very small and fast, this does not cause big delays.
Interrupts from Linux are disabled.
No virtual memory.
Scheduler
RT-Linux contains a dynamic scheduler.
UNIX-processes &
Processes Pthreads Lightweight processes
Pthreads
Priorities
(0-100) (0-1,000,000) 0x3fffFfff-0)
lower - higher
Semaphores, Mutexes,
Inter-process Semaphores, Mutexes, Condition-var., Semaphores, Mutexes,
Condition-var., FIFO, Mailbox,
communication shared-mem, signals, pipes. Condition-var., FIFO
shared-mem, net_rpc, Pqueues.
Linux, RTLinux, and RTAI (2)
Linux RTLinux RTAI
Priority inversion
None Immediate ceiling Inheritance
control
Time
Configurable (HighResTimers) Hardware dependant Hardware dependant
resolution
Timers POSIX timers None None
Low level
No interrupt programming. Full control HW Full control HW
programming
Semaphores, Mutexes,
Inter-process Semaphores, Mutexes, Condition-var., Semaphores, Mutexes,
Condition-var., FIFO, Mailbox,
communication shared-mem, signals, pipes. Condition-var., FIFO
shared-mem, net_rpc, Pqueues.
Linux, RTLinux, and RTAI (3)
API
Debug Languages
compatibility
Custom,
RTAI KGDB C
POSIX 1003.1b
Conclusions (1)
0 1 2 3 4 5 6 7 8
Rate Monotonic Scheduling Algorithm (2)
• Critical Instant
– An instant at which a request of the process have the
largest completion/response time.
– An instance at which the process is requested
simultaneously with requests of all higher priority
processes.
• Usages
– Worst-case analysis
– Fully utilization of the processor power
– Example: T1 (p1=4, c1=2) and T2 (p2=5, c2=1)
0 1 2 3 4 5 6 7 8
Rate-Monotonic Analysis
• Schedulability Test:
n(2 1) 1/ n
– A sufficient but not necessary condition.
– Achievable utilization factor αof a scheduling policy ci
P: any process set with total utilization factor P
no more than α is schedulable. i
– Given n processes,
• Stability:
– Let processes be sorted in RMi c order. The ith
process is schedulable if j i (21/ i 1)
j 1 p j
0 1 2 3 4 5 6 7 8
Earliest Deadline First Scheduling
Algorithm (2)
• Schedulability Test:
– A sufficient and necessary condition
– Any process set is schedulable by EDF iff
ci
P 1
i
• EDF is optimal for any independent process
scheduling algorithms.
• However, its implementation has considerable
overheads on OS’s with a fixed-priority scheduler
and is bad for (transiently) overloaded systems.