Skip to content

sys/bhp_*: add initial support for generic Bottom Half Processor#18435

Merged
jia200x merged 4 commits intoRIOT-OS:masterfrom
jia200x:pr/bhp
Aug 12, 2022
Merged

sys/bhp_*: add initial support for generic Bottom Half Processor#18435
jia200x merged 4 commits intoRIOT-OS:masterfrom
jia200x:pr/bhp

Conversation

@jia200x
Copy link
Copy Markdown
Member

@jia200x jia200x commented Aug 10, 2022

Contribution description

This PR addresses this comment and adds a generic Bottom Half Processor mechanism to be used by any device that requires ISR offloading.
The mechanism is agnostic to the underlying processing module (events, messages, thread flags), as it simply defines an interface for storing an (IRQ) handler and a context.

On top of that, a dedicated Bottom Half Processor module (bhp_*) exposes an init function that configures the underlying mechanism and setups the callback. Then, the device driver init function sets the ISR callback to bhp_*_cb and passes the bhp_*_t descriptor as the ISR context. The module will take care of the rest.

Based on this, I implemented an event based Bottom Half Processor (see bhp_event), which allows to offload the handler to an event queue. In the future, there could be more of these implementations (bhp_thread_flags, bhp_msg, bhp_mbox, etc).

Testing procedure

Unittests should pass.

Issues/PRs references

It will be come extremely handy to implement network-stack-and-device-agnostic IRQ offloaders for SPI radios (#18383)

@jia200x jia200x requested review from benpicco and maribu August 10, 2022 15:18
@jia200x jia200x requested a review from miri64 as a code owner August 10, 2022 15:18
@github-actions github-actions bot added Area: sys Area: System Area: tests Area: tests and testing framework labels Aug 10, 2022
@jia200x
Copy link
Copy Markdown
Member Author

jia200x commented Aug 10, 2022

I have a follow up PR that adapts #18383 to this mechanism. See it in action

@github-actions github-actions bot added the Area: Kconfig Area: Kconfig integration label Aug 10, 2022
@jia200x
Copy link
Copy Markdown
Member Author

jia200x commented Aug 10, 2022

@leandrolanzieri, @MrKevinWeiss could you please check if the Kconfig modelling looks ok?

sys/bhp/Kconfig Outdated
Comment on lines +15 to +16
depends on MODULE_EVENT
select MODULE_BHP
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems a bit redundant to define both?
@leandrolanzieri might know better

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is relatively low-risk here to select MODULE_EVENT, if that's what you mean

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm now that I see it, probably will need to change the modelling a bit.
My idea was to use MODULE_BHP as a feature request that the driver can select.
Then, another module (e.g gnrc_netif) can select MODULE_BHP_EVENT if MODULE_BHP is present. That way we don't pull BHP code when devices don't require it

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just had an offline discussion with @leandrolanzieri and we agreed on leaving MODULE_BHP to compile sys/bhp. This is also used to indicate in Make that a driver requires a Bottom Half Processor, but it doesn't force the user to bring any of the bhp_* modules.
For Kconfig I simply added a HAVE_BHP_IRQ_HANDLER feature to the driver that indicates there's an IRQ handler expected to be offloaded.

@github-actions github-actions bot added the Area: drivers Area: Device drivers label Aug 11, 2022
@github-actions github-actions bot removed the Area: drivers Area: Device drivers label Aug 11, 2022
@jia200x
Copy link
Copy Markdown
Member Author

jia200x commented Aug 11, 2022

if this is merged before #18383, I can adapt the kinetis radio to this BHP mechanism

Copy link
Copy Markdown
Contributor

@benpicco benpicco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let’s do this then

@jia200x jia200x added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Aug 11, 2022
@miri64 miri64 added the Type: new feature The issue requests / The PR implemements a new feature for RIOT label Aug 11, 2022
@jia200x jia200x merged commit 50e4498 into RIOT-OS:master Aug 12, 2022
@jia200x
Copy link
Copy Markdown
Member Author

jia200x commented Aug 12, 2022

thanks for the review!

@kaspar030
Copy link
Copy Markdown
Contributor

The mechanism is agnostic to the underlying processing module (events, messages, thread flags), as it simply defines an interface for storing an (IRQ) handler and a context.

Is it that simple? The memory model of the four methods is very different.

@jia200x
Copy link
Copy Markdown
Member Author

jia200x commented Aug 17, 2022

The mechanism is agnostic to the underlying processing module (events, messages, thread flags), as it simply defines an interface for storing an (IRQ) handler and a context.

Is it that simple? The memory model of the four methods is very different.

It is agnostic from an interface point of view. Neither the device nor the network stack care about which underlying mechanism is being used and these can be exchanged at any time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: Kconfig Area: Kconfig integration Area: sys Area: System Area: tests Area: tests and testing framework CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: new feature The issue requests / The PR implemements a new feature for RIOT

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants