之所以要写这篇东西是因为想把之前在公司的一些问题总结一下,在内存相关操作中一些ordering和dependency的问题一直没能太搞明白,所以最近空闲下来静下心研究了一下,觉得还是有所收获,期待各路IA高手们来进行拍砖。一直存在的问题有如下三个
- memory ordering究竟是指的什么ordering
- 为什么在IA强ordering的情况下RAR还要加lfence
- 为什么load相关的操作一直只需要一个port
memory ordering
what is memory ordering这个问题真的是困惑了我好久。
from the IA developer manual volume3 chapter8.2 we can find the definition
*The term memory ordering refers to the order in which the processor issues reads(loads) the writes(store) through the system bus to system memory
然后在manual里面就指出了其实在单processor的系统下面有如下ordering的规则
- 两个read之间是不能乱序的
- write after write是不能乱序的
- write after read 是不能乱序的
- read after write是不能乱序的(此时read和write的地址一致)
初看不会去细想这个乱序究竟是什么,但是当要深入去思考其out of order的一些机制时就发现不得不考虑以上的问题。
下面我就给大家说下order的概念。
其实order要分为不同的层面来看
1. 指令被