📄 posix.tex
字号:
\item When migrating tasks from the RTAI execution domain to the Linuxdomain, a time-critical transition must occur, during which RTAIdelegates the control of this task to the Linux scheduler. This phasemust be fast and perfectly synchronized, to guarantee a safereentrancy into the Linux kernel code. Additionally, since the onlysafe transition point is the Linux rescheduling procedure, the delayincurred to reach the next rescheduling point inside any preemptibleportion of the Linux kernel must be bounded and as short as possible.\end{itemize}Transitions from RTAI to Linux are obtained by sending avirtual ADEOS interrupt from the RTAI domain to the Linuxdomain. The interrupt handler into the Linux kernel wakes upthe process as requested.If the Linux kernel code was last preempted by RTAI outsideof a critical section, a Linux rescheduling takes placeimmediately on the return path of the virtualinterrupt. Otherwise, the preemptible kernel will ensure thata rescheduling takes place as soon as the critical section isexited. With the additional benefit of the low latency patch,those sections are kept as short as possible, enforcinglock-breaking preemption points as needed.% ----------------------------------------------------------------------------\section{Practical Assumptions, Limits and Guarantees}The new scheme has some practical assumptions and limits: \begin{itemize}\item A vast majority of RTAI-based applications in user-space would relyon POSIX services mainly for thread synchronization and hi-resolutiontiming. Thread synchronization services would only pay the additionalcost of RTAI/Linux migrations - needed to re-enter the Linux kernelfrom a RTAI task for performing the system call - when the access tosome resource is effectively contended by more than a single POSIXthread. Provided this cost is at most a handful of microseconds, it isassumed that the advantages of RTAI-enabling the Linux system callsinstead of rewriting specific APIs outweight this single drawback,especially since most of the Linux syscalls issued for synchronizationby the native POSIX layer tend to put the caller to sleep. In anycase, very time-critical services could still be substituted with amere RTAI add-on if needed.\item "In the POSIX interface we trust". IOW, it is assumed that thestandard POSIX interface used to program the real-time applications isefficient as far as thread concurrency is concerned. As a consequenceof this, and aside of the kernel time consumed in executing syscallsfor its threads, rewriting another dedicated RTAI-specific interfaceshould not be significantly more efficient performance-wise.\item "In the Linux kernel we trust". IOW, the syscalls internally used bythe standard POSIX interface for common operations are assumed to beefficiently written and would not charge unacceptable CPU cost to anyapplication which currently targets user-space real-time support. Thepreemptible and low latency kernel patches are expected to provide forlimited and bounded \_scheduling\_ latencies inside the Linux kernel.\item Running a RTAI task into the Linux domain with an effectivereal-time priority must not impact on the preemptability inside theRTAI domain. The following assertions remain true at any point intime: \begin{itemize} \item Adeos's pipelined interrupt model ensures that any unmasked interrupt is immediately dispatched to the RTAI domain if unstalled, regardless of the currently running domain (RTAI, shielding domain or Linux). \item Interrupt shielding ensures that Linux targeted interrupts are not propagated to the Linux handlers when a real-time task executes into the Linux kernel. \end{itemize}\item The Linux kernel provides for a \texttt{SCHED\_FIFO} scheduling policyenforcing static real-time priorities among the tasks itcontrols. This is especially important as Linux's scheduling decisionsmust not break the RTAI priority hierarchy when real-time tasks areoperating into the Linux domain.\end{itemize}RTAI/fusion will be adapted for running on the Linux 2.6 kernel inthe future, but as of now, please put on your 2.4 glasses when readingthis document.% ----------------------------------------------------------------------------\section{Implementation}\subsection{Current Implementation}RTAI/fusion is built upon the implementation of a mutable priorityscheme for the Linux placeholder task. As a remainder, thispseudo-task currently represents all the non real-time Linux tasks,and acts as a common fallback schedulable object to pick when noreal-time RTAI tasks are ready to run.The test code is built upon the Xenomai nucleus. Xenomai provides thescheduling of kernel-based and user-space threads, using a technologyderived from LXRT, and incorporating the implementation details listedbelow (see 7). This nucleus includes a real-time, FIFO-based, staticpriority scheduler.Like LXRT, the Xenomai scheduler defines a Linux placeholder calledthe "root" thread which gets scheduled as a fallback option when noother Xenomai threads are runnable into the RTAI domain. This causesthe RTAI domain to suspend itself Adeos-wise, yielding control to thenext domain down the pipeline.Each Xenomai thread capable of executing in user-space has onekernel-based TCB called a "shadow", along with its standardLinux-controlled task structure. Real-time scheduling of shadowthreads is done using those TCBs, but the register state isexclusively saved into the Linux task structures by both Linux andXenomai schedulers during context switching. In Xenomai's terminology,a shadow thread is the real-time control block of a Linux task alsoschedulable by Xenomai. Both schedulers control the task in a mutuallyexclusive manner.The priority of the root thread is mutable, and can be changeddynamically to reflect the position of the Linux kernel activitywithin the real-time priority hierarchy.A Linux-controlled gatekeeper task is in charge of resuming a Xenomaithread migrating from Linux to the RTAI domain. This thread is theequivalent of LXRT's kthread\_b() helper task.Mutable priority works like this:In a system defining T1(prio=1,domain=RTAI), T2(prio=2,domain=RTAI),and ROOT(prio=0,domain=Linux), we would have the following transition:\begin{code}T2 runs in domain RTAI... T2 migrates to the Linux domain (for executing a syscall) ROOT inherits priority(T2) T2 executes the syscall on behalf of ROOT (at this point, interrupts are no more propagated to the Linux kernel) T2 migrates back to the RTAI domain (after the syscall completes) T2 resumes into the RTAI domain ROOT priority is lowered back (to 0 if no other real-time threads are runnable into the Linux domain, or inherited from the next real-time thread to execute in this domain). As soon as the root thread recovers its base priority (0), the interrupt flow is restarted toward the Linux kernel.T2 suspends...T1 resumes...\end{code}As shown, T2 migration would not cause the preemption of the rootthread by T1 despite its lower initial priority, since ROOT's prioritywould not allow it after it has been dynamically raised.In practice, T2 would not be forced to exit the Linux domain rightafter the syscall completes, but only when it issues a RTAIsyscall. The migration back to RTAI has been described forillustration purposes.Obviously, ROOT never migrates to RTAI, and is always runnable.% ----------------------------------------------------------------------------\subsection{Implementation details with regard to priority mutation}When informed by Adeos that a new Linux task is about to be switchedin (ADEOS\_SCHEDULE\_HEAD event), we check in the event handler whethera shadow thread is paired with the incoming task. In such a case, theroot thread priority is raised to the priority of the shadow,otherwise, this priority is set to the "idle" priority level(i.e. non-realtime priority).In the RTAI code controlling the migration of the current threadfrom RTAI to the Linux domain, the priority of the root thread isinherited from the migrating thread.In the RTAI code controlling the migration from the current Xenomaithread from Linux to the RTAI domain, the priority of the gatekeeperthread is inherited from the migrating thread.\section{Hardware/Software pre-requisites}The experimental RTAI/fusion subsystem currently runs on the followingconfiguration:\begin{itemize}\item Linux 2.4.21/ia32\item ADEOS combo patch (Adeos + Kpreempt + Lolat)\item Xenomai nucleus from the RTAI vesuvio branch.\end{itemize}A simple demo is available for download here:\centerline{http://savannah.gnu.org/download/xenomai/fusion/}% ----------------------------------------------------------------------------\section{Programming with POSIX API}\subsection{Threads}\subsection{...}\subsection{API Reference}\section{Interprocess Communication}\subsection{Overview}\subsection{Mutexes}\subsection{Conditional Variables}\subsection{Queues}\subsection{API Reference}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -