网站公告列表

  没有公告

加入收藏
设为首页
联系本站
您现在的位置: Analog安诺电子网 >> 文章 >> 技术交流 >> 文章正文
  uclinux-2008R1-RC8(bf561)到VDSP5的移植(30):atomic_t           ★★★ 【字体:
uclinux-2008R1-RC8(bf561)到VDSP5的移植(30):atomic_t
作者:快乐虾    文章来源:http://blog.csdn.net/lights_joy    点击数:    更新时间:2008-5-12    
atomic的相关操作定义都在include/asm/atomic.h中,各个平台有不同的实现方法,比如在x86平台上,CPU提供了在指令执行期间对总线加锁的手段。CPU芯片上有一条引线#HLOCK pin,如果汇编语言的程序中在一条指令前面加上前缀"LOCK",经过汇编以后的机器代码就使CPU在执行这条指令的时候把#HLOCK pin的电位拉低,持续到这条指令结束时放开,从而把总线锁住,这样同一总线上别的CPU就暂时不能通过总线访问内存了,保证了这条指令在多处理器环境中的原子性。
在uclinux目前对atomic的实现中,有这样一个注释:
 
/*
 * Atomic operations that C can't guarantee us. Useful for
 * resource counting etc..
 *
 * Generally we do not concern about SMP BFIN systems, so we don't have
 * to deal with that.
 *
 * Tony Kou (tonyko@lineo.ca)   Lineo Inc.   2001
 */
也就是它并不考虑SMP的情况,我希望对此进行适当的修改。但是在bf561中,它并没有提供类似x86这样锁定总线的功能,它有的仅仅是一个TESTSET的指令,而无法在硬件上提供其它的锁定机制,因此我们需要为其添加一个类似于spinlock这样的锁。
查了下linux-2.6.19的内核代码,在asm-sparc/atomic.h中有一个类似的作法:
/* We do the bulk of the actual work out of line in two common
 * routines in assembler, see arch/sparc/lib/atomic.S for the
 * "fun" details.
 *
 * For SMP the trick is you embed the spin lock byte within
 * the word, use the low byte so signedness is easily retained
 * via a quick arithmetic shift. It looks like this:
 *
 *   ----------------------------------------
 *   | signed 24-bit counter value | lock | atomic_t
 *   ----------------------------------------
 *   31                          8 7      0
 */
为省事,干脆单独在atomic_t的结构体中加上一个spinlock:
 
typedef struct {
     int counter;
     testset_t lock;
} atomic_t;
相应的操作函数也作一下修改,如:
#define atomic_add_negative(a, v)    (atomic_add_return((a), (v)) < 0)
static inline int atomic_sub_return(int i, atomic_t * v)
{
     int __temp = 0;
     long flags;
 
     adi_acquire_lock(&v->lock);
 
     local_irq_save(flags);
     v->counter -= i;
     __temp = v->counter;
     local_irq_restore(flags);
 
     adi_release_lock(&v->lock);
 
     return __temp;
}
以后再考虑一下性能问题。
文章录入:admin    责任编辑:admin 
  • 上一篇文章:

  • 下一篇文章:
  • 发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
    最新热点 最新推荐 相关文章
    [连载]TigerSHARC系列DSP概貌
    超声便携式设备的系统划分
    基于ADSP-TS201的实时SAR成像
    binutils-2.18/libiberty/Ma
    bfin-xxx-gcc主控Makefile中
    host-i686-pc-cygwin/gcc/Ma
    bfin-xxx-gcc中native目标的
    bfin-xxx-gcc中collect2目标
    bfin-xxx-gcc中objc目标的生
    [连载]TigerSHARC系列DSP概貌
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
    版权所有:Analog安诺电子网 湘ICP备06016315号