Re: MemoryFence()
Andrew Fish <afish@...>
Ray,
toggle quoted messageShow quoted text
Yes I was writing a mail when I wrote the bugzilla…. Ray, Function calls are not compiler fences. The compiler just optimized the code way as dead code. For non VC++ we have a real compiler fence/barrier for MemoryFence(). I filed a bugzilla [1] so we can investigate this some more. I hit a real bug with clang using the MMIO functions a long time ago and I think that might be why the GCC version of the MemoryFence() got the compiler fence/barrier. If I had to guess VC++ is probably more conservative about volatiles and that is why we have not seen issue with VC++, but that is depending on non standard behavior. Well this probably explains why we don’t have many MemoryFence() calls in the x86 CPU code, given they don’t do anything on VC++. I have noticed from debugging MP code that was developed using VC++, that we seem to hit more issues when compiled via clang. I wonder if the behavior difference with volatile would explain some of those? VOID EFIAPI MemoryFence ( VOID ) { return; } And: VOID EFIAPI MemoryFence ( VOID ) { // This is a little bit of overkill and it is more about the compiler that it is // actually processor synchronization. This is like the _ReadWriteBarrier // Microsoft specific intrinsic __asm__ __volatile__ ("":::"memory"); } So I think for VC++ it should be… VOID EFIAPI MemoryFence ( VOID ) { _ReadWriteBarrier(); return; } [1] https://bugzilla.tianocore.org/show_bug.cgi?id=3213 Thanks, Andrew Fish
On Feb 5, 2021, at 9:53 AM, Ni, Ray <ray.ni@...> wrote:
|
|