Skip to content

Commit

Permalink
Fix busy polling in startup phase
Browse files Browse the repository at this point in the history
During the startup phase, the socket file descriptors (socket-fds) of
the streams are added to the select fd-sets. However, these file
descriptors are not read or written, causing the select operation to be
non-blocking and leading to busy polling.

To address this issue, a separate fd-set is introduced specifically for
the startup phase, which includes only the control socket.

In most scenarios, this results in a short period of increased CPU usage
during startup. However, in more uncommon situations, such as
simulations that utilize target code, this creates unnecessary load on
the system.

Signed-off-by: Benjamin Beichler <[email protected]>
  • Loading branch information
BenjaminBeichler committed Sep 25, 2023
1 parent 57bbb05 commit 987181f
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/iperf_client_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ iperf_run_client(struct iperf_test * test)
{
int startup;
int result = 0;
fd_set read_set, write_set;
fd_set startup_read_set, read_set, write_set;
struct iperf_time now;
struct timeval* timeout = NULL;
struct iperf_stream *sp;
Expand Down Expand Up @@ -563,6 +563,8 @@ iperf_run_client(struct iperf_test * test)
rcv_timeout_us = 0;

startup = 1;
FD_ZERO(&startup_read_set);
memcpy(&startup_read_set, &test->read_set, sizeof(fd_set));
while (test->state != IPERF_DONE) {
memcpy(&read_set, &test->read_set, sizeof(fd_set));
memcpy(&write_set, &test->write_set, sizeof(fd_set));
Expand All @@ -584,7 +586,7 @@ iperf_run_client(struct iperf_test * test)
timeout = &used_timeout;
}

result = select(test->max_fd + 1, &read_set, &write_set, NULL, timeout);
result = select(test->max_fd + 1, (startup)? &startup_read_set : &read_set, (startup)? NULL : &write_set, NULL, timeout);
if (result < 0 && errno != EINTR) {
i_errno = IESELECT;
goto cleanup_and_fail;
Expand Down

0 comments on commit 987181f

Please sign in to comment.