Question

On one processor, in the same thread, first raw_spin_lock() is called, then it starts a hrtimer and goes back to raw_spin_lock() again where it will spin there. In the hrtimer interrupt handler function, raw_spin_unlock() will be called.

Will this cause a deadlock or not? Will spinning on raw_spin_lock() disable interrupt?

Was it helpful?

Solution

raw_spin_lock_irq() and raw_spin_lock_irqsave() disable local interrupts, however interrupts on other CPUs still may occur. raw_spin_lock() does not.

Using spin locks with local interrupts enabled carelessly may lead to a deadlock if any interrupt handler attempts to lock already held spin lock. For the same reason none of the functions I mentioned is re-entrant. It will not be possible for the lock owner to ever release the lock. However, since in this case ISR will release the lock deadlock should not be a problem.

I think you should also check out completion variables which were designed to do what you seem to try to accomplish using spin lock in such unusual way. See this and also functions wait_on_completion(_interruptible)(_timeout)() here.

More information on spin locks can be found here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top