Skip to content

Commit

Permalink
net:Support jumbo frame prealloc the iob for the ICMP/UDP/TCP.
Browse files Browse the repository at this point in the history
For the ICMP, UDP and TCP, pre-alloc an iob for a jumbo frame.

Signed-off-by: liqinhui <[email protected]>
  • Loading branch information
liqinhuixm authored and acassis committed Jun 2, 2024
1 parent 45fc68e commit 05b1011
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 1 deletion.
15 changes: 15 additions & 0 deletions include/nuttx/net/netdev.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
7 changes: 7 additions & 0 deletions net/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions net/icmp/icmp_sendmsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions net/icmpv6/icmpv6_sendmsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
37 changes: 37 additions & 0 deletions net/netdev/netdev_iob.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
18 changes: 18 additions & 0 deletions net/tcp/tcp_send_buffered.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions net/udp/udp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

/****************************************************************************
Expand Down
8 changes: 8 additions & 0 deletions net/udp/udp_sendto_buffered.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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)
{
Expand Down
11 changes: 10 additions & 1 deletion net/udp/udp_wrbuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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");
Expand Down

0 comments on commit 05b1011

Please sign in to comment.