Skip to content

Replace the workqueue executor entirely #85

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 12 commits into from
Apr 14, 2025
Merged

Replace the workqueue executor entirely #85

merged 12 commits into from
Apr 14, 2025

Conversation

d3zd3z
Copy link
Collaborator

@d3zd3z d3zd3z commented Apr 10, 2025

Now that we have an async executor that runs on a regular thread, remove the previous work-queue based executor entirely. This incorporates improvements to the bench sample developed while making this change.

d3zd3z added 3 commits April 9, 2025 10:41
Implement a proc macro that allows a declaration like:

```rust
fn mythread(arg: usize, arg2: &'static Thing) { .. }
```

With this change, creation of threads, with arbitrary "Send" arguments
can be done without needing allocation.  The macros reserves a static
area alongside the `k_thread` structure to use for handing the threads
over.

This creates a function `mythread` with the given args that returns a
ReadyThread.  This has a `start()` method which will begin execution of
the thread.  This results in a RunningThread, which has a join method
that can be used to wait for termination.

Signed-off-by: David Brown <[email protected]>
Move away from the `kobj_define` task declaration to use the new
`#[zephyr::thread]` to define these.  This allows for a more natural
declaration where the thread just looks like an attribute added to a
regular function declaration.

This also eliminates the static Mutex, as the Mutex now has a
constructor that avoids allocation (it is still put in an Arc, though).

Signed-off-by: David Brown <[email protected]>
To help with debugging, try to give created Zephyr threads a readable
name.  Currently, this is based off of the name of the function used in
the declaration of the thread.

Signed-off-by: David Brown <[email protected]>
@d3zd3z d3zd3z requested review from teburd and cfriedt April 10, 2025 20:46
d3zd3z added 7 commits April 11, 2025 13:36
Remove the sample that depended on the old non-standard executor built
around work queues, and use the zephyr-executor.

Signed-off-by: David Brown <[email protected]>
Change this to be more general about the async executor used, instead of
the zephyr-specific workq-based one.

This doesn't change the sample itself, just the name.

Signed-off-by: David Brown <[email protected]>
The work-queue-based executor was an attempt to implement a Rust
executor that worked with Zephyr work queues.  Although it was possible
to make something that kind of worked, and did have the advantage of
being able to use a few Zephyr primitives, it suffers from several
problems:

- It isn't very efficient, basically combining the overhead of async
  scheduling, triggered work, and the Zephyr thread scheduler.
- It plays poorly with any other use of async.  Since it is useful to be
  able to use external crates for async utilities, this normally just
  results in undefined-behavior.

Now that we have another executor (built from Embassy), this code is
also mostly unneeded.

Signed-off-by: David Brown <[email protected]>
Convert away from the Zephyr-specific async to standard Rust async.
This uses the Embassy crates for time and synchronization.  All tasks
are spawned within a single executor that runs in the main thread.

Signed-off-by: David Brown <[email protected]>
Import the embassy crates, but not by path.  Also, remove the specific
time instance.  Although and specific application will likely want to
use a non-default tick rate, leaving at the 1us tick will allow the time
to be used (with a slight performance cost) with any time base.

Signed-off-by: David Brown <[email protected]>
The pin-weak provides a weak pointer that is compatible with `Pin<Arc>`.
Unfortunately, these are not compatible with the Arc that we use from
portable-atomic-utils.  Provide a simplified implementation of this
until the pin-weak is able to gain this functionality.

Signed-off-by: David Brown <[email protected]>
The current benchmarks are failing with a stack overflow on 64-bit
targets, so increase the size a bit.

Signed-off-by: David Brown <[email protected]>
d3zd3z added 2 commits April 11, 2025 14:29
This only makes sense when alloc is enabled.  Move the type into a
module, and use it, all conditional on having alloc defined.

Signed-off-by: David Brown <[email protected]>
Semaphores no longer use alloc in `new`.  Remove the incorrect
conditional based on allocation that remained.

Signed-off-by: David Brown <[email protected]>
@d3zd3z d3zd3z merged commit 14618bd into main Apr 14, 2025
4 checks passed
@d3zd3z d3zd3z deleted the no-wq-exec branch April 14, 2025 20:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants