-
Notifications
You must be signed in to change notification settings - Fork 6
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
[RFC] Restartable sequences #12
Comments
Hi Is this not a special case to determine (for some reason) that a code block has executed without preemptions? Or in a more general setting, atomic implies that the number of preemptions the code has been exposed to is 0. This is not currently a notion of RTFM (but can be encoded by hand if so wished by manually inserting some entry code in each handler similarly to your suggestion). Alternatively one could think of exploiting the underlying debugging features (not sure exactly how, but I think there are probing counters for interrupts). If this is to be a feature of RTFM either the OH should be 0 when not used, or explicitly opted in. It would require some changes to RTFM app analysis and code generation. Regarding the implementation: Best regards |
Correct.
I might be mistaken, but it seems like you can't actually add any code to handlers used for software tasks. (Instead of supporting this directly, would adding something more general to allow this be preferred instead? Maybe something like
I searched for a bit but couldn't find one for the cortex-m3, at least.
Gating it behind a feature seems like the easiest option for this.
Sure, a better implementation could commit with a double (or triple) buffer (and avoid blocking interrupts entirely), but that's up to the user. A double/triple buffer allows you to publish a consistent view, this proposal allows you to generate the consistent view that you're publishing to your buffer. |
Any further thoughts on this? |
Summary
Add functionality similar to Linux's restartable sequences, which allows for the running of code sequences atomically, without disabling interrupt handlers.
Motivation
This allows the execution of side-effect-free code atomically without blocking interrupts. For example, a device could repeatedly poll its input pins in the idle task, and continuously commit a fresh, but consistent, view of the state of its inputs to be read and used by other tasks.
Design
Add a per-core sequence number that's atomically incremented at the beginning of every interrupt handler, and run a given lambda until we have the same sequence number before and after.
The implementation should hopefully be fairly straight-forward, and will probably resemble something like the following:
Example
(handwavey strawman)
Unresolved questions
What should the return type of a restartable sequence be?
Three obvious options:
T
Option<T>
(orResult<T, ()>
Result<T, E>
!
?What do we do if we can never finish?
If there's too much work in the restartable sequence relative to the frequency of interrupts, we might never actually commit, and it probably won't be super obvious what's happening. Should we have a cap (user specified? hard-coded assumption?) on the number of retries we attempt before we assume that we're never going to succeed, so that we can return failure instead of just silently doing nothing but generating heat?
Is it possible to get rid of the horrible
unsafe
s?Shared access to resources (#129) might help?
The text was updated successfully, but these errors were encountered: