I have read Intel 64 and IA-32 Architectures SDM vol 3A, 9.2 MEMORY ORDERING, but there was one question that kept bothering me.
If I first write to a memory address, then send an interprocessor interrupt(IPI) with x2APIC, that mean sending IPI doesn't need writing memory (just use wrmsr). Another core recive the IPI and read the memory, will it read the correct value?
For example:
Initially x = 0
Processor 0:
mov [ _x], 1
wrmsr # use x2APIC to send IPI
Processor 1:
# resive IPI, in the interrupt service routine:
mov r1, [ _x]
Is r1 = 0 allowed ?
That is an interesting question. On the face of it, one would think that since
WRMSRis a serializing instruction it flushes the preceding memory writes and all is well. Even then, to quote the manual:(Emphasis mine)
It doesn't say anything about the ordering with respect to sending the IPI as that is part of the current instruction, not the next one. So this theoretically means the other core could execute the
mov r1, [ _x]while the originating core is still busy flushing stuff but is very unlikely given that the target core would need to service the interrupt which probably has a lot higher latency.As @harold mentioned, this point is moot since
WRMSRis not always serializing. Reading the footnote that I initially missed:So there is absolutely no guarantee that the write to
xis flushed.