summaryrefslogtreecommitdiff
path: root/schulung_tools/notes/kernel-locking.txt
diff options
context:
space:
mode:
authorManuel Traut <manut@linutronix.de>2019-01-11 08:35:12 +0100
committerJohn Ogness <john.ogness@linutronix.de>2019-01-28 19:59:32 +0106
commit0f2bdbda59d69191eb80ee223bbbbf2f8061e891 (patch)
treede351ab3f8191079bb1a425f07fd303f5c72821c /schulung_tools/notes/kernel-locking.txt
parent2268f2b2371e02762bf511cf1db1e3609b58f849 (diff)
schulung_tools/notes add some kernel notes
they should be converted to a 'Kernel API' slideset. Signed-off-by: Manuel Traut <manut@linutronix.de>
Diffstat (limited to 'schulung_tools/notes/kernel-locking.txt')
-rw-r--r--schulung_tools/notes/kernel-locking.txt50
1 files changed, 50 insertions, 0 deletions
diff --git a/schulung_tools/notes/kernel-locking.txt b/schulung_tools/notes/kernel-locking.txt
new file mode 100644
index 0000000..1757227
--- /dev/null
+++ b/schulung_tools/notes/kernel-locking.txt
@@ -0,0 +1,50 @@
+ ++ locking
+ Documentation/kernel-hacking/locking.rst
+ - atomic operations
+ Documentation/atomic_t.txt
+ atomic_t atomic64_t and atomic_long_t
+ atomic_read(), atomic_set()
+ atomic[_fetch]_{add,sub,inc,dec}()
+ atomic[_fetch]_{and,or,xor,andnot}()
+ ..
+ - mutex
+ waiter can sleep, not usable in tasklets/timer/irqs
+ - spinlock / rwlock
+ spin_lock # use if lock is shared in different tasklets / only in user context
+ spin_lock_bh / disables softirqs # use if lock is shared in user context and softirqs (tasklets/timer)
+ spin_lock_irqsave / disables irqs # use if lock is shared in user context and irq context
+ --> Use irqsave variant if you're unsure
+ --> Avoid holding spinlock for more than 5 lines of code and across any
+ function call (except accessors like :c:func:`readb()`).
+
+============== ============= ============= ========= ========= ========= ========= ======= ======= ============== ==============
+. IRQ Handler A IRQ Handler B Softirq A Softirq B Tasklet A Tasklet B Timer A Timer B User Context A User Context B
+============== ============= ============= ========= ========= ========= ========= ======= ======= ============== ==============
+IRQ Handler A None
+IRQ Handler B SLIS None
+Softirq A SLI SLI SL
+Softirq B SLI SLI SL SL
+Tasklet A SLI SLI SL SL None
+Tasklet B SLI SLI SL SL SL None
+Timer A SLI SLI SL SL SL SL None
+Timer B SLI SLI SL SL SL SL SL None
+User Context A SLI SLI SLBH SLBH SLBH SLBH SLBH SLBH None
+User Context B SLI SLI SLBH SLBH SLBH SLBH SLBH SLBH MLI None
+============== ============= ============= ========= ========= ========= ========= ======= ======= ============== ==============
+
+Table: Table of Locking Requirements
+
++--------+----------------------------+
+| SLIS | spin_lock_irqsave |
++--------+----------------------------+
+| SLI | spin_lock_irq |
++--------+----------------------------+
+| SL | spin_lock |
++--------+----------------------------+
+| SLBH | spin_lock_bh |
++--------+----------------------------+
+| MLI | mutex_lock_interruptible |
++--------+----------------------------+
+
+Table: Legend for Locking Requirements Table
+