Round Robin scheduling explained

Unlike many other RTOSes, ChibiOS/RT supports multiple threads at the same priority level and schedules them using an round-robin strategy.

When it happens

A round-robin rotation can happen because of the following events:

  • The currently executed thread voluntarily invokes the chThdYield() API in order to allow the execution of another thread at the same priority level, if any.
  • The currently executed thread voluntarily goes into a sleep state, when the thread is awakened it goes behind any other ready thread at the same priority level.
  • If the CH_CFG_TIME_QUANTUM configuration constant is set to a value greater than zero and if the specified time quantum expired and if a thread with equal priority is ready then the currently executing thread is preempted and reinserted in the ready list behind any other thread at the same priority level.

Recommendations

As you can see the CH_CFG_TIME_QUANTUM setting is really useful only if there are threads at the same priority level that can run not preempted for long periods of time and that do not explicitly yield using chThdYield(). Because of this you should consider setting CH_CFG_TIME_QUANTUM to zero in your configuration file, this makes the kernel much faster and smaller and does not forbid the use of multiple threads at the same priority level.

More articles and guides are available on the technical wiki.

learn more

Need Tutorials?

Try the video tutorials and guides on Play Embedded.

learn more

Need Support?

The forums is the best place, registration required.

learn more