• 您現在的位置是:首頁 >綜合 > 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類似。

    本文到此講解完畢了,希望對大家有幫助。

  • 成人app