-
Notifications
You must be signed in to change notification settings - Fork 39
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
Avoid emulating wider atomics #196
Avoid emulating wider atomics #196
Conversation
Generally, Rust eschews emulating atomics where it can. This is done precisely so people can write interrupt handlers in Rust, without accidentally arriving in other interrupt handlers, or other complications that such things tend to induce. No solution is yet proposed for the xtensa-esp32s2-espidf target. However, it would be less-than-ideal if an ecosystem grew up around Rust-on-Xtensa that was dependent on something historically rejected by upstream Rust in the cases where it was easily avoidable.
Thank you for taking the time to look into this!
I would agree with this in general, however we actually discussed this when upstreaming our RISC-V based targets where we decided it was okay because: a) The implementation is in esp-idf lock-free, and disables all interrupts globally (no chance of preemption when emulating atomic instructions.) Note that the no_std targets only emit |
Ah, yet another consensus decision consigned to the artifact of "halfway down a pull request thread", with no other location recorded. |
I would not call "taking a lock on interrupts" as "lock-free" but I suppose I will take that up with upstream. |
Sorry to bother, I was just mildly perplexed that it wasn't somewhat more... discoverable, or clear why the reasons were what they were. |
No bother at all! I appreciate you taking the time to look into this. Upon reflection (sleep) I think you are actually correct. The difference between the upstream RISC-V targets, and the Xtensa targets listed here is that these Xtensa targets are dual core, and therefore the 64bits atomic emulation is not lock-free. The impl can be found here. I believe this will be an issue for the upstream RISCV targets soon, as the new ESP32-P4 will be a dual-core RISCV chip. Not having 64bit atomics available blocks a lot of crates in the std Rust ecosystem, and it does work in practice. What do you suggest? Is this something better discussed upstream? |
Well. About 64-bit specifically: I think those that want to support 32-bit platforms should probably be using AtomicUsize. There are plenty of crates that will compile for 32-bit platforms but only "support" them in the loosest sense, and using AtomicUsize is the first and obvious step towards actually supporting a 32-bit platform for most "I need an atomic of a decent size" cases. I maintain one such crate, where compiling for 32-bit support is technically possible, but in practice... it's a small miracle it works at all? But yes, I do think this should be discussed upstream for the RISC-V chip you mentioned. Though it's on your shoulders, as I see it, for how Xtensa currently goes, so I will reopen this. If nothing else, to reflect that there are some open questions still. |
I'd be interested in knowing what crates you're most concerned about losing access to... whether it's just a general smattering of crates or whether we're also talking about some "keystone" crates that a lot of the ecosystem depends on. Given some names and (web) addresses, this sort of problem can be dealt with one way or another. Your platform, after all, is not the only one that gets shortchanged by having weakened atomic support, here. It's in the greater interest to at least better understand the scale of the problem. |
These targets are about to become the exception amongst ESP targets, so I believe these targets are about to engender more confusion by their existence than not: |
Ah,
Yes, it is quite understandable to be concerned about tokio! There are also ecosystem crates like portable-atomic that allow shimming a lot of behavior, somewhat similarly to how your current implementation does. Personally, I am exploring making a crate for better signal handler support. The design I am currently intending is one that will probably need atomics that are lockfree inside the signal handler, as well, which means anything involving recursive interruption would be... subpar. |
7459f78
to
2ea63cb
Compare
My latest commit also narrows ESP32-S2's width, as I believe the rationale for support does fully apply and, while emulation via various schemes is possible, most of those schemes involve making performance harder to reason about. |
UPDATE:
Argh, sorry. I did not realize this is for the |
A bit offtopic, but... I'm struggling to understand Can you clarify? |
@ivmarkov The support code involved may see more general usage if I carry my experiment to the end. I'm just expressing a concern that it's impossible to apply bottom-up reasoning if the bottom I'm reasoning from has been undercut. |
@workingjubilee I've gone ahead and reflected your changes in the 1.74 release. Thanks for bringing this to my attention! |
Generally, Rust eschews emulating atomics where it can. This is done precisely so people can write interrupt handlers in Rust, without accidentally arriving in other interrupt handlers, or other complications that such things tend to induce.
No solution is yet proposed for the xtensa-esp32s2-espidf target. However, it would be less-than-ideal if an ecosystem grew up around Rust-on-Xtensa that was dependent on something historically rejected by upstream Rust in the cases where it was easily avoidable.