Network Loopback Driver: A configuration option to control packet size.

Historically, the loopback driver used the largest packet size of all enabled link layer protocols.  This permitted packets to be forward via the loopbak device with no major loss of performance.  However, in experimenting with configurations where no other link layer protocols were enabled, this means the loopback packet size was set to the smallest possible size, to the SLIP minimum of 296 bytes.  This resulted in terrible loopback performance.

    This commit adds an option to increase the loopback packet size with the option CONFIG_NET_LOOPBACK_PACKETSIZE.

    The loopback driver packet buffer should be quite large.  The larger the loopback packet buffer, the better will be TCP performance of the loopback transfers.  The Linux loopback device historically used packet buffers of size 16Kb, but that was increased in recent Linux versions to 64Kb.  Those sizes may be excessive for resource constrained MCUs, however.

    The network still enforces the lower limit that is the maximum packet size of all enabled link layer protocols.  But this new option permits the loopback packet size to be increased from that.

    * net/Kconfig:  Adds CONFIG_NET_LOOPBACK_PKTSIZE option
    * include/nuttx/net/netconfig.h:  Assures that the packet size that is used is at least as large as the largest packet size of other link layer protocols.
    * drivers/net/loopback.c:  Use that larger packet size.
    * boards/sim/sim/sim/configs/tcploop/defconfig:  Set the loopback packet size to 1500
This commit is contained in:
Gregory Nutt 2020-02-10 18:35:02 -06:00 committed by Alan Carvalho de Assis
parent 2af17da334
commit 3c0b49448a
4 changed files with 35 additions and 3 deletions

View File

@ -45,6 +45,7 @@ CONFIG_NETDEVICES=y
CONFIG_NET_IPv6=y
CONFIG_NET_IPv6_NCONF_ENTRIES=4
CONFIG_NET_LOOPBACK=y
CONFIG_NET_LOOPBACK_PKTSIZE=1500
CONFIG_NET_MAX_LISTENPORTS=16
CONFIG_NET_SOCKOPTS=y
CONFIG_NET_TCP=y

View File

@ -54,6 +54,7 @@
#include <nuttx/irq.h>
#include <nuttx/wdog.h>
#include <nuttx/wqueue.h>
#include <nuttx/net/netconfig.h>
#include <nuttx/net/netdev.h>
#include <nuttx/net/ip.h>
#include <nuttx/net/loopback.h>
@ -108,7 +109,7 @@ struct lo_driver_s
****************************************************************************/
static struct lo_driver_s g_loopback;
static uint8_t g_iobuffer[MAX_NETDEV_PKTSIZE + CONFIG_NET_GUARDSIZE];
static uint8_t g_iobuffer[NET_LO_PKTSIZE + CONFIG_NET_GUARDSIZE];
/****************************************************************************
* Private Function Prototypes

View File

@ -184,9 +184,21 @@
#define MIN_NETDEV_PKTSIZE _MIN_6LOWPAN_PKTSIZE
#define MAX_NETDEV_PKTSIZE _MAX_6LOWPAN_PKTSIZE
/* For the loopback device, we will use the largest MTU */
/* The loopback driver packet buffer should be quite large. The larger the
* loopback packet buffer, the better will be TCP performance of the loopback
* transfers. The Linux loopback device historically used packet buffers of
* size 16Kb, but that was increased in recent Linux versions to 64Kb. Those
* sizes may be excessive for resource constrained MCUs, however.
*
* For the loopback driver, we enforce a lower limit that is the maximum
* packet size of all enabled link layer protocols.
*/
#if CONFIG_NET_LOOPBACK_PKTSIZE < MAX_NETDEV_PKTSIZE
# define NET_LO_PKTSIZE MAX_NETDEV_PKTSIZE
#else
# define NET_LO_PKTSIZE CONFIG_NET_LOOPBACK_PKTSIZE
#endif
/* Layer 3/4 Configuration Options ******************************************/

View File

@ -132,6 +132,24 @@ config NET_LOOPBACK
---help---
Add support for the local network loopback device, lo.
config NET_LOOPBACK_PKTSIZE
int "Loopback packet buffer size"
default 0
depends on NET_LOOPBACK
range 0 65535
---help---
The loopback driver packet buffer should be quite large. The larger
the loopback packet buffer, the better will be TCP performance of
the loopback transfers. The Linux loopback device historically used
packet buffers of size 16Kb, but that was increased in recent Linux
versions to 64Kb. Those sizes may be excessive for resource
constrained MCUs, however.
The network enforces a lower limit that is the maximum packet size
of all enabled link layer protocols. The default value of
CONFIG_NET_LOOPBACK_PKTSIZE is zero, meaning that this maximum
packet size will be used by loopback driver.
menuconfig NET_SLIP
bool "SLIP support"
select ARCH_HAVE_NETDEV_STATISTICS