Some useful resources:
http://www.makelinux.net/books/lkd2/?u=ch09lev1sec2
Introduce the basic knowlodge of SPIN_LOCK
http://h21007.www2.hp.com/portal/download/files/unprot/ddk/DDG/chap3.pdf
This paper introduce the spin_lock of hp_unix
and introduce some basic terminology such as: Driver's upper half and Driver's lower half
The classic illustration of a deadlock
Therefore, the core rule that applies to spinlocks is that any code must, while holding a spinlock, be atomic. It cannot sleep; in fact, it cannot relinquish the processor for any reason except to service interrupts (and sometimes not even then).
上述代码关键在于LDREX和STREX指令的应用。DREX和STREX指令是在V6以后才出现的,代替了V6以前的swp指令。可以让bus监控LDREX和STREX指令之间有无其它CPU和DMA来存取过这个地址,若有的话STREX指令的第一个寄存器里设置为1(动作失败),若没有,指令的第一个寄存器里设置为0(动作成功)。
不仅是自旋锁用到LDREX和STREX指令,信号量的实现也是利用LDREX和STREX指令来实现的。
09/23
Linux config difference
(1) origin config
CONFIG_PREEMPT
CONFIG_DEBUG_SPINLOICK is not defined
CONFIG_DEBUG_LOCK_ALLOC is not defined
CONFIG_SMP is not defined