I am working on a performance improvement of a driver and should consider the possibility of deadlock. In a SoftIRQ context, spin_lock will be held and protect some variable. In this case, should I use spin_lock or spin_lock_bh? spin_lock_bh sounds like safer, but I have a general question about SoftIRQ implementation.
- the same softIRQ function can be scheduled on the same CPU during the execution of the SoftIRQ -> we need to use spin_lock_bh in the SoftIRQ
- the same softIRQ function can be scheduled on the other CPU, but not the same CPU -> we may use spin_lock in the SoftIRQ
What is true from the above statement?
From Linux Kernel Development (2nd edition):
The reason is simple: during softIRQ software interrupts are disabled.
So it is sufficient to use plain
spin_lock()
in a softIRQ function.