casaroli opened a new pull request, #22356:
URL: https://github.com/apache/nuttx/pull/22356

   ## Summary
   
   An epoll set keeps the poll of each file set up across its waits (it sets 
`POLLALWAYS`), and with `EPOLLET` it does not set the poll up again after an 
event (`epoll_teardown()` in `fs/vfs/fs_epoll.c`). The poll callbacks of TCP, 
UDP and packet sockets were written for `poll()`, which is woken once and then 
tears its poll down. This gave wrong edges for an epoll set:
   
   - TCP: `tcp_poll_eventhandler()` stopped its callback after the first event. 
An `EPOLLET` TCP socket got its first event and then no other. For example, new 
data on a kept-alive connection was never reported.
   - TCP, UDP and packet sockets: the event handlers set `POLLOUT` on each poll 
of the device (`TCP_POLL`, `UDP_POLL`, `PKT_POLL`). The device polls all 
connections when one of them has data to send, and this does not change the 
other sockets. So an idle `EPOLLOUT | EPOLLET` socket got an event each time 
another socket sent data.
   
   - Commit 1 (TCP): for an epoll set, only an ACK, new data, a connection or a 
closed peer reports `POLLOUT`, not a poll of the device alone.
   - Commit 2 (TCP): the callback of an epoll set stays active until the poll 
teardown.
   - Commit 3 (UDP, without `CONFIG_NET_UDP_WRITE_BUFFERS`): the connection 
counts the `sendto()` calls that wait for the device. An epoll set gets 
`POLLOUT` only while one of them waits, that is, for a datagram of this socket.
   - Commit 4 (packet sockets, without `CONFIG_NET_PKT_WRITE_BUFFERS`): the 
same, and also when the last check found no free IOB, so a socket that could 
not send gets its edge when an IOB is free again.
   
   Linux reports `EPOLLOUT` when the data that the socket sent leaves it, not 
when another socket sends.
   
   ## Impact
   
   Behaviour of `epoll` with TCP, UDP and packet sockets. `poll()` and 
`select()` do not change: the new checks apply only when `POLLALWAYS` is set, 
which only epoll sets. With write buffers, UDP and packet sockets do not 
change: there a send can fail with `EAGAIN`, and each poll of the device still 
reports `POLLOUT`, so that no edge is lost.
   
   No API, ABI or Kconfig change. One `uint16_t` in each UDP and packet 
connection without write buffers, one `bool` in the packet poll information. 
Common network code: the same in flat, protected and kernel builds and on all 
architectures.
   
   ## Testing
   
   New cases in `testing/nettest` (apache/nuttx-apps#NNNN): 
`test_tcp_epollet_in`, `test_tcp_epollet_out`, `test_tcp_epollet_eagain`, 
`test_udp_epollet_idle`, `test_udp_epollet_send`, `test_pkt_lo_epollet`. Each 
run was the full `cmocka_net_tcp`, `cmocka_net_udp` and `cmocka_net_pkt`, 
except where the table says. The base commit and this branch carry the arm64 
commit of apache/nuttx#22329 (without it `qemu-armv8a:knsh` does not start 
init).
   
   | Config | Base commit | This PR |
   |---|---|---|
   | qemu-armv8a:knsh (kernel), QEMU TCG, UDP and packet sockets without write 
buffers, TCP with them, 3 boots each | `test_tcp_epollet_in`, `_out`, 
`_eagain`, `test_udp_epollet_idle`, `test_pkt_lo_epollet` FAIL in 3 of 3 | all 
6 pass in 3 of 3 |
   | qemu-armv8a:nsh (flat), TCG, all write buffers swapped (TCP without, UDP 
and packet with), 1 boot, `cmocka_net_tcp` limited to the EPOLLET cases with a 
local cmocka filter | `test_tcp_epollet_in`, `_out` FAIL | pass; the idle UDP 
and packet cases skip |
   | qemu-intel64:knsh_romfs (kernel, CMake), KVM, 1 boot | the same 5 cases 
FAIL | all 6 pass |
   
   The other cases give the same result with and without this PR. 
`test_tcp_close_timewait` fails on both, and on x86_64 also 
`test_tcp_reset_send`. In the flat build without TCP write buffers, 
`test_tcp_send_limit_wakeup` fails and `test_tcp_listen_recv` does not return, 
on both. `ostest` passes on qemu-armv8a:knsh with this PR.
   
   Builds with `-Werror` (CI image, gcc 12.3): qemu-armv8a:knsh and :nsh (also 
with UDP and packet sockets off), rv-virt:knsh and :nsh (32-bit), 
qemu-intel64:knsh_romfs (CMake). Each touched file is built with and without 
its write buffers.
   


-- 
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]

Reply via email to