One thing that I have noticed in many projects is people who seem to misuse spinlocks, they are used instead of the other fixing primitives that should have been used.
Linux spin-lock exists only in multiprocessor assemblies (in single processes the gating of the spin-lock preprocessor jobs is empty), which are used for short circuits on a multiprocessor platform.
If the code cannot use the spin lock, it simply rotates the processor until the lock becomes free. Thus, any other process running on another processor should release the lock, or perhaps it can be released by the interrupt handler, but the wait event mechanism is a much better way to wait for an interrupt.
The ipqsave-spinlock primitive is a neat way to disable / enable interrupts so that the driver can block the interrupt handler, but it must be done long enough so that the process can update some variables shared by the interrupt handler if you disable it and you are not going to schedule it.
If you need to block an interrupt handler, use spin lock with irqsave.
For a general kernel lock, you should use the mutex / semaphore api, which will sleep on the lock if necessary.
To lock code running in other processes, use muxtex / semaphore. To block code running in an interrupt context, use irq save / restore or spinlock_irq save / restore
To block code running on other processors, use spin blocks and do not hold the lock for long.
I hope this helps
source share