You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ac...@apache.org on 2020/02/11 01:13:13 UTC

[incubator-nuttx] branch pr248 updated: Network Loopbacka Driver: A configuration option to control packet size.

This is an automated email from the ASF dual-hosted git repository.

acassis pushed a commit to branch pr248
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git


The following commit(s) were added to refs/heads/pr248 by this push:
     new c2f31d4  Network Loopbacka Driver:  A configuration option to control packet size.
c2f31d4 is described below

commit c2f31d4da0f890b582f277b933ee89232930da64
Author: Gregory Nutt <gn...@nuttx.org>
AuthorDate: Mon Feb 10 18:35:02 2020 -0600

    Network Loopbacka 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
---
 boards/sim/sim/sim/configs/tcploop/defconfig |  1 +
 drivers/net/loopback.c                       |  3 ++-
 include/nuttx/net/netconfig.h                | 16 ++++++++++++++--
 net/Kconfig                                  | 18 ++++++++++++++++++
 4 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/boards/sim/sim/sim/configs/tcploop/defconfig b/boards/sim/sim/sim/configs/tcploop/defconfig
index 888c68c..00c9d7e 100644
--- a/boards/sim/sim/sim/configs/tcploop/defconfig
+++ b/boards/sim/sim/sim/configs/tcploop/defconfig
@@ -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
diff --git a/drivers/net/loopback.c b/drivers/net/loopback.c
index 88a5d05..36ae9f2 100644
--- a/drivers/net/loopback.c
+++ b/drivers/net/loopback.c
@@ -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
diff --git a/include/nuttx/net/netconfig.h b/include/nuttx/net/netconfig.h
index 1fdb71f..7ed1dbd 100644
--- a/include/nuttx/net/netconfig.h
+++ b/include/nuttx/net/netconfig.h
@@ -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 ******************************************/
 
@@ -206,7 +218,7 @@
    * of the timer is 8-bits.
    */
 
-#    define CONFIG_NET_TCP_REASS_MAXAGE (20*10) /* 20 seconds */
+#    define CONFIG_NET_TCP_REASS_MAXAGE (20 * 10) /* 20 seconds */
 #  endif
 #endif
 
diff --git a/net/Kconfig b/net/Kconfig
index fffbfa8..5019cd5 100644
--- a/net/Kconfig
+++ b/net/Kconfig
@@ -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