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类似。

參考:

http://www.cs.ru.nl/lab/xenomai/api/group__shadow.html





本文转自mfrbuaa博客园博客,原文链接:http://www.cnblogs.com/mfrbuaa/p/5339047.html,如需转载请自行联系原作者

相关文章
|
前端开发 JavaScript Java
MVX模式是什么?
MVX模式是什么?
213 0
|
分布式计算 自然语言处理 并行计算
运用Aggregator模式实现MapReduc
运用Aggregator模式实现MapReduc
运用Aggregator模式实现MapReduc
|
C语言
模式
模式
113 0
|
并行计算 搜索推荐 算法
Notepad++输入模式之修改模和插入模式的切换
Notepad++中输入内容提供了两种模式: 一种是插入,另一种是改写。分别对应光标的两种状态:横线(_)、竖线(|)
3848 0