From e67134f656ac15088ed41111f3e06ef90308f3d2 Mon Sep 17 00:00:00 2001 From: Swetha Seelam Date: Wed, 29 May 2024 12:18:02 -0400 Subject: [PATCH 1/7] Sleep for the full duration of the test --- src/throughputmanagement.c | 115 +------------------------------------ 1 file changed, 2 insertions(+), 113 deletions(-) diff --git a/src/throughputmanagement.c b/src/throughputmanagement.c index 77cbdd5..ab35955 100644 --- a/src/throughputmanagement.c +++ b/src/throughputmanagement.c @@ -37,61 +37,11 @@ void check_bandwidth_limit(struct ntttcp_test_endpoint *tep) } } -struct report_segment report_real_time_throughput(struct ntttcp_test_endpoint *tep, - struct report_segment last_checkpoint, - uint total_test_threads) -{ - struct report_segment this_checkpoint; - - uint64_t this_total_bytes = 0; - uint64_t last_total_bytes = last_checkpoint.bytes; - uint64_t total_bytes = 0; - - struct timeval this_check_time; - struct timeval last_check_time = last_checkpoint.time; - double test_time = 0; - uint n = 0; - - for (n = 0; n < total_test_threads; n++) { - if (tep->test->client_role == true) - this_total_bytes += tep->client_streams[n]->total_bytes_transferred; - else - this_total_bytes += tep->server_streams[n]->total_bytes_transferred; - } - gettimeofday(&this_check_time, NULL); - test_time = get_time_diff(&this_check_time, &last_check_time); - total_bytes = this_total_bytes - last_total_bytes; - - if (!tep->test->quiet) { - char *throughput = format_throughput(total_bytes, test_time); - char line_end = '\n'; - if (tep->running_tty) { - printf("%c[2K", 27); /* cleanup current line */ - line_end = '\r'; - } - printf("%s: %s%c", "Real-time throughput", throughput, line_end); - fflush(stdout); - free(throughput); - } - - this_checkpoint.interval_sec = test_time; - this_checkpoint.time = this_check_time; - this_checkpoint.bytes = this_total_bytes; - - return this_checkpoint; -} - void run_ntttcp_throughput_management(struct ntttcp_test_endpoint *tep) { uint n = 0; - uint i = 0; - double elapsed_sec = 0.0; - struct timeval now; double actual_test_time = 0; - - struct report_segment last_checkpoint; - uint64_t total_bytes_warmup = 0; uint64_t total_bytes_duration = 0; uint64_t nbytes; @@ -107,26 +57,7 @@ void run_ntttcp_throughput_management(struct ntttcp_test_endpoint *tep) /* 1) run test warm-up, if it is specified */ if (tep->test->warmup > 0) { - gettimeofday(&last_checkpoint.time, NULL); - last_checkpoint.bytes = 0; - elapsed_sec = 0; - while (elapsed_sec < (double)tep->test->warmup) { - /* - * wait 0.5 second, or 1000 test status poll cycles. - * we don't roll up the warmup bytes into final throughput report, - * so we don't care the time accuracy - */ - usleep(THROUGHPUT_INTERVAL_U_SEC); /* 500000 micro-seconds */ - last_checkpoint = report_real_time_throughput(tep, last_checkpoint, total_test_threads); - - elapsed_sec += last_checkpoint.interval_sec; - - /* if test was interrupted by CTRL + C */ - if (!is_light_turned_on()) { - PRINT_INFO("Test was interrupted."); - goto END; - } - } + sleep(tep->test->warmup); PRINT_INFO("Test warmup completed."); /* * 1) reset each stream's total_bytes_transferred counter to 0 (discard warmup bytes) @@ -146,10 +77,7 @@ void run_ntttcp_throughput_management(struct ntttcp_test_endpoint *tep) } /* 2) now, let's run the real test duration */ - elapsed_sec = 0; /* reset the counter */ - last_checkpoint.bytes = 0; /* the counters in streams have been reset to 0 above */ gettimeofday(&now, NULL); /* reset the timestamp to now */ - last_checkpoint.time = now; tep->start_time = now; /* calculate the initial resource usage */ @@ -160,30 +88,7 @@ void run_ntttcp_throughput_management(struct ntttcp_test_endpoint *tep) tep->results->init_rx_packets = get_single_value_from_os_file(tep->test->show_interface_packets, "rx"); tep->results->init_interrupts = get_interrupts_from_proc_by_dev(tep->test->show_dev_interrupts); - while (is_light_turned_on()) { - /* - * Wait 500 micro-seconds. We don't want to pull the status too often. - * But, we also don't want to wait too long time; - * otherwise, in the case of CTRL+C, the test streams have been stopped by CTRL+C (then light is turned off), but we are still waiting here - * which will make the "actual_test_time" longer than actual stream run time, - * and eventually make the final throughput reported inaccurate (will be lower than actual throughput) - */ - usleep(TEST_STATUS_POLL_INTERVAL_U_SEC); - - check_bandwidth_limit(tep); - - /* if we have already waited 1000 poll times (0.5 second), then let's report the throughput */ - i++; - if (i == THROUGHPUT_INTERVAL_POLLS) { - last_checkpoint = report_real_time_throughput(tep, last_checkpoint, total_test_threads); - i = 0; /* reset the counter */ - elapsed_sec += last_checkpoint.interval_sec; - } - - /* if test duration time is reached, then exit this stage */ - if (elapsed_sec > tep->test->duration) - break; - } + sleep(tep->test->duration); /* calculate the end resource usage */ get_cpu_usage(tep->results->final_cpu_usage); @@ -236,20 +141,4 @@ void run_ntttcp_throughput_management(struct ntttcp_test_endpoint *tep) wait_light_off(); PRINT_INFO("Test cycle finished."); - -END: - if (tep->test->client_role == true && tep->test->no_synch == false) { - /* - * if actual_test_time < tep->negotiated_test_cycle_time; - * then this indicates that in the sender side, test is being interrupted. - * hence, tell receiver about this. - */ - if (actual_test_time < tep->negotiated_test_cycle_time) { - tell_receiver_test_exit(tep->synch_socket); - } - close(tep->synch_socket); - } - - tep->state = TEST_FINISHED; - return; } \ No newline at end of file From 59d7593872fd7fa371bbeffe78bf9576f3a7997c Mon Sep 17 00:00:00 2001 From: Swetha Seelam Date: Wed, 29 May 2024 16:08:44 -0400 Subject: [PATCH 2/7] Use nanosleep instead of sleep --- src/throughputmanagement.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/throughputmanagement.c b/src/throughputmanagement.c index ab35955..aa9c6ae 100644 --- a/src/throughputmanagement.c +++ b/src/throughputmanagement.c @@ -57,7 +57,15 @@ void run_ntttcp_throughput_management(struct ntttcp_test_endpoint *tep) /* 1) run test warm-up, if it is specified */ if (tep->test->warmup > 0) { - sleep(tep->test->warmup); + + /*Sleep for warm-up duration*/ + struct timespec req, rem; + req.tv_sec = tep->test->warmup; + + while(nanosleep(&req, &rem) == -1){ + req = rem; + } + PRINT_INFO("Test warmup completed."); /* * 1) reset each stream's total_bytes_transferred counter to 0 (discard warmup bytes) @@ -88,7 +96,13 @@ void run_ntttcp_throughput_management(struct ntttcp_test_endpoint *tep) tep->results->init_rx_packets = get_single_value_from_os_file(tep->test->show_interface_packets, "rx"); tep->results->init_interrupts = get_interrupts_from_proc_by_dev(tep->test->show_dev_interrupts); - sleep(tep->test->duration); + /*Sleep for the test duration*/ + struct timespec req, rem; + req.tv_sec = tep->test->duration; + + while(nanosleep(&req, &rem) == -1){ + req = rem; + } /* calculate the end resource usage */ get_cpu_usage(tep->results->final_cpu_usage); From 6f84c8b17b16940973d8255dd21554df80fcd6ff Mon Sep 17 00:00:00 2001 From: Swetha Seelam Date: Wed, 29 May 2024 16:17:35 -0400 Subject: [PATCH 3/7] Adding back the test cycle finished code --- src/throughputmanagement.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/throughputmanagement.c b/src/throughputmanagement.c index aa9c6ae..85a2171 100644 --- a/src/throughputmanagement.c +++ b/src/throughputmanagement.c @@ -155,4 +155,19 @@ void run_ntttcp_throughput_management(struct ntttcp_test_endpoint *tep) wait_light_off(); PRINT_INFO("Test cycle finished."); + + if (tep->test->client_role == true && tep->test->no_synch == false) { + /* + * if actual_test_time < tep->negotiated_test_cycle_time; + * then this indicates that in the sender side, test is being interrupted. + * hence, tell receiver about this. + */ + if (actual_test_time < tep->negotiated_test_cycle_time) { + tell_receiver_test_exit(tep->synch_socket); + } + close(tep->synch_socket); + } + + tep->state = TEST_FINISHED; + return; } \ No newline at end of file From 53ff2a1100b8158303af3191a9891447f22e2192 Mon Sep 17 00:00:00 2001 From: Swetha Seelam Date: Fri, 31 May 2024 12:58:37 -0400 Subject: [PATCH 4/7] Check for errors in nanosleep --- src/throughputmanagement.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/throughputmanagement.c b/src/throughputmanagement.c index 85a2171..6f62894 100644 --- a/src/throughputmanagement.c +++ b/src/throughputmanagement.c @@ -63,7 +63,15 @@ void run_ntttcp_throughput_management(struct ntttcp_test_endpoint *tep) req.tv_sec = tep->test->warmup; while(nanosleep(&req, &rem) == -1){ - req = rem; + if (errno == EINTR) { + req = rem; + } else if (errno == EFAULT) { + PRINT_ERR("EFAULT: Problem with copying information from user space."); + break; + } else if (errno == EINVAL) { + PRINT_ERR("EINVAL: The time specified to sleep was not in the range [0,999999999]"); + break; + } } PRINT_INFO("Test warmup completed."); @@ -100,8 +108,16 @@ void run_ntttcp_throughput_management(struct ntttcp_test_endpoint *tep) struct timespec req, rem; req.tv_sec = tep->test->duration; - while(nanosleep(&req, &rem) == -1){ - req = rem; + while (nanosleep(&req, &rem) == -1){ + if (errno == EINTR) { + req = rem; + } else if (errno == EFAULT) { + PRINT_ERR("EFAULT: Problem with copying information from user space."); + break; + } else if (errno == EINVAL) { + PRINT_ERR("EINVAL: The time specified to sleep was not in the range [0,999999999]"); + break; + } } /* calculate the end resource usage */ From 247765fa196c46122b90bdf8b9ef70aac4b72622 Mon Sep 17 00:00:00 2001 From: Swetha Seelam Date: Mon, 3 Jun 2024 12:42:45 -0400 Subject: [PATCH 5/7] Print unknown error --- src/throughputmanagement.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/throughputmanagement.c b/src/throughputmanagement.c index 6f62894..2985b6c 100644 --- a/src/throughputmanagement.c +++ b/src/throughputmanagement.c @@ -71,7 +71,10 @@ void run_ntttcp_throughput_management(struct ntttcp_test_endpoint *tep) } else if (errno == EINVAL) { PRINT_ERR("EINVAL: The time specified to sleep was not in the range [0,999999999]"); break; - } + } else { + fprintf(stderr, "Unexpected error (errno %d): %s\n", errno, strerror(errno)); + break; + } } PRINT_INFO("Test warmup completed."); @@ -117,7 +120,10 @@ void run_ntttcp_throughput_management(struct ntttcp_test_endpoint *tep) } else if (errno == EINVAL) { PRINT_ERR("EINVAL: The time specified to sleep was not in the range [0,999999999]"); break; - } + } else { + fprintf(stderr, "Unexpected error (errno %d): %s\n", errno, strerror(errno)); + break; + } } /* calculate the end resource usage */ From 93c47399bf207fe46fe66dc7f98df2ff44463585 Mon Sep 17 00:00:00 2001 From: Swetha Seelam Date: Tue, 4 Jun 2024 12:14:58 -0400 Subject: [PATCH 6/7] quit the program on unexpected errors --- src/throughputmanagement.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/throughputmanagement.c b/src/throughputmanagement.c index 2985b6c..17bd9e6 100644 --- a/src/throughputmanagement.c +++ b/src/throughputmanagement.c @@ -114,15 +114,9 @@ void run_ntttcp_throughput_management(struct ntttcp_test_endpoint *tep) while (nanosleep(&req, &rem) == -1){ if (errno == EINTR) { req = rem; - } else if (errno == EFAULT) { - PRINT_ERR("EFAULT: Problem with copying information from user space."); - break; - } else if (errno == EINVAL) { - PRINT_ERR("EINVAL: The time specified to sleep was not in the range [0,999999999]"); - break; } else { fprintf(stderr, "Unexpected error (errno %d): %s\n", errno, strerror(errno)); - break; + exit(EXIT_FAILURE); } } From 935e4a2db19322752dd1aa196df66e666ef9610f Mon Sep 17 00:00:00 2001 From: Swetha Seelam Date: Tue, 4 Jun 2024 12:17:09 -0400 Subject: [PATCH 7/7] exit on unexpected error --- src/throughputmanagement.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/throughputmanagement.c b/src/throughputmanagement.c index 17bd9e6..5e1bf1d 100644 --- a/src/throughputmanagement.c +++ b/src/throughputmanagement.c @@ -65,17 +65,11 @@ void run_ntttcp_throughput_management(struct ntttcp_test_endpoint *tep) while(nanosleep(&req, &rem) == -1){ if (errno == EINTR) { req = rem; - } else if (errno == EFAULT) { - PRINT_ERR("EFAULT: Problem with copying information from user space."); - break; - } else if (errno == EINVAL) { - PRINT_ERR("EINVAL: The time specified to sleep was not in the range [0,999999999]"); - break; } else { fprintf(stderr, "Unexpected error (errno %d): %s\n", errno, strerror(errno)); - break; - } - } + exit(EXIT_FAILURE); + } + } PRINT_INFO("Test warmup completed."); /* @@ -117,7 +111,7 @@ void run_ntttcp_throughput_management(struct ntttcp_test_endpoint *tep) } else { fprintf(stderr, "Unexpected error (errno %d): %s\n", errno, strerror(errno)); exit(EXIT_FAILURE); - } + } } /* calculate the end resource usage */