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.
- A 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.
- A 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.