Professional Documents
Culture Documents
Linux
RTHAL
B
A RTAI Core
1 Terminate and stay resident. B
Hardware
On the PowerPC
The RTAI schedulers use the
architecture, the existing
facilities and abstractions
timing facility is embodied
provided by the core RTAI
by the decrementer and
module described in the
provides a mechanism akin
previous section to provide
the one-shot mode of the
high-level programming
8254 found on the PC. In
abstractions to the
actuality, the processor’s
programmer such as tasks
internal counter is used to
and various communication
generate an interrupt at a
mechanisms. There are
given time and needs to be
three schedulers that come
reprogrammed upon firing.
with RTAI: a uniprocessor
Periodic mode is therefore
(UP) scheduler, an SMP
attained on this architecture
scheduler and a Multi-
by reloading a constant
Uniprocessor (MUP)
value.
scheduler. All these
schedulers can be used
The following subsections
either in one-shot mode or
provide details about each
in periodic mode. These
scheduler available. Keep in
modes relate to the way the
mind that regardless of the
timer is programmed and
differences, the facilities
take their roots from the PC
provided by RTAI remain
architecture where the
the same and need not be
8254 timer may be
used differently from one SMP scheduler
scheduler to the next.
• rt isrpc() Determines
• rt semsignal()
whether the given task Signals a
semaphore.
is waiting for a
response to an RPC. • rt semwait() Waits on a
• rt return() Replies to an semaphore.
LXRT symmetrical
interface Communication from user
space to kernel space is
possible through a software
Of all the services and interrupt handled by LXRT.
abstractions provided by Using this software
the different RTAI modules, interrupt, user space tasks
LXRT remains the most can call on exported RTAI
flexible and the most services in very much the
complex of them all. By same way they call on
providing the programmer exported Linux system calls.
with a symmetrical Among the services
programming interface, exported to userspace using
LXRT integrates the best of LXRT, we find all the
both worlds in the hybrid services previously only
GPOS/RTOS combination. In available to loadable
effect, it provides user modules such as mailboxes,
applications with means to messages, RPCs and
communicate transparently semaphores. In actuality,
with real-time tasks and the LXRT API makes it
vice-versa. Figure 3 shows possible to render usage of
the possible communication these services to be
interactions between tasks completely transparent to
belonging to different the context. In other words,
execution domains. Note one can use the same
that tests functions and semantics in
either user space or kernel
space with the same effect.
The only difference being
2 When a task is rescheduled
the usage of a main()
before it had the time to complete
its intended job. function instead of an init
module() and cleanup GPOS/RTOS configuration
module() interfaces. This tasks could either belong to
makes it possible to one domain or the other and
effectively test real-time would be programmed
applications in user space differently depending on the
prior to inserting them as domain they belonged to.
kernel modules. However, The initial user space
note that user space services provided by LXRT
applications using LXRT to blurred this divide. The
access RTAI services are not addition of a routine
hard-real-time tasks, they enabling normal GPOS tasks
are only soft-realtime tasks. to become RTOS tasks takes
Although, as we will see in this further by providing a
the next section, they can means for normal Linux
become hard-real-time processes to become hard-
tasks using LXRT. In any real-time bound tasks
case, prior to using any through the use of the rt
other LXRT services, the make hard real time() call.
user space applications Contrary to loadable
need to instantiate a real- modules, such real-time
time shadow task which will tasks run in their own
be used to maintain isolated memory space and,
coherent data structures hence, provide for memory
within RTAI while dealing protection of real-time
with intertask tasks.
communication and
scheduling. Process stealing is done in
two steps. The first part of
With that said, LXRT is not the transition is done as
limited to the predefined set part of the call made by the
of exported services and Linux process and consists
may be extended quite of the following sequence:
easily by providing an
alternative function table
which includes the initial 1. Disable global
table while adding to it the interrupts.
extra entries required. Such
2. Set Linux process state
an extension is used by the
to TASK LXRT OWNED.
RT COM module to provide
real-time com port 3. Raise the priority of the
communication to tasks idle task (this is
through LXRT. necessary for the
second part of the
transition).
Stealing tasks from
4. Enqueue the function
Linux dealing with the
secondstep as part of
the normal Linux
It was originally thought
that with the hybrid
IMMEDIATE tasks to return to soft-real-time,
queue. as a normal Linux process,
using the inverse of the
5. Mark the IMMEDIATE above steps.
bottom half to run.
7. Enable global
interrupts. Given the memory
protection possible with the
8. Reset idle task to its process stealing method
original priority. and the growing need to full
(and fool) proof real-time
programming, it becomes
After this first step, the
useful to implement
Linux process is in a state of
exception handling to
limbo and will remain in
enforce protection policies
this state until the second
and provide for other
part of the stealing process
capabilities such as
is carried out. This second
debugging. For this purpose,
part will come to run within
LXRT now handles
the standard bottom-half
processor exceptions. As
framework in Linux and
RTAI is the first to receive
consists of the following:
processor exceptions, it
provides for identifying the
1. Disable global current execution context
interrupts and passes exceptions onto
the Linux exceptions
2. Set the real-time task’s handlers whenever
state as READY necessary.
3. Run the LXRT
scheduler
QNX-like services
4. Enable global
interrupts
As some RTOSes have been
widely used and adopted for
The LXRT scheduler will different uses, it is desirable
take the necessary steps to to being able to use the
insure that the task runs in same functionalities on
a consistent memory open realtime kernels. Such
configuration and will is the case with the the
interact with the other RTAI synchronous IPC services
modules to provide for provided in LXRT akin
scheduling of the task as if it similar QNX services. This
were yet another RTAI task. service enables tasks to
communicate together
Just as it was possible to synchronously using name
transition into hard- schemes to locate
realtime space, it is possible
recipients. In addition to • rt Proxy attach()
synchronous
Attaches a proxy to a
communication, this facility
also adds raw proxies given task.
functionality. Proxies are
real-time tasks which can • rt Proxy detach()
send a predefined message
Detaches the proxy of a
to a waiting task and hence
trigger a certain behavior. given task.
Proxies may be used within
interrupt handlers to signal • rt Trigger() Triggers
a certain event to a waiting the action of a proxy.
task; provided that the
trigger is the last action
taken by the handler.
Unix Server
The following is a sample of
the services provided by As real-time tasks do not
this facility: have access to standard
Linux services many ways
• rt Name attach()
have been provided to
Attaches a name to the circumvent this limitation,
the unix server capability
current task. from LXRT is one of them.
• rt Name locate() By starting a unix server
prior to entering hard-real-
Locates a task time mode, a Linux
processor can have access
identifying itself with
to some of the most
the given name. commonly used Linux
services. Starting a unix
• rt Name detach() server is done through the
rt start unix server() call. In
Detaches a name from
effect, starting a unix server
a given task. forks the current process to
execute an agent who will
• rt Send() Send a be in charge of the non-
message to a task and deterministic
communication with Linux.
wait for an answer. Exchanges between the
agent and the real-time
• rt Receive() Receives a
tasks are done via a shared
message from a given memory region to minimize
overhead.
task.
The following services are
• rt Reply() Reply to a
provided by the unix server:
received message.
• rt scanf()
• rt printf() • aio open()
• rt close()
• aio return()
• rt write()
• aio cancel()
• rt read()
• aio fsync()
• rt select()
Paolo Montegazza
Stuart Hughes
Lorenzo Dozio
Trevor Wolven
Giuseppe Renoldi
Tomasz Motylewski
Pierre Cloutier
Steve Papacharalambous
David Schleef
Ian Soanes
Emanuele Bianchi
Brendan Knox
Erwin Rol
Karim Yaghmour
References
http://www.aero.polimi.it/
projects/rtai/