Saturday, April 18, 2020

Linux: Why do we need an idle task?

There are two main reasons for having the idle task in the Linux kernel design:
  • Historical reason: In the older days, CPUs were not capable of idling in a lower power state, so they would constantly execute the no-operation (nop[1]) instruction. Now, with the advances in the CPU design, most processors will leverage a variant of the halt (HLT[2]) instruction that will allow them to go to a lower power mode.
  • Convenience: Instead of coding up and handling a special case for what to do when none of the processes are runnable i.e. the run queue is empty, we instead schedule the idle task, which is always runnable.