From 91c33dcfd08be3c00f7993dfc27c71212d2e9c32 Mon Sep 17 00:00:00 2001 From: David Bar-On <61089727+davidBar-On@users.noreply.github.com> Date: Fri, 4 Dec 2020 18:26:53 +0200 Subject: [PATCH] Bitrate throttling when burst is specified (#1090) When the -b option specifies a burst value, throttling the bitrate does not work. This is because iperf_check_throttle() does not perform the check when burst value was defined. This change removes the dependency of iperf_check_throttle() on the burst value and moves that check to the caller of that function. (Except for the call by send_timer_proc() which does not seem to be related to the change.) --- src/iperf_api.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/iperf_api.c b/src/iperf_api.c index dad864b..64f83fb 100644 --- a/src/iperf_api.c +++ b/src/iperf_api.c @@ -1539,7 +1539,7 @@ iperf_check_throttle(struct iperf_stream *sp, struct iperf_time *nowP) double seconds; uint64_t bits_per_second; - if (sp->test->done || sp->test->settings->rate == 0 || sp->test->settings->burst != 0) + if (sp->test->done || sp->test->settings->rate == 0) return; iperf_time_diff(&sp->result->start_time_fixed, nowP, &temp_time); seconds = iperf_time_in_secs(&temp_time); @@ -1598,6 +1598,7 @@ iperf_send(struct iperf_test *test, fd_set *write_setP) register int multisend, r, streams_active; register struct iperf_stream *sp; struct iperf_time now; + int no_throttle_check; /* Can we do multisend mode? */ if (test->settings->burst != 0) @@ -1607,8 +1608,11 @@ iperf_send(struct iperf_test *test, fd_set *write_setP) else multisend = 1; /* nope */ + /* Should bitrate throttle be checked for every send */ + no_throttle_check = test->settings->rate != 0 && test->settings->burst == 0; + for (; multisend > 0; --multisend) { - if (test->settings->rate != 0 && test->settings->burst == 0) + if (no_throttle_check) iperf_time_now(&now); streams_active = 0; SLIST_FOREACH(sp, &test->streams, streams) { @@ -1623,7 +1627,8 @@ iperf_send(struct iperf_test *test, fd_set *write_setP) streams_active = 1; test->bytes_sent += r; ++test->blocks_sent; - iperf_check_throttle(sp, &now); + if (no_throttle_check) + iperf_check_throttle(sp, &now); if (multisend > 1 && test->settings->bytes != 0 && test->bytes_sent >= test->settings->bytes) break; if (multisend > 1 && test->settings->blocks != 0 && test->blocks_sent >= test->settings->blocks) @@ -1633,7 +1638,7 @@ iperf_send(struct iperf_test *test, fd_set *write_setP) if (!streams_active) break; } - if (test->settings->burst != 0) { + if (!no_throttle_check) { /* Throttle check if was not checked for each send */ iperf_time_now(&now); SLIST_FOREACH(sp, &test->streams, streams) if (sp->sender)