码迷,mamicode.com
首页 > 其他好文 > 详细

Xenomai 的模式切换浅析

时间:2014-07-20 23:23:54      阅读:324      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   color   使用   

在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

Xenomai 的模式切换浅析,布布扣,bubuko.com

Xenomai 的模式切换浅析

标签:des   style   blog   http   color   使用   

原文地址:http://blog.csdn.net/robertsong2004/article/details/37993441

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!