Unreliable Guide To Locking

Paul Rusty Russell

      
     

This documentation is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

For more details see the file COPYING in the source distribution of Linux.


Table of Contents
1. Introduction
1.1. The Problem With Concurrency
2. Two Main Types of Kernel Locks: Spinlocks and Semaphores
2.1. Locks and Uniprocessor Kernels
2.2. Read/Write Lock Variants
2.3. Locking Only In User Context
2.4. Locking Between User Context and BHs
2.5. Locking Between User Context and Tasklets/Soft IRQs
2.6. Locking Between Bottom Halves
2.6.1. The Same BH
2.6.2. Different BHs
2.7. Locking Between Tasklets
2.7.1. The Same Tasklet
2.7.2. Different Tasklets
2.8. Locking Between Softirqs
2.8.1. The Same Softirq
2.8.2. Different Softirqs
3. Hard IRQ Context
3.1. Locking Between Hard IRQ and Softirqs/Tasklets/BHs
4. Common Techniques
4.1. No Writers in Interrupt Context
4.2. Deadlock: Simple and Advanced
4.2.1. Preventing Deadlock
4.2.2. Overzealous Prevention Of Deadlocks
4.3. Per-CPU Data
4.4. Big Reader Locks
4.5. Avoiding Locks: Read And Write Ordering
4.6. Avoiding Locks: Atomic Operations
4.7. Protecting A Collection of Objects: Reference Counts
4.7.1. Macros To Help You
4.8. Things Which Sleep
4.9. The Fucked Up Sparc
4.10. Racing Timers: A Kernel Pastime
5. Further reading
6. Thanks
Glossary
List of Tables
1-1. Expected Results
1-2. Possible Results
4-1. Consequences