zephyr的執行上下文(多線程)

zepyhr的內核支持三種類型的多線程:

1、任務線程,可搶佔,通常用來執行冗長和複雜的事務。任務的調度基於優先級,任務執行時高優先級任務搶佔低優先級任務。

內核可選支持時間片輪轉調度,也就是說同優先級別的任務可以輪流執行,不會出現CPU被獨佔的風險(換句話說,看樣

子是打開時間片輪轉且所有線程優先級相等此時纔會出現cpu不被獨佔)。

2、纖程,輕量級的不可搶佔線程,通常用於設備驅動程序和性能的關鍵性工作,也是基於優先級調度,纖程在操作阻塞時被

調度,纖程的執行權限優先於任務線程,也就是說任務線程的執行需要在所有纖程被執行完後才能得到調度執行。

3、中斷上下文,內核中執行權限最高,用於處理ISRs(中斷處理程序)。只有在所有ISR被處理完成後纖程、任務線程纔會

得到CPU的執行。

調度的情況大致上 ISR-->纖程-->任務線程,看樣子沒有併發的情況。

zephyr不同內核在app使用任務線程和纖程上的區別:

microkernel 不限制app使用任務線程或者纖塵的個數

nanokernel 限制app只能使用單個。


The Zephyr kernel supports multi-threaded processing for three types of execution contexts.

  • task context is a preemptible thread, normally used to perform processing that is lengthy or complex. Task scheduling is priority-based, so that the execution of a higher priority task preempts the execution of a lower priority task. The kernel also supports an optional round-robin time slicing capability so that equal priority tasks can execute in turn, without the risk of any one task monopolizing the CPU.
  • fiber context is a lightweight and non-preemptible thread, typically used for device drivers and performance critical work. Fiber scheduling is priority-based, so that a higher priority fiber is scheduled for execution before a lower priority fiber; however, once a fiber is scheduled it remains scheduled until it performs an operation that blocks its own execution. Fiber execution takes precedence over task execution, so tasks execute only when no fiber can be scheduled.
  • The interrupt context is a special kernel context used to execute ISRs Interrupt Service Routines. The interrupt context takes precedence over all other contexts, so tasks and fibers execute only when no ISR needs to run. (See below for more on interrupt handling.)

The Zephyr microkernel does not limit the number of tasks or fibers used in an application; however, an application that uses only the nanokernel is limited to a single task.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章