Skip to content

Deeper async integration #117

@d3zd3z

Description

@d3zd3z

Although the current async support is fully featured, despite the simplicity of the implementation, there is a bit of a barrier between async code, and the various Zephyr primitives. As there are already several readily-available synchronization crates available that work well from async mode, this is sufficient for code that is entirely written in Rust.

However, many interfaces in Zephyr user Zephyr primitives for synchronization. Specifically, semaphores are used fairly pervasively. In addition, using callbacks is not possible with userspace, so it is desirable to be able to use these other mechanisms.

A small bit of background as to how async works in Rust will be helpful. Any time the async keyword is used in Rust, the compiler converts this to a block of code that returns a (hidden definition) structure that implements
Future. This trait has requires two
things, one is an Output type which defines the final return type when the future has completed,
and the other is a poll function. The poll function runs the async code until it reaches a
blocking point, or finishes. It returns a value indicating which is the case. The implementation
is responsible for using the Context parameter passed to the future, specifically, it's Waker,
and to arrange for that Waker to be called when the Future is able to run again.

There are several possibilities for how to implement an async-able Semaphore.

  • Enhance the executor to be aware of semaphores. This is the approach used to desktop/server async
    implementations (such as Tokio). This will add a fixed cost to all async
    operations.
  • Use triggered work on a workqueue (possibly just the system work queue) where each registered work
    item invokes the necessary wake function when that resource becomes available. This makes waiting
    for Semaphores a bit more expensive, but does not increase the cost for any other async
    operations.
  • Add callback support to the Zephyr implementation of Semaphores. This is likely to meet
    resistance from the C-focused core kernel developers in Zephyr, but would be the most efficient.
    There is some complexity to making this work with userspace, and would be the first Rust-specific
    mechanism introduced to the core of Zephyr.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions