-
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] generator tasks #22
base: master
Are you sure you want to change the base?
Conversation
Looks great. I don't see any advantage to support static variable in the generator constructor. Do you have any? |
Someone asked on the matrix channel why the example program prints "A" before "idle". Answering here for visibility:
The function As a rule of thumb you can think of it like this: inside a task generator function, the code outside the "bars" ( |
Hmm, off the top of my head: having a task local pool allocator is one use case. If you declare the pool inside the task generator function then no other task will be able to use it. Something like this: #[rtfm::app(/* .. */)]
const APP: () = {
#[task]
fn a(cx: a::Context) -> impl Generator<Yield = (), Return = !> {
static mut M: [u8; 1024] = [0; 1024];
pool!(A: [u8; 128]); // empty pool
let m: &'static mut [u8; 1024] = M;
A::grow(m); // give some memory to the pool
move || loop {
// use the pool
let x = A::alloc();
// ..
}
}
#[task]
fn b(cx: b::Context) {
// pool A cannot be used here
}
}; One could have declared the pool outside the |
I want to address @perlindgren 's comment from the other thread I see two ways to recover the BASEPRI optimization but one of them may actually
|
Thanks Jorge for the follow up to #18. This was +/- what I expected. Regarding the cost of locks, there is also increased register pressure when reading/storing the old BASEPRI, so in practice the cost may be higher (of not optimizing the lock out/away). In any case, for now it cannot be applied (as we don't have resume arguments), also its not for granted that the compiler would be able to optimize out the locks even with the approach suggested (it would depend on how generators are internally represented in the rust compiler - and later presented to LLVM). Having resume arguments, can however be useful (as to send in message payloads eg.), so I think still it would be great if the embedded WG can push for that in meetings with the the teams. |
Given that some time has passed and all but the generator drawbacks has been solved,
Is it worth looking into this again? I would assume the generator and generator_trait are pretty closely coupled such that we can treat them as one unstable feature. |
Summary
Add experimental support (behind a Cargo feature) for generators to Real Time
for The Masses.
Motivation
Support generator sugar (i.e.
yield
) to ease the creation of interrupt-drivenstate machines.
Rendered
Here's an MVP implementation but please note that at the moment it only implements the simplest case of hardware generator tasks -- it doesn't support software tasks or integration with the
schedule
API.