Replies: 8 comments
-
The likely more appropriate way to write with eventfd from kernel code (e.g. in an ISR) would be via Only non-blocking eventfd's can (currently) be written in ISR context. @chmorgan - do you think a documentation enhancement would help to clarify in here? |
Beta Was this translation helpful? Give feedback.
-
@cfriedt for sure a documentation change could help. Are you suggesting that one can call zvfs_eventfd_write() from isr context, or that zephyr should call zvfs_eventfd_write() if eventfd_write() is called from isr context? It seemed like there could be a mechanism to enable eventfd_write() work from isr context, but even if its possible that doesn't mean it isn't a ton of work. |
Beta Was this translation helpful? Give feedback.
-
I think it should be possible today, as long as it's a non-blocking eventfd.
It's more like good API hygiene. An ISR should probably depend mostly on the ZVFS API and applications should rely on the eventfd API. That way there are no dependency cycles. |
Beta Was this translation helpful? Give feedback.
-
@cfriedt eventfd_write() is mapped to zvfs_eventfd_write() which calls zvfs_eventfd_wr_op() against zvfs_eventfd_write_locked(). I tried it here on an eventfd created with flags of 0 and it reports EAGAIN (on v4.0.0-rc1).
and zvfs_eventfd_rw_op() is where the isr check is:
|
Beta Was this translation helpful? Give feedback.
-
If the write eventfd was non-blocking, then execution would not make it to the zephyr/lib/os/zvfs/zvfs_eventfd.c Line 322 in 193eeae So again, as in the testsuite linked above, can you please try to create a non-blocking eventfd? I.e. please use the flag Generally, we can't service anything in ISR context that will block. |
Beta Was this translation helpful? Give feedback.
-
@cfriedt ahh yes, this makes sense. It didn't occur to me, although it should have, that eventfd_write() could block and of course we can't block in isr context. In terms of documentation, something like "Use in ISR: eventfd_write() will fail with EWOULDBLOCK if EFD_NONBLOCK is not set. Set EFD_NONBLOCK for use in ISR." would have helped. It's working here now that EFD_NONBLOCK is set. If the failure mode matches the documentation for other implementations of eventfd_write, in that an overflow might result in the write not occurring, then I'm ok with that (its a 64bit number and I'm writing 1 each time so nothing will be missed). |
Beta Was this translation helpful? Give feedback.
-
Probably better to use
🙌 Awesome! Thanks for your help to sort this out! |
Beta Was this translation helpful? Give feedback.
-
Thank you for the help. I should have realized sooner what was going on :-p
Hopefully this shows up in search if anyone else is using eventfd and poll
with zephyr.
…On Fri, Nov 1, 2024 at 4:08 PM Chris Friedt ***@***.***> wrote:
In terms of documentation, something like "Use in ISR: eventfd_write()
will fail with EWOULDBLOCK if EFD_NONBLOCK is not set. Set EFD_NONBLOCK for
use in ISR." would have helped.
Probably better to use zvfs_eventfd_write() from inside of an ISR.
Hopefully soon we can make ZVFS a proper public API, and at that point,
I'll definitely include a bit about using it in ISR context.
It's working here now that EFD_NONBLOCK is set.
🙌 Awesome!
Thanks for your help to sort this out!
—
Reply to this email directly, view it on GitHub
<#80690 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAJH4AAWIHZ7ZZ2L4LKKHMTZ6PNULAVCNFSM6AAAAABQ6IVCVCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDINJSGUYTQMRSG4>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Describe the bug
Calling eventfd_write() from isr context on an eventfd created with flags of 0 results in an error being returned. Calling eventfd_write() on the same FD from thread context works as expected.
There is no mention of ISR related restrictions in the documentation, https://docs.zephyrproject.org/apidoc/latest/posix_2sys_2eventfd_8h.html, and there are other primitives such as events (I know these aren't the same as eventfd) that can signal from ISR to thread.
Without eventfd_write() support from ISR context I can't make use of poll() in my thread.
To Reproduce
Attempt to send a eventfd_write() to a valid FD from isr context.
Expected behavior
Should send correctly as it shouldn't be a blocking operation.
Impact
Not sure. Have to look at how to work around this limitation. Any thoughts on how I should address this? I'd like to maintain cross platform portable code for testing purposes but moving to k_poll() came to mind (without knowing if its possible to wake up a k_poll from ISR context).
Environment (please complete the following information):
Beta Was this translation helpful? Give feedback.
All reactions