ChibiOS/RT implements a strictly priority-based scheduling strategy, the module responsible for threads scheduling is called the scheduler. In this module are also defined the data structures used globally by the RTOS.
The scheduler is affected by the following global settings:
|Time slice, in system ticks, of the round-robin interval.|
The ChibiOS/RT scheduler is the module responsible for threads scheduling, it also exports a low level API that is used by the other modules in order to implement synchronization primitives of any kind.
ChibiOS/RT is designed to be upgradeable to a multi-core capable RTOS. Because of this all the internal data structures are encapsulated into a single system class. In a single core implementation there is a single system object. When multi core MCUs will become common multiple system instances will be possible.
System class diagram:
This, diagram of the system class shows the most important classes relationships in ChibiOS/RT:
The ready list is probably the most important data structure in ChibiOS/RT. It is a closed bidirectional ordered list of threads representing the threads eligible for execution. The list is organized as follow:
Note that the current thread is not part of the list, it is pointed by a global pointer.
The system always runs a special thread called “idle thread”. This thread has the lowest priority level in the system (one), and is executed only when no other thread is ready for execution.
The purpose of the idle thread is to define what the system does when there is nothing to do, usually it is an empty loop or a loop containing a single, architecture-dependent, “Wait for Interrupt” instruction that stops the CPU until a interrupt is detected. Stopping the CPU can reduce during idle times can reduce the system power consumption.
One important details is that the idle thread can only be in the READY or CURRENT states, it is not allowed to go in any of the sleeping states nor to terminate. The idle thread is automatically created on system initialization and lasts until the system is shut down.