diff --git a/src/main.c b/src/main.c index 7ac0e85..6ed269b 100644 --- a/src/main.c +++ b/src/main.c @@ -81,19 +81,6 @@ int run_ntttcp_sender(struct ntttcp_test_endpoint *tep) /* prepare to create threads */ pthread_attr_init(&pth_attrs); pthread_attr_setstacksize(&pth_attrs, THREAD_STACK_SIZE); - - /* create throughput management thread */ - rc = pthread_create(tep->throughput_mgmt_thread, - &pth_attrs, - run_ntttcp_throughput_management, - (void*)tep); - if (rc) { - ASPRINTF(&log, "pthread_create(): failed to create throughput management thread. errno = %d", errno); - PRINT_ERR_FREE(log); - pthread_attr_destroy(&pth_attrs); - return ERROR_PTHREAD_CREATE; - } - /* create test threads */ for (t = 0; t < test->server_ports; t++) { for (n = 0; n < test->threads_per_server_port; n++ ) { @@ -146,8 +133,11 @@ int run_ntttcp_sender(struct ntttcp_test_endpoint *tep) return err_code; } - /* wait for test done (after the timer fired, or CTRL+C) */ - wait_light_off(); + /* manage the test cycle + * will return after light is turned off + * (calling wait_light_off() inside of below + */ + run_ntttcp_throughput_management(tep); for (n = 0; n < threads_created; n++) { if (pthread_join(tep->threads[n], &p_retval) !=0 ) { @@ -155,7 +145,6 @@ int run_ntttcp_sender(struct ntttcp_test_endpoint *tep) continue; } } - pthread_join(*(tep->throughput_mgmt_thread), &p_retval); return err_code; } @@ -170,17 +159,6 @@ int run_ntttcp_receiver(struct ntttcp_test_endpoint *tep) struct ntttcp_stream_server *ss; int rc; - /* create throughput management thread */ - rc = pthread_create(tep->throughput_mgmt_thread, - NULL, - run_ntttcp_throughput_management, - (void*)tep); - if (rc) { - ASPRINTF(&log, "pthread_create(): failed to create throughput management thread. errno = %d", errno); - PRINT_ERR_FREE(log); - return ERROR_PTHREAD_CREATE; - } - /* create test threads */ for (t = 0; t < test->server_ports; t++) { ss = tep->server_streams[t]; @@ -270,8 +248,11 @@ int run_ntttcp_receiver(struct ntttcp_test_endpoint *tep) return err_code; } - /* wait test done */ - wait_light_off(); + /* manage the test cycle + * will return after light is turned off + * (calling wait_light_off() inside of below function) + */ + run_ntttcp_throughput_management(tep); /* reset thiss variable, in case receiver is running as '-H' (receiver is running in loop) */ tep->num_remote_endpoints = 0; @@ -288,7 +269,6 @@ int run_ntttcp_receiver(struct ntttcp_test_endpoint *tep) continue; } } - pthread_join(*(tep->throughput_mgmt_thread), NULL); return err_code; } diff --git a/src/main.h b/src/main.h index 34ac6bc..7451cf8 100644 --- a/src/main.h +++ b/src/main.h @@ -7,6 +7,5 @@ #define _GNU_SOURCE #include #include -#include "endpointsync.h" #include "throughputmanagement.h" #include "udpstream.h" diff --git a/src/ntttcp.c b/src/ntttcp.c index 1b1563f..8b094ec 100644 --- a/src/ntttcp.c +++ b/src/ntttcp.c @@ -127,8 +127,6 @@ struct ntttcp_test_endpoint *new_ntttcp_test_endpoint(struct ntttcp_test *test, return NULL; } } - /* for throughput management thread */ - e->throughput_mgmt_thread = malloc( sizeof(pthread_t) ); /* for test results */ e->results = (struct ntttcp_test_endpoint_results *) malloc(sizeof(struct ntttcp_test_endpoint_results)); @@ -215,7 +213,6 @@ void free_ntttcp_test_endpoint_and_test(struct ntttcp_test_endpoint* e) free( e->results->final_tcp_retrans); free( e->results ); free( e->threads ); - free( e->throughput_mgmt_thread ); free( e->test ); free( e ); } diff --git a/src/ntttcp.h b/src/ntttcp.h index b66585b..eace329 100644 --- a/src/ntttcp.h +++ b/src/ntttcp.h @@ -66,7 +66,6 @@ struct ntttcp_test_endpoint{ struct ntttcp_stream_client **client_streams; /* alloc memory for this if client/sender role */ struct ntttcp_stream_server **server_streams; /* alloc memory for this if server/receiver role */ pthread_t *threads; /* linux threads created to transfer test data */ - pthread_t *throughput_mgmt_thread; /* linux thread created to manage the throughput on endpoint */ struct ntttcp_test_endpoint_results *results; /* test results */ diff --git a/src/throughputmanagement.c b/src/throughputmanagement.c index 8b4a77c..c1f4bbd 100644 --- a/src/throughputmanagement.c +++ b/src/throughputmanagement.c @@ -42,9 +42,8 @@ struct report_segment report_real_time_throughput(struct ntttcp_test_endpoint *t return this_checkpoint; } -void *run_ntttcp_throughput_management(void *ptr) +void run_ntttcp_throughput_management(struct ntttcp_test_endpoint *tep) { - struct ntttcp_test_endpoint *tep = (struct ntttcp_test_endpoint *) ptr; uint n = 0; uint i = 0; double elapsed_sec = 0.0; @@ -59,7 +58,7 @@ void *run_ntttcp_throughput_management(void *ptr) uint64_t nbytes; uint total_test_threads = tep->total_threads; - wait_light_on(); + /* light is already turned on before entering this function */ /* Now the ntttcp test traffic is running now */ tep->state = TEST_RUNNING; @@ -210,5 +209,5 @@ void *run_ntttcp_throughput_management(void *ptr) } tep->state = TEST_FINISHED; - return NULL; + return; } diff --git a/src/throughputmanagement.h b/src/throughputmanagement.h index e4c6ce7..efe6f7b 100644 --- a/src/throughputmanagement.h +++ b/src/throughputmanagement.h @@ -21,4 +21,4 @@ struct report_segment uint64_t bytes; }; -void *run_ntttcp_throughput_management(void *ptr); +void run_ntttcp_throughput_management(struct ntttcp_test_endpoint *tep);