From bf12abbeb825989b839f6b0134ca5f787996785a Mon Sep 17 00:00:00 2001 From: DavidBar-On Date: Thu, 19 Sep 2024 15:55:44 +0300 Subject: [PATCH] Remove the usage of pacing_timer and simplify iperf_mt_send --- src/iperf_api.c | 96 ++++++++++++++-------------------------------- src/iperf_locale.c | 6 +-- 2 files changed, 30 insertions(+), 72 deletions(-) diff --git a/src/iperf_api.c b/src/iperf_api.c index dcf386c30..d0feafd0c 100644 --- a/src/iperf_api.c +++ b/src/iperf_api.c @@ -1993,10 +1993,10 @@ iperf_check_total_rate(struct iperf_test *test, iperf_size_t last_interval_bytes int iperf_send_mt(struct iperf_stream *sp) { - register int multisend, r, streams_active; + register int multisend, r, message_sent; register struct iperf_test *test = sp->test; struct iperf_time now; - int no_throttle_check; + int throttle_check_per_message; /* Can we do multisend mode? */ if (test->settings->burst != 0) @@ -2007,45 +2007,38 @@ iperf_send_mt(struct iperf_stream *sp) 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 (no_throttle_check) - iperf_time_now(&now); - streams_active = 0; - { - if (sp->green_light && sp->sender) { - // XXX If we hit one of these ending conditions maybe - // want to stop even trying to send something? - 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) - break; - if ((r = sp->snd(sp)) < 0) { - if (r == NET_SOFTERROR) - break; - i_errno = IESTREAMWRITE; - return r; - } - streams_active = 1; - test->bytes_sent += r; - if (!sp->pending_size) - ++test->blocks_sent; - if (no_throttle_check) - iperf_check_throttle(sp, &now); - } - } - if (!streams_active) - break; + throttle_check_per_message = test->settings->rate != 0 && test->settings->burst == 0; + + for (message_sent = 0; sp->green_light && multisend > 0; --multisend) { + // XXX If we hit one of these ending conditions maybe + // want to stop even trying to send something? + 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) + break; + if ((r = sp->snd(sp)) < 0) { + if (r == NET_SOFTERROR) + break; + i_errno = IESTREAMWRITE; + return r; + } + test->bytes_sent += r; + if (!sp->pending_size) + ++test->blocks_sent; + if (throttle_check_per_message) { + if (message_sent == 0) + iperf_time_now(&now); + iperf_check_throttle(sp, &now); + } + message_sent = 1; } #if defined(HAVE_CLOCK_NANOSLEEP) || defined(HAVE_NANOSLEEP) if (!sp->green_light) { /* Should check if green ligh can be set, as pacing timer is not supported in this case */ #else /* !HAVE_CLOCK_NANOSLEEP && !HAVE_NANOSLEEP */ - if (!no_throttle_check) { /* Throttle check if was not checked for each send */ + if (!throttle_check_per_message || message_sent == 0) { /* Throttle check if was not checked for each send */ #endif /* HAVE_CLOCK_NANOSLEEP, HAVE_NANOSLEEP */ iperf_time_now(&now); - if (sp->sender) - iperf_check_throttle(sp, &now); + iperf_check_throttle(sp, &now); } return 0; } @@ -2098,46 +2091,15 @@ iperf_init_test(struct iperf_test *test) return 0; } -#if !defined(HAVE_CLOCK_NANOSLEEP) && !defined(HAVE_NANOSLEEP) -static void -send_timer_proc(TimerClientData client_data, struct iperf_time *nowP) -{ - struct iperf_stream *sp = client_data.p; - - /* All we do here is set or clear the flag saying that this stream may - ** be sent to. The actual sending gets done in the send proc, after - ** checking the flag. - */ - iperf_check_throttle(sp, nowP); -} -#endif /* !HAVE_CLOCK_NANOSLEEP && !HAVE_NANOSLEEP) */ int iperf_create_send_timers(struct iperf_test * test) { + // Note: No times for the multi-thread versions struct iperf_stream *sp; -#if !defined(HAVE_CLOCK_NANOSLEEP) && !defined(HAVE_NANOSLEEP) - TimerClientData cd; - struct iperf_time now; - - if (iperf_time_now(&now) < 0) { - i_errno = IEINITTEST; - return -1; - } -#endif /* !HAVE_CLOCK_NANOSLEEP && !HAVE_NANOSLEEP) */ SLIST_FOREACH(sp, &test->streams, streams) { sp->green_light = 1; -#if !defined(HAVE_CLOCK_NANOSLEEP) && !defined(HAVE_NANOSLEEP) - if (test->settings->rate != 0 && sp->sender) { - cd.p = sp; - sp->send_timer = tmr_create(NULL, send_timer_proc, cd, test->settings->pacing_timer, 1); - if (sp->send_timer == NULL) { - i_errno = IEINITTEST; - return -1; - } - } -#endif /* !HAVE_CLOCK_NANOSLEEP && !HAVE_NANOSLEEP) */ } return 0; } diff --git a/src/iperf_locale.c b/src/iperf_locale.c index 5c6e66dfd..32883da84 100644 --- a/src/iperf_locale.c +++ b/src/iperf_locale.c @@ -163,12 +163,8 @@ const char usage_longstr[] = "Usage: iperf3 [-s|-c host] [options]\n" " -b, --bitrate #[KMG][/#] target bitrate in bits/sec (0 for unlimited)\n" " (default %d Mbit/sec for UDP, unlimited for TCP)\n" " (optional slash and packet count for burst mode)\n" -#if !defined(HAVE_CLOCK_NANOSLEEP) && !defined(HAVE_NANOSLEEP) - " --pacing-timer #[KMG] set the timing for pacing, in microseconds (default %d)\n" -#else " --pacing-timer #[KMG] set the Server timing for pacing, in microseconds (default %d)\n" - " (used by the server only if this option is in its help message)\n" -#endif /* !HAVE_CLOCK_NANOSLEEP && !HAVE_NANOSLEEP */ + " (deprecated - for servers using older versions ackward compatibility)\n" #if defined(HAVE_SO_MAX_PACING_RATE) " --fq-rate #[KMG] enable fair-queuing based socket pacing in\n" " bits/sec (Linux only)\n"