您现在的位置是:首页 >综合 > 2023-10-18 03:00:07 来源:

xenomai高版本实时性差(Xenomai)

导读 大家好,我是小夏,我来为大家解答以上问题。xenomai高版本实时性差,Xenomai很多人还不知道,现在让我们一起来看看吧!在Xenomai的用户空...

大家好,我是小夏,我来为大家解答以上问题。xenomai高版本实时性差,Xenomai很多人还不知道,现在让我们一起来看看吧!

在Xenomai的用户空间下,有两种模式:primary mode (主模式) 和 secondary mode(次模式).

在主模式下调用Linux系统调用后程序就会进入次模式,反之,在次模式下调用Xenomai的系统调用后程序会进入主模式。

主模式和次模式的引入主要是丰富了实时程序可调用的库,实时程序也可以调用Linux的库,但是实时性受Linux自身的影响。

参考:http://www.xenomai.org/index.php/Porting_POSIX_applications_to_Xenomai

To ease working with this dual-kernel system, a Xenomai application thread may run in two modes: either the primary mode, where it is scheduled by the Xenomai kernel, and benefits from hard real-time scheduling latencies, or the secondary mode, where it is an ordinary Linux thread, and as such may call any Linux services.

Such a thread may change mode dynamically, that is, when this thread calls a Xenomai real-time service while running in secondary mode, it switches to primary mode, when it calls any non real-time Xenomai service or any Linux service (including exceptions such as page faults) while running in primary mode, it switches to secondary mode.

内部的处理流程如下:

1. 初始化

在引用各个skin的创建任务的接口时,系统会作如下处理:映射一个和linux thread匹配的xenomai thread, 这个xenomai thread被称为影子线程 (shadow thread)。因为Linux下的调度器其实是无法知道Xenomai下的任务的,所以这个影子线程就是给Xenomai进行调度使用的。

2. 系统调用处理时

这时会根据线程所在Domain和系统调用的Domain进行判断,如果有发生模式切换。主要是调用如下两个函数处理:

int xnshadow_harden (void)

Migrate a Linux task to the Xenomai domain.

void xnshadow_relax (int notify)

Switch a shadow thread back to the Linux domain.

前者是迁移到Xenomai域,后者是迁移到Linux域 。

以前者为例:

参考xnshadow_harden的代码,这时会唤醒一个守护线程gatekeeper, 守护线程会将对应的影子线程放在xenomai的可执行队列时,并调用xenomai自身的调度器xnpod_schedule(),这里会恢复linux thread下的寄存器并执行影子线程。

而后者的情况下,有一点要注意:xenomai是通过virq的方式通知linux,

lostage_apc =

rthal_apc_alloc("lostage_handler", &lostage_handler, NULL);

这里注册了虚拟中断的处理函数: lostage_hander,其他的跟xnshadow_harden类似。

本文到此讲解完毕了,希望对大家有帮助。