Details of ART-Linux
Summary page of ART-Linux
Overview
- Motivation
- Points Lacking in currently available Real-Time operating
Systems
- Characteristics and Usage of ART-Linux
- Real-Time methodology of ART-Linux
- Stablization from SMP Kernel Extentions
- Performance measuremnt
Motivation: Example of a large scale Real-Time System - Robot
Software
Development of a General Purpose Real-Time Operating System
A large scale Real-Time Operating System should be:
- Capable of executing hard Real-Time tasks
- Capable of executing general tasks for development
- Can use off the shelf hardware/software as components
- Exists abundance of hardware/software components
Both are IMPORTANT
Possible approaches include:
- Extend a general purpose operating system for hard Real-Time use.
- Extend a Real-Time operating system for general purpose use.
Former approach requires less code
Development of a General Purpose Real-Time Operating System - Why
Linux?
Conditions:
- Numerous readily available applications
- Support for different types of devices
- Open Source
- Release under a free license
Decision: Use Linux as the base general purpose operating system
- ART-Linux
- Extended Linux to include Hard Real-Time scheduling capabilities
based on priority inheritance
Comparison with Other Real-Time Operating Systems
- VxWorks
- No memory protection
- Operating System can crash due to bug in application
- LynxOS
- Few device drivers available for hardware
- Requires writing device drivers using Kernel Threads which
are a special feature of this Operating System. Makes
writing device drivers difficult.
Lacking Features in readily available Hard Real-Time Linux
Kernels
Kernels with technically sufficient hard Real-Time performance
Both require specialised Real-Time capable device drivers
Both have restricted priority inheritance which can cause trouble when
designing large Real-Time Processing Systems
Characteristics of RT-Linux
- Task Scheduling using fixed priority
- Non Real-Time parts of the kernel are executed as if they have
the lowest priority
- Simulation of Hardware Interrupt Handling using the Real-Time
Kernel
- Inter-Process/Task communication using RT-FIFO's
Points Lacking in RT-Linux
- Real-Time tasks do not have memory protection
- Real-Time tasks are linked to the kernel so software bugs
can cause the Kernel to crash
- Nothing mechanism to check whether any priority inversion has
occured
- Non Real-Time task can be run before a Real-Time task
Characteristics of ART-Linux
- Hard Real-Time Scheduling
- Memory protection for Real-Time tasks
- Real-Time tasks can co-exist with non Real-Time tasks
- Multiple levels of priority inheritance
- Binary compatibility for applications
- Source compatibility for Device Drivers
New System Calls
- int art_enter(art_prio_t prio, art_flags_t flags, int usec)
- Enable real-time for process
- int art_wait(void)
- Sleep until next execution period arrives
- int art_exit(void)
- Relinquish real-time capabilities
- int art_wait_phase(unsigned long usec, art_prio_t prio)
- Wait for specified amount of time
- int art_yield(void)
- Yield from real-time state
Sample Program
#include <stdio.h>
#include <stdlib.h>
#include <sys/io.h>
#include <linux/art_task.h>
#define TRUE 1
#define KBD_PORT 0x61
#define SPK_BIT 0x02
main(int argc, char *argv[])
{
int temp, hz, i;
hz = atoi(argv[1]);
ioperm(KBD_PORT, 1, TRUE);
art_enter(ART_PRIO_MAX, ART_TASK_PERIODIC, 500000 / hz);
for (i = 0; i < hz * 5; ++i) {
art_wait();
temp = inb(KBD_PORT);
temp = (i & 1) ? temp | SPK_BIT : temp & ~SPK_BIT;
outb(temp, KBD_PORT);
}
art_exit();
}
Sample Program
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <linux/art_task.h>
int main(int argc, char *argv[])
{
art_prio_t prio;
if (argc < 3 || (prio = atoi(argv[1])) < ART_PRIO_MIN ||
prio > ART_PRIO_MAX) {
fprintf(stderr, "usage: %s prio file arg .../n", argv[0]);
return -1;
}
if (art_enter(prio, ART_TASK_RR, 0) == -1) {
perror("art_enter");
return -1;
}
if (execvp(argv[2], &argv[2]) == -1) {
perror("execvp");
return -1;
}
return 0;
}
Problems adding Real-Time capabilities to the Linux Kernel, and
their Solutions
- No fixed priority scheduling capabilities
- Implemented a Real-Time Scheduler
- Long periods of non-preemptive activity
- Interrupt Handler, Kernel Lock Waits re-implemented as
Real-Time locks
- No Reversed Priority Checking
- Implemented Real-Time locks with priority inheritance
- Inter-process synchronization implemented using Real-Time
locks
- Impossible to predict amount of time required to handle hardware
interrupt
- Interrupt handler re-implemented as a periodic Real-Time
task
Method Used for adding Real-Time Capabilities
- Interrupt Handler implemented as periodic task
- Non-Realtime processes inherit their priority from parent
processes
- Hardware Interrupts management emulated using real-time locks
- Inter-process synchronization primitives emulated using
real-time locks
Interrupt Handler as Periodic Task
- Hardware interrupt handler is executed as a periodic real-time
task
- Latency increase for interrupts
- Are interrupts appropriate for real-time?
- Real-time tasks and Interrupt handling conflict each other
- Periodic interrupt handling could be thought of as an
alternative
- Can devices be controlled properly?
- Higher functionality of surrounding IC chips no longer
require immediate handling of hardware interrupts
Real-time Locking Methods
- Locks are linked to the tasks that are blocking them
- These tasks are sorted according to their priority
- When a lock is disengaged the higher priority task gets woken
first
Priority Inheritance in Real-Time Locks
- Tasks are linked to the lock that are blocking them
- Locks are linked to the task which is locking them
- Both tasks and locks have priority levels
- Priority levels are inherited along these links
- If the inherited priority level is higher than the current
priority level, the priority level is changed
Hardware Interrupt Management Emulated Through Real-Time Locks
- Real-time Lock to manage Hardware Interrupts art_lock_t
interrupt_lock
- Interrupt Mask Macro cli() is replaced with a lock
function art_lock(&interrupt_lock)
- Interrupt Unmask Macro sti() is replaced with an unlock
function art_unlock(&interrupt_lock)
Emulation of process synchronization primitives through Real-time
Locks
Inter-process Synchronization Primitives Emulated using Real-Time
Locks
Adaptation of Linux Kernel 2.2(2.4)
- Shortcomings of kernel 2.0 adaptation
- To prevent real-time performance degradation, preempts occur
within non-preempt locations
- This is okay in most areas
- A lot of debugging is required to stablise code
- Characteristics of kernel 2.2(2.4) adaptation
- System calls can now be preempted due to efficient SMP
implementation
- Protection of the critical section using spin locks
- Reliable real-time performance just by replacing the spin
locks with real-time locks
- No support for real-time processing on SMP
SMP implementation on Linux kernel 2.0.x
SMP implementation on Linux kernel 2.2.x (2.4.x)
Real-time processing using SMP capabilities
Performance Measurement
- Periodic tasks at 100, 200, 500, 1k, 2k, 5k, 10k, 20k, 50k,
100kHz
- Intervals measured using the Time Stamp Counter within processor
- 10000 samples are taken and averaged while storing maximum and
minimum values
Pentium !!! 600EB
Pentium !!! 800EB
Pentium !!! 1000
Pentium !!! 600EB (dhrystone)
Pentium !!! 800EB (dhrystone)
Pentium !!! 1000 (dhrystone)
Pentium !!! 600EB (copy)
Pentium !!! 800EB (copy)
Pentium !!! 1000 (copy)
To Summarise
- We showed how a real-time operating system which can run
available software was required
- We showed the requirements of a real-time operating system
- We showed how readily available real-time operating systems were
lacking in functionality
- We showed how ART-Linux allowed for binary compatibility in
applications and source level compatibility for device drivers
- Methods used to add real-time capabilities in ART-Linux
- It has decent real-time capabilities
Case with Priority Inversion
Til t=T1
| Process 1 which has the highes priority is executed
|
---|
At t=T1
| Process 1 has to wait for the result from Process 3
|
---|
From t=T1 to t=T2
| Process 2 which has the next highest priority is run
|
---|
At t=T2
| Process 2 finishes
|
---|
From t=T2 to t=T3
| Process 3 is executed
|
---|
From t=T3 on
| Process 1 is executed
|
---|
Scheduling with Priority Inheritance
Til t=T1
| Highest priority process is run
|
---|
At t=T1
| Process 1 waits for results of Process 3
|
---|
| Priority of Process 1 is inherited by Process 3
|
---|
From t=T1 to T2
| Process 3 is run
|
---|
At t=T2
| Process 3 ends
|
---|
From t=T2 on
| Process 1 is run
|
---|
Embedded Linux and Real-Time Linux
- Embedded Linux
Linux that runs on computer systems with low system resources
- Minimumization of Kernel: Deletion of unnecessary drivers
and features
- Minimumization of File System: Removal of unnecessary
commands
- Removal of external memory: Use NFS
- Real-Time Linux
- Kernel with Real-Time capabilities
- Tool to develop applications
Both provide different features and capabilities. Some systems require
features from both types