xenomai-GNU/Linux上的RTOS模拟架构实现

Posted sung_june

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了xenomai-GNU/Linux上的RTOS模拟架构实现相关的知识,希望对你有一定的参考价值。

Xenomai - Implementing aRTOS emulation

framework on GNU/Linux

xenomai-GNU/Linux上的RTOS模拟架构实现

PhilippeGerum

FirstEdition

Copyright? 2004

Copyright ? 2002Philippe Gerum

Permission is granted to copy, distribute and/or modify thisdocument under the terms of the GNU Free Documentation License, Version 1.2 orany later version published by the Free Software Foundation; with no InvariantSections, no FrontCover Texts, and no Back-Cover Texts. A copy of the licenseis published on gnu.org: "GNU FreeDocumentation License" [http://www.gnu.org/licenses/fdl.html].

April2004

Abstract

Generally speaking, the Xenomai technology first aims at helpingapplication designers relying on traditional RTOS to move as smoothly aspossible to a GNU/ Linux-based execution environment, without having to rewritetheir application entirely.

This paper discusses the motivations for proposing this framework,the general observations concerning the traditional RTOS directing thistechnology, and some in-depth details about its implementation.

The Xenomai project has been launched in August 2001. It has mergedin 2003 with theRTAI project[http://www.gna.org/projects/rtai/]to produce an industrialgrade real-time Free Software platform for GNU/Linuxcalled RTAI/fusion, on top of Xenomai‘s abstract RTOS core. Eventually, theRTAI/fusion effort became independent from RTAI in 2005 as thexenomai project [http://www.gna.org/projects/xenomai/].

Linux is a registered trademark ofLinus Torvalds. Other trademarks cited in this paper are the property of theirrespective owner.


Table of Contents

1.  White paper.................................................................................................2

1.1.  Introduction.......................................................................................2

1.2.  Porting traditional RTOS-basedapplications to GNU/Linux ........................ 3

1.3.  A common emulation framework.......................................................... 7

1.4.  Nucleus description........................................................................... 10

1 . White paper

1.1 . Introduction

A simpler migration path from traditionalRTOS to GNU/Linux can favour a wider acceptance of the latter as a real-timeembedded platform. Providing emulators to mimic the traditional RTOS APIs isone of the initiative the free software community can take to fill the gapbetween the very fragmented traditional RTOS world and the GNU/Linux world, inorder for the application designers relying on traditional RTOS to move assmoothly as possible to the GNU/

把传统的RTOS移植到GNU/Linux,使linux成为一个实时嵌入式系统,是被广泛接受的。它提供了类传统的RTOS接口,本身这就是自由软件组织推崇的精神所在,这消除了各个分类的传统RTOS和LINUX世界之间的隔阂,为了那些在传统RTOS世界里工作的应用设计者提供了一种平滑过渡的方式。

There is a lack of common softwareframework for developing these emulators, whereas the behavioural similaritiesbetween the traditional RTOS are obvious.

在开发这些模拟接口的是缺乏一个通用的软件架构,然后传统的RTOS之间的行为的相似性是显然的存在的。(译者注:行为相似性,即读、写、调度上的实现原理差不多,不过是代码差异而已

The Xenomai technology aims at fulfillingthis gap, by providing a consistent architecture neutral and generic emulationlayer taking advantage of these similarities. It is also committed to providean increasing set of traditional RTOS emulators built on top of this layer.

Xenomai志在消除这种隔阂,通过提供一致性的架构中间层和一般性的模拟接口层,有效利用了这种相似性。建立在中间层之上的,当然也需要提供一种持续增长的传统RTOS仿真者的接口集合。

Xenomai relies on the common features andbehaviours found between many embedded traditional RTOS, especially from thethread scheduling and synchronization standpoints. These similarities areexploited to implement a nucleus exporting a set of generic services. Theseservices grouped in a high-level interface can be used in turn to implementemulation modules of real-time application programming interfaces, which mimicthe corresponding real-time kernel APIs.

Xenomai依赖于发现不同RTOS之间的共性,尤其从线程调度和同步方面。通过利用这种相似性构建出一个微内核输出一系列的一般服务接口。在更高水平的接口可以利用这些服务,反过来即实现了实时的应用的编程接口的模拟实现,即最小化相应的实时内核API。

A similar approach was used for the CarbonKernel [http://savannah.gnu.org/projects/carbonkernel/] project [1]in the simulation field, in which RTOS simulation models are built on top of ageneric virtual RTOS based on event-driven techniques.

1.2 . Porting traditional RTOS-based applications toGNU/Linux(移植)

The idea of using GNU/Linux as an embeddedsystem with real-time capabilities is not novel. The reader can refer to JerryEpplin‘s article in the October 97 issue of Embedded Systems Programming for adiscussion about GNU/Linux potential in the embedded field [2].

把GNU/Linux当做一个嵌入式实时系统不是天方夜谭。读者可以参考JerryEpplin的97年10月份发表的关于GNU/Linux在嵌入式领域的嵌入式系统编程的讨论。

Throughout this document, we will use theexpression source RTOS to indicatethe traditional real-time operating from which the application is to be ported,andtarget OS to indicate GNU/Linuxor any other free operating system to which the application could be ported.

1.2.1 . Limited high-level code modification(有限的高层代码修改)

Keeping the initial design andimplementation of a hard real-time application when attempting to port it toanother architecture is obviously of the greatest interest.Reliability andperformance may have been obtained after a long, complex and costly engineeringprocess,one does not want to compromise. Consequently, the best situation is to have the closest possibleequivalence between the source and destination RTOS programming interfaces, asfar as both the syntax and the semantics are concerned.

移植RTOS到其他架构代码中最感兴趣的部分,必然是保持初始化的设计和硬实时应用的实现。可靠性和运行性能需要经历一个长期、复杂和消耗的工程设计过程才能得出结果,当然这部分可能不想去妥协。因此,最好的情形,在源与目的的RTOS变成接口间建立最可能的等同性,尽量把语法和语义考虑在内。

An illustration of this can be taken fromthe support of a priority inheritance protocol [3]  by the mutual exclusion services. Theseservices allow concurrent threads to protect themselves from race conditionsthat could occur into critical sections of code. The purpose of this discussionis not to argue whether relying on priority inheritance for resolving priorityinversion problems is a major design flaw or a necessary safety belt for areal-time application, but only to emphasize that any cases, if this feature isused in the source RTOS, but not available from the target OS, the resourcemanagement strategy must be reevaluated for the application, since priorityinversion risks will exists.

这部分的解释,可参考互斥服务中的优先级继承的实现支持。服务允许当前线程保护自己的临界代码部分不受其他部分的干扰。当然这个讨论的重点不是说是否依赖于优先级继承来解决优先级反转,而是一个在实时应用系统的一个主流的设计和必须的安全保护。但仅仅强调的任意情况下,如果这种特性被用在源RTOS,而没有在目标OS中存在,那么源OS的管理策略必须根据应用被重新评估,尽管优先级的反转的危险仍然存在。

1.2.2 . RTOS behavioural compatibility

During the past years, major embedded RTOS,such as VRTX, VxWorks, pSOS+ and a few others, have implemented a real-timekernel behaviour which has become a defacto standard, notably for threadscheduling, inter-thread synchronization, and asynchronous event management. Toillustrate this, let us talk about a specific concern in the interrupt servicemanagement.

在过去一段时间,主流的RTOS,比如VRTX,VxWorks,pSOS+等,已经实现了实时内核的行为标准,主要体现在线程调度,内部线程同步,和事件的异步管理。为了说明这个问题,我们可以先就中断服务管理中断管理中的担忧来具体说明。

A well-known behaviour of such RTOS is tolock the rescheduling procedure until the outer interrupt service routine (orISR) - called first upon possibly nested interrupts - has exited, after which aglobal rescheduling is finally stated. This way, an interrupt service routinecan always assume that no synchronous thread activity may run until it hasexited. Moreover, all changes impacting the scheduling order of threads, due toactions taken by any number of nested ISRs (e.g. signaling a synchronizationobject on which one or more threads are pending) are considered once andconjunctively, instead of disjunctively.

一个广为人知的RTOS使用的方法即,锁住重新调度进程,直至ISR执行退出(第一个被嵌套的中断)。之后才允许进行再调度进程。这种方法,即ISR运行时,总是假设没有同步线程被激活运行,直至ISR退出。更多的是,由于考虑到嵌套中断的ISR运行的一次性和组合性,其动作带来的改变,会影响着重新调度线程的顺序,

For instance, if a suspended thread isfirst resumed by an ISR, then forcibly suspended later by another part of thesame ISR, the outcome will be that the thread will not run, and remainsuspended after the ISR has exited. In the other hand, if the RTOS sees ISRs asnon-specific code that can be preempted by threads, the considered thread willbe given the opportunity to execute immediately after it is resumed, until itis suspended anew. Obviously, the respective resulting situations won‘t beidentical.

例如,如果一个悬挂的线程被ISR恢复,然后又被该ISR的另外一部分代码强制suspend,最终的输出可能就是这个线程不是可运行的,同时会保持suspend直至该ISR退出。换句话说,如果RTOS,把ISR看做一段具体的可以被线程抢占的代码,相应的线程可能就会在被恢复时,立即去执行,直至被重新suspend。显然,相应的结果可能并不是相同的。

1.2.3 . Reevaluation of the real-time constraints

Making GNU/Linux a hard real-time system iscurrently achieved by using a co-kernel approach which takes control of thehardware interrupt management, and allows running real-time tasks seamlesslyaside of the hosting GNU/Linux system [4]. The ‘regular‘ Linux kernel iseventually seen as a low-priority, background of the small real-time executive.TheRTLinux [http://www.rtlinux.org]project is representative of this technical path. However, this approach has amajor drawback when it comes to port complex applications from a foreignsoftware platform: since the real-time tasks run outside the Linux kernelcontrol, the GNU/Linux programming model cannot be preserved when porting theseapplications. The result is an increased complexity in redesigning anddebugging the ported code.

使GNU/LINUX成为一个实时操作系统,可以通过一个协内核的方法实现,它可以接管硬件中断的管理,同时允许实时任务允许在宿主GNU/LINUX系统中。传统的linuxkernel被看做一个低优先级任务,作为一个实时内核的后台任务执行。RTlinux就是此种技术的代表。但是,这种方法有一个主要的问题,就是移植一个复杂的应用。尽管实时任务允许在linuxkernel之外,不受linuxkernel的控制,但是并不影响GNU/Linux在移植应用时的编程模型的的实现。结果就是,调试和设计移植代码的复杂度增加了。

In some cases, choosing a traditional RTOSto run an embedded application has been initially dictated by the memoryconstraints imposed by the target hardware, instead of actual realtimeconstraints imposed by the application itself. Since embedded devices tend toexhibit ever increasing memory and processing horsepower, it seems judicious toreevaluate the need for real-time guarantee when considering the porting effortto GNU/Linux on a new target hardware. This way, the best underlying softwarearchitecture can be selected. In this respect, the following, the followingcriteria need to be considered:

有些情况下,选择的一个传统RTOS运行一个嵌入式的应用,被简单的口述为,被目标硬件的内存约束,而不是被应用本身的实时性约束。尽管,嵌入式设备的趋势是更大的内存和更高的功率,重新评估实时性是非常明智的,以保证移植到GNU/Linux到目标平台的影响降到最低。按照这种方式,选择最优的软件架构。一方面,接下来的情形也需要被考虑:

?   Determinism and criticality.

What is theworst case interrupt and dispatch latencies needed ?

最坏情形下的中断执行延迟?

Does a misseddeadline lead to a catastrophic failure ?

中断的丢失是否会导致灾难性的后果?

?   Programming model

What is theoverall application complexity, provided that the higher the complexity, thegreater the need for powerful debugging aid and monitoring tools.

?   Is there a need need forlow-level hardware control ?

?   是否需要一个低级的硬件控制?

Is the real-timeactivity coupled to non real-time services, such as GUI or databases, requiringsophisticated communications with the non real-time world ?

实时的代码耦合到非实时的服务中,比如GUI或者数据库,是否要求复杂的通信?

1.2.4 . Some existing solutions

In order to get whether hard or softreal-time support, several GNU/Linux-based solutions exist [5][6]. It is notthe purpose of this paper to present them all exhaustively. We will onlyconsider a two fold approach based on free software solutions which is likelyto be suited for many porting taskings, depending on the actual real-timeconstraints imposed by the application.

1.2.4.1 . Partial rewriting using a real-time GNU/Linuxextension

Real-timeenabling GNU/Linux using RTAI. Strictly speakingLinux/RTAI [7] is not a real-time operating system but rather a real-time Linuxkernel extension, which allows running real-time tasks seamlessly aside of thehosting GNU/Linux system. The RTAI cokernel shares hardware interrupts andsystem-originated events like traps and faults with the Linux kernel using theAdeos [http://www.adeos.org/]virtualization layer, which in turn ensures RTAI low interrupt latencies. Thenative RTAI API provides the applications a wealth of useful services,including counting semaphores, POSIX 1003.1-1996 facilities such as pthreads,mutexes and condition variables, also adding remote procedure call facility, mailboxes,and precision timers. Most services are symmetrically available from kernelmodule and user-space programs.

利用RTAI使能GNU/Linux的实时性。严格的说,RTAI并不是一个实时性OS,仅仅是作为linuxkernel的实时性扩展,允许以任务的状态与LinuxKernel运行达到实时性的目的。RTAI协内核共享硬件中断和利用adeos虚拟层触发的错误和陷阱事件,反过来说这样能保证RTAI最低的中断延迟。原始的RTAIapi提供给应用大量的有效的服务,包括计数信号量,POSIX1003.1-1996的兼容性,比如支持pthread,mutex和条件变量,同样增加了远程调用兼容性,邮箱,和精确的timer。大多数的服务都是可以从内核模块和用户空间获得。

RTAI 2.x and 3.x provide a means to executehard real-time tasks in user-space context (x86 only), but still outside theLinux kernel control, which is best described as running ‘user-space kernelmodules‘. This feature, namely LXRT, is a major step toward a simpler migrationpath from traditional RTOS, since programming errors occuring within real-timetasks don‘t jeopardize the overall GNU/Linux system sanity, at the expense of afew microseconds more latency.

RTAI 2.X 和3.x版本提供一种用户空间内上下文的硬实时任务机制,但是仍然是脱离linux内核的控制,最贴切的描述为’用户空间内内核模块’。这种特点,美其名曰:LXRT,是在进行从传统RTOS移植过程中的主要步骤,且实时任务的代码编程错误并不影响linux系统的完整性,但需要消耗一部分微秒级的延迟时间。

Adhoc services emulation. A first approach consistsin emulating each real-time facility needed by the application using acombination of the RTAI services. An ad hoc wrapping interface has to bewritten to support the needed function calls. The benefit of the wrappingapproach lies in the limited modifications made to the original code. However,some RTAI behaviours may not be compliant with the source operating system‘s.For the very same reason, conflicts between the emulated and native RTAIservices may occur in some way.

Ad hoc 服务仿真。第一种方法由每一个实时设备根据应用所需的,同时利用RTAI服务来实现仿真。Adhoc封装接口必须支持所需的函数调用。封装的好处在于,在一个有限的范围内进行原始代码的修改。但是,一些RTAI的行为可能并不是与源操作系统匹配。基于许多原因,存在许多方式在仿真与原始RTAI服务的之间的冲突可能会发生。

Complete port to RTAI. A second approach consists in fully porting the application overthe native RTAI API. In such a case, RTAI facilities are globally substitutedfrom the facilities from the source RTOS. This solution brings improvedconsistency at the expense of a possible large-scale rewriting of theapplication, due to some fundamental behavioural differences that may existbetween the traditional RTOS and the native RTAI interface.

RTAI的代码移植。第二种方法讲述的是移植应用到原始的RTAIAPI。在这种情况下,RTAI设备是被源RTOS所替代。这种方案会带来一致性的增加,由于在传统的RTOS和原始RTAI接口上的基本的差异性存在,将会以损失更高的应用代码的重写为代价。

1.2.4.2 . Unconstrained user-space emulations

A few traditional RTOS emulators exists inthe free software world. There are generally designed on top of the GNU/LinuxPOSIX 1003.1-1996 layer, and allow to emulate the source RTOS API in auser-space execution context, under the control of the Linux kernel.

在自由软件世界,存在一小部分的传统的RTOS模拟器。他们被设计在运行在GNU/Linux的 POSIX层之上,允许用户接口的RTOS API,并且受linuxkernel的控制。

Once one of the most proeminent effort inthis area used to be the Legacy2linux project [8]. This project, sponsored byMontavista Software, aimed at providing ["a series of Linux-residentemulators for various legacy RTOS kernels."] Just like Xenomai, [ theseemulators are designed to ease the task of porting legacy RTOS code to anembedded Linux environment".] Two emulators have been made available bythis project, respectively mimicking the APIs of WindRiver‘s pSOS+ and VxWorksreal-time operating systems. However, this project has stalled due to a lack ofmaintenance and contribution.

曾经,这个领域里最突出的一个项目Legacy2linux。这个项目,由MontavistaSoftware赞助,旨在提供类xenomai。通过这个项目可以获得两个仿真器,一个是模仿了WindRiver的 pSOS+,另外一个是仿的VxWorks实时操作系统。但是,由于维护性和赞助方面的缺乏这个项目已经落伍了。

The benefits of this approach is mainly tokeep the development process in the GNU/ Linux user-space environment, insteadof moving to a rather ‘hostile‘ kernel/supervisor mode context. This way, therich set of existing tools such as debuggers, code profilers, and monitorsusable in this context are immediatly available to the application developer. Moreover, the standard GNU/Linux programming model is preserved,allowing the application to use the full set of of facilities existing in theuser space (e.g. full POSIX support, including inter-process communication).Last but not least, programming errors occuring in this context don‘tjeopardize the overall GNU/Linux system stability, unlike what can happen if abug is encountered on behalf of a hard real-time RTAI task which could causeserious damages to the running Linux kernel.

这个方法的有事在于开发了GNU/LINUX的用户空间的进程上下文,而不是在一个“hostfile”的内核超级模式的上下文。这种方式,借助已存在的丰富的工具,比如调试器、代码配置器和监视器,应用开发者可以轻易的获取。更多的,标准的linux编程模式是保留的,允许应用利用完整的用户空间的工具(完整的POSIX支持,包括进程内通信)。当然最后的不代表是最不重要的,发生在上下文的编程错误,不会影响整体的系统的稳定性,不像发生在硬实时RTAI系统任务中的错误,会导致运行中的linuxkernel发生严重的损坏。

However, we can see at least three problemsin using these emulators, depending on the application constraints:

依赖应用,我们至少可以看到三个问题:

?    First, the emulated API they provide is usually incomplete for aneasy port from the source RTOS. In other words, only a limited syntacticcompatibility is available.

?    首先,被模拟的接口经常是不完整的从源RTOS的轻量型移植。换句话说,就是只有有限的语法兼容性。

?    Second, the exact behaviour of the source RTOS is not reproduced forall the functional areas. In other words, the semantic compatibility might notbe guaranteed.

?    第二,源RTOS的准确的具体表示并不会在所有调用处重现。换句话说,语义的兼容性是不能被保证的。(译者注:太监在某些情境下的功能是不完整的

?   These emulators don‘t share anycommon code base for implementing the fundamental real-time behaviours, even soboth pSOS+ and VxWorks share most of them.The resulting situation leads to redundant implementation efforts, without anybenefit one can see in code mutualization.

?    第三,那些模拟的实现,在实现基本的实时行为,不会共享任何相同的基础代码,即便如此pSOS+和VxWorks之间还是共享了大部分代码。这种情形的结果就是大妈冗余问题,在代码的互助性来说看不到任何好处。

?    And finally, even combined to the latest Linux 2.6 features likefine-grain kernel preemption and low latency efforts, these emulators cannotdeliver deterministic real-time performance.

?    最后,结合最新的linux2.6内核的抢占和低延迟影响,这些模拟器在实时性能上没有起到决定性的作用。

1.3 . A common emulation framework

1.3.1 . Common traditional RTOS behaviours

In order to build a generic and versatileframework for emulating traditional RTOS, we chose to concentrate on a set ofcommon behaviours they all exhibit. A limited set of specific RTOS featureswhich are not so common, but would be more efficiently implemented into thenucleus than into the emulators, has also been retained. The basic behavioursselected cover four distinct fields:

为了仿真传统的RTOS建立通用的架构,我们选择集中在所看到的通用的具体行为。具体RTOS的特点是有限的,并不会一那么一般通用,但是相对模仿来说会更有效的实现到微内核中去,因此会被保留。基本行为的选择覆盖了4个不同的领域。

1.3.1.1 . Multi-threading

Multi-threading provides the fundamentalmechanism for an application to control and react to multiple, discrete externalevents. The nucleus provides the basic multi-threading environment.

多线程,为那些多重的分散的外部事件做集中控制,提供了一种基础机制。微内核提供了基本的多线程环境

Threadstates. The nucleus has to maintain the currentstate of each thread in the system. A state transition from one state toanother may occur as the result of specific nucleus services called by the RTOSemulator. The fundamental thread states defined by the nucleus are:

线程状态。微内核必须维持系统的每个线程的当前状态。RTOS仿真器调用具体的微内核服务,会导致状态从这个状态到另外一个状态的转化。基本的线程状态定义如下:

?    DORMANT and SUSPENDED states are cumulative, meaning that the newlycreated thread will still remain in a suspended state after being resumed fromthe DORMANT state.

?    DORMANT 和 SUSPENDED状态是累计的,意味着新创建的线程在从DORMANT恢复后仍然保留在一个suspended的状态。

?    PENDING and SUSPENDED states are cumulative too, meaning that athread can be forcibly suspended by another thread or service routine whilepending on a synchronization resource (e.g. semaphore, message queue). In sucha case, the resource is dispatched to it, but it remains suspended untilexplicitly resumed by the proper nucleus service.

?    PENDING 和SUSPENDED也是一样,意味着,一个线程在悬停一个同步资源时,可以被另外一个线程强制suspend,或者另外一个服务程序suspend。在在这种情况下,资源被获得后,仍然保留suspend状态,直到合适的微内核服务将其唤醒。

?    PENDING and DELAYED states may be combined to express a timed waiton a resource. In such a case, the time the thread can be blocked is bound to alimit enforced by a watchdog.

?    PENDING 和DELAYED状态组合起来,可能是表达一个对资源的时间上的等待。在这种情况下,线程会阻塞,会被一个看门狗限定到一个有限的时间内。

Schedulingpolicies. By default, threads are scheduledaccording to a fixed priority value, using a preemptive algorithm. There isalso a support for round-robin scheduling among a group of threads having thesame priority, allowing them to run during a given time slice, in rotation.Moreover, each thread undergoing the round-robin scheduling is given anindividual time quantum.

调度机制。默认的,线程的调度按照固定的优先级,利用了一个抢占逻辑。在具有相同优先级的一组线程中也是适用的,允许他们在给定的时间片内运行。更多的是,每个线程的轮转调度是分别独立的时间片。

Prioritymanagement. It is possible to use either anincreasing or decreasing thread priority ordering, depending on an initialconfiguration. In other words, numerically higher priority values could eitherrepresent higher or lower scheduling priorities depending on the configurationchosen. This feature is motivated by the existence of this two possibleordering among traditional RTOS. For instance, VxWorks, VRTX, ThreadX and ChorusO/S use a reversed priority management scheme, where the higher the value, thelower the priority. pSOS+ instead uses the opposite ordering, in which thehigher the value, the higher the priority.

优先级管理。依赖于初始化的配置,增加或降低线程的优先级是允许的。换句话说,数字化的更高的优先级可以代表更高调度权限或者更低调度权限,依赖于选择的配置。在传统的RTOS,这种特点是可以激活的。例如,VxWorks,VRTX,ThreadX和ChorusO/S 用到了反转优先级管理机制,数值越大优先级越低。pSOS+反而利用相反的顺序,数值越大,优先级越高。

Runningthread. At any given time, the highest prioritythread which has been ready to run for the longest time among the currently runnablethreads (i.e. not currently blocked by any delay or resource wait) is electedto run by the scheduler.

运行中的线程。任何给定的时间,在当前可运行线程中,最高优先级的线程的可运行时间,完全有调度器决定的。

Preemption. When preempted by a higher priority thread, the running thread isput at the front of the ready thread queue waiting for the processor resource,provided it has not been suspended or blocked in any way. Thus it is expectedto regain the processor resource as soon as no other higher priority activity(i.e. a thread having a higher priority level, or an interrupt service routine)is eligible for running.

抢占。当被一个更高优先级线程抢占,运行中的线程被放置到ready 队列头,等待处理器资源,它也没有被suspended或者阻塞。因此在没有任何更高优先级请求运行之前,它期望重新获取处理器资源。

Manualround-robin. As a side-effect of attempting toresume an already runnable thread or the running thread itself, this thread ismoved at the end of its priority group in the ready thread queue. Thisoperation is functionally equivalent to a manual round-robin scheduling.

人为的轮转。类似尝试恢复一个准备好的可运行的线程或者正在运行的线程本身的副作用,这个线程被移动都优先级组的ready队列的末尾。这个操作等同于手动的进行循环调度。

Even if they are not as widespread as thoseabove in traditional RTOS, the following features are also retained for thesake of efficiency in the implementation of some emulators:

即便没有和上面列出的传统RTOS那样传播广泛,为了一些仿真器在实现效率的考虑,接下来的特点也是被保留的。

Priorityinversion. In order to provide support forpreventing priority inversion when using inter-thread synchronization services,the priority inheritance protocol is supported.

优先级反转。当利用内部线程的同步服务,为了支持阻止优先级反转,优先级继承的协议是支持的。

Signaling. A support for sending signals to threads and running asynchronousservice routines to process them is available. The asynchronous service routineis run on behalf of the signaled thread context the next time it returns fromthe nucleus level of execution, as soon as one or more signals are pending.

信号。对进程来说,发送信号和运行异步的服务例程是可获得的。异步服务例程的运行,代表了信号线程的上下文切换,一旦一个或多个信号处于pending,下一次它从内核级的执行过程返回

Disjunctivewait. A thread is able to wait in a disjunctivemanner on multiple resources. The nucleus unblocks the thread when at least oneof the pending resources is available.

分离等待。一个线程能够以分离的方式等待多重资源。当至少一个pending的资源可获取时,微内核将线程设置为非阻塞。

1.3.1.2 . Thread synchronization

Traditional RTOS provide a large spectrumof inter-thread communication facilities involving thread synchronization, suchas semaphores, message queues, event flags or mailboxes.Lookingat them closely, we can define the characteristics of a basic mechanism whichwill be usable in turn to build these facilities.

传统的RTOS提供了许多线程间的同步方式,包括信号量、消息队列、标志或者邮箱。仔细观察,我们可以定义一个基本的可用的建立这些设备的机制。

Pending mode. The thread synchronization facility provides a means for threads topend either by priority or FIFO ordering. Multiple threads should be able topend on a single resource.

Pending模式。线程同步设备提供一些方法要么通过优先级要么通过FIFO序列。多线程可以同时pend同一个资源

Priorityinheritance protocol. In order to prevent priorityinversion problems, the thread synchronization facility implements a priorityinheritance protocol in conjunction with the thread scheduler. Theimplementation allows for supporting the priority ceiling protocol as a derivativeof the priority inheritance protocol.

优先级继承。为了阻止优先级反转的问题,线程同步设备结合线程调度器,实现了一个优先级继承的协议。实现机制允许支持优先级的上限协议,作为一个优先级继承的衍生品。

Time-boundedwait. The thread synchronization facility providesa means to limit the time a thread waits for a given resource using a watchdog.

时间等待有限性。线程同步设备提供了一种方法限制线程的等待时间,利用自身的watchdog,为了所谓的资源进行等待。

Forcibledeletion. It is legal to destroy a resource whilethreads are pending on it. This action resumes all waiters atomically.

强制删除。当线程在pend资源的时候销毁资源是合法的,这个动作自动会唤醒所有的等待者。

1.3.1.3 . Interrupt management

Since the handling ofinterrupts is one of the least well defined areas in RTOS design,the nucleus focuses on providing a simple mechanism with sufficienthooks for specific implementations to be built onto according to the emulatedRTOS flavour.

由于中断的处理过程,在RTOS设计中是最不好定义的过程之一,微内核集中提供一种简单的机制,按照模拟的RTOS特点,建立具体的实现高效的回调机制。

Nesting. Interrupt management code is reentrant in order to supportinterrupt nesting safely.

嵌套:为了支持中断嵌套,中断管理代码是可重入的。

Atomicity. Interrupts are associated with dedicated service routines calledISRs. In order for these routines not to be preempted by thread execution, therescheduling procedure is locked until the outer ISR has exited (i.e. in caseof nested interrupts).

原子性:中断就是中断服务子程序,被称作ISR。为了服务子程序不被线程抢占,重调度的进程在ISR退出之前一直保持被锁状态。

Priority. ISRs are always considered as priority over thread execution.Interrupt prioritization is left to the underlying hardware.

优先级:ISR的优先级总是认为比线程优先级高。中断的优先级低于顶层硬件。

1.3.1.4 . Time management

Traditional RTOS usually represent time inunits of ticks. These are clock-specific time units and are usually the periodof the hardware timer interrupt, or a multiple thereof. Since it needs tosupport both periodic and aperiodic time sources, the nucleus transparentlyswitches from periodic jiffies to time-stamp counter values depending on thecurrent timer operating mode.

 

Softwaretimer support. A watchdog facility is provided tomanage time-bound operations by the nucleus.

Absoluteand relative clock. The nucleus keeps a globalclock value which can be set by the RTOS emulator as being the system-definedepoch.

Some RTOS like pSOS+ also provide supportfor date-based timing, but conversion of ticks into conventional time and dateunits is an uncommon need that should be taken in charge by the RTOS emulatoritself.

1.3.2 . An architecture-neutral abstraction layer

After having selected the basic behaviours shared by traditionalRTOS, we have implemented them in a nucleus exporting a few service classes.These generic services will then serve as a founding layer for developing eachemulated RTOS API, according to their own flavour and semantics.

In order for this layer to be architectureneutral, the needed support for hardware control and real-time capabilitieswill be obtained from an underlying host software architecture, through arather simple standardized interface. Thus, porting the nucleus to a newrealtime architecture will solely consist in implementing this low-levelinterface for the target platform.

1.3.3 . Real-time capabilities

The host software architecture is expected to provide the primaryreal-time capabilities to the RTOS abstraction layer. Basically, the hostreal-time layer must handle at least the following tasks:

?    On request start/stop dispatching the external interrupts to aspecialized handler ;

?    Provide a means to mask and unmask interrupts ;

?    Provide a means to create new threads of control in their simplestform ;

?    Provide support for periodic and aperiodic interrupt sources used intimer management ;

?    Provide support for allocating chunks of non-pageable memory.

1.3.4 . Benefits

Xenomai aims at helping applicationdesigners relying on traditional RTOS to move as smoothly as possible to aGNU/Linux-based execution environment, without having to rewrite theirapplications entirely. Aside of the advantages of using GNU/Linux as anembedded system, the benefits expected from the described approach is mainly areduced complexity in designing new RTOS emulations. The architecture-neutralabstraction layer provides the foundation for developing accurate emulations oftraditional RTOS API, saving the burden of repeatedly implementing theirfundamental real-time behaviours. Since the abstraction layer also favours codesharing and mutualization, we can expect the RTOS emulations to take advantageof them in terms of code stability and reliability.

1.4 . Nucleus description

RTOS emulations are software modules whichconnect to the nucleus through the pod abstraction. The pod is responsible forthe critical housekeeping chores, and the real-time scheduling of threads.

RTOS仿真器是软件模块,它通过一个pod抽象链接到微内核。Pod代表了关键的维护工作,和线程的实时调度。

1.4.1 . Multi-threading support

The nucleus provides thread object (xnthread) and pod (xnpod)abstractions which exhibit the following characteristics:

微内核提供了线程对象(xnthread)和pod抽象(xnpod)的具体表示,具备以下特点:

?    Threads are scheduled according to a 32bit integer priority value,using a preemptive algorithm. Priority ordering can be increasing or decreasingdepending on the pod configuration.

?    线程通过一个32bit的整形优先级值,利用抢占逻辑来实现再调度。优先级可以增加也可以降低,具体依赖于pod的配置。

?    A thread can be either waiting for initialization, forciblysuspended, pending on a resource, delayed for a count of ticks, ready-to-run orrunning.

?    线程要么是等待初始化,要么是被强制suspended,要么是等待资源进入pending,要么是等待一系列的时钟tick,要么是等待运行或者运行中。

?    Timed wait for a resource can be bounded by a per-thread watchdog.

?    资源的时间等待可以被每个线程的看门狗的所限定。

?    The priority inheritance protocol is supported to prevent threadpriority inversion when it is detected by a synchronization object.

?    优先级的继承协议支持,当一个同步目标检测到时,将阻止优先级的反转。

?    A group of threads having the same base priority can undergo around-robin scheduling, each of them being given an individual time quantum.

?    具有相同优先级的一组线程可以进行循环调度,每个个体都给定一个单独的时间片。

?    A support for sending signals to threads and running asynchronousservice routines (ASR) to process them is built-in.

?    内建的信号发送机制,和异步服务支持机制

?    FPU support can be optionally enabled or disabled for any thread atcreation time.

?    线程创建时,选择性的支持FPU.

?    Each thread can enter a disjunctive wait on multiple resources.

?    等待多重资源时,每个线程都可进入一个独立的等待不干扰。

1.4.2 . Basic synchronization support

The nucleus provides a synchronizationobject abstraction (xnsynch) aimed atimplementing the common behaviour of RTOS resources, which has the followingcharacteristics:

?    Support for the priority inheritance protocol, in order to preventpriority inversion problems. The implementation is shared with the schedulercode.

?    Support for time-bounded wait and forcible deletion with waitersawakening.

微内核提供了一个同步对象抽象(xnsynch),旨在RTOS资源上具备一般的行为,具备以下特点:

?    支持优先级继承,防止优先级反转。实现和调度器代码共享。

?   支持限定时间的等待和强制删除户的等待唤醒。

1.4.3 . Timer and clock management

The nucleus needs a time source to providethe time-related services to the upper interfaces. The timer hardware needs tobe configured so that a user-defined routine is called according to a givenfrequency. On architectures that provide a oneshot-programmable time source,the system timer can operate either in aperiodic or periodic mode. Using theaperiodic mode still allows to run periodic nucleus timers over it: theunderlying hardware will simply be reprogrammed after each tick by the timermanager using the appropriate interval value.

Each incoming clock tick is announced tothe timer manager which fires in turn the timeout handlers of elapsed timers.The scheduler itself uses per-thread watchdogs to wake up threads undergoing abounded time wait, while waiting for a resource availability or being delayed.

A special care has been taken to offerbounded worst-case time for starting, stopping and maintaining timers. Thetimer facility is based on the timer wheel algorithm[11] described by Adam M.Costello and George Varghese, which is implemented in the NetBSD operatingsystem for instance.

微内核需要一个时钟源,为上层接口提供时钟相关服务接口。配置硬件的时间片,让应用按照给定的频率调用用户定义的服务。架构上提供了一个oneshot的可编程的时钟源,系统时间片可以按照不定期或者定期模式运行。不定期周期模式仍然运行定时周期的微内核时间片。经过每个tick之后,由时间片管理器通过一个合适的内部值对硬件进行重新编程。

每一个的时钟tick都被通知到时间片管理器,即流逝时间的处理者。调度器本身利用每个线程自己的watchdog,由于一个资源的获取或者其他原因等待,在经过一个有限的时间等待后,来唤醒线程。

提供一个最坏情况的有限的时间,进行启动、停止或者保持,需要进行特别的关注。基于时间片轮转的算法的时间片实现一键在NETBSD系统上实现。

1.4.4 . Basic memory allocation

Xenomai‘s nucleus provides dynamic memory allocation support withreal-time guarantee, based on McKusick‘s and Karels‘ proposal for a generalpurpose memory allocator[10]. Any number of memory heaps can be maintaineddynamically by Xenomai, only limited by the actual amount of system memory.

基于McKusick和Karels的一般目的性的内存分配的建议,Xenomai内核提供了一种动态的内存分配保证了实时性的要求。任何的数量的内存堆都可以有xenomai动态保持,唯一的限制在于系统的内存的数量。

以上是关于xenomai-GNU/Linux上的RTOS模拟架构实现的主要内容,如果未能解决你的问题,请参考以下文章

在非 RTOS 系统中是不是可以中断任务

是否可以在 RTOS 上运行 node.js?

为啥 MPC5554 板不需要 RTOS?它是不是带有内置操作系统?

HI3861学习笔记——HarmonyOS(CMSIS-RTOS2)软件定时器

RTOS训练营I2C和UART知识和预习安排 + 晚课提问

RTOS训练营I2C和UART知识和预习安排 + 晚课提问