]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[tftp] Allow for profiling of client and server turnaround times
authorMichael Brown <mcb30@ipxe.org>
Fri, 22 Jan 2021 21:05:07 +0000 (21:05 +0000)
committerMichael Brown <mcb30@ipxe.org>
Fri, 22 Jan 2021 21:05:07 +0000 (21:05 +0000)
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 <mcb30@ipxe.org>
src/net/udp/tftp.c

index a0dac1ec58b8e02643bd4182b6098822aa36afa9..3073e682fcd5f28bea2d8d458909d12290ab1e4c 100644 (file)
@@ -43,6 +43,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
 #include <ipxe/settings.h>
 #include <ipxe/dhcp.h>
 #include <ipxe/uri.h>
+#include <ipxe/profile.h>
 #include <ipxe/tftp.h>
 
 /** @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 "