Why disabling interrupts disables kernel preemption and how spin lock disables preemption

前端 未结 4 1895
梦谈多话
梦谈多话 2020-12-13 10:55

I am reading Linux Kernel Development recently, and I have a few questions related to disabling preemption.

  1. In the \"Interrupt Control\" section of

4条回答
  •  被撕碎了的回忆
    2020-12-13 11:55

    Interrupt disabling disables some forms of kernel preemption, but there are other ways kernel preemption can happen. For this reason, disabling interrupts is not considered a safe way to prevent kernel preemption.

    For instance, with interrupts disabled, cond_resched() would still cause preemption, but wouldn't if preemption was explicitly disabled.

    This is why, in regards to your second question, spin locks don't use interrupt disabling to disable preemption. They explicitly call preempt_disable() which increments preempt_count, and disables all ways that preemption can happen except for explicit calls to schedule().

提交回复
热议问题