⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 posix.tex

📁 rtai-3.1-test3的源代码(Real-Time Application Interface )
💻 TEX
📖 第 1 页 / 共 2 页
字号:
\chapter{Posix - RTAI/fusion}% ----------------------------------------------------------------------------\section{The New POSIX Approach}In older RTAI versions POSIX compatiblity has been achieved by writing several modules which implemented the standard POSIX APIs in RTAI modules. This approach has turned out to be problematic and difficultto maintain, so a new scheme has been invented. Instead of rewriting a complete POSIX layer usable in a real-timecontext, a way has been found to move the existing user-space Linuxsupport seamlessly into the RTAI realm. This basically allows to callregular Linux syscalls synchronously from RTAI tasks running inuser-space, while keeping the scheduling priority of the callerunaffected by the domain migration.This approach offers a number of advantages:\begin{itemize}\item Conflicts (source-wise and execution-wise) between the RTAI-specificand native POSIX interfaces (Linuxthreads/NPTL) cannot occur, sincethere is no need for any RTAI-specific interface in the first place.\item Since user-space thread interfaces use kernel syscalls to performthread synchronization and other management, interface upgrades shouldhave very little impact on the RTAI POSIX support. Conversely, RTAIshould benefit from POSIX interface upgrades at low or even no cost.\item All user-space services are now automatically RTAI-enabled,i.e. real-time compatible, provided they are thread-safe in the firstplace. Obviously, this does not mean that Linux services miraculouslybecome time-bounded with this extension, but at least, they are nowcallable from any RTAI task context. It is still up to the user toevaluate the suitability of calling such code in a real-time contextthough.\end{itemize}% ----------------------------------------------------------------------------\subsection{How it works}LXRT is able to migrate user-space tasks back and forth between theLinux and RTAI domains, depending on the requested operating mode.Hard real-time mode is obtained by stealing the current task from theLinux's scheduler runqueue and readying it for the LXRTscheduler. Since the latter also reinstates the MMU-context of anyincoming task, the net result is that we have memory protected taskssolely scheduled by RTAI. After this transition, the migrated/stolentask left in \texttt{TASK\_UNINTERRUPTIBLE} state disappears from Linux's radar,just like any suspended task, assuming that some code somewhere willcare for resuming it when it's due. At this point, the RTAI schedulercan pick this task and reinstate its MMU-context when it switches itback in.Migration from Linux to RTAI needs a helper task controlled by Linux(namely, \texttt{kthread\_b}) which is resumed by RTAI, and whose job is to moveany given real-time task to RTAI's ready task queue, then trigger afast real-time rescheduling to make such task resume into the RTAIdomain immediately. The action of waking up this helper task after themigrating task has been suspended (state == \texttt{TASK\_UNINTERRUPTIBLE})conveniently ensures that the Linux runqueue correctly reflects thenew situation.The following pseudo-code example shows how it works: \begin{code}T1 runs in soft real-time mode...        T1 calls make_hard_realtime()                T1 Linux state is set TASK_UNINTERRUPTIBLE                kthread_b() kernel thread is woken upkthread_b() runs... (T1 is now out of Linux's runqueue)        kthread_b() fast schedules back T1T1 immediately resumes in hard real-time mode...\end{code}Migration from RTAI to Linux is somewhat simpler, only requiring aRTAI service request to be scheduled so that \texttt{wake\_up\_process()} iscalled on the migrating task as soon as the Linux kernel gets back incontrol.% ----------------------------------------------------------------------------\subsection{Side-effect of a soft-mode transition in LXRT}Soft-mode transition is caused by an explicit call to\texttt{make\_soft\_realtime()}, or implicitely done by LXRT when a Linux syscallis caught from a hard real-time task. LXRT also makes sure that suchtask goes back to hard real-time as soon as the Linux syscall hascompleted.The first effect of the soft-mode transition is to lower the callingtask's priority down to the Linux placeholder task(i.e. \texttt{rt\_linux\_task}), representing the idle -- non real-time fallbackcontext. This is an accepted side-effect that such lowering alsoaffects the real-time priority handling, de facto excluding the softentask from the real-time realm.% ----------------------------------------------------------------------------\section{Issues and solutions}The following issues are raised when it comes to integrate the LinuxGeneral Purpose Operating System (GPOS) kernel within the execution domain of a RTOS like RTAI:\begin{itemize}\item Linux internal design promotes fairness and throughput, at theexpense of determinism. The net effect is that many code paths in thevanilla 2.4 Linux kernel are not preemptible for serving interruptsand/or rescheduling tasks.\end{itemize}By increasing the overall preemptibility of the Linuxkernel, Montavista's "kpreempt" extension partly solves thisissue, by limiting the non-preemptible sections to thoseprotected by a spinlock, and calling the reschedulingprocedure on exit of such sections if needed. Coupling AndrewMorton's low latency patch further reduces the length of suchnon-preemptible sections.\begin{itemize}\item Fine grained Linux kernel preemptibility does not help prioritizingthe interrupt load from a real-time point of view, which means that low-prioritybottom-halves can still preempt high-priority real-time Linux tasks(SCHED\_FIFO) under this model, thus introducing unbounded latencies.\end{itemize}By implementing a technique called "interrupt shielding"using ADEOS capabilities, we can control the interrupt flowso that Linux IRQ handlers are not fired while real-timeRTAI tasks tread on Linux kernel code. This is obtained byinserting an intermediate ADEOS domain between RTAI and Linux,and stalling/unstalling this stage at the proper time. Thisway, whatever Linux actions are regarding its own interruptstate, ADEOS guarantees that the effective interrupt controlfor the GPOS kernel is left in the hands of the shieldingdomain above Linux in the pipeline.\begin{verbatim}i.e. IRQ -> [RTAI] -->-- [Shield] -->-- [Linux] (std mode)     IRQ -> [RTAI] -->-- [Shield] --/   [Linux] (rt mode)\end{verbatim}\begin{itemize}\item Interrupt shielding has one drawback: RTAI tasks which end upsuspending themselves on a Linux kernel resource waiting for a Linuxinterrupt to occur (e.g. I/O or timing wait) will be woken up onlyafter the shield is deactivated, i.e. when no other RTAI task isrunning into the Linux kernel domain. This fact is a source ofpriority inversions, since low priority RTAI tasks could preventhi-priority ones to wake up until they relinquish the processor.Additionally, Linux's periodic timer resolution is not suitable forhi-frequency real-time processing.\end{itemize}Timing syscalls (\texttt{gettimer()}/\texttt{setitimer()} and \texttt{nanosleep()}) used bythe POSIX layer are transparently intercepted by RTAI/fusion,and converted to their RTAI-based hard real-timecounterparts. This conversion has two positive effects: RTAI'stimer resolution is much higher, and timed RTAI tasksare suspended into the RTAI domain, thus cannot be shieldedfrom timer interrupts by the intermediate domain.However, RTAI tasks waiting on I/O events only handled by theLinux kernel are still subject to priority inversions. Fornow, the best way to prevent this undesirable side-effect isto have those tasks handled by RTAI I/O drivers instead ofrelying on Linux drivers, since wakeups in the RTAI domainare performed immediately by the RTAI interrupt handler.\begin{itemize}\item RTAI currently provides determinism \emph{aside} of Linux by adding apreemptive and concurrent kernel. Services requests from RTAI to Linuxthen cause the requested services to run outside the real-timeexecution domain. RTAI tasks can only send asynchronous requests(i.e. srqs) to perform Linux services which will be processed when noreal-time tasks are runnable.  Moreover, the service inherits thescheduling priority of the last Linux task which happened to have beenpreempted by RTAI. This situation currently prevents the Linux kernelcode to be part of the real-time execution domain.\end{itemize}By tracking the priority of the RTAI task running the Linuxkernel code and applying it dynamically to the Linuxplaceholder task controlled by the RTAI scheduler(i.e. rt\_linux\_task), the position of the RTAI taskwithin the real-time priority hierarchy is kept unchanged,even when it executes into the Linux domain.Additionally, the priority of the Linux task coupled to thereal-time RTAI task is set to a value preserving the overallRTAI priority scheme.  This way, we have two schedulers(i.e. RTAI and Linux) cooperating for the execution ofreal-time tasks inside a single priority scheme across bothexecution domains.Example: \begin{verbatim}RTAI domain   -- RTAI (pseudo-)task "T0" scheduled by rtai_sched        (pri = 10)Linux domain  -- Linux task "foo" (mapped to T0) scheduled by Linux        (pri = sched_getpriority_max(SCHED_FIFO) + 1 + pri(T0))\end{verbatim}\begin{itemize}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -