-
Notifications
You must be signed in to change notification settings - Fork 167
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 critical-section 1.0 implementation, fix multicore unsoundness. #110
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! Looks good. but I will defer to disasm for final review.
[dependencies] | ||
bare-metal = "1.0.0" | ||
bit_field = "0.10.0" | ||
critical-section = "1.1.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make it optional maybe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's required unconditionally by the singleton!
macro
(and the macro can still be used if critical-section-single-core
is not enabled, if the user supplies a c-s implementation from somewhere else, such as a chip-specific impl for a multicore chip, from its HAL crate)
Next release will be "breaking" anyways because one breaking change is already merged. I'd prefer to have this change together with other critical-section-related changes. |
Oh okay, hadn't noticed that. I've folded PR #111 into this one. |
651: Use `critical_section` for `Peripherals::take`. r=therealprof a=reitermarkus - `cortex_m` rust-embedded/cortex-m#447 - `msp430` rust-embedded/msp430#13 - `riscv` rust-embedded/riscv#110 - `xtensa_lx` esp-rs/xtensa-lx#20, esp-rs/esp-hal#151 - `mips_mcu` kiffie/pic32-rs#5 Co-authored-by: Markus Reiter <me@reitermark.us>
@Dirbaio sorry I complicated this a bit, we released 0.9 due to a botched 0.8.1 (which contained some other breaking changes and we had to yank it). Could you please bump the changelog? I think that's the only blocker here. |
Rebased |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but I think we might want to look at core
vs hart
terminlogy and meaning before proceeding.
src/interrupt.rs
Outdated
|
||
/// Disables all interrupts | ||
/// Disables all interrupts in the current core. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should specify what core
means in RISC-V context here. e.g. is it a hard or an actual core with its own fetching unit.
CHANGELOG.md
Outdated
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/). | |||
|
|||
## [Unreleased] | |||
|
|||
### Added | |||
|
|||
- Added `critical-section-single-core` feature which provides an implementation for the `critical_section` crate for single-core systems, based on disabling all interrupts. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as below, I wonder if this should be critical-section-single-hart
instead. TBF I'm not quite sure on this myself, I didn't use interrupts much yet, will review the spec a bit better.
I'm afraid I don't know enough about riscv to know what's the difference between "core" and "hart" so I'll do whatever you guys choose :) |
Heh sadly neither do I. My current understanding is that a Interrupts seem to be mixed between these two, some seem to be |
In this case, I think
As far as I am aware, there is nothing ratified that defines "core-wide" interrupts, although an interrupt controller like the PLIC could be configured to route a set of interrupts to all of the harts on a core. This eventually may not always be true, as Section 2 of the Smclic extension does say:
However, there isn't any further mention of this in the spec so far. It's entirely possible that I've missed something here; there are a lot of specs relating to interrupts. |
I think you are correct, we should probably rename things to be hart specific. |
This is unsound on multi-hart because it only disables interrupts in the current hart. For multi-hart chips, a chip-specific critical section implementation is needed instead. Unsoundness is fixed by not returning the `CriticalSection` token. This is a breaking change.
Changed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
bors r+ |
Build succeeded:
|
110: fix: avoid rust-analyzer snake case warning r=almindor a=sethp It seems that rust-analyzer needs to operate over the expanded text of the proc macro (in order to e.g. support completion in the function body, see #11014 for way more details), so it "sees" the non-snake-case name emitted by riscv-rt's `entry` here. Without this change, rust-analyzer will show a "weak warning" on invocations of `#[entry]` with the text: ``` Function `__risc_v_rt__main` should have snake_case name, e.g. `__risc_v_rt_main` ``` Co-authored-by: sethp <seth@codecopse.net>
Requires #109This adds a 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 thecurrent 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