Intel® Moderncode for Parallel Architectures
Support for developing parallel programming applications on Intel® Architecture.

MFENCE and CLFLUSH

jimdempseyatthecove
Black Belt
262 Views

I have a question regarding CLFLUSH.

Presumably if I code in assembler (or equivilent intrinsics)

MFENCE
CLFLUSH [location]
SomeReadInstruction [location]

The processor will "drill" through the cache to obtain the contents of [location] (or locations in samecache line as location).

The problem I see though is what happens if an interruptand possiblythread context switch occures during the CLFLUSH? i.e. between CFLUSH and SomeReadInstruction.

It is potentialy possible that the interrupt, the O/S or read-ahead logic may have populated the cache line and then returning much later resume at SomeReadInstruction and then re-read the now stale cache line.

Alternately if I were only interested in read

XOR RAX,RAX
MFENCE
LOCK CMPXCHG [location], RAX

Is there any sequencing rules such as if MFENCE is followed by CFLUSH, is followed by memory reference instruction that the chain of instructions occure without interruption? If so, then would anyone have these rules? Or the Intel document name?

(the rule would have to nip abusive use of the rule such as the CIF problem in the old PDP-8 system)

TIA

Jim

0 Kudos
0 Replies
Reply