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

Add implementation for critical-section 1.0, for cortex-m v0.7.x #448

Merged
merged 1 commit into from Aug 11, 2022

Conversation

Dirbaio
Copy link
Member

@Dirbaio Dirbaio commented Aug 10, 2022

This is a subset of #447 without any breaking changes, just adding the critical-section implementation.

The goal is to release it in 0.7.6 so critical-section becomes usable without having to wait for cortex-m 0.8.

TODO before merging:

@rust-highfive
Copy link

r? @thalesfragoso

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive
Copy link

⚠️ Warning ⚠️

  • Pull requests are usually filed against the master branch for this repo, but this one is against v0.7.x. Please double check that you specified the right target!

@rust-highfive rust-highfive added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-cortex-m labels Aug 10, 2022
@Dirbaio Dirbaio force-pushed the cs-v07x branch 2 times, most recently from e30b3b2 to d54404f Compare August 10, 2022 16:28
@Dirbaio
Copy link
Member Author

Dirbaio commented Aug 10, 2022

Made critical-section an optional dep because it doesn't build for the 1.38 MSRV due to using #[doc(include_str!(..))]

@Dirbaio Dirbaio force-pushed the cs-v07x branch 5 times, most recently from ffa005e to 470759a Compare August 10, 2022 23:54
@reitermarkus
Copy link
Member

So in 0.7.6, interrupt::free will keep using bare_betal::CriticalSection but the feature will allow other crates to already migrate to using critical_section::with, correct?

@adamgreig
Copy link
Member

So in 0.7.6, interrupt::free will keep using bare_betal::CriticalSection but the feature will allow other crates to already migrate to using critical_section::with, correct?

That's right. We couldn't have interrupt::free use critical-section without breaking things unless we provided an impl by default, but doing so would stop people using a different impl on platforms that require them. Unless there's some clever trick to make interrupt::free on cortex-m 0.7.6 use critical-section with the single-core impl by default but still allow another impl to be defined...

@Dirbaio
Copy link
Member Author

Dirbaio commented Aug 11, 2022

I wouldn't make interrupt::free do something other than just disabling interrupts though. That'd be very confusing. Especially since in 0.8 it'll be back to just disabling interrupts (but not returning the CS token).

I'd just accept the fact that interrupt::free in 0.7 is unsound, and fix it in 0.8.

Copy link
Member

@adamgreig adamgreig left a comment

Choose a reason for hiding this comment

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

bors r+

@bors
Copy link
Contributor

bors bot commented Aug 11, 2022

Build succeeded:

@bors bors bot merged commit dc539a9 into rust-embedded:v0.7.x Aug 11, 2022
bors bot added a commit to rust-embedded/riscv that referenced this pull request Oct 13, 2022
110: Add critical-section 1.0 implementation, fix multicore unsoundness. r=almindor a=Dirbaio

~~Requires #109~~

This adds a [critical-section](https://github.com/rust-embedded/critical-section) implementation for single-core chips, based on disabling all interrupts.

`interrupt::free` is is unsound on multicore systems because it only disables interrupts in the
current core. For multicore chips, a chip-specific critical section implementationis needed instead. Unsoundness is fixed by not returning the `CriticalSection` token.

This is a breaking change.

This is the riscv equivalent of rust-embedded/cortex-m#447 and rust-embedded/cortex-m#448



Co-authored-by: Dario Nieuwenhuis <dirbaio@dirbaio.net>
bors bot added a commit that referenced this pull request Jan 4, 2023
458: cortex-m v0.7.7: add documentation for critical-section-single-core r=thejpster a=adamgreig

This got missed in #448; this PR copies the documentation added in #451 to the v0.7.x branch.

Co-authored-by: Adam Greig <adam@adamgreig.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-cortex-m
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants