計算機體係結構3_單處理器內存訪問順序
一,單處理器訪問順序
1.指令execute和指令retire
Instruction execution creates results and status and determines whether or not the instruction causes an exception.
Instruction retirement commits the results of instruction execution, in program order, to software-visible resources such as memory, caches, write-combining
buffers, and registers, or it causes an exception to occur if instruction execution created one.
Retire instructions in program order, but implementations can execute instructions in any order, subject only to data dependencies.
2.讀順序
Generally, reads do not affect program order because they do not affect the state of software-visible resources other than register contents.
However, some system devices might be sensitive to reads. In such a situation software can map a read-sensitive device to a memory type that enforces strong
read-ordering, or use read/write barrier instructions to force strong read-ordering.
讀不會影響程序運行順序,因為讀不會影響軟件可見資源的狀態和內容,對於讀敏感的設備,軟件可以將設備映射到strong-read-ordering的內存,或使用
barrier強製讀順序。
3.讀準則
對於可緩存的內存,以下規則管理讀的順序:
當亂序讀對軟件透明,與順序執行具有相同的效果時,亂序讀允許。
允許預讀。
當讀的位置與寫位置相同時,不允許讀重排到寫前邊,否則,可以重排讀操作到寫操作前邊。
4.寫準則
寫會影響程序運行順序,因為寫會影響軟件可見資源的狀態和內容,以下規則管理寫的順序:
通常不允許亂序寫,如果執行亂序寫,寫操作隻有知道前邊的操作完成時,才可以寫內存。處理器需要在軟件不可見的buffer保存亂序寫的結果,
直到可以將結果寫到內存中。
對write-combining內存可能會執行亂序寫。
不允許預測寫,像亂序寫一樣,隻有之前所有的操作都完成時,才可以將預寫的結果保存到內存中,處理器通過一個私有buffer暫存預寫結果直
到被這些結果寫到內存中。
允許將寫的結果緩存在buffer中,之後按照程序執行順序將buffer中結果再寫入到主存中。用於暫存寫結果的buffer不被軟件可見,但是之後
對被緩存數據的讀寫操作可以直接通過此buffer來完成。
允許寫合並,通過使用使用類型為wc內存或non-temporal store指令,將多個寫操作合並為一個寫操作。當使用寫合並時,其他寫不同地址的
操作可能會被提前執行,隻有當寫順序不影響程序執行順序時,才可以被使用。
參考:
AMD64 Architecture Programmer’s Manual Volume 2: System Programming Chpter7
最後更新:2017-04-03 14:54:04