Chapter 5. Cheat Sheet For Locking

Table of Contents

Table of Minimum Requirements

Pete Zaitcev gives the following summary:

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_irqsaveNone        
Softirq Aspin_lock_irqspin_lock_irqspin_lock       
Softirq Bspin_lock_irqspin_lock_irqspin_lockspin_lock      
Tasklet Aspin_lock_irqspin_lock_irqspin_lockspin_lockNone     
Tasklet Bspin_lock_irqspin_lock_irqspin_lockspin_lockspin_lockNone    
Timer Aspin_lock_irqspin_lock_irqspin_lockspin_lockspin_lockspin_lockNone   
Timer Bspin_lock_irqspin_lock_irqspin_lockspin_lockspin_lockspin_lockspin_lockNone  
User Context Aspin_lock_irqspin_lock_irqspin_lock_bhspin_lock_bhspin_lock_bhspin_lock_bhspin_lock_bhspin_lock_bhNone 
User Context Bspin_lock_irqspin_lock_irqspin_lock_bhspin_lock_bhspin_lock_bhspin_lock_bhspin_lock_bhspin_lock_bhdown_interruptibleNone