net/devif_poll: optimize device buffer alloc in txpoll

Allocate the device buffer only if the protocol really need to send data.
not all protocols require the driver to prepare additional iob before
sending, especially UDP, each iob reserves l2/l3 header in advance
after prepare write buffer, net device could reuse this entry to send directly

Signed-off-by: chao an <anchao@xiaomi.com>
This commit is contained in:
chao an
2023-01-11 16:09:20 +08:00
committed by Xiang Xiao
parent 0cbbbb9215
commit 8a63d29c6e
19 changed files with 96 additions and 83 deletions
+9 -2
View File
@@ -78,12 +78,19 @@ void devif_send(FAR struct net_driver_s *dev, FAR const void *buf,
return;
}
iob_update_pktlen(dev->d_iob, offset);
/* Copy in iob to target device buffer */
if (len <= iob_navail(false) * CONFIG_IOB_BUFSIZE)
{
/* Prepare device buffer before poll callback */
if (netdev_iob_prepare(dev, false, 0) != OK)
{
return;
}
iob_update_pktlen(dev->d_iob, offset);
dev->d_sndlen = iob_trycopyin(dev->d_iob, buf, len, offset, false);
}
else