zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    js和css
    主题
    php.ini
    css 选择器、元素默认宽度、media screen
    linux 重要笔记
    cookie和session、
    tp5 报 A non well formed numeric value encountered 的错解决办法
    pdo
    二叉树
    顺序串
  • 原文地址:https://www.cnblogs.com/mfrbuaa/p/5339047.html
Copyright © 2011-2022 走看看