casaroli opened a new pull request, #22511:
URL: https://github.com/apache/nuttx/pull/22511
## Summary
`epoll_wait()` takes down the poll of each level-triggered file that it
reports (`epoll_teardown()`). Only the next `epoll_wait()` of the same set sets
it up again (`epoll_setup()`). A poll of the set itself (`poll()` of the epoll
descriptor, or an epoll set that holds the set) looks only at the files that
are still set up (`epoll_do_poll()`).
A library that keeps its files in its own epoll set and gives that
descriptor to the event loop of its user does one `epoll_wait()` with timeout 0
on its set for each wakeup, reads the reported files until EAGAIN, and returns.
After that no one watches those files: their next events do not wake the outer
loop, and the program sleeps with data in the files. On Linux an epoll set is
readable while a member is ready, and a level-triggered member stays watched
after `epoll_wait()` reported it.
This PR (one commit, `fs/vfs/fs_epoll.c` only):
- A reported level-triggered file keeps its poll set up until the next
`epoll_wait()` checks it again. A reported event is consumed: the node waits
for a new notification.
- A poll of the set first checks again the files that the last
`epoll_wait()` reported, so a file with data left makes the set ready. It also
counts the notified nodes of the teardown list.
- Each node records if its poll is set up (`epoll_arm()`, `epoll_disarm()`),
so close, `EPOLL_CTL_DEL` and `EPOLL_CTL_MOD` take down only a poll that is set
up.
- A set that holds itself through other sets stops the recursion in
`epoll_setup()`.
- Edge-triggered and `EPOLLONESHOT` nodes keep their behaviour.
#21477 rewrites the same functions of `fs_epoll.c` (with 36 other files) to
stop the full re-registration on every wait. The two conflict in `fs_epoll.c`:
this PR is the small fix of the lost wakeup; whichever merges first, the other
rebases.
## Impact
- Common code: all architectures and all build modes. No API or ABI change.
- `poll()` of an epoll descriptor now also sets up again the nodes that the
last `epoll_wait()` reported (only those, not the whole set).
## Testing
Hosts: macOS arm64 (Arm GNU 13.2.Rel1, QEMU 11.1, TCG and HVF) for the arm64
builds and runs; Fedora x86_64 with the NuttX CI image for the CI-image builds.
All builds use `-Werror`. Master is 0c45a2fc48b with nuttx-apps master
c621be657. The configs add pipes, timerfd, local sockets, cmocka and the apps
epoll test.
Two test programs (not part of this PR; a writer thread gives the late
events):
- `xepollrearm`: inner set {pipe}, outer set {inner}. One round as the
library does it, then a byte, then a wait on the outer set (nest-pending); the
same with the byte 200 ms after the wait began (nest-later); `poll()` on the
inner set after one round (poll-pending); 20 bytes 20 ms apart through the
nested set (nest-stream).
- `xepollnest`: 15 cases of `poll()` and epoll on an epoll descriptor
(ready, drained, late event, a set in a set in a set, a timerfd in the inner
set).
| qemu-armv8a | master | this PR |
|---|---|---|
| nsh (flat), TCG and HVF | xepollrearm 4 of 4 FAIL ("second wait on outer
returned 0 after 2002 ms"); xepollnest 10 passed, 5 failed (poll-still-ready,
nest-wakes, nest-level, nest-drained, nest-3) | xepollrearm 4 of 4 PASS;
xepollnest 15 passed, 0 failed |
| knsh (kernel, TCG) | the same 4 + 5 FAIL | 4 of 4 PASS; 15 passed, 0
failed |
apps `cmocka_epoll` (`testing/fs/epoll`) gives the same result on master and
with this PR, flat and kernel, 3 runs each on HVF: epoll01 and epoll02 fail at
the same line on both (the check after `timerfd_stop()`), and epoll03 fails at
`connect()` (and at `bind()` in a repeated run). These failures exist on master
and do not come from this PR.
With #22431: `git merge-tree` shows no conflict. The merged tree with apps
#4169 passes xepollrearm and xepollnest (flat and kernel), and `cmocka_epoll`
gives the same result as #22431 alone (the new epoll04 and epoll05 pass).
Builds with `-Werror` in the CI image: rv-virt:nsh64 (also CMake, and with
the options above), rv-virt:knsh64, qemu-armv8a:nsh (with the options above),
qemu-armv8a:knsh. 0 warnings (rv-virt has the RWX segment linker warning of
master).
`tools/checkpatch.sh -c -u -m -g`: pass.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]