-
-
Notifications
You must be signed in to change notification settings - Fork 125
use crate critical-section in defmt-rtt #640
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
What are the safety invariants of this function that we have to uphold?
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.
@jannic Could you shed light on this?
Uh oh!
There was an error while loading. Please reload this page.
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.
As @jonas-schievink already mentioned,
critical-sectionis missing some documentation.This is part of it: The intended safety-guarantees are not specified.
As far as I can tell, there are no real requirements. The current implementations of
critical_section::acquire()are not really unsafe, but just disable interrupts.My guess is that it's just for symmetry with
critical_section::release(), which is obviously unsafe, as enabling interrupts could break other code expecting to run exclusively.@Dirbaio, any comments?
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.
@jannic Could you please add safety comments for
critical_section::acquireandcritical_section::release, with what you wrote here? Then we should be good to go.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 still have to write docs for
critical-section(sorry! 🙈 ), but the safety contract is essentially:a=acquire(); b=acquire(); release(a); release(b);.Code in this PR complies with the safety contract, so LGTM 👍
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.
Thanks, that sounds good for now.
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.
As
fn acquire()is not unsafe, one could break this contract by just callingLogger::acquire()in some random location.But as far as I can tell, nothing bad would happen with that alone? eg:
This would lead to a sequence of calls like
a=acquire(); b=acquire(); release(a).But as long as you neither call
release(b)(which would beunsafe) or rely on being inside a critical section afterrelease(a), I don't see any bad effect of that call sequence.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.
One can't, as
Logger::acquire()is private.I still think that it wouldn't do harm if one could call it, but as one can't, either way it doesn't matter.
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.
Oops, too fast...
There is
defmt::export::acquire();, which ispuband notunsafe. So it's perfectly possible to callacquire()out of order. AFAIK the only thing bad which will happen is that the next call to a defmt logger will panic ("defmt logger taken reentrantly"), which seems to be a perfectly fine response.However, there is something much more dangerous:
defmt::export::release(). which allows to end a critical section unconditionally (or, before merging this pull request, to enable interrupts). I think this should beunsafe, right?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.
→ #659