mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <sha@pengutronix.de>
To: Enrico Scholz <enrico.scholz@sigma-chemnitz.de>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH 11/13] tftp: reorder tftp packets
Date: Tue, 9 Aug 2022 10:58:17 +0200	[thread overview]
Message-ID: <20220809085817.GK31528@pengutronix.de> (raw)
In-Reply-To: <14bf205ffe1ba093e93531b8a43758e18c18a94d.1658144543.git.enrico.scholz@sigma-chemnitz.de>

On Mon, Jul 18, 2022 at 02:22:26PM +0200, Enrico Scholz wrote:
> With the tftp "windowsize" option, reordering of udp datagrams becomes
> an issue.  Depending on the network topology, this reordering occurs
> several times with large tftp transfers and will heavily reduce the
> transfer speed.
> 
> This patch adds a packet cache so that datagrams can be reassembled in
> the correct order.
> 
> Because it increases memory usage, it is an Kconfig option.
> 
> Signed-off-by: Enrico Scholz <enrico.scholz@sigma-chemnitz.de>
> ---
>  fs/Kconfig |  22 +++++++
>  fs/tftp.c  | 165 +++++++++++++++++++++++++++++++++++++++++++++++++++--
>  2 files changed, 181 insertions(+), 6 deletions(-)
> 
> diff --git a/fs/Kconfig b/fs/Kconfig
> index 0c4934285942..02aa25d6abf7 100644
> --- a/fs/Kconfig
> +++ b/fs/Kconfig
> @@ -57,6 +57,28 @@ config FS_TFTP_MAX_WINDOW_SIZE
>  	  Requires tftp "windowsize" (RFC 7440) support on server side
>  	  to have an effect.
>  
> +config FS_TFTP_REORDER_CACHE_SIZE
> +	int
> +	prompt "number of out-of-order tftp packets to be cached"
> +	depends on FS_TFTP
> +	default 16 if FS_TFTP_MAX_WINDOW_SIZE > 16
> +	default  0 if FS_TFTP_MAX_WINDOW_SIZE = 1
> +        ## TODO: it should be 'FS_TFTP_MAX_WINDOW_SIZE - 1' but this
> +        ## is not supported by Kconfig
> +	default FS_TFTP_MAX_WINDOW_SIZE
> +	range 0 FS_TFTP_MAX_WINDOW_SIZE
> +	help
> +	  UDP allows reordering of datagrams; with this option,
> +	  unexpected tftp packets will be cached and later
> +	  reassembled.  This increases stability of the tftp download
> +	  with the cost of memory (around 1440 bytes per cache
> +	  element).
> +
> +          A value of 0 disables caching.
> +
> +	  Requires tftp "windowsize" (RFC 7440) support on server side
> +	  to have an effect.
> +
>  config FS_OMAP4_USBBOOT
>  	bool
>  	prompt "Filesystem over usb boot"
> diff --git a/fs/tftp.c b/fs/tftp.c
> index f85136f03e22..2c2ff081be51 100644
> --- a/fs/tftp.c
> +++ b/fs/tftp.c
> @@ -68,6 +68,9 @@
>  #define TFTP_MTU_SIZE		1432	/* MTU based block size */
>  #define TFTP_MAX_WINDOW_SIZE	CONFIG_FS_TFTP_MAX_WINDOW_SIZE
>  
> +/* size of cache which deals with udp reordering */
> +#define TFTP_WINDOW_CACHE_NUM	CONFIG_FS_TFTP_REORDER_CACHE_SIZE
> +
>  /* calculate fifo so that it can hold the complete window plus the incoming
>     packet.  Add some extra space just in case...  */
>  #define TFTP_FIFO_SIZE		(TFTP_MTU_SIZE * TFTP_MAX_WINDOW_SIZE + 2048)
> @@ -76,6 +79,15 @@
>  
>  static int g_tftp_window_size = TFTP_MAX_WINDOW_SIZE / 1;
>  
> +struct tftp_block {
> +	uint16_t id;
> +	uint8_t data[TFTP_MTU_SIZE];
> +
> +	/* len will not exceed TFTP_MTU_SIZE; 14 bits should suffice... */
> +	uint16_t len:14;
> +	bool valid:1;
> +};
> +
>  struct file_priv {
>  	struct net_connection *tftp_con;
>  	int push;
> @@ -93,12 +105,49 @@ struct file_priv {
>  	int blocksize;
>  	unsigned int windowsize;
>  	bool is_getattr;
> +#if TFTP_WINDOW_CACHE_NUM > 0
> +	struct tftp_block window_cache[TFTP_WINDOW_CACHE_NUM];
> +#endif
>  };

Can you use a struct list_head here rather than an array? With that
you can use list_add_sort() to sort the cached packets by id and it
becomes easy to see if the next packet is already there or not without
iterating over the cache multiple times. Also by allocating a tftp_block
dynamically when you need it you only occupy memory for packets that are
received in the wrong order, not for a fixed number of blocks.

Sascha

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



  reply	other threads:[~2022-08-09  8:59 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-18 12:22 [PATCH 00/13] add "windowsize" (RFC 7440) support for tftp Enrico Scholz
2022-07-18 12:22 ` [PATCH 01/13] progress: add close_progress() to display some statistics Enrico Scholz
2022-07-18 12:22 ` [PATCH 02/13] libfile:copy_file: show statistics in verbose mode Enrico Scholz
2022-07-18 12:22 ` [PATCH 03/13] tftp: minor refactoring of RRQ/WRQ packet generation code Enrico Scholz
2022-07-18 12:22 ` [PATCH 04/13] tftp: replace hardcoded blksize by global constant Enrico Scholz
2022-07-18 12:22 ` [PATCH 05/13] tftp: record whether tftp file is opened for lookup operation only Enrico Scholz
2022-07-18 12:22 ` [PATCH 06/13] tftp: reduce block size on lookup requests Enrico Scholz
2022-07-18 12:22 ` [PATCH 07/13] tftp: refactor data processing Enrico Scholz
2022-07-18 12:22 ` [PATCH 08/13] tftp: detect out-of-memory situations Enrico Scholz
2022-07-18 12:22 ` [PATCH 09/13] tftp: implement 'windowsize' (RFC 7440) support Enrico Scholz
2022-07-31 11:36   ` [PATCH v2 " Enrico Scholz
2022-08-09  8:49     ` Sascha Hauer
2022-08-09  9:28       ` Enrico Scholz
2022-08-09  9:52         ` Sascha Hauer
2022-07-18 12:22 ` [PATCH 10/13] tftp: do not use 'priv->block' for RRQ Enrico Scholz
2022-07-18 12:22 ` [PATCH 11/13] tftp: reorder tftp packets Enrico Scholz
2022-08-09  8:58   ` Sascha Hauer [this message]
2022-07-18 12:22 ` [PATCH 12/13] tftp: allow to change tftp port Enrico Scholz
2022-08-09  8:12   ` Sascha Hauer
2022-07-18 12:22 ` [PATCH 13/13] tftp: add sanity check for OACK response Enrico Scholz
2022-07-31 11:36   ` [PATCH v2 " Enrico Scholz
2022-08-09  9:02 ` [PATCH 00/13] add "windowsize" (RFC 7440) support for tftp Sascha Hauer
2022-08-09  9:35   ` Enrico Scholz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220809085817.GK31528@pengutronix.de \
    --to=sha@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=enrico.scholz@sigma-chemnitz.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox