- 论坛徽章:
- 0
|
理解后面的MarkExclusiveGlobal(physical_address,processor_id,4)和MarkExclusiveLocal(physical_address,processor_id,4)需要消耗一定的脑细胞,如果从实用角度,作为一个底层驱动程序的开发者,理解了Linux内核中的信号量和自旋锁的软件实现原理已经足够,因为99.9%的读者并没有多少机会要亲自写一个信号量和自旋锁的实现(如果要自己写这么个东东,那么透彻理解ARM中的这种为实现并发共享而存在的指令原理是必需的),再则海豚自己也比较懒,一看ARM的手册上大篇幅的讲解这种并发共享原理就有点害怕,而且现在要学的东西太多,有些东西了解个大概其实是一种很明智的选择。三国时候诸葛亮就是个典型,《三国演义》第三十七回(司马徽再荐名士 刘玄德三顾草庐)有精彩的描写: ...徽曰:“孔明与博陵崔州平,颖川石光元,汝南孟公威与徐元直四人为密友。此四人务于精纯,惟孔明独观其大略。...”
所以海豚这里偷懒啦,把ARM V6手册上的两条重要的段落摘录于下,再加一点点自己的理解作为小点评,供同学们参考:
1.MarkExclusiveGlobal(<physical_address>,<processor_id>,<size>) records the fact that processor
<processor_id> has requested exclusive access covering at least <size> bytes from address
<physical_address>. The size of region marked as exclusive is IMPLEMENTATION DEFINED, up to a
limit of 128 bytes, and no smaller than <size>, and aligned in the address space to the size of the
region. It is UNPREDICTABLE whether this causes any previous request for exclusive access to any
other address by the same processor to be cleared.
2.MarkExclusiveLocal(<physical_address>,<processor_id>,<size>) records in a local record the fact
that processor <processor_id> has requested exclusive access to an address covering at least <size>
bytes from address <physical_address>. The size of the region marked as exclusive is
IMPLEMENTATION DEFINED, and can at its largest cover the whole of memory, but is no smaller than
<size>, and is aligned in the address space to the size of the region. It is IMPLEMENTATION DEFINED
whether this also performs a MarkExclusiveGlobal(<physical_address>,<processor_id>,<size>).
上面的这两段文字很好很强大,即使是出来打酱油的同学也应该好好读一读的。海豚已经把相关的内容精简到上面这两段了,如果再能耐着性子看完下面的STREX的伪代码,简历上也许就可以号称精通ARM processor :
STREX operation:
if ConditionPassed(cond) then
processor_id = ExecutingProcessor()
physical_address = TLB(Rn)
if IsExclusiveLocal(physical_address,processor_id,4) then
if Shared(Rn) == 1 then
if IsExclusiveGlobal(physical_address,processor_id,4) then
Memory[Rn,4] = Rm
Rd = 0
ClearExclusiveByAddress(physical_address,processor_id,4)
else
Rd = 1
else
Memory[Rn,4] =Rm
Rd = 0
else
Rd = 1
ClearExclusiveLocal(processor_id) |
|