Skip to content

Commit

Permalink
Merge pull request #1773 from davidBar-On/pacing_timer-remove__and__m…
Browse files Browse the repository at this point in the history
…t_sent-simplify

Remove the usage of pacing_timer and simplify iperf_mt_send
  • Loading branch information
bmah888 authored Nov 1, 2024
2 parents 80e657f + bf12abb commit 0586e1c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 72 deletions.
96 changes: 29 additions & 67 deletions src/iperf_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
6 changes: 1 addition & 5 deletions src/iperf_locale.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 0586e1c

Please sign in to comment.