|
Re: MemoryFence()
Ray,
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
Ray,
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
|
By
Andrew Fish <afish@...>
·
#516
·
|
|
Re: MemoryFence()
I saw the proposal of fences in first mail by Laszlo. Please forgive my ignorance. What is asm(“”) in x86? A nop? The how a nop can help as a processor level load store
I saw the proposal of fences in first mail by Laszlo. Please forgive my ignorance. What is asm(“”) in x86? A nop? The how a nop can help as a processor level load store
|
By
Ni, Ray
·
#515
·
|
|
Re: MemoryFence()
Andrew,
I just read the link you provided. It recommends to use mutex semaphore spin lock over volatile.
But the funny thing here is we are talking about how to implement the mutex semaphore spin lock
Andrew,
I just read the link you provided. It recommends to use mutex semaphore spin lock over volatile.
But the funny thing here is we are talking about how to implement the mutex semaphore spin lock
|
By
Ni, Ray
·
#514
·
|
|
Re: MemoryFence()
The proposed ReleaseMemoryFence() should already have that effect. All the proposed fences except CompilerFence() are both compiler optimization barriers and processor barriers.
The proposed ReleaseMemoryFence() should already have that effect. All the proposed fences except CompilerFence() are both compiler optimization barriers and processor barriers.
|
By
Paolo Bonzini <pbonzini@...>
·
#513
·
|
|
Re: MemoryFence()
Without calling _ReadWriteBarrier, is it possible that compiler generates the assembly in the wrong location? I mean the compiler may in-line the LibWaitForSemaphore and call cmpxchg earlier than the
Without calling _ReadWriteBarrier, is it possible that compiler generates the assembly in the wrong location? I mean the compiler may in-line the LibWaitForSemaphore and call cmpxchg earlier than the
|
By
Ni, Ray
·
#512
·
|
|
Re: MemoryFence()
We do link time optimization on VC++ and clang.
Thanks,
Andrew Fish
We do link time optimization on VC++ and clang.
Thanks,
Andrew Fish
|
By
Andrew Fish <afish@...>
·
#511
·
|
|
Re: MemoryFence()
Ray,
I agree the C definition of volatile is not thread safe.
I was doing some research on volatile and I realize the Linux kernel guides recommend against using volatile [1]. I think it has to do
Ray,
I agree the C definition of volatile is not thread safe.
I was doing some research on volatile and I realize the Linux kernel guides recommend against using volatile [1]. I think it has to do
|
By
Andrew Fish <afish@...>
·
#510
·
|
|
Re: MemoryFence()
Not as long as it's a pointer or smaller.
Paolo
Not as long as it's a pointer or smaller.
Paolo
|
By
Paolo Bonzini <pbonzini@...>
·
#509
·
|
|
Re: MemoryFence()
OK I see Linux recommends not using volatile [1], so I think this makes sense to me. It is not that volatile is not useful, but it is not thread safe, so not using volatile encourages people to use
OK I see Linux recommends not using volatile [1], so I think this makes sense to me. It is not that volatile is not useful, but it is not thread safe, so not using volatile encourages people to use
|
By
Andrew Fish <afish@...>
·
#508
·
|
|
Re: MemoryFence()
No concern that the store might not be atomic?
Thanks
Laszlo
No concern that the store might not be atomic?
Thanks
Laszlo
|
By
Laszlo Ersek
·
#507
·
|
|
Re: MemoryFence()
Agreed. I would prefer an explicit compiler fence before the "Value = *Sem" assignment and no volatile anywhere, but it is okay.
The _ReadWriteBarrier (aka compiler fence) is pointless too; it is
Agreed. I would prefer an explicit compiler fence before the "Value = *Sem" assignment and no volatile anywhere, but it is okay.
The _ReadWriteBarrier (aka compiler fence) is pointless too; it is
|
By
Paolo Bonzini <pbonzini@...>
·
#506
·
|
|
Re: MemoryFence()
Let's focus on the "down" operations first.
At commit c6be6dab9c4b:
789 /**
790 Decrement the semaphore by 1 if it is not zero.
791
792 Performs an atomic decrement operation for
Let's focus on the "down" operations first.
At commit c6be6dab9c4b:
789 /**
790 Decrement the semaphore by 1 if it is not zero.
791
792 Performs an atomic decrement operation for
|
By
Laszlo Ersek
·
#505
·
|
|
Re: MemoryFence()
Maybe that explains why the MemoryFence was implemented so confidently.
I trust Mike:)
In UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize.c, the LibWaitForSemaphore,
Maybe that explains why the MemoryFence was implemented so confidently.
I trust Mike:)
In UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize.c, the LibWaitForSemaphore,
|
By
Ni, Ray
·
#504
·
|
|
Re: MemoryFence()
Oops... Well, it *was* okay at the time MemoryFence() was first implemented. :(
Paolo
Oops... Well, it *was* okay at the time MemoryFence() was first implemented. :(
Paolo
|
By
Paolo Bonzini <pbonzini@...>
·
#503
·
|
|
Re: MemoryFence()
We rely heavily on LTO for both Visual Studio and GNU/Clang toolchains.
We rely heavily on LTO for both Visual Studio and GNU/Clang toolchains.
|
By
Ard Biesheuvel <ardb@...>
·
#502
·
|
|
Re: MemoryFence()
I think it's okay-ish (it works as long as you don't do link-time optimization, but it's less efficient than a compiler intrinsic) because X86MemoryFence.c is a separate file.
Paolo
I think it's okay-ish (it works as long as you don't do link-time optimization, but it's less efficient than a compiler intrinsic) because X86MemoryFence.c is a separate file.
Paolo
|
By
Paolo Bonzini <pbonzini@...>
·
#501
·
|
|
Re: MemoryFence()
That's because your CompilerFence() function is not correct. You did:
which is wrong. It enforces a C-language sequence point, but it does not
implement a compiler barrier.
And your code is wrong
That's because your CompilerFence() function is not correct. You did:
which is wrong. It enforces a C-language sequence point, but it does not
implement a compiler barrier.
And your code is wrong
|
By
Laszlo Ersek
·
#500
·
|
|
Re: MemoryFence()
A compiler barrier (in case that's sufficient), or even a memory fence
-- seems more appropriate for inter-CPU synchronization -- which I think
should be implemented to automatically force a compiler
A compiler barrier (in case that's sufficient), or even a memory fence
-- seems more appropriate for inter-CPU synchronization -- which I think
should be implemented to automatically force a compiler
|
By
Laszlo Ersek
·
#499
·
|
|
Re: MemoryFence()
Ah, thanks; also good example where a CompilerFence() would be justified.
Laszlo
Ah, thanks; also good example where a CompilerFence() would be justified.
Laszlo
|
By
Laszlo Ersek
·
#498
·
|
|
Re: MemoryFence()
This should be
#define CompilerFence _ReadWriteBarrier
Paolo
This should be
#define CompilerFence _ReadWriteBarrier
Paolo
|
By
Paolo Bonzini <pbonzini@...>
·
#497
·
|