Chapter 5. Cheat Sheet For Locking

Pete Zaitcev gives the following summary:

5.1. Table of Minimum Requirements

The following table lists the minimum locking requirements between various contexts. In some cases, the same context can only be running on one CPU at a time, so no locking is required for that context (eg. a particular thread can only run on one CPU at a time, but if it needs shares data with another thread, locking is required).

Remember the advice above: you can always use spin_lock_irqsave(), which is a superset of all other spinlock primitives.

Table 5-1. Table of Locking Requirements

 IRQ Handler AIRQ Handler BSoftirq ASoftirq BTasklet ATasklet BTimer ATimer BUser Context AUser Context B
IRQ Handler ANone         
IRQ Handler Bspin_lock_irqsave()None        
Softirq Aspin_lock_irq()spin_lock_irq()spin_lock()       
Softirq Bspin_lock_irq()spin_lock_irq()spin_lock()spin_lock()      
Tasklet Aspin_lock_irq()spin_lock_irq()spin_lock()spin_lock()None     
Tasklet Bspin_lock_irq()spin_lock_irq()spin_lock()spin_lock()spin_lock()None    
Timer Aspin_lock_irq()spin_lock_irq()spin_lock()spin_lock()spin_lock()spin_lock()None   
Timer Bspin_lock_irq()spin_lock_irq()spin_lock()spin_lock()spin_lock()spin_lock()spin_lock()None  
User Context Aspin_lock_irq()spin_lock_irq()spin_lock_bh()spin_lock_bh()spin_lock_bh()spin_lock_bh()spin_lock_bh()spin_lock_bh()None 
User Context Bspin_lock_irq()spin_lock_irq()spin_lock_bh()spin_lock_bh()spin_lock_bh()spin_lock_bh()spin_lock_bh()spin_lock_bh()down_interruptibleNone