-
Notifications
You must be signed in to change notification settings - Fork 8.3k
kernel: k_poll: Introduce separate status for cancelled events #9556
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
Conversation
|
@Vudentz, some thing just can't be put to rest ;-). Turned out, your change 48fadfe actually broke POSIX poll() implementation done on top of k_poll(). POSIX semantics is that when EOF happens (and that condition is being signaled with k_fifo_cancel_wait() translates to "read data available" (POLLIN). User tries to read, and discovers that there's no data on this socket no more (EOF). So, it's imperative that cancel_wait() leads to "active" poll state, while you in 48fadfe#diff-ec46254d7d7d1ff37f681251c352e3f8L98 set it in this case to K_POLL_STATE_NOT_READY, which is null, non-signaled state. The only hint of cancellation is -EINTR return code, but as may imagine, that doesn't differentiate among multiple fifos. So, instead of submitting a revert of that commit and go on another spin of that vicious cycle, I did more homework. So, what you need is cancellation to have separate, explicit return code (IIRC, to differentiate of race condition between multiple k_fifo_get callers). What I need is "active" poll state. The solution is thus to introduce a new poll state, which would map to -EINTR return. And that's what this patch does, and even documents the behavior of funcs more explicitly. Hopefully, this patch finally will put this issue to rest. |
Codecov Report
@@ Coverage Diff @@
## master #9556 +/- ##
==========================================
+ Coverage 52.17% 52.17% +<.01%
==========================================
Files 212 212
Lines 25914 25914
Branches 5583 5583
==========================================
+ Hits 13520 13521 +1
+ Misses 10145 10144 -1
Partials 2249 2249
Continue to review full report at Codecov.
|
|
@pfalcon Sorry. I'm on vacation now and don't have a chance to test it. |
|
@rlubos: Ack, thanks for the response, no hurries/worries. Just trying to understand how that issue could go unnoticed for so long (will definitely add echo_async to my usual set of smoke tests). |
|
@pfalcon LGTM but perhaps we should add a test for the new state then so we ensure the behaviour is not changed again. Btw, I don't see you using the new state, is the code you attempt to fix out of the tree? |
OK, will look into that.
Nope, it just smartly used |
df6ecc8 to
6422b84
Compare
|
@Vudentz: Indeed, there was no testcase for k_poll returning -EINTR at all. Now added, tests for both -EINTR and K_POLL_STATE_CANCELLED. |
Previously (as introduced in 48fadfe), if k_poll() waited on a queue (or subclass like fifo), and wait was cancelled on queue's side using k_queue_cancel_wait(), k_poll returned -EINTR. But it did not set event->state field (to anything else but K_POLL_STATE_NOT_READY), so in case of waiting on multiple queues, it was not possible to differentiate which of them was cancelled. This in particular broke detection of network socket EOF conditions in POSIX poll() implementation. This situation is now resolved with introduction of explicit K_POLL_STATE_CANCELLED state, which is now set for cancelled queue (-EINTR return remains the same). This change also elaborates docstring for the functions mentioned, to document this behavior. Fixes: zephyrproject-rtos#9032 Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
6422b84 to
4258ba7
Compare
In this case k_poll() returns -EINTR, while still fills in event states. Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
This is similar to change which was done in 21f31e9, unfortunately this case was missed. Fixes: zephyrproject-rtos#9032 Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
4258ba7 to
8c22527
Compare
|
CI issues now fixed. |
|
@Vudentz, ping. A test was added on your suggestion, this is ready for review. Thanks. |
dcpleung
left a comment
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.
Looks good to me.
Vudentz
left a comment
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.
LGTM
Previously (as introduced in 48fadfe), if k_poll() waited on a
queue (or subclass like fifo), and wait was cancelled on queue's
side using k_queue_cancel_wait(), k_poll returned -EINTR. But it
did not set event->state field (to anything else but
K_POLL_STATE_NOT_READY), so in case of waiting on multiple queues,
it was not possible to differentiate which of them was cancelled.
This in particular broke detection of network socket EOF conditions
in POSIX poll() implementation.
This situation is now resolved with introduction of explicit
K_POLL_STATE_CANCELLED state, which is now set for cancelled queue
(-EINTR return remains the same).
This change also elaborates docstring for the functions mentioned, to
document this behavior.
Fixes: #9032
Signed-off-by: Paul Sokolovsky paul.sokolovsky@linaro.org