????????????????????????????ibm???????
???????????semaphore???????? ???д??
???????????????????????????????????????????????
????/* Please don't access any members of this structure directly */
????struct semaphore {
????raw_spinlock_t        lock;
????unsigned int        count;
????struct list_head    wait_list;
????};
????void sema_init(struct semaphore *sem?? int val)?? // val??????????????????????????????????1 ??????????????????>1 ???????????????????????????
????down_interruptible(struct semaphore *sem); // ???????? ??????????ж???
????up(struct semaphore *sem); // ????????????????????????????????????????????
??????д???????rwsem ?????д?????????? ?????????????
/* the rw-semaphore definition
* - if activity is 0 then there are no active readers or writers
* - if activity is +ve then that is the number of active readers
* - if activity is -1 then there is one active writer
* - if wait_list is not empty?? then there are processes waiting for the semaphore
*/
struct rw_semaphore {
__s32            activity;
raw_spinlock_t        wait_lock;
struct list_head    wait_list;
#ifdef CONFIG_DEBUG_LOCK_ALLOC
struct lockdep_map dep_map;
#endif
};
init_rwsem(sem)    ??
// ?????
down_read(struct rw_semaphore *sem);
// ??????????
up_read(struct rw_semaphore *sem);
//?????????
down_write(struct rw_semaphore *sem);
//???д?????
up_write(struct rw_semaphore *sem);
// ???д?????
?????????壨mutex??????count=1???????????????????????л???????????????????????????????
struct mutex {
/* 1: unlocked?? 0: locked?? negative: locked?? possible waiters */
atomic_t        count;
spinlock_t        wait_lock;
struct list_head    wait_list;
#if defined(CONFIG_DEBUG_MUTEXES) || defined(CONFIG_SMP)
struct task_struct    *owner;
#endif
#ifdef CONFIG_DEBUG_MUTEXES
const char         *name;
void            *magic;
#endif
#ifdef CONFIG_DEBUG_LOCK_ALLOC
struct lockdep_map    dep_map;
#endif
};
mutex_init(mutex)??
// init ??????
mutex_lock();
//?????????????????????
mutex_unlock??????
//????????
????????????atomic????????????????????????????????У????????????
???????????smp???????壬????????????cpu??С?????????????
???????????sequence??
???????
???????д?????????????????????д????????д?????????????????????????????t????????д?????????????????α????????????????????д???????????????????????????????????С????????????????????д?????????????????????????????seqlock??
Seqlock??
typedef struct {
unsigned sequence;
spinlock_t lock;
} seqlock_t;
seqlock_init(x) / DEFINE_SEQLOCK(x)
// init
write_seqlock(seqlock_t *sl) ;
// ???д??
write_sequnlock(seqlock_t *sl);
read_seqbegin ?? read_seqretry ??????
//????????д????????????????????.
??????????drivers/md/md.c
retry:
seq = read_seqbegin(&bb->lock);
memset(bbp?? 0xff?? PAGE_SIZE);
for (i = 0 ; i < bb->count ; i++) {
u64 internal_bb = p[i];
u64 store_bb = ((BB_OFFSET(internal_bb) << 10)
| BB_LEN(internal_bb));
bbp[i] = cpu_to_le64(store_bb);
}
bb->changed = 0;
if (read_seqretry(&bb->lock?? seq))
goto retry;
RCU??read-copy-update
??????linux?????????????????????????????????????Rcu???迼?????д?????????
?????????????rwlock?????????????????????д?????????RCU???????????????д????????????д??????????????10%????????????????????????????????????????????????????????
????Rcu_read_lock //???????????
????Rcu_read_unlock //?????
????Rcu_assign_pointer(ptr??new_ptr)
????//??????У?????????????????????????comletion??
????//???????????????????????
????//????????wait/ wake_up
????struct __wait_queue_head {
????spinlock_t lock;
????struct list_head task_list;
????};
????typedef struct __wait_queue_head wait_queue_head_t;
??????????completion?? ???????????????????·???????????????Э????????·????????????????????壬???????wait_list???????usb ????urb????????
????????????????????к????????????????????????????????wait_for_completion???????????????????
????Completion??????????????????????????????????????????????????????????
????struct completion {
????unsigned int done;
????wait_queue_head_t wait;
????};
????????
????DECLARE_COMPLETION(x)
????// ???????completion
????init_completion(struct completion *x)??
????// ???init
????INIT_COMPLETION(x);
????// ?????????????ù???completion
????Wait_for_completion??struct completion *x????
????complete(struct completion *);
????//done +1???????????????
????Complete_all
????// ???????е????????á?
???????????
???????????????У????????д????????????????????
????????????????????????????????????μ????????????????μ???????????
?????????????????????????????????????
?????? ????????????????????????????????????????????????????????????????????д????????????????????????????????????????????? д????????????д???????????????????д???????????á??????????????????????????????????????????д?????????????????????????????????磺
????tmp = ttt; *addr = 5; mb(); val = *data;
???????????????????????????????????????????????????????????tmp?????????????????????????????????????????????????????????У??????????????????
??????Linux?У??????????barrier()????????asm volatile(“”:::”memory”)
????smp_rmb(); // ??????
????smp_wmb(); //д????
????smp_mb?????? // ???????
????Blk?????????
????BKL???????????????????????????????????????????????Linux????SMP??????????????????????????????????
????BKL???????
????????BKL???????????????? ????????????????????????????????????????????????????????????????á????????????????????????BKL???????????????????????????????????????????????????
????BKL?????????????????????????????????????????????????????????????BKL????????????????С?
????BKL???к???:
??????????в????????BKL???????????????????????lock_kernel()?????????????????????????????unlock_kernel()???????????????????????????????????BKL???????????????????????????????£?BKL?????????????????????????.
?????????????????????? ?????????????ж? ??????????????????ж???ɡ?????????????????????? ???????ж? ???н???????????????????????cpu???????????????????Щ??????????????????