- 论坛徽章:
- 0
|
SMP BARRIER PAIRING
-------------------
When dealing with CPU-CPU interactions, certain types of memory barrier should
always be paired. A lack of appropriate pairing is almost certainly an error.
A write barrier should always be paired with a data dependency barrier or read
barrier, though a general barrier would also be viable. Similarly a read
barrier or a data dependency barrier should always be paired with at least an
write barrier, though, again, a general barrier is viable:
CPU 1 CPU 2
=============== ===============
a = 1;
<write barrier>
b = 2; x = b;
<read barrier>
y = a;
Or:
CPU 1 CPU 2
=============== ===============================
a = 1;
<write barrier>
b = &a; x = b;
<data dependency barrier>
y = *x;
内核memory-barrier.txt的document摘下来的一段:
第一种情况我能够理解,cpu0会保证先写a=1, 然后再写b=2, cpu1保证,如果读到b=2,那么a肯定已经先读过a=1了。
第二种情况,cpu0 a=1, b=&a 这个用写屏障可以理解,但是cpu1 x=b, y=*x 这两条指令有天生的依赖关系,cpu不会乱序吧,为什么还要用这个什么data dependency barrier?
这个data dependency barrier和read barrier到底有什么区别,到现在还没有搞清楚,以前也没有搞清楚。
求指导。
|
|