real time linux

22
Real Time Linux Real Time Linux B.Gustafsson European Southern Observatory ESO Feb 5 2004 ESO

Upload: nola

Post on 16-Jan-2016

67 views

Category:

Documents


0 download

DESCRIPTION

Real Time Linux. B.Gustafsson European Southern Observatory. ESO Feb 5 2004. ESO. Why Real Time Linux. Investigate the possibility to replace VxWorks on LCU Expensive (licensed) Bad support Present version (Tornado 2.0.2/VxWorks 5.4) has old compiler (gcc 2.7.2, C++ egcs 1.0) - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Real Time Linux

Real Time LinuxReal Time Linux

B.GustafssonEuropean Southern Observatory

ESO Feb 5 2004 ESO

Page 2: Real Time Linux

B.Gustafsson ESO, 5 Feb 2004 Real Time Linux 2

ALMA Project

Why Real Time Linux

• Investigate the possibility to replace VxWorks on LCU– Expensive (licensed)– Bad support– Present version (Tornado 2.0.2/VxWorks 5.4)

has old compiler (gcc 2.7.2, C++ egcs 1.0)• No namespace, limited STL support• TAO not supporting native exceptions

– Tornado 2.2 has gcc 2.96

Page 3: Real Time Linux

B.Gustafsson ESO, 5 Feb 2004 Real Time Linux 3

ALMA Project

Plan

• 3 Phases– Phase 1, feasibility study, finished end of July 2002, report

available– Phase 2, implementation, finished August 2003– Phase 3, test, was performed Oct 2003

• Implementation is finished. First target CPU Motorola MV2700 (PowerPC), but switched to VMIC 7766, Intel CPU

• Linux and RTAI installed, ACS working• Drivers for CAN, VME and parallel I/O done• Booting over network• CAN device software and mount control done

Page 4: Real Time Linux

B.Gustafsson ESO, 5 Feb 2004 Real Time Linux 4

ALMA Project

Real Time: Introduction

• Real-time systems are concerned with when things happen as well as what happens. A real-time program must not only produce a correct answer, it must do so "on time." A late answer is a wrong answer.

• Real-time systems can be further characterized as either "soft" real-time or "hard" real-time.

• A hard real-time system absolutely must meet its scheduling deadline every time. Failure to meet the deadline may have catastrophic consequences, including loss of life.

A fly-by-wire aircraft control system is an example of hard real-time. The control algorithms depend on regular sampling intervals. If sampling is delayed, the algorithm can become unstable.

• A soft real-time system may cause cosmetic or annoying disturbances, but in general it will be more tolerant of missed deadlines.

A video playback system may not look good when missing deadlines, but it should not cause serious damage to a process.

Page 5: Real Time Linux

B.Gustafsson ESO, 5 Feb 2004 Real Time Linux 5

ALMA Project

Is Linux Real-Time ?

• For these several reasons, standard Linux isn't capable of a real-time response:

• Coarse-grained synchronization. • Paging. • The scheduler tries to be "fair." • Linux reorders requests from multiple processes to

make it more efficient. • Linux will perform "batch" or "queued" operations

to make more efficient use of hardware. • Kernel not interruptable

Page 6: Real Time Linux

B.Gustafsson ESO, 5 Feb 2004 Real Time Linux 6

ALMA Project

Real Time Linux

• Two hard real time linux, RTAI and RTLinux

• RTAI selected

• RTAI – tweaks the Linux interrupt– Installs its own scheduler– Linux is just another task with low priority

Page 7: Real Time Linux

B.Gustafsson ESO, 5 Feb 2004 Real Time Linux 7

ALMA Project

The RTAI solution

• Whenever Linux tries to disable interrupts, the real-time kernel intercepts the request, records it. and returns to Linux.

• But, it does not disable interrupts! • When a hardware interrupt occurs, the real-time kernel

first determines where it is directed: • Real-Time Task. Then schedule the task. • Linux. Check the software interrupt flag:

– If enabled, invoke the appropriate Linux interrupt handler. – If disabled, note that the interrupt occurred, and deliver it when

Linux re-enables interrupts.

Page 8: Real Time Linux

B.Gustafsson ESO, 5 Feb 2004 Real Time Linux 8

ALMA Project

Real Time Interrupts

• When Real Time services are enabled the interrupt dispatch table is replaced by a "Real Time IDT " table.

• With the Real Time system in place the mechanism for disabling and enabling interrupts no longer prevent interrupt processing. Linux locks do not prevent the Real Time Scheduler running. Interrupts are now divided into two classes.

• Real Time interrupts • Linux Interrupts • The status of Linux Interrupts is now held in an interrupt pending register. A

Linux interrupt will be acknowledged and the pending bit set. If the system is running in a Linux context the Interrupt will be serviced as normal. If the system is running in a Real Time Context the Linux interrupt will be serviced when the system returns to normal Linux (after completing all real time tasks).

• Normal Linux Interrupts cannot preempt Real Time Linux. • Real Time Linux can preempt normal Linux and other Real Time Linux tasks

of lower priority

Page 9: Real Time Linux

B.Gustafsson ESO, 5 Feb 2004 Real Time Linux 9

ALMA Project

Kernel Modules

• RTAI processes run as kernel modules

