博文

目前显示的是 九月, 2013的博文

理解ARMV8 Device Memory的三个属性

ARMV8的spec.对device memory新引入了3个概念,分别是:Gathering, Reordering和Early Write acknowledge.下面从软件工程师的角度去阐述这三个概念。 Gathering The Gathering attribute determines whether it is permissible for either: • Multiple memory accesses of the same type, read or write, to the same memory location to be merged into a single transaction. • Multiple memory accesses of the same type, read or write, to different memory locations to be merged into a single memory transaction on an interconnect. 当某条load/store指令在pipeline的access memory阶段,发生cache miss(对于non-cacheable的memory就直接跳过,不过对于device memory一般都是non-cacheable的)后,需要将access memory请求发到总线上(例如AXI总线),通过AXI总线访问device memory,这个通过总线访问memory的过程被称为一次transaction. 为了优化性能考虑,在core内,会引入一个Buffer, 当发生一个access memory请求后,会将这个请求信息丢到Buffer中,若某条指令和上一条指令共享同一个cache line或者是访问同一个地址,那么,该条指令便不会再向总线发送transaction了,它share上一条指令 读到buffer中的结果。这个share的过程称为gathering. 读到buffer中的数据,如果是cacheable的,会在某个时间内腾到cache中。 Reordering reordering也是针对device memory的transaction, that is, 某个device memory的

Understanding DMB

DMB: Data memory barrier 理解DMB指令,先看下面例子,在core 0和core1上同时跑两个不同的指令(如下表所示) core 0 core 1 Write A; Write B; Load B; Load A; 这里core0在执行两个指令,写A B两个值的时候, 可能会发生乱序 也可能 Write A时发生Cache Miss ,那么就会导致在cache中 A的最新值更新慢于B的最新值。于是在core1中的指令Load B就会拿到新值,而Load A 就会拿到旧值。如果A与B有相互关系的话,便可能产生死锁等问题。这里有一个典型的例子: https://lkml.org/lkml/2012/7/13/123   于是,就有了下面的解决方法: core 0 core 1 Write A DMB; Write B Load B Load A 在core0所执行的两条指令之间加入一个DMB. 这样,若core1在Load B时,拿到了最新值。那么Load A 也一定拿到了最新值。这就是DMB的作用: DMB前面的LOAD/STORE读写的最新值的acknowledgement在时间上一定先于DMB之后的指令。 DSB 和DMB容易混淆。他们的区别在于:DMB可以继续执行之后的指令,只要这条指令不是内存访问指令。而DSB不管它后面的什么指令,都会强迫CPU等待它之前的指令执行完毕。其实在很多处理器设计的时候,DMB和DSB没有区别(DMB完成和DSB同样的功能)。他们以及ISB在arm reference中的解释如下[1]: A  Data Synchronization Barrier (DSB)  completes when all instructions before this instruction complete. A  Data Memory Barrier (DMB)  ensures that all explicit memory accesses before the DMB instruction complete before any explicit memory accesses after the DMB instruct