net:Support jumbo frame prealloc the iob for the ICMP/UDP/TCP.

For the ICMP, UDP and TCP, pre-alloc an iob for a jumbo frame.

Signed-off-by: liqinhui <liqinhui@xiaomi.com>
This commit is contained in:
liqinhui 2024-05-09 15:55:24 +08:00 committed by Alan Carvalho de Assis
parent 45fc68e904
commit 05b101134a
9 changed files with 107 additions and 1 deletions

View File

@ -997,6 +997,21 @@ int netdev_lladdrsize(FAR struct net_driver_s *dev);
int netdev_iob_prepare(FAR struct net_driver_s *dev, bool throttled,
unsigned int timeout);
/****************************************************************************
* Name: netdev_iob_prepare_dynamic
*
* Description:
* Pre-alloc the iob for the data to be sent.
*
* Assumptions:
* The caller has locked the network.
*
****************************************************************************/
#ifdef CONFIG_IOB_ALLOC
void netdev_iob_prepare_dynamic(FAR struct net_driver_s *dev, uint16_t size);
#endif
/****************************************************************************
* Name: netdev_iob_replace
*

View File

@ -146,6 +146,13 @@ config NET_LL_GUARDSIZE
the L2/L3 (MAC/IP) data on Network layer, which will be beneficial
to L3 network layer protocol transparent transmission and forwarding
config NET_JUMBO_FRAME
bool "Net jumbo frame"
depends on IOB_ALLOC
default n
---help---
Optimize the sending of the JUMBO frame in network stack.
config NET_RECV_BUFSIZE
int "Net Default Receive buffer size"
default 0

View File

@ -99,6 +99,10 @@ static void sendto_request(FAR struct net_driver_s *dev,
{
FAR struct icmp_hdr_s *icmp;
#ifdef CONFIG_NET_JUMBO_FRAME
netdev_iob_prepare_dynamic(dev, pstate->snd_buflen + IPv4_HDRLEN);
#endif
/* Set-up to send that amount of data. */
devif_send(dev, pstate->snd_buf, pstate->snd_buflen, IPv4_HDRLEN);

View File

@ -98,6 +98,10 @@ static void sendto_request(FAR struct net_driver_s *dev,
{
FAR struct icmpv6_echo_request_s *icmpv6;
#ifdef CONFIG_NET_JUMBO_FRAME
netdev_iob_prepare_dynamic(dev, pstate->snd_buflen + IPv6_HDRLEN);
#endif
/* Set-up to send that amount of data. */
devif_send(dev, pstate->snd_buf, pstate->snd_buflen, IPv6_HDRLEN);

View File

@ -84,6 +84,43 @@ int netdev_iob_prepare(FAR struct net_driver_s *dev, bool throttled,
return OK;
}
/****************************************************************************
* Name: netdev_iob_prepare_dynamic
*
* Description:
* Pre-alloc the iob for the data to be sent.
*
* Assumptions:
* The caller has locked the network.
*
****************************************************************************/
#ifdef CONFIG_IOB_ALLOC
void netdev_iob_prepare_dynamic(FAR struct net_driver_s *dev, uint16_t size)
{
FAR struct iob_s *iob;
size += CONFIG_NET_LL_GUARDSIZE;
if (dev->d_iob && size <= IOB_BUFSIZE(dev->d_iob))
{
return;
}
/* alloc new iob for jumbo frame */
iob = iob_alloc_dynamic(size);
if (iob == NULL)
{
nerr("ERROR: Failed to allocate an I/O buffer.");
return;
}
iob_reserve(iob, CONFIG_NET_LL_GUARDSIZE);
netdev_iob_replace(dev, iob);
}
#endif
/****************************************************************************
* Name: netdev_iob_replace
*

View File

@ -747,6 +747,15 @@ static uint16_t psock_send_eventhandler(FAR struct net_driver_s *dev,
tcp_setsequence(conn->sndseq, TCP_WBSEQNO(wrb));
#ifdef CONFIG_NET_JUMBO_FRAME
if (sndlen <= conn->mss)
{
/* alloc iob */
netdev_iob_prepare_dynamic(dev, sndlen + tcpip_hdrsize(conn));
}
#endif
ret = devif_iob_send(dev, TCP_WBIOB(wrb), sndlen,
0, tcpip_hdrsize(conn));
if (ret <= 0)
@ -1074,6 +1083,15 @@ static uint16_t psock_send_eventhandler(FAR struct net_driver_s *dev,
* won't actually happen until the polling cycle completes).
*/
#ifdef CONFIG_NET_JUMBO_FRAME
if (sndlen <= conn->mss)
{
/* alloc iob */
netdev_iob_prepare_dynamic(dev, sndlen + tcpip_hdrsize(conn));
}
#endif
ret = devif_iob_send(dev, TCP_WBIOB(wrb), sndlen,
TCP_WBSENT(wrb), tcpip_hdrsize(conn));
if (ret <= 0)

View File

@ -546,7 +546,11 @@ FAR struct udp_wrbuffer_s *udp_wrbuffer_timedalloc(unsigned int timeout);
****************************************************************************/
#ifdef CONFIG_NET_UDP_WRITE_BUFFERS
#ifdef CONFIG_NET_JUMBO_FRAME
FAR struct udp_wrbuffer_s *udp_wrbuffer_tryalloc(int len);
#else
FAR struct udp_wrbuffer_s *udp_wrbuffer_tryalloc(void);
#endif
#endif /* CONFIG_NET_UDP_WRITE_BUFFERS */
/****************************************************************************

View File

@ -720,6 +720,13 @@ ssize_t psock_udp_sendto(FAR struct socket *psock, FAR const void *buf,
* unlocked here.
*/
#ifdef CONFIG_NET_JUMBO_FRAME
/* alloc iob of gso pkt for udp data */
wrb = udp_wrbuffer_tryalloc(len + udpip_hdrsize(conn) +
CONFIG_NET_LL_GUARDSIZE);
#else
if (nonblock)
{
wrb = udp_wrbuffer_tryalloc();
@ -729,6 +736,7 @@ ssize_t psock_udp_sendto(FAR struct socket *psock, FAR const void *buf,
wrb = udp_wrbuffer_timedalloc(udp_send_gettimeout(start,
timeout));
}
#endif
if (wrb == NULL)
{

View File

@ -235,7 +235,11 @@ FAR struct udp_wrbuffer_s *udp_wrbuffer_timedalloc(unsigned int timeout)
*
****************************************************************************/
#ifdef CONFIG_NET_JUMBO_FRAME
FAR struct udp_wrbuffer_s *udp_wrbuffer_tryalloc(int len)
#else
FAR struct udp_wrbuffer_s *udp_wrbuffer_tryalloc(void)
#endif
{
FAR struct udp_wrbuffer_s *wrb;
@ -262,7 +266,12 @@ FAR struct udp_wrbuffer_s *udp_wrbuffer_tryalloc(void)
/* Now get the first I/O buffer for the write buffer structure */
wrb->wb_iob = iob_tryalloc(false);
wrb->wb_iob =
#ifdef CONFIG_NET_JUMBO_FRAME
iob_alloc_dynamic(len);
#else
iob_tryalloc(false);
#endif
if (!wrb->wb_iob)
{
nerr("ERROR: Failed to allocate I/O buffer\n");