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:
- Why cannot we call irqsave version of spinlock inside wait_for_completion() ?
- Despite having good interface, is it not making completion unpopular synchronization technique vis a vis semaphore?