RTOS scheduler simulator
Pick one of 21 scenarios, step through what the kernel does on every tick next to its source code, and change the parameters to see what happens. It runs line-by-line models of FreeRTOS and Zephyr, checked against the real kernels.
The simulator and its data files are not covered by the site's CC BY-SA license; see their license notices. Does it show something a real kernel does not do? Tell us in a GitHub issue.
The scenarios
Choose a scenario to load it into the simulator above. The lessons explain what happens in it, and why.
Task states
One task goes through every state: it runs, is preempted, is suspended and resumed, sleeps, waits for a signal and ends, mostly because of a more urgent task.
Lessons: Task states, Suspending, resuming and ending a task in FreeRTOS, Suspending, resuming and ending a thread in Zephyr
Preemption
A high-priority task wakes from a delay and takes the CPU from a low-priority task at once. Turn preemption off and it waits until the low-priority task gives up the CPU.
Lessons: Main loop vs RTOS, Preemption, The context switch in FreeRTOS, The context switch in Zephyr
Time slicing
Three tasks of equal priority share the CPU, one tick each, as the tick interrupt rotates them in the ready list.
Lessons: Time slicing, How FreeRTOS chooses the next task, How Zephyr chooses the next thread
Blocking and the idle task
Every task blocks in a delay, so the idle task runs. The delayed list is sorted by wake-up tick, and the tick interrupt makes each task ready again.
Lessons: How an RTOS scheduler decides what runs, The tick and vTaskDelay in FreeRTOS, The tick and k_sleep in Zephyr
Priority inversion (binary semaphore)
A low-priority task holds a binary semaphore that a high-priority task needs, and a medium-priority task runs ahead of both: priority inversion.
Lesson: Priority inversion
Priority inheritance (mutex)
The same tasks with a mutex: the holder inherits the priority of the task waiting for it, so the medium-priority task can no longer get in the way.
Lessons: Priority inheritance, Priority inheritance in FreeRTOS, Priority inheritance in Zephyr
Nested mutexes
A task holds two mutexes and inherits a priority through one of them, then gives that one back. FreeRTOS keeps the inherited priority until the task holds no mutex at all.
Mutex with a timeout
A high-priority task waits for a mutex for at most 3 ticks. When it gives up, the priority the holder inherited from it has to be undone.
Mutex handoff
A mutex is given back while two tasks wait for it. FreeRTOS lets the running task take it again; Zephyr hands it straight to the most urgent waiter.
A semaphore as a signal
A binary semaphore used as a signal: each give wakes a more urgent handler task, which preempts the task that gave it. Nobody owns the semaphore, so nothing is inherited.
Lesson: Semaphores as signals
A counting semaphore as a pool
A counting semaphore as a pool of two buffers shared by three tasks. The most urgent one waits for a free buffer, and no priority is inherited.
Lessons: Counting semaphores, Semaphores in FreeRTOS, Semaphores in Zephyr
Producer and consumer
A message queue between a fast producer and a slow consumer. The queue fills up, and from then on the producer blocks until there is room.
Lessons: Queues between tasks, Queues in FreeRTOS, Message queues in Zephyr
Queue handoff
An item is sent to a queue that a task waits on. FreeRTOS lets a more urgent receiver take it first; Zephyr copies it straight to the task that was waiting.
Lesson: Queue handoff: who gets an item sent to a waiting task
Deferred interrupt handling
An interrupt handler only gives a semaphore, and a task does the work. FreeRTOS can leave out portYIELD_FROM_ISR(): the task then runs late, and an interrupt is lost.
Lessons: Interrupts and deferred handling, Interrupts in FreeRTOS, Interrupts in Zephyr
Periodic tasks and deadlines
Two periodic tasks, one with delayUntil and one with delay: the first keeps its period, the second drifts, and a burst of work makes a job miss its deadline.
Lessons: Periodic tasks and deadlines, xTaskDelayUntil in FreeRTOS, Periodic sleep in Zephyr
Software timers
An auto-reload software timer whose callback signals a task. FreeRTOS runs the callback in its timer service task; Zephyr runs it in the tick interrupt.
Lessons: Software timers, Software timers in FreeRTOS, Timers in Zephyr
Event group
Tasks wait on an event group, one for all of two bits and one for any of two, set from an interrupt and from a task. One bit wakes both waiters at once.
Lessons: Event groups, Event groups in FreeRTOS, Events in Zephyr
Task notification(FreeRTOS only)
A FreeRTOS task notification used as a lighter semaphore: an interrupt and a task count up the handler task's own notification value, with no kernel object.
Lesson: Task notifications in FreeRTOS
Deadlock (ABBA)
Two tasks take the same two mutexes in opposite order (ABBA) and wait for each other forever. The kernel does not notice; the wait-for graph shows the cycle.
Lesson: Deadlock
Cooperative threads(Zephyr only)
A Zephyr cooperative thread is never preempted: a more urgent thread that wakes while it runs has to wait until it sleeps.
Lesson: Cooperative threads in Zephyr
Tick count overflow(FreeRTOS only)
The 32-bit FreeRTOS tick count wraps to 0. One wake-up time falls after the wrap and goes into the overflow delayed list, and the two lists swap at the wrap.
Lesson: Tick count overflow in FreeRTOS
How the simulator works
- Models of the real kernels. The simulator runs line-by-line models of FreeRTOS V11.3.3 and Zephyr v4.5.0, and shows the kernel source next to the run with the line it has reached. Every scenario also runs on the real kernels (FreeRTOS under QEMU, Zephyr as a
native_simprogram), and the models must make the same scheduling decisions. - What you can change. Depending on the scenario: task priorities and start times, preemption and time slicing, whether an object is a mutex or a semaphore, the length of a queue, a deadline. Switching the kernel keeps the current tick.
- Keyboard. In the simulator, Space plays and pauses, ← and → step back and forward,, and . step one kernel line, Home starts again and C runs to the next event ticked under "Break on".
- Share a moment. "Copy link" makes a link to the scenario, kernel, step and parameters on screen.