-
Notifications
You must be signed in to change notification settings - Fork 38
Atomic C functions are not atomic. #41
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
Comments
The Since I'd be happy to take a crack at moving over to |
IIRC I measured it and it was much faster. In particular a |
Yikes, for some reason I thought that a MutVar's contents would be unboxed if the contained type was unboxed, but it seems that's not the case: https://gitlab.haskell.org/ghc/ghc/-/blob/master/includes/rts/storage/Closures.h#L181
|
I'll look into cutting new releases during the weekend. |
I’d definitely like to get more eyes on #42 before it lands in a release. I’ve been using it since I opened the PR, but my use cases might not hit certain issues. |
This commit attempts to address issue haskell-github-trust#41 of tibbe/ekg-core by replaceing the C code for `Atomic` with GHC prim ops (`fetchAddIntArray`). However, we insist on a 64-bit counter, so if machine does not support 64-bit prim ops, we fall back to using an `IORef` and `atomicModifyIORefCAS`. The performance of the 64-bit prim ops implementation is somewhat slower than the existing C code, perhaps due to the additional conversion between `Int` and `Int64`.
This commit attempts to address issue haskell-github-trust#41 of tibbe/ekg-core by replacing the C code for the distribution metric with GHC prim ops. The performance of this implementation is about half that of the existing C code in a single-threaded benchmark; without masking the performance is comparable. This commit is based on the work of Travis Whitaker in PR haskell-github-trust#42 of tibbe/ekg-core.
This commit attempts to address issue haskell-github-trust#41 of tibbe/ekg-core by replaceing the C code for `Atomic` with GHC prim ops (`fetchAddIntArray`). However, we insist on a 64-bit counter, so if machine does not support 64-bit prim ops, we fall back to using an `IORef` and `atomicModifyIORefCAS`. The performance of the 64-bit prim ops implementation is somewhat slower than the existing C code, perhaps due to the additional conversion between `Int` and `Int64`.
This commit attempts to address issue haskell-github-trust#41 of tibbe/ekg-core by replacing the C code for the distribution metric with GHC prim ops. The performance of this implementation is about half that of the existing C code in a single-threaded benchmark; without masking the performance is comparable. This commit is based on the work of Travis Whitaker in PR haskell-github-trust#42 of tibbe/ekg-core.
hs_atomic_read
andhs_atomic_write
aren't atomic at all on machines without strong memory models (total read and store ordering). To see an example of the kind of havoc this bad assumption can cause, see this (thankfully now fixed) GHC issue https://gitlab.haskell.org/ghc/ghc/-/issues/15449Here's the aarch64 code that GCC 8.2 yields for these functions: https://godbolt.org/z/giVdtx No barriers or acq/rel lda/sta emitted...
I'm curious why C functions are used for these atomic operations at all. Are these functions really that much faster than
atomicModifyIORef
?The text was updated successfully, but these errors were encountered: