net: Rename tcp_dataconcat to net_iob_concat

Allow other protocols like UDP to use concat logic.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
This commit is contained in:
Zhe Weng 2023-07-04 14:24:16 +08:00 committed by Xiang Xiao
parent b79671a336
commit 4b7604cf81
9 changed files with 116 additions and 75 deletions

View file

@ -266,20 +266,6 @@ config NET_TCP_WRBUFFER_DUMP
endif # NET_TCP_WRITE_BUFFERS
config NET_TCP_RECV_PACK
bool "Enable TCP/IP receive data in a continuous poll"
default y
---help---
This option will enable TCP/IP receive data into a continuous iob chain.
Fragmentation of network data will intensify iob consumption, if
the device receives a message storm of fragmented packets, the iob
cache will not be effectively used, this is not allowed on iot devices
since the resources of such devices are limited. Of course, this
also takes some disadvantages: data needs to be copied.
This option will brings some balance on resource-constrained devices,
enable this config to reduce the consumption of iob, the received iob
buffers will be merged into the contiguous iob chain.
config NET_TCPBACKLOG
bool "TCP/IP backlog support"
default n

View file

@ -1373,21 +1373,6 @@ uint16_t tcp_datahandler(FAR struct net_driver_s *dev,
FAR struct tcp_conn_s *conn,
uint16_t offset);
/****************************************************************************
* Name: tcp_dataconcat
*
* Description:
* Concatenate iob_s chain iob2 to iob1, if CONFIG_NET_TCP_RECV_PACK is
* endabled, pack all data in the I/O buffer chain.
*
* Returned Value:
* The number of bytes actually buffered is returned. This will be either
* zero or equal to iob1->io_pktlen.
*
****************************************************************************/
uint16_t tcp_dataconcat(FAR struct iob_s **iob1, FAR struct iob_s **iob2);
/****************************************************************************
* Name: tcp_backlogcreate
*

View file

@ -36,6 +36,7 @@
#include "devif/devif.h"
#include "tcp/tcp.h"
#include "utils/utils.h"
#ifdef NET_TCP_HAVE_STACK
@ -143,7 +144,7 @@ static uint16_t tcp_ofoseg_data_event(FAR struct net_driver_s *dev,
rcvseq = TCP_SEQ_ADD(rcvseq,
seg->data->io_pktlen);
net_incr32(conn->rcvseq, seg->data->io_pktlen);
tcp_dataconcat(&conn->readahead, &seg->data);
net_iob_concat(&conn->readahead, &seg->data);
}
else if (TCP_SEQ_GT(rcvseq, seg->left))
{
@ -177,7 +178,7 @@ static uint16_t tcp_ofoseg_data_event(FAR struct net_driver_s *dev,
rcvseq = TCP_SEQ_ADD(rcvseq,
seg->data->io_pktlen);
net_incr32(conn->rcvseq, seg->data->io_pktlen);
tcp_dataconcat(&conn->readahead, &seg->data);
net_iob_concat(&conn->readahead, &seg->data);
}
}
}
@ -350,43 +351,6 @@ uint16_t tcp_callback(FAR struct net_driver_s *dev,
return flags;
}
/****************************************************************************
* Name: tcp_dataconcat
*
* Description:
* Concatenate iob_s chain iob2 to iob1, if CONFIG_NET_TCP_RECV_PACK is
* endabled, pack all data in the I/O buffer chain.
*
* Returned Value:
* The number of bytes actually buffered is returned. This will be either
* zero or equal to iob->io_pktlen.
*
****************************************************************************/
uint16_t tcp_dataconcat(FAR struct iob_s **iob1, FAR struct iob_s **iob2)
{
if (*iob1 == NULL)
{
*iob1 = *iob2;
}
else
{
iob_concat(*iob1, *iob2);
}
*iob2 = NULL;
#ifdef CONFIG_NET_TCP_RECV_PACK
/* Merge an iob chain into a continuous space, thereby reducing iob
* consumption.
*/
*iob1 = iob_pack(*iob1);
#endif
return (*iob1)->io_pktlen;
}
/****************************************************************************
* Name: tcp_datahandler
*
@ -438,7 +402,7 @@ uint16_t tcp_datahandler(FAR struct net_driver_s *dev,
/* Concat the iob to readahead */
tcp_dataconcat(&conn->readahead, &iob);
net_iob_concat(&conn->readahead, &iob);
/* Clear device buffer */

View file

@ -315,7 +315,7 @@ static bool tcp_rebuild_ofosegs(FAR struct tcp_conn_s *conn,
else if (ofoseg->left == seg->right)
{
tcp_dataconcat(&seg->data, &ofoseg->data);
net_iob_concat(&seg->data, &ofoseg->data);
seg->right = ofoseg->right;
}
@ -338,7 +338,7 @@ static bool tcp_rebuild_ofosegs(FAR struct tcp_conn_s *conn,
ofoseg->data =
iob_trimhead(ofoseg->data,
TCP_SEQ_SUB(seg->right, ofoseg->left));
tcp_dataconcat(&seg->data, &ofoseg->data);
net_iob_concat(&seg->data, &ofoseg->data);
seg->right = ofoseg->right;
}
}
@ -355,7 +355,7 @@ static bool tcp_rebuild_ofosegs(FAR struct tcp_conn_s *conn,
if (ofoseg->right == seg->left)
{
tcp_dataconcat(&ofoseg->data, &seg->data);
net_iob_concat(&ofoseg->data, &seg->data);
seg->data = ofoseg->data;
seg->left = ofoseg->left;
ofoseg->data = NULL;
@ -390,7 +390,7 @@ static bool tcp_rebuild_ofosegs(FAR struct tcp_conn_s *conn,
ofoseg->data =
iob_trimtail(ofoseg->data,
ofoseg->right - seg->left);
tcp_dataconcat(&ofoseg->data, &seg->data);
net_iob_concat(&ofoseg->data, &seg->data);
seg->data = ofoseg->data;
seg->left = ofoseg->left;
ofoseg->data = NULL;

View file

@ -29,7 +29,8 @@ set(SRCS
net_incr32.c
net_lock.c
net_snoop.c
net_cmsg.c)
net_cmsg.c
net_iob_concat.c)
# IPv6 utilities

View file

@ -28,3 +28,17 @@ config NET_ARCH_CHKSUM
config NET_SNOOP_BUFSIZE
int "Snoop buffer size for interrupt"
default 4096
config NET_RECV_PACK
bool "Enable TCP/IP receive data in a continuous poll"
default y
---help---
This option will enable TCP/IP receive data into a continuous iob chain.
Fragmentation of network data will intensify iob consumption, if
the device receives a message storm of fragmented packets, the iob
cache will not be effectively used, this is not allowed on iot devices
since the resources of such devices are limited. Of course, this
also takes some disadvantages: data needs to be copied.
This option will brings some balance on resource-constrained devices,
enable this config to reduce the consumption of iob, the received iob
buffers will be merged into the contiguous iob chain.

View file

@ -22,7 +22,7 @@
NET_CSRCS += net_dsec2tick.c net_dsec2timeval.c net_timeval2dsec.c
NET_CSRCS += net_chksum.c net_ipchksum.c net_incr32.c net_lock.c net_snoop.c
NET_CSRCS += net_cmsg.c
NET_CSRCS += net_cmsg.c net_iob_concat.c
# IPv6 utilities

View file

@ -0,0 +1,74 @@
/****************************************************************************
* net/utils/net_iob_concat.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <nuttx/mm/iob.h>
#ifdef CONFIG_MM_IOB
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: net_iob_concat
*
* Description:
* Concatenate iob_s chain iob2 to iob1, if CONFIG_NET_RECV_PACK is
* endabled, pack all data in the I/O buffer chain.
*
* Returned Value:
* The number of bytes actually buffered is returned. This will be either
* zero or equal to iob->io_pktlen.
*
****************************************************************************/
uint16_t net_iob_concat(FAR struct iob_s **iob1, FAR struct iob_s **iob2)
{
if (*iob1 == NULL)
{
*iob1 = *iob2;
}
else
{
iob_concat(*iob1, *iob2);
}
*iob2 = NULL;
#ifdef CONFIG_NET_RECV_PACK
/* Merge an iob chain into a continuous space, thereby reducing iob
* consumption.
*/
*iob1 = iob_pack(*iob1);
#endif
return (*iob1)->io_pktlen;
}
#endif /* CONFIG_MM_IOB */

View file

@ -192,6 +192,23 @@ uint8_t net_ipv6_mask2pref(FAR const uint16_t *mask);
void net_ipv6_pref2mask(uint8_t preflen, net_ipv6addr_t mask);
#endif
/****************************************************************************
* Name: net_iob_concat
*
* Description:
* Concatenate iob_s chain iob2 to iob1, if CONFIG_NET_RECV_PACK is
* endabled, pack all data in the I/O buffer chain.
*
* Returned Value:
* The number of bytes actually buffered is returned. This will be either
* zero or equal to iob1->io_pktlen.
*
****************************************************************************/
#ifdef CONFIG_MM_IOB
uint16_t net_iob_concat(FAR struct iob_s **iob1, FAR struct iob_s **iob2);
#endif
/****************************************************************************
* Name: net_chksum_adjust
*