Espressif ESP32-S2 Programming Manual page 1372

Table of Contents

Advertisement

Chapter 4. API Guides
Fixed Priority
In Vanilla FreeRTOS, when scheduler selects a new task to run, it will always select the current highest priority ready
state task. In ESP-IDF FreeRTOS, each core will independently schedule tasks to run. When a particular core selects
a task, the core will select the highest priority ready state task that can be run by the core. A task can be run by the
core if:
• The task has a compatible affinity (i.e., is either pinned to that core or is unpinned)
• The task is not currently being run by another core
However, users should not assume that the two highest priority ready state tasks are always run by the scheduler as a
task's core affinity must also be accounted for. For example, given the following tasks:
• Task A of priority 10 pinned to CPU0
• Task B of priority 9 pinned to CPU0
• Task C of priority 8 pinned to CPU1
The resulting schedule will have Task A running on CPU0 and Task C running on CPU1. Task B is not run even
though it is the second highest priority task.
Preemption
In Vanilla FreeRTOS, the scheduler can preempt the currently running task if a higher priority task becomes ready to
execute. Likewise in ESP-IDF FreeRTOS, each core can be individually preempted by the scheduler if the scheduler
determines that a higher priority task can run on that core.
However, there are some instances where a higher priority task that becomes ready can be run on multiple cores. In
this case, the scheduler will only preempt one core. The scheduler always gives preference to the current core when
multiple cores can be preempted. In other words, if the higher priority ready task is unpinned and has a higher priority
than the current priority of both cores, the scheduler will always choose to preempt the current core. For example,
given the following tasks:
• Task A of priority 8 currently running on CPU0
• Task B of priority 9 currently running on CPU1
• Task C of priority 10 that is unpinned and was unblocked by Task B
The resulting schedule will have Task A running on CPU0 and Task C preempting Task B given that the scheduler
always gives preference to the current core.
Time Slicing
The Vanilla FreeRTOS scheduler implements time slicing meaning that if current highest ready priority contains
multiple ready tasks, the scheduler will switch between those tasks periodically in a round robin fashion.
However, in ESP-IDF FreeRTOS, it is not possible to implement perfect Round Robin time slicing due to the fact
that a particular task may not be able to run on a particular core due to the following reasons:
• The task is pinned to the another core.
• For unpinned tasks, the task is already being run by another core.
Therefore, when a core searches the ready state task list for a task to run, the core may need to skip over a few tasks
in the same priority list or drop to a lower priority in order to find a ready state task that the core can run.
The ESP-IDF FreeRTOS scheduler implements a Best Effort Round Robin time slicing for ready state tasks of the
same priority by ensuring that tasks that have been selected to run will be placed at the back of the list, thus giving
unselected tasks a higher priority on the next scheduling iteration (i.e., the next tick interrupt or yield)
The following example demonstrates the Best Effort Round Robin time slicing in action. Assume that:
• There are four ready state tasks of the same priority AX, B0, C1, D1 where: - The priority is the current
highest priority with ready state tasks - The first character represents the task's names (i.e., A, B, C, D)
- And the second character represents the tasks core pinning (and X means unpinned)
• The task list is always searched from the head
Espressif Systems
1361
Submit Document Feedback
Release v4.4

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the ESP32-S2 and is the answer not in the manual?

Table of Contents

Save PDF