全部博文(32)
分类: LINUX
2011-06-26 22:47:04
wangjianchangdx2011-06-29 00:10:59
Ticket lock
http://en.wikipedia.org/wiki/Ticket_lock
A ticket lock works as follows; there are two integer values which begin at 0. The first value is the queue ticket, the second is the dequeue ticket.
When a thread arrives, it atomically obtains and then increments the queue ticket. It then atomically compares its ticket with the dequeue ticket. If they are the same, the thread is permitted to e
wangjianchangdx2011-06-28 23:40:22
spinlock operations for SMP:
in include/linux/spinlock.h,
spin_lock --> raw_spin_lock --> _raw_spin_lock -->
in kernel/spinlock.c,
__raw_spin_lock --> {preempt_disable(), spin_acquire(), LOCK_CONTENDED()}:
preempt_disable():
spin_acquire(): lockdep related operations, ignore it now
LOCK_CONTENDED(lock, do_raw_spin_trylock, do_raw_spin_lock) --> :
based on kernel's configuration
wangjianchangdx2011-06-28 22:17:41
In include/linux/spinlock_types.h still:
typedef struct raw_spinlock {
arch_spinlock_t raw_lock;
/* 去掉非必选项 */
} raw_spinlock_t;
Use arch_spinlock_t definition for x86 as default in arch/x86/include/asm/spinlock_types.h:
typedef struct arch_spinlock {
unsigned int slock;
} arch_spinlock_t;
就一个unsigned int, 还搞这么神秘
下面看spinlock的操作
wangjianchangdx2011-06-28 22:09:24
inlucde/linux/spinlock.h包含:
include/linux/spinlock_types.h:
typedef struct spinlock {
union {
struct raw_spinlock rlock;
#ifdef CONFIG_DEBUG_LOCK_ALLOC
# define LOCK_PADSIZE (offsetof(struct raw_spinlock, dep_map))
struct {
&