Chinaunix首页 | 论坛 | 博客
  • 博客访问: 244718
  • 博文数量: 32
  • 博客积分: 557
  • 博客等级: 中士
  • 技术积分: 431
  • 用 户 组: 普通用户
  • 注册时间: 2011-04-20 23:05
文章分类

全部博文(32)

文章存档

2015年(4)

2014年(2)

2012年(4)

2011年(22)

分类: LINUX

2011-06-26 22:47:04

Understanding the Linux Kernel:

spinlock header file relationships:
阅读(4138) | 评论(13) | 转发(2) |
给主人留下些什么吧!~~

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 {
                  &

wangjianchangdx2011-06-28 22:03:49

lockdep: lock class先放下