summaryrefslogtreecommitdiff
path: root/src/tools/operf/operf_client.c
diff options
context:
space:
mode:
authordimitri staessens <dimitri.staessens@intec.ugent.be>2016-11-19 16:28:11 +0100
committerdimitri staessens <dimitri.staessens@intec.ugent.be>2016-11-19 16:30:06 +0100
commit26b338bbb6d10ca19eabee2bcb0bdf9ef82bca63 (patch)
tree1489683642a77e8a860e88fecbc7484ea2ad901f /src/tools/operf/operf_client.c
parent74a93600f89066cc210838ff2eddafee4448bf4e (diff)
downloadouroboros-26b338bbb6d10ca19eabee2bcb0bdf9ef82bca63.tar.gz
ouroboros-26b338bbb6d10ca19eabee2bcb0bdf9ef82bca63.zip
tools: Use busy waiting in operf
Using nanosleep in between sending SDUs is not accurate enough when sending thousands of SDUs per second. The --sleep option is added for lowering CPU consumption in low bandwidth tests.
Diffstat (limited to 'src/tools/operf/operf_client.c')
-rw-r--r--src/tools/operf/operf_client.c23
1 files changed, 19 insertions, 4 deletions
diff --git a/src/tools/operf/operf_client.c b/src/tools/operf/operf_client.c
index 1f6226d4..902a7b41 100644
--- a/src/tools/operf/operf_client.c
+++ b/src/tools/operf/operf_client.c
@@ -36,6 +36,17 @@
#include <errno.h>
#include <float.h>
+static void busy_wait_until(const struct timespec * deadline)
+{
+ struct timespec now;
+ clock_gettime(CLOCK_REALTIME, &now);
+ while (now.tv_sec < deadline->tv_sec)
+ clock_gettime(CLOCK_REALTIME, &now);
+ while (now.tv_sec == deadline->tv_sec
+ && now.tv_nsec < deadline->tv_nsec)
+ clock_gettime(CLOCK_REALTIME, &now);
+}
+
void shutdown_client(int signo, siginfo_t * info, void * c)
{
(void) info;
@@ -85,6 +96,7 @@ void * writer(void * o)
struct timespec now;
struct timespec start;
struct timespec intv = {(gap / BILLION), gap % BILLION};
+ struct timespec end = {0, 0};
char * buf = malloc(client.size);
if (buf == NULL)
@@ -123,6 +135,9 @@ void * writer(void * o)
}
} else {
while (ts_diff_ms(&start, &now) < client.duration) {
+ clock_gettime(CLOCK_REALTIME, &now);
+ ts_add(&now, &intv, &end);
+
if (flow_write(*fdp, buf, client.size) == -1) {
printf("Failed to send SDU.\n");
flow_dealloc(*fdp);
@@ -131,10 +146,10 @@ void * writer(void * o)
}
++client.sent;
-
- nanosleep(&intv, NULL);
-
- clock_gettime(CLOCK_REALTIME, &now);
+ if (client.sleep)
+ nanosleep(&intv, NULL);
+ else
+ busy_wait_until(&end);
}
}