Why spin_lock_irqsave() is not used in wait_for_completion()?

86 views Asked by At

I was going through with internals of "Completion" APIs, and found out that we cannot use wait_for_completion() if interrupts are already disabled on the processor. However semaphore does not have this restriction.

Excerpt from kernel doc: https://docs.kernel.org/scheduler/completion.html

Note that wait_for_completion() is calling spin_lock_irq()/spin_unlock_irq(), so it can only be called safely when you know that interrupts are enabled. Calling it from IRQs-off atomic contexts will result in hard-to-detect spurious enabling of interrupts.

My queries are:

  1. Why cannot we call irqsave version of spinlock inside wait_for_completion() ?
  2. Despite having good interface, is it not making completion unpopular synchronization technique vis a vis semaphore?
0

There are 0 answers