Skip to content

Commit 14a716b

Browse files
committed
Get rid of the additional throughput management thread
1) Additional thread brings extra overhead to system; 2) Current main thread can run the throughput management.
1 parent ac01688 commit 14a716b

File tree

6 files changed

+14
-40
lines changed

6 files changed

+14
-40
lines changed

src/main.c

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -81,19 +81,6 @@ int run_ntttcp_sender(struct ntttcp_test_endpoint *tep)
8181
/* prepare to create threads */
8282
pthread_attr_init(&pth_attrs);
8383
pthread_attr_setstacksize(&pth_attrs, THREAD_STACK_SIZE);
84-
85-
/* create throughput management thread */
86-
rc = pthread_create(tep->throughput_mgmt_thread,
87-
&pth_attrs,
88-
run_ntttcp_throughput_management,
89-
(void*)tep);
90-
if (rc) {
91-
ASPRINTF(&log, "pthread_create(): failed to create throughput management thread. errno = %d", errno);
92-
PRINT_ERR_FREE(log);
93-
pthread_attr_destroy(&pth_attrs);
94-
return ERROR_PTHREAD_CREATE;
95-
}
96-
9784
/* create test threads */
9885
for (t = 0; t < test->server_ports; t++) {
9986
for (n = 0; n < test->threads_per_server_port; n++ ) {
@@ -146,16 +133,18 @@ int run_ntttcp_sender(struct ntttcp_test_endpoint *tep)
146133
return err_code;
147134
}
148135

149-
/* wait for test done (after the timer fired, or CTRL+C) */
150-
wait_light_off();
136+
/* manage the test cycle
137+
* will return after light is turned off
138+
* (calling wait_light_off() inside of below
139+
*/
140+
run_ntttcp_throughput_management(tep);
151141

152142
for (n = 0; n < threads_created; n++) {
153143
if (pthread_join(tep->threads[n], &p_retval) !=0 ) {
154144
PRINT_ERR("sender: error when pthread_join");
155145
continue;
156146
}
157147
}
158-
pthread_join(*(tep->throughput_mgmt_thread), &p_retval);
159148

160149
return err_code;
161150
}
@@ -170,17 +159,6 @@ int run_ntttcp_receiver(struct ntttcp_test_endpoint *tep)
170159
struct ntttcp_stream_server *ss;
171160
int rc;
172161

173-
/* create throughput management thread */
174-
rc = pthread_create(tep->throughput_mgmt_thread,
175-
NULL,
176-
run_ntttcp_throughput_management,
177-
(void*)tep);
178-
if (rc) {
179-
ASPRINTF(&log, "pthread_create(): failed to create throughput management thread. errno = %d", errno);
180-
PRINT_ERR_FREE(log);
181-
return ERROR_PTHREAD_CREATE;
182-
}
183-
184162
/* create test threads */
185163
for (t = 0; t < test->server_ports; t++) {
186164
ss = tep->server_streams[t];
@@ -270,8 +248,11 @@ int run_ntttcp_receiver(struct ntttcp_test_endpoint *tep)
270248
return err_code;
271249
}
272250

273-
/* wait test done */
274-
wait_light_off();
251+
/* manage the test cycle
252+
* will return after light is turned off
253+
* (calling wait_light_off() inside of below function)
254+
*/
255+
run_ntttcp_throughput_management(tep);
275256

276257
/* reset thiss variable, in case receiver is running as '-H' (receiver is running in loop) */
277258
tep->num_remote_endpoints = 0;
@@ -288,7 +269,6 @@ int run_ntttcp_receiver(struct ntttcp_test_endpoint *tep)
288269
continue;
289270
}
290271
}
291-
pthread_join(*(tep->throughput_mgmt_thread), NULL);
292272

293273
return err_code;
294274
}

src/main.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,5 @@
77
#define _GNU_SOURCE
88
#include <stdio.h>
99
#include <limits.h>
10-
#include "endpointsync.h"
1110
#include "throughputmanagement.h"
1211
#include "udpstream.h"

src/ntttcp.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,6 @@ struct ntttcp_test_endpoint *new_ntttcp_test_endpoint(struct ntttcp_test *test,
127127
return NULL;
128128
}
129129
}
130-
/* for throughput management thread */
131-
e->throughput_mgmt_thread = malloc( sizeof(pthread_t) );
132130

133131
/* for test results */
134132
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)
215213
free( e->results->final_tcp_retrans);
216214
free( e->results );
217215
free( e->threads );
218-
free( e->throughput_mgmt_thread );
219216
free( e->test );
220217
free( e );
221218
}

src/ntttcp.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ struct ntttcp_test_endpoint{
6666
struct ntttcp_stream_client **client_streams; /* alloc memory for this if client/sender role */
6767
struct ntttcp_stream_server **server_streams; /* alloc memory for this if server/receiver role */
6868
pthread_t *threads; /* linux threads created to transfer test data */
69-
pthread_t *throughput_mgmt_thread; /* linux thread created to manage the throughput on endpoint */
7069

7170
struct ntttcp_test_endpoint_results *results; /* test results */
7271

src/throughputmanagement.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,8 @@ struct report_segment report_real_time_throughput(struct ntttcp_test_endpoint *t
4242
return this_checkpoint;
4343
}
4444

45-
void *run_ntttcp_throughput_management(void *ptr)
45+
void run_ntttcp_throughput_management(struct ntttcp_test_endpoint *tep)
4646
{
47-
struct ntttcp_test_endpoint *tep = (struct ntttcp_test_endpoint *) ptr;
4847
uint n = 0;
4948
uint i = 0;
5049
double elapsed_sec = 0.0;
@@ -59,7 +58,7 @@ void *run_ntttcp_throughput_management(void *ptr)
5958
uint64_t nbytes;
6059
uint total_test_threads = tep->total_threads;
6160

62-
wait_light_on();
61+
/* light is already turned on before entering this function */
6362

6463
/* Now the ntttcp test traffic is running now */
6564
tep->state = TEST_RUNNING;
@@ -210,5 +209,5 @@ void *run_ntttcp_throughput_management(void *ptr)
210209
}
211210

212211
tep->state = TEST_FINISHED;
213-
return NULL;
212+
return;
214213
}

src/throughputmanagement.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ struct report_segment
2121
uint64_t bytes;
2222
};
2323

24-
void *run_ntttcp_throughput_management(void *ptr);
24+
void run_ntttcp_throughput_management(struct ntttcp_test_endpoint *tep);

0 commit comments

Comments
 (0)