arm linux多核同时获取读写锁, 会死循环吗, 还是都得到写锁
2017-01-18
文来自本人的旧博客: http://blog.163.com/awaken_ing/blog/static/120613197201631133058159
本篇只提问, 不解答, 祝开心.
如果读写锁是unlocked, 然后cpu 0和cpu 1都想获取写锁, 如表格所示, CPU 0在t2时刻执行的是wfene, 这时, CPU 1执行的是ldrex, 然后是否会有cpu能够获取到锁? 源码来自 linux-3.10.86/arch/arm/include/asm/spinlock.h archwritelock()
时间 | CPU0 | 时间 | CPU1 |
---|---|---|---|
t0/t6 | 1: ldrex %0, [%1] | ||
t1/t7 | teq %0, #0 | ||
t2 | WFE("ne") | t2 | 1: ldrex %0, [%1] |
t3 | strexeq %0, %2, [%1] | t3 | teq %0, #0 |
t4 | teq %0, #0 | t4 | WFE("ne") |
t5 | bne 1b | t5 | strexeq %0, %2, [%1] |
t6 | t6 | teq %0, #0 | |
t7 | t7 | bne 1b |
CPU 0和CPU 1都拿到 写锁? 两个CPU都死循环? 好像不应该啊? 本篇只提问, 不解答, 祝开心. ^_^
附 linux-3.10.86/arch/arm/include/asm/spinlock.h
static inline void arch_write_lock(arch_rwlock_t *rw)
{
unsigned long tmp;
__asm__ __volatile__(
"1: ldrex %0, [%1]\n"
" teq %0, #0\n"
WFE("ne")
" strexeq %0, %2, [%1]\n"
" teq %0, #0\n"
" bne 1b"
: "=&r" (tmp)
: "r" (&rw->lock), "r" (0x80000000)
: "cc");
smp_mb();
}
本文地址: https://awakening-fong.github.io/posts/arm/arm_smp_rwlock
转载请注明出处: https://awakening-fong.github.io
若无法评论, 请打开JavaScript, 并通过proxy.
blog comments powered by Disqus