x86 sfence vs cache flush

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
garyv
Posts: 6
Joined: Wed Feb 26, 2014 4:43 am
Location: Southern China

x86 sfence vs cache flush

Post by garyv »

Code example:

mov [mem], eax
sfence

After sfence instruction is executed, the data in eax is written to cache or memory?

If it's written to memory, "cache flush" operation is NOT needed. Right?

If it's written to cache, how to do cache flush on x86?

This question is very important when a processor load some code to mem then execute the code.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: x86 sfence vs cache flush

Post by Combuster »

This serializing operation guarantees that every store instruction that precedes in program order the SFENCE instruction is globally visible before any store instruction that follows the SFENCE instruction is globally visible
Since this is the x86 manual, globally here means the scope of hardware mentioned in the documents, i.e. all processors. It might be RAM, but it can just as well be the cache coherency mechanisms that make sure all CPUs read the expected answer.
This question is very important when a processor load some code to mem then execute the code.
If the processor loads the code, then it doesn't matter if it ends up in cache or in memory, because it will see it just as it put it there.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Post Reply