Why do we need a swapper task in linux?

后端 未结 4 1462
失恋的感觉
失恋的感觉 2020-12-08 02:11

The idle task (a.k.a. swapper task) is chosen to run when no more runnable tasks in the run queue at the point of task scheduling. But what is the usage for this so special

4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-08 02:54

    The linux kernel maintains a waitlist of processes which are "blocked" on IO/mutexes etc. If there is no runnable process, the idle process is placed onto the run queue until it is preempted by a task coming out of the wait queue.

    The reason it has a task is so that you can measure (approximately) how much time the kernel is wasting due to blocks on IO / locks etc. Additionally it makes the code that much easier for the kernel as the idle task is the same as every task it needs to context switch, instead of a "special case" idle task which could make changing kernel behaviour more difficult.

提交回复
热议问题