• Kernel modules are effectively an extension to the kernel that can be introduced into a running system

Page 10: Real Time Linux

B.Gustafsson ESO, 5 Feb 2004 Real Time Linux 10

ALMA Project

Kernel Modules

• As extensions of the kernel, modules execute at Privilege Level 0 and have access to the kernel's symbol table.

• A module can execute privileged instructions such as I/O. • A module can call any global kernel function. • A failure in a module can easily bring down the entire

system. • A module that fails to install cannot be removed. • There's no protection against anything at Privilege Level 0.

Page 11: Real Time Linux

B.Gustafsson ESO, 5 Feb 2004 Real Time Linux 11

ALMA Project

Real Time Scheduler

• RTAI gives the user a real time scheduler. When triggered from a timer interrupt the Real Time task can be scheduled in a Real Time context if required. NO matter what regular linux is doing.

• Spinlocks and interrupt masks are no longer honored within the Real Time context. Special Real Time components replace the normal linux components.

• The basic scheduler is priority based. Other scheduling options are available and, in fact, it is easy to add your own options.

• Zero is the highest priority and some very large number is the lowest. The lowest is reserved for Linux.

Page 12: Real Time Linux

B.Gustafsson ESO, 5 Feb 2004 Real Time Linux 12

ALMA Project

The Real Time Timer

• The core of RTAI lies in its use of the system timer.

• Normally (under Linux) set to interrupt at a 10 milliSecond interval The timer is modified in two ways. – Its period can be adjusted

– It is served by a real time interrupt handler.

• When RTAI is "mounted" the timer comes under Real Time Control

Page 13: Real Time Linux

B.Gustafsson ESO, 5 Feb 2004 Real Time Linux 13

ALMA Project

Managing the timer

• RTAI manages the timer in two distinct ways. – Periodic – Absolute or "one-shot"

• In Periodic mode the timer is set to interrupt at a fixed, non varying, period. There are no updates to the timer from the scheduler. Periodic mode is available to reduce the significant overhead required to program the timer registers.

• In One-shot mode the timer is reprogrammed every time the scheduler is called. There is an overhead involved but better time resolution and more adaptable scheduling

Page 14: Real Time Linux

B.Gustafsson ESO, 5 Feb 2004 Real Time Linux 14

ALMA Project

Real Time Communications

• Fifos

• Message Queues

• RPC processes

• Shared Memory

• Fifos and shared memory can be used for communication with user space (Linux)

Page 15: Real Time Linux

B.Gustafsson ESO, 5 Feb 2004 Real Time Linux 15

ALMA Project

Other system calls

• Suspend/resume

• Semaphores

• Sleep

• Get time

• Set priority

Page 16: Real Time Linux

B.Gustafsson ESO, 5 Feb 2004 Real Time Linux 16

ALMA Project

RTAI pros and cons

• Very good real time response

• All resources avalaible

• Debugging difficult

• No Linux system calls available

• Limited set of system calls

Page 17: Real Time Linux

B.Gustafsson ESO, 5 Feb 2004 Real Time Linux 17

ALMA Project

RTAI Example

User Process

X-Window SystemLinux Kernel RT-Process

RT-FIFO

RT-FIFO

Display Disk Network Peripheral Device

Page 18: Real Time Linux

B.Gustafsson ESO, 5 Feb 2004 Real Time Linux 18

ALMA Project

RTAI in User space

• LXRT (Linux - Real Time ) arose from a desire to make the rich API provided for RTAI kernel modules available to user space tasks. The ease with applications could be crafted using the Kernel API was contrasted with the limited options available within standard user space Linux.

• In particular task timing and messaging could be considered to be more advanced and easier to use within the RTAI kernel modules.

• As a result a large section of the kernel RTAI API became available to regular users.

Page 19: Real Time Linux

B.Gustafsson ESO, 5 Feb 2004 Real Time Linux 19

ALMA Project

Soft and hard real time

• There are two modes of working with LXRT. Soft real-time allows the user to use the RTAI API but the task is scheduled under the regular linux scheduler. This means that normal linux system calls can be used alongside the additional RTAI calls. The task will make use of the RTAI API but will not execute as a real time task. Hard real-time allows a special lxrt scheduler to steal the task from the normal linux scheduler. This then runs the task in a real time context. Normal Linux System calls are not allowed and the task must have its working space locked in memory.

Page 20: Real Time Linux

B.Gustafsson ESO, 5 Feb 2004 Real Time Linux 20

ALMA Project

Our approach

• Run ACS under Linux

• Only put a small part under RTAI

Page 21: Real Time Linux

B.Gustafsson ESO, 5 Feb 2004 Real Time Linux 21

ALMA Project

TICS ABM LCU

ticsAntMount

ticsBgLoop

ticsFgLoop

ticsAntVa

CANManager

CAN Driver

CAN I/O board

LCUClock

Dig. I/O Driver

Dig. I/O board

Client

Clock PulseCAN bus

Page 22: Real Time Linux

B.Gustafsson ESO, 5 Feb 2004 Real Time Linux 22

ALMA Project

Useful links

• http://www.aero.polimi.it/~rtai/

• http://www.realtimelinuxfoundation.org/

• http://fsmlabs.com/community/