uclinux-2008R1-RC8(bf561)到VDSP5的移植(30):atomic_t
来源:互联网 发布:spring源码视频教程 编辑:程序博客网 时间:2024/05/11 22:34
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;
}
以后再考虑一下性能问题。
- uclinux-2008R1-RC8(bf561)到VDSP5的移植(30):atomic_t
- uclinux-2008R1-RC8(bf561)到VDSP5的移植(13):未命名union的问题
- uclinux-2008R1-RC8(bf561)到VDSP5的移植(41):PLL造成的困扰
- uclinux-2008R1-RC8(bf561)到VDSP5的移植(42):__bad_size的问题
- uclinux-2008R1-RC8(bf561)到VDSP5的移植(43):__builtin_return_address的问题
- uclinux-2008R1-RC8(bf561)到VDSP5的移植(44):kmalloc和kzalloc的问题
- uclinux-2008R1-RC8(bf561)到VDSP5的移植(47): d_alloc引出的问题
- uclinux-2008R1-RC8(bf561)到VDSP5的移植(48): __cmpxchg的问题
- uclinux-2008R1-RC8(bf561)到VDSP5的移植(49):kernel_thread_helper的问题
- uclinux-2008R1-RC8(bf561)到VDSP5的移植(50):jiffies_64的定义问题
- uclinux-2008R1-RC8(bf561)到VDSP5的移植(52):cache.s的问题
- uclinux-2008R1-RC8(bf561)到VDSP5的移植(53):reboot.c的问题
- uclinux-2008R1-RC8(bf561)到VDSP5的移植(54): initramfs的问题
- uclinux-2008R1-RC8(bf561)到VDSP5的移植(55): filemap.c的问题
- uclinux-2008R1-RC8(bf561)到VDSP5的移植(1):前言
- uclinux-2008R1-RC8(bf561)到VDSP5的移植(2):代码注释
- uclinux-2008R1-RC8(bf561)到VDSP5的移植(3):Head.s
- uclinux-2008R1-RC8(bf561)到VDSP5的移植(5):CONFIG_BANK_x
- Flash纯脚本生成饼图
- tasklet学习实例
- Excel2007根据SQL语句生成透视图的一些关键点
- 在默认的设置下 SQL Server 不允许进行远程连接可能会导致此失败
- tasklet实验(加中断后的)
- uclinux-2008R1-RC8(bf561)到VDSP5的移植(30):atomic_t
- 网站日志系统的设计(一)
- SQL 导出导入大全(引)
- DB2中的数据类型
- 中国开发者的一个大的特点
- enable flashback database feature
- IIS常见问题
- ASP.NET 信任级别和策略文件
- MySQL入门学习