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

   ## Summary
   NET_BUFPOOL is a thin wrapper that the network code keeps on top of the 
generic mempool. These four commits move the remaining non-CAN pools over to 
mempool directly, so there is one
   allocator instead of two.
   
   net/bluetooth, net/ieee802154, net/usrsock: Use MEMPOOL_DEFINE for 
connections.
   Moves the bluetooth, ieee802154 and usrsock connection pools to 
MEMPOOL_DEFINE. Two details are worth noting. NET_BUFPOOL_LOCK() protected both 
the pool and the active connection list;
   mempool has its own lock, so the list is now protected by the existing 
per-protocol lock. And NET_BUFPOOL_TRYALLOC() returned zeroed memory only for 
blocks it had just grown with
   kmm_zalloc(), while each *_alloc() sets only part of the connection, so the 
block is now cleared explicitly after mempool_allocate() to keep a recycled 
connection from starting with stale fields.
   
   net/tcp: Use MEMPOOL_DEFINE for the TCP write buffers.                       
                                                                                
                               Moves the TCP write buffer pool to 
MEMPOOL_DEFINE. tcp_wrbuffer_test() reports the free count with 
mempool_navail() and keeps returning OK or -ENOSPC, as NET_BUFPOOL_TEST() did.
   
   net/tcp: Use MEMPOOL_DEFINE for the TCP connections.
   Moves the TCP connection pool to MEMPOOL_DEFINE. tcp_conn_list_lock() and 
tcp_conn_list_unlock() were built on the pool lock, which mempool does not 
expose, so the connection list gets itsown rmutex g_tcp_connections_lock, and 
both functions become inline wrappers around it in tcp.h.
   
   net/can: Fix the build with CONFIG_NET_CAN_NBUFFERS enabled.
   An unrelated pre-existing build failure found while testing this series. 
can_bufpool.c did not compile when the CAN buffer pool was enabled:
   
   can/can_bufpool.c:103:19: warning: implicit declaration of function 
'mempool_zallocate_throttled'
   can/can_bufpool.c:140:28: error: 'throttled' undeclared (first use in this 
function)
   
   
   can_iob_timedalloc() allocated with mempool_zallocate_throttled(), which 
does not exist here, while the pool is declared with NET_BUFPOOL_DECLARE(). 
Allocation now uses
   NET_BUFPOOL_TIMEDALLOC() to match the pool declaration, and the throttled 
argument is marked unused because that pool has no throttling. The buffer still 
starts cleared, because
   iob_init_with_data() clears the header. Separately, can_iob_clone() passed a 
throttled variable that is not in its scope; it takes no such parameter 
upstream, so it now passes false, whichis what the can_iob_clone() fallback 
macro does when the pool is disabled. This commit deliberately does not migrate 
the CAN pool to mempool, since the upstream mempool has no throttled
   or zeroing variant; that would be a migration rather than a build fix.
   
   ## Impact
   
   No Kconfig change and no new configuration options. The *_MAX_CONNS options 
that MEMPOOL_DEFINE takes already have fallback defines in each file.
   
   No API change outside the network stack. tcp_conn_list_lock() and 
tcp_conn_list_unlock() change from out-of-line functions to inline wrappers in 
tcp.h, and g_tcp_connections_lock is added;both are private to net/tcp.
   
   No behaviour change intended. The connection pools keep the same 
preallocated, dynamic and maximum counts, and tcp_wrbuffer_test() keeps its OK 
/ -ENOSPC contract.
   
   CONFIG_NET_CAN_NBUFFERS can be enabled again; it did not build before.
   
   On the configuration below, the series adds 456 bytes of text, 672 bytes of 
data and 32 bytes of bss. The data growth is the mempool bookkeeping replacing 
the NET_BUFPOOL one.
   
   The remaining NET_BUFPOOL users (net/can/can_raw.c, net/can/can_isotp.c, 
net/can/can_bufpool.c) and the wrapper itself in net/utils/ are untouched, so 
this series does not depend on, nor
   block, the other MEMPOOL_DEFINE migration covering icmp, icmpv6, pkt, 
netlink, udp, route, devif and netforward. The two can be merged in either 
order; I verified they share no files and
   that the merged result builds.
   
   ## Testing
   
   Host: x86_64 Linux. Configuration: sim:dynconns (flat build) with 
DEBUG_ASSERTIONS enabled, which also enables NET_TCP, NET_TCP_WRITE_BUFFERS, 
NET_USRSOCK, NET_BLUETOOTH, NET_IEEE802154
   and NET_CAN, so all six changed source files are compiled. For the runtime 
test the TAP device is bridged to the host bridge nuttx0 (10.0.1.1/24) and the 
device is 10.0.1.2/24.
   
   Data path, with tcpecho running on the device:
   
   ICMP, 4 pings from the host:
   
   4 packets transmitted, 4 received, 0% packet loss, time 3005ms
   rtt min/avg/max/mdev = 1.511/5.004/10.049/3.156 ms
   
   
   TCP, 4 concurrent echo connections of 256 KiB each, which exercises both the 
connection pool and the write buffer pool:
   
   conn0: sent=262144 recv=262144 err=None
   conn1: sent=262144 recv=262144 err=None
   conn2: sent=262144 recv=262144 err=None
   conn3: sent=262144 recv=262144 err=None
   
   
   This test caught a regression during development. tcp_wrbuffer_timedalloc() 
only sets wb_iob, and NET_BUFPOOL_TIMEDALLOC() happened to return zeroed 
memory, so a reused write buffer kept astale wb_sent and tripped 
DEBUGASSERT(TCP_WBSENT(wrb) <= TCP_WBPKTLEN(wrb)) in tcp_send_buffered.c. The 
same load passes on the base commit and fails without the explicit clear, so the
   buffer is now cleared after mempool_allocate(). The fix is part of the write 
buffer commit.
   
   Build with CONFIG_NET_CAN_NBUFFERS unset (the default): builds and links 
clean.
   
   Build with CONFIG_IOB_ALLOC=y and CONFIG_NET_CAN_NBUFFERS=8: builds and 
links clean, with no warning or error from can_bufpool.c. Before the last 
commit the same configuration failed with the two diagnostics quoted above.
   
   ./tools/checkpatch.sh -c -u -m -g <base>..HEAD passes on all four commits, 
and -c -u -f passes on all seven changed files.
   
   Independence from the other MEMPOOL_DEFINE series was checked by merging the 
two branches: no shared files, a clean merge with no conflicts, and the merged 
tree builds.
   


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

  • [PR] net: Use MEMPOOL_DEFINE ... zhhyu7 (via GitHub) via commits

Reply via email to