From 8ef22d819b688e17d7e20380631caed29acc9d63 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Fri, 22 Jan 2021 21:05:07 +0000 Subject: [PATCH] [tftp] Allow for profiling of client and server turnaround times Provide some visibility into the turnaround times on both client and server sides as perceived by iPXE, to assist in debugging inexplicably slow TFTP transfers. Signed-off-by: Michael Brown --- src/net/udp/tftp.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/net/udp/tftp.c b/src/net/udp/tftp.c index a0dac1ec5..3073e682f 100644 --- a/src/net/udp/tftp.c +++ b/src/net/udp/tftp.c @@ -43,6 +43,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include #include #include +#include #include /** @file @@ -158,6 +159,14 @@ enum { /** Maximum number of MTFTP open requests before falling back to TFTP */ #define MTFTP_MAX_TIMEOUTS 3 +/** Client profiler */ +static struct profiler tftp_client_profiler __profiler = + { .name = "tftp.client" }; + +/** Server profiler */ +static struct profiler tftp_server_profiler __profiler = + { .name = "tftp.server" }; + /** * Free TFTP request * @@ -802,6 +811,10 @@ static int tftp_rx_data ( struct tftp_request *tftp, } block += ( ntohs ( data->block ) - 1 ); + /* Stop profiling server turnaround if applicable */ + if ( block ) + profile_stop ( &tftp_server_profiler ); + /* Extract data */ offset = ( block * tftp->blksize ); iob_pull ( iobuf, sizeof ( *data ) ); @@ -834,6 +847,12 @@ static int tftp_rx_data ( struct tftp_request *tftp, /* Acknowledge block */ tftp_send_packet ( tftp ); + /* Stop profiling client turnaround */ + profile_stop ( &tftp_client_profiler ); + + /* Start profiling server turnaround */ + profile_start ( &tftp_server_profiler ); + /* If all blocks have been received, finish. */ if ( bitmap_full ( &tftp->bitmap ) ) tftp_done ( tftp, 0 ); @@ -906,7 +925,10 @@ static int tftp_rx ( struct tftp_request *tftp, struct tftp_common *common = iobuf->data; size_t len = iob_len ( iobuf ); int rc = -EINVAL; - + + /* Start profiling client turnaround */ + profile_start ( &tftp_client_profiler ); + /* Sanity checks */ if ( len < sizeof ( *common ) ) { DBGC ( tftp, "TFTP %p received underlength packet length "