Skip to content

Commit

Permalink
Get rid of the additional throughput management thread
Browse files Browse the repository at this point in the history
1) Additional thread brings extra overhead to system;
2) Current main thread can run the throughput management.
  • Loading branch information
simonxiaoss committed Jul 9, 2018
1 parent ac01688 commit 14a716b
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 40 deletions.
40 changes: 10 additions & 30 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++ ) {
Expand Down Expand Up @@ -146,16 +133,18 @@ 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 ) {
PRINT_ERR("sender: error when pthread_join");
continue;
}
}
pthread_join(*(tep->throughput_mgmt_thread), &p_retval);

return err_code;
}
Expand All @@ -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];
Expand Down Expand Up @@ -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;
Expand All @@ -288,7 +269,6 @@ int run_ntttcp_receiver(struct ntttcp_test_endpoint *tep)
continue;
}
}
pthread_join(*(tep->throughput_mgmt_thread), NULL);

return err_code;
}
Expand Down
1 change: 0 additions & 1 deletion src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@
#define _GNU_SOURCE
#include <stdio.h>
#include <limits.h>
#include "endpointsync.h"
#include "throughputmanagement.h"
#include "udpstream.h"
3 changes: 0 additions & 3 deletions src/ntttcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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 );
}
Expand Down
1 change: 0 additions & 1 deletion src/ntttcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down
7 changes: 3 additions & 4 deletions src/throughputmanagement.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -210,5 +209,5 @@ void *run_ntttcp_throughput_management(void *ptr)
}

tep->state = TEST_FINISHED;
return NULL;
return;
}
2 changes: 1 addition & 1 deletion src/throughputmanagement.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

0 comments on commit 14a716b

Please sign in to comment.