-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Relaxed exchange appears stronger than on real hardware #16
Comments
On Wed, Aug 30, 2023 at 5:02 AM Aleksei Borzenkov ***@***.***> wrote:
I've been testing my data structures for correctness with relacy, and
found an odd behavior where atomic.exchange(..., rl::memory_order_relaxed)
appears to be stronger than expected. I then checked with real hardware
(apple m1) and confirmed that it is indeed much weaker.
As far as I under the standard says this on the topic:
Atomic read-modify-write operations shall always read the last value (in
the modification order) written before the write associated with the
read-modify-write operation.
And relacy always returns the last written value. However it seems the
last relaxed store is always considered the last value, where on real
hardware (at least apple m1) it might get reordered with other stores and
really happen later in the order.
Here's a minimal example test where relacy passes. Note how all atomic
operations are relaxed:
I need to look at it further when I get some more time. Humm, let me try to
recall something... Be sure to use rl:backoff for spinning, iirc, instead
of:
asm volatile ("yield");
Anytime you want to spin be sure to use rl::backoff, it's been some
years since I have used Relacy. Btw, I used to converse with Dmitry
Vyukov all the time over on comp.programming.threads. He is a friend.
[...]
… Message ID: ***@***.***>
|
Hi Aleksei, You are right. However, for stores/rmw operations we cannot later easily change the execution order because modification order of atomic variables must be consistent for all threads and there may be threads that already observed original modification order. So for stores/rmw we simply always act on the latest value according to the program order: I think it may be possible to add at least some relaxations for store operations. Namely: if no threads have observed some last modifications, then potentially we can "insert" the current store somewhere in the past. Just to manage expectations: the library is not actively maintained by me now. But if you will send a patch I will try to do my best to review it and merge. |
Thanks, Chris :) |
I've been testing my data structures for correctness with relacy, and found an odd behavior where
atomic.exchange(..., rl::memory_order_relaxed)
appears to be stronger than expected. I then checked with real hardware (apple m1) and confirmed that it is indeed much weaker.As far as I under the standard says this on the topic:
And relacy always returns the last written value. However it seems the last relaxed store is always considered the last value, where on real hardware (at least apple m1) it might get reordered with other stores and really happen later in the order.
Here's a minimal example test where relacy passes. Note how all atomic operations are relaxed:
check_relaxed_lock.cpp
And here's an example test that runs on real hardware and quickly fails, because counters don't match:
realcheck_relaxed_lock.cpp
The text was updated successfully, but these errors were encountered: