FreeRTOS Scheduler Types

  • Pre-emptive

    • Round robin

      Given the time slice, the scheduler will choose which task to run as planned. The fixed pattern will be repeated. Each task could be not completed by the time slice if the task needs more time. It will continue with the next cycle. This can be achieved by setting all task's priorities to be the same.

    • Priority base

      The higher priority task will be handled until it gets deleted/blocked/suspended. When the higher priority is unhandled, the processor will start the next higher-priority task. It is called a context switch.

  • Co-operative

    The running task will never be stopped by the scheduler. The task will yield to others to run another task.

Each type can be chosen by configUSE_PREMPTION flag in FreeRTOSConfig.h. To use Co-operative, make sure to use taskYIELD() in FreeRTOS's task.

Here is an example of Pre-emptive Scheduling:

There are two tasks running in the example above. Each task takes turn by every SysTick ISR. After the ISR, you can see that scheduler executes context switching.

Here is an example of Co-operative Scheduling:

It is the same code but changing FreeRTOSConfig.h to disable pre-emption and add taskYIELD() each task function. You can see each task does not take turn by every SysTick ISR anymore. Also, you do not see scheduler because there are no context switching is happeneing. SysTick ISR is happening middle of the task running.

Did you find this article valuable?

Support Hyunwoo Choi by becoming a sponsor. Any amount is appreciated!