Skip to content
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

Completely remove atomic emulation #985

Merged
merged 2 commits into from
Dec 4, 2023

Conversation

MabezDev
Copy link
Member

@MabezDev MabezDev commented Nov 30, 2023

This PR completely removes atomic emulation. Now that the +forced-atomics feature is enabled on -a RISCV targets, the trap is less useful. Most crates in the embedded ecosystem that need cas will opt to use portable-atomic to support targets without cas.

Must

  • The code compiles without errors or warnings.
  • All examples work.
  • cargo fmt was run.
  • Your changes were added to the CHANGELOG.md in the proper section.
  • You updated existing examples or added examples (if applicable).
  • Added examples are checked in CI

Nice to have

  • You add a description of your work to this PR.
  • [~] You added proper docs for your newly added features and code.

@bugadani
Copy link
Contributor

FYI smartled is checked with the CI host as target, that causes the portable-atomic madness (can't enable unsafe-assume-single-core on x86). Though if this came up, we shouldn't enable unsafe-assume-single-core anyway as per portable-atomic recommendation.

@MabezDev
Copy link
Member Author

MabezDev commented Dec 1, 2023

I opened rust-lang/futures-rs#2805 to add esp32s2 target to the no cas list. This was important as embassy-sync depends on futures-util.

As @bugadani mentioned we need everything to move to heapless 0.8, this requires a release of embassy-sync at a minimum, but for esp-wifi we know we'll need more.

@jessebraham
Copy link
Member

I opened rust-lang/futures-rs#2805 to add esp32s2 target to the no cas list. This was important as embassy-sync depends on futures-util.

Well, so much for that 😅

@MabezDev MabezDev force-pushed the remove-atomic-emulation branch 3 times, most recently from f9f76ed to ea1c891 Compare December 4, 2023 10:55
@MabezDev
Copy link
Member Author

MabezDev commented Dec 4, 2023

I found a way around it, though we should eventually fix it upstream. The last step is to remove the patched embassy_sync with a new release.

@MabezDev MabezDev force-pushed the remove-atomic-emulation branch 4 times, most recently from fd7d28d to cbedcd1 Compare December 4, 2023 14:08
@MabezDev MabezDev marked this pull request as ready for review December 4, 2023 14:10
@MabezDev
Copy link
Member Author

MabezDev commented Dec 4, 2023

With heapless 0.7.17 released we can punt the embassy upgrades to a different PR. This is now ready for review!

Copy link
Member

@jessebraham jessebraham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you for resolving this 🙏🏻

@jessebraham
Copy link
Member

With heapless 0.7.17 released we can punt the embassy upgrades to a different PR. This is now ready for review!

Handling this in #994

@MabezDev MabezDev added this pull request to the merge queue Dec 4, 2023
Merged via the queue into esp-rs:main with commit 05f9d21 Dec 4, 2023
17 checks passed
esp32c6 = ["riscv", "esp32c6/rt", "procmacros/esp32c6"]
esp32h2 = ["riscv", "esp32h2/rt", "procmacros/esp32h2"]
esp32s2 = ["xtensa", "esp32s2/rt", "procmacros/esp32s2", "xtensa-lx/esp32s2", "xtensa-lx-rt/esp32s2", "usb-otg", "portable-atomic?/unsafe-assume-single-core"]
esp32s2 = ["xtensa", "esp32s2/rt", "procmacros/esp32s2", "xtensa-lx/esp32s2", "xtensa-lx-rt/esp32s2", "usb-otg", "portable-atomic/critical-section"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently we shouldn't enable these in a library:

critical-section
...
Note:
...
It is usually not recommended to always enable this feature in dependencies of the library.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I read that too, however, I feel that although esp-hal is a library, its also not a platform-agnostic library, we know exactly what the intended target is capable of. If it causes problems in the future we can revert this.

@brychanrobot
Copy link
Contributor

Was this tested on esp32c6? I just tried to compile a project that runs on the c6 with embassy and it failed with

       consider enabling one of the `unsafe-assume-single-core` or `critical-section` Cargo features.
       see <https://docs.rs/portable-atomic/latest/portable_atomic/#optional-features> for more.
   --> /home/bryant/.cargo/registry/src/index.crates.io-6f17d22bba15001f/portable-atomic-1.6.0/src/lib.rs:434:1
    |
434 | / compile_error!(
435 | |     "dependents require atomic CAS but not available on this target by default;\n\
436 | |     consider enabling one of the `unsafe-assume-single-core` or `critical-section` Cargo features.\n\
437 | |     see <https://docs.rs/portable-atomic/latest/portable_atomic/#optional-features> for more."
438 | | );
    | |_^

I noticed that unsafe-assume-single-core is enabled on the c3, but c6 doesn't use either of these features.

@bugadani
Copy link
Contributor

bugadani commented Dec 28, 2023

Yes, this works as intended. The C6 did not use the atomic emulation mechanism at all. Don't enable unsafe-assume-single-core, C6 has native support for atomic operations and portable-atomic should be able to pick that up.

Could you share your project?

@brychanrobot
Copy link
Contributor

Interesting. Thanks! In case anyone else has the same problem and comes across this thread. It turns out that I had converted a project from c3 to c6 and missed updating the target string. riscv32imc-unknown-none-elf -> riscv32imac-unknown-none-elf.

@MabezDev MabezDev deleted the remove-atomic-emulation branch December 28, 2023 23:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants