-
Notifications
You must be signed in to change notification settings - Fork 20
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
AtomicBool layout changes to become amo biased rather than bool biased #249
Comments
I need to think about whether or not |
I don't think we can/should do this. The docs on
Changing that seems like a breaking change of the worst kind. I realize the actual impact of this will be limited to some rather niche platforms, but we've promised it will have the same layout as How common of a need is it to be maximally efficient here on platforms where our current |
That change was a regression from using a usize, the costs of which were not discussed, and previously it was also a breaking change (de facto if not de jure). |
@workingjubilee Is that a rebuttal? An FYI? Can you elaborate please? |
Mostly just a remark, I guess? The flipside of this is that RISCV itself has a de facto (if not de jure) encoding for byte-level atomic instructions, and it's not clear what the performance characteristics of most RISCV architectures with high core counts and full implementation of the atomic instruction set will be, because... most RISCV architectures aren't printed yet. |
Yeah, I think I'm inclined to agree with @BurntSushi -- I don't think we should make a habit of considering concrete promises we make about type layout to be things we can go back on. |
It's not even obvious if that's a win. Making the type larger can blow up the size of structs containing them. It's a size vs. instruction-overhead tradeoff. |
What? It's the difference between looping load-reserve/store-conditional instructions and an amo instruction. I don't have an arm or riscv machine to benchmark things, but I would be very surprised if those had comparable performance under contention. |
That's the overhead part. Smaller structs, more expensive instructions. |
The comparison you're making is bizarre. In what scenario do people have millions of atomic booleans laying around? |
how about a lock-free hash table of some sort? |
or Java-style mutex-per-object where you want them to be 1 byte to save space |
Both of those would be questionable implementations without some way to wait (consider the case where the OS context switches in the middle of the critical section) which on linux requires a 32-bit atomic. But if people are against changing the layout of AtomicBool, then I can switch this proposal to AtomicFlag which would look just like the AtomicBool I proposed. |
Are you suggesting changing
I think this would be more reasonable, although I'm not sure it's worth having, given the additional complexity it adds. |
That doesn't sound too crazy to me, but no. I think there are still many use cases where you just want to know if something is active. Then again, AtomicFlag would be simpler if it was always a u32, but it's easy to imagine regretting that later when some architecture decides it only supports 42 bit atomics or something.
Yeah, I think that's probably what this issue should be about. I personally don't think having a memory layout compatible type and an amo compatible type is too much added complexity. |
The fact that we also need to create another type that only allows 0 and 1 for this is a more significant issue in terms of complexity, I think. It will need its own API and conversions, for example. |
Ok, the discussion on Zulip concluded that rust-lang/rust#114034 and llvm/llvm-project#64090 were satisfactory solutions. |
Proposal
Problem statement
See Zulip thread: https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/AtomicBool.20useless.20on.20riscv.
Gist: AtomicBool uses a u8 under the hood, but not all hardware supports 8/16 bit atomics even if it support 32 bit atomics. Change the memory layout of bool to match the hardware's amo type size.
Solution sketch
Downsides
People that are relying to AtomicBool being layout compatible with bool are going to be sad.
Upside
We can be maximally efficient on all hardware while still letting people do weird transmutes since they have
AtomicBoolType
.The text was updated successfully, but these errors were encountered: