在armv8中,因为processor的预取,流水线, 以及多线程并行的执行方式,并且armv8-a中,使用的是一种weakly-ordered memory model,性能优化
不保证program order和execute order一致。多线程
因此有时须要显式的执行一些指令,来order本身的代码。架构
armv8涉及到的优化包括:app
1) multiple issue of instructions,超流水线技术,每一个cycle,都会有多个issue和execute,保证不了各个指令的执行order。dom
2) out-of-order execution,不少processor,都会对non-dependent的指令,作out-of-order的执行,性能
3) Speculation,分组预测,在遇到conditional instruction时,判断condition以前,就会执行以后的instruction。fetch
4) Speculative loads,预取,在执行上一条指令的同时,将下一条指令的数据,预取到cache中。优化
5) Load and Store optimizations,因为写主存的latency很大,processor能够作不少优化,write-merge,write-buffer等。ui
6) External memory systems,某些外部device,像DRAM,能够同时接受不一样master的req,Transaction可能会被buffered,reordered。线程
7) Cache coherent multi-core,一个cluster中的各个core,对同一个cache的update,看到的顺序不会是一致的。
8) Optimizing compilers,编译器在编译时的性能优化,可能打乱program order。
armv8支持的memory types:Normal memory和Device memory
Normal memory,主要指RAM,ROM,FLASH等memory,这类memory,processor以及compiler均可以对program作优化,
processor还能够增长repeate,reorder,merge的操做。
在须要固定memory order的状况下,须要显式调用barrier operations,
还有一些存在address dependence的状况,processor必须可以正确处理这些状况。
Device memory,一般都是peripheral对应的memory mapped。对于该memory type,processor的约束会不少;
1) write的次数,processor内部必须与program中的相同;
2) 不能将两次的writes,reads,等效为一个;
3) 可是对于不一样的device之间的memory access是不限制order的;
4) speculative是不容许的,对device的memory;
5) 在device memory中execute,也是不容许的;
Device memory的几个attribute:
1) Gather或者non-Gather,多个memory access merge为同一个single transaction,如两个byte write merge为一个halfword write
2) Reordering,同一个block中的access是否可以reorder。
3) Early Write Ack,write不写入device,经过中间buffer以后,即 return ack,是否能够。
四种device memory:
1) Device nGnRnE,最严的约束;
2) Device nGnRE,容许early
3) Device nGRE,容许reorder,early
4) Device GRE,容许gather,reorder,early
Memory attribute,arm系统中,memory都被分为各个region,每一个region都有本身的privilege level,memory type,cache policy;
这部分的管理是由MMU,来实现的,各个region都对应其中的一个或几个block、page。
对于normal memory,有shareable和cache property;
对于device memory,老是non-cacheable,outer-shareable,
shareable,用来指定这个location是不是与其余的core,共用的,share的。share的core之间须要保证coherency。
non-shareable,典型应用在AMP,有本身的独自cache,
inner,主要指processor本身的cache,在big-little中,表现为一个cluster,(仍是取决于具体实现)
outer,主要指processor外的cache,在big-little中,表现为两个cluster,(仍是取决于具体实现)
system,整个system的master,可能会包含GPU等
ARM架构中,包括几个barrier instruction,用来force必定的memory order,可是这样的指令,会减少一些软件的优化性能;
因此最好在须要的时候,再加这样的指令。
1) Instruction Synchronization Barrier(ISB),保证当前的pipeline中没有数据,ISB指令以前的指令都已经执行结束;
多用在context-switching code,cache control等。
2) Data Memory Barrier(DMB),保证全部data access的指令,load,store,在DMB指令以前都已经执行结束。
并不妨碍instruction的fetch。
3) Data Synchronization Barrier(DSB),等待某一类的指令结束,包括data access,instruction fetch。还会等待全部的
由该processor发起的cache,tlb,BP maintenance操做都已经完成,
DSB指令会直接stall processor,DMB不会,instruction仍然是能够执行的。
DMB和DSB,均可以加params,指定某些domain,load/store,
store-store,load-load,any-any指相应的乱序类型。
one-way barriers,AARCH64提供了一组显式指定before、after的指令,Load-Acquire,Store-Rlease,
Load-Acquire(LDAR),全部的load,store,完成以后,才开始执行,LDAR以后的指令开始执行。
Store-Release(STLR),全部的load,store,在STLR执行以后,才开始执行。