-
Notifications
You must be signed in to change notification settings - Fork 8.2k
zbus: Add Zephyr message bus #48509
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
zbus: Add Zephyr message bus #48509
Conversation
2611560 to
fd3cb95
Compare
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 for your contribution, I've done a first pass review. My main concern is on how channels/messages are defined. Could you take a look at iterable sections? I think they would simplify things and would allow for a cleaner solution.
Thank you for the comments.
I will take a look at that. This is, in fact, a tricky part of the code. |
fd3cb95 to
411927d
Compare
|
I have made some heavy changes to the way of generating channels. Now it is using Iterable Sections. The code is cleaner and smaller. I really good improvement. Thanks a lot, @gmarull, for the advice. There is a lot of work to do. I will address that in the next few days. |
|
@rodrigopex please make sure CI passes and that commit structure is ok (for example, 9adf191 misses proper commit description) |
|
Sorry for that. I will do. Could you take a look at the new way of defining channels? |
be9e00b to
f465c3e
Compare
|
@gmarull The issues I am facing with CI now seem to be something other them my submission. The building errors seem related to iterable sections. I could not replicate those locally. The documentation is not ready yet and needs a lot of revision. I am working on that this week. The code I guess it is in a stable version. Please take a look at that. |
68b411c to
ba3f794
Compare
Add zbus message bus as a Zephyr subsystem. No message bus or communication abstraction other than the usual (message queues, mailboxes, etc.) enabled developers to implement event-driven systems in Zephyr quickly. Zbus would fill that gap by providing the community with a lightweight and flexible message bus. The implementation tries to be closest as possible to the existing ones. We use the claim/finish approach, and the API for publishing and reading channels are similar in message queues. Zbus is about channels, messages, and observers. Signed-off-by: Rodrigo Peixoto <[email protected]>
Add zbus subsystem test to verify read-only and hard channels. Signed-off-by: Rodrigo Peixoto <[email protected]>
Add zbus subsystem test to verify threads integration based on usual interaction, masking observers, and delayed interaction to verify semaphore and queue event dispatcher timeout. Signed-off-by: Rodrigo Peixoto <[email protected]>
Add zbus subsystem test to verify the user_data usage does not affect the normal behavior. Signed-off-by: Rodrigo Peixoto <[email protected]>
Add zbus subsystem test to verify the dynamic channel usage. It demonstrates the use of static and dynamic external messages. Signed-off-by: Rodrigo Peixoto <[email protected]>
Add zbus subsystem test to verify the channel's runtime observers list usage. It demonstrates the use of dynamically add and remove observer to and from channels at runtime. Signed-off-by: Rodrigo Peixoto <[email protected]>
The hello world sample illustrates a simple way of using zbus. There is a listener and a subscriber interacting each other by using a read-only and a regular channel. The APIs are called by using the function and macro variation. Signed-off-by: Rodrigo Peixoto <[email protected]>
The work_queue sample illustrates three reaction styles available for using zbus. The first is a listener that reacts by callback; use it should for urgent reaction. The second is a listener that responds by callback; instead of executing the code, it pushes a job to a work queue that will be executed shortly but not immediately. The last one is the subscriber that reacts using a queue; use it for an asynchronous reaction where the developer would like to control the flow. Signed-off-by: Rodrigo Peixoto <[email protected]>
The sample illustrates a way of using dynamically allocated messages in static channels. Signed-off-by: Rodrigo Peixoto <[email protected]>
The sample illustrates a way of send all the channel event to the host by using the UART, a user_data portion, and the claim/finish APIs. Signed-off-by: Rodrigo Peixoto <[email protected]>
The sample illustrates a way of exchange message with a host mock running in a Python script. It can be used to improve the testability and controllability of the tests. Signed-off-by: Rodrigo Peixoto <[email protected]>
The sample illustrates a way of using the runtime observer registration feature. With this sample the developer can understand how to use static and runtime observer registration. Signed-off-by: Rodrigo Peixoto <[email protected]>
The sample measures the time to transfer 256KB from the producer to the consumers. Signed-off-by: Rodrigo Peixoto <[email protected]>
7a08ade to
8c08b1e
Compare
|
Thank you very much to everyone involved who gave suggestions and discussed the feature and pitfalls of the solution. I am happy to have that merged. Now let's search for bugs and fix them if they happen. Regards. |
|
@rodrigopex How did you create those insanely pretty SVGs? 👀 |
Thanks @M1cha. I used Figma. The assets and images are public. You can use that by follwing the link. Feel free to change. Regards. |
Pull request for adding zbus to Zephyr.
The Zephyr message bus - Zbus is a lightweight and flexible message bus enabling a simple way for threads to talk to one another. Threads can broadcast messages to all interested observers using zbus. Many-to-many communication is possible. The bus implements message-passing and publish/subscribe communication paradigms that enable threads to communicate synchronously or asynchronously through shared memory. The communication through zbus channel-based, where threads publish and read to and from using messages. Additionally, threads can observe channels and receive notifications when the channels are modified.
Note for reviewers - Remaining compliance warnings⚠️
The only one I added is the _ZBUS_ASSERT macro which is necessary to verify the asserts coverage during tests. I have discussed it with @yperess about it. The remaining compliance errors seem to be related to
checkpatchand/orclang-formatissues.Zbus presentation slides
Zbus documentation
Features table
This pull request aims to add zbus (message bus/event manager) discussed at RFC #45910 to Zephyr. With the implemented tests, it was possible to reach 90%+ of line and 80%+ of branch coverage. All the APIs were designed to be like the Zephyr's. For example, the channel publish is almost the same as a message queue put function. There is a claim/finish like the ring buffer and so on. I guess zbus would help several developers to create even more reusable and decoupled code. The pull request commits are separated into feature code, tests, and samples. I have made individual commits to help reviewers.
Base feature code commit:
Zbus tests:
Zbus samples:
Activities during the PR: