<dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><small id="yhprb"></small><dfn id="yhprb"></dfn><small id="yhprb"><delect id="yhprb"></delect></small><small id="yhprb"></small><small id="yhprb"></small> <delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"></dfn><dfn id="yhprb"></dfn><s id="yhprb"><noframes id="yhprb"><small id="yhprb"><dfn id="yhprb"></dfn></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><small id="yhprb"></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn> <small id="yhprb"></small><delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn>

新聞中心

EEPW首頁(yè) > 嵌入式系統 > 設計應用 > 分析Linux中Spinlock在A(yíng)RM及X86平臺上的實(shí)現

分析Linux中Spinlock在A(yíng)RM及X86平臺上的實(shí)現

作者: 時(shí)間:2012-12-08 來(lái)源:網(wǎng)絡(luò ) 收藏

  本文主要以2.6.22.6內核分析中spinlock在上的實(shí)現(不同版本的內核實(shí)現形式會(huì )有一些差異,但原理大致相同)。此處默認大家已經(jīng)熟悉了spinlock的使用,重點(diǎn)解釋容易引起迷惑的體系結構相關(guān)的實(shí)現部分。

  一、spin_lock(lock)的實(shí)現

  /***include/linux/spinlock.h中***/

  #if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)

  //如果配置了SMP或配置自旋鎖調試功能

  # include linux/spinlock_api_smp.h>

  #else //如果是單處理器且不配置自旋鎖調試功能

  # include linux/spinlock_api_up.h>

  #endif

  ……

  #define spin_lock(lock) _spin_lock(lock)

  1、如果是單處理器

  /****include/linux/spinlock_api_up.h****/

  #define _spin_lock(lock) __LOCK(lock)

  #define __LOCK(lock)

  do { preempt_disable(); __acquire(lock); (void)(lock); } while (0)

 ?。?)preempt_disable():禁止搶占

 ?。?)__acquire(lock):在include/linux/compiler.h中有定義

  #ifdef __CHECKER__

  ……

  # define __acquire(x) __context__(x,1)

  # define __release(x) __context__(x,-1)

  #else

  ……

  # define __acquires(x)

  # define __releases(x)

  這是一對用于sparse對代碼檢測的相互關(guān)聯(lián)的函數定義,第一句表示要增加變量x的計數,增加量為1,第二句則正好相反,這個(gè)是用來(lái)函數編譯的過(guò)程中。如果在代碼中出現了不平衡的狀況,那么在Sparse的檢測中就會(huì )報警。如果要使用Sparse檢測功能就需要安裝sparse工具(參考相關(guān)安裝方法),然后編譯內核

  #make zImage C=1 (C=1,只檢測新編譯的文件,C=2是查所有文件)

  Sparse會(huì )定義__CHECKER__,如果你沒(méi)有使用sparse工具,__acquire(lock)則定義為空

 ?。?)(void)(lock):通過(guò)插入一個(gè)變量本身的求值表達式,使編譯器不再報警,如:“variable 'lock' is defined but never used”。這種求值不會(huì )影響運行時(shí)的速度。

  2、如果配置了SMP

  /****include/linux/spinlock_api_smp.h中****/

  void __lockfunc _spin_lock(spinlock_t *lock) __acquires(lock);

  /***kernel/spinlock.c***/

  void __lockfunc _spin_lock(spinlock_t *lock)

  {

  preempt_disable();

  //關(guān)閉搶占

  spin_acquire(lock->dep_map, 0, 0, _RET_IP_);

  //自旋鎖調試用,在沒(méi)有定義自旋鎖調試的時(shí)候是空函數

  _raw_spin_lock(lock);

  }

  /***include/linux/spinlock.h***/

  #ifdef CONFIG_DEBUG_SPINLOCK

  extern void _raw_spin_lock(spinlock_t *lock);//在lib/spinlock_debug.c中實(shí)現

  #else //smp情況

  # define _raw_spin_lock(lock) __raw_spin_lock((lock)->raw_lock)

  3、__raw_spin_lock在處理器上的實(shí)現

  /******include/asm-arm/spinlock_types.h***/

  typedef struct {

  volatile unsigned int lock;

  } raw_spinlock_t;

  #define __RAW_SPIN_LOCK_UNLOCKED { 0 }

  /******include/asm-arm/spinlock.h***/

  #if __LINUX__ARCH__ 6

  #error SMP not supported on pre-ARMv6 CPUs //ARMv6后,才有多核ARM處理器

  #endif

  ……

linux操作系統文章專(zhuān)題:linux操作系統詳解(linux不再難懂)

上一頁(yè) 1 2 下一頁(yè)

關(guān)鍵詞: Linux Spinlock ARM X86平臺

評論


相關(guān)推薦

技術(shù)專(zhuān)區

關(guān)閉
国产精品自在自线亚洲|国产精品无圣光一区二区|国产日产欧洲无码视频|久久久一本精品99久久K精品66|欧美人与动牲交片免费播放
<dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><small id="yhprb"></small><dfn id="yhprb"></dfn><small id="yhprb"><delect id="yhprb"></delect></small><small id="yhprb"></small><small id="yhprb"></small> <delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"></dfn><dfn id="yhprb"></dfn><s id="yhprb"><noframes id="yhprb"><small id="yhprb"><dfn id="yhprb"></dfn></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><small id="yhprb"></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn> <small id="yhprb"></small><delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn>