DMB DSB ISB 简介
DMB: Data memory barrier
理解DMB指令,先看下面例子,在core 0和core1上同時跑兩個不同的指令(如下表所示)
| Write A; | Load B; |
| Write B; | Load B; |
這里core0在執(zhí)行兩個指令,寫A B兩個值的時候,可能會發(fā)生亂序也可能Write A時發(fā)生Cache Miss,那么就會導致在cache中 A的最新值更新慢于B的最新值。于是在core1中的指令Load B就會拿到新值,而Load A 就會拿到舊值。如果A與B有相互關(guān)系的話,便可能產(chǎn)生死鎖等問題。這里有一個典型的例子:https://lkml.org/lkml/2012/7/13/123
于是,就有了下面的解決方法:
| Write A | Load B |
| DMB; | Load A |
| Write B |
在core0所執(zhí)行的兩條指令之間加入一個DMB. 這樣,若core1在Load B時,拿到了最新值。那么Load A 也一定拿到了最新值。這就是DMB的作用:DMB前面的LOAD/STORE讀寫的最新值的acknowledgement在時間上一定先于DMB之后的指令。
SB 和DMB容易混淆。他們的區(qū)別在于:DMB可以繼續(xù)執(zhí)行之后的指令,只要這條指令不是內(nèi)存訪問指令。而DSB不管它后面的什么指令,都會強迫CPU等待它之前的指令執(zhí)行完畢。其實在很多處理器設(shè)計的時候,DMB和DSB沒有區(qū)別(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 instruction start.
An Instruction Synchronization Barrier (ISB) flushes the pipeline in the processor, so that all instructions following the ISB are fetched from cache or memory, after the ISB has been completed.
ISB不僅做了DSB所做的事情,還將流水線清空[2]。于是他們的重量級排序可以是:ISB>DSB>DMB
總結(jié)
以上是生活随笔為你收集整理的DMB DSB ISB 简介的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 2020-12-7(字节,半字,字,双字
- 下一篇: 2020-12-14(全局/静态对象的构