From 358985eb580b9141808385053da41e12df619de9 Mon Sep 17 00:00:00 2001 From: Jef Poskanzer Date: Fri, 1 Mar 2013 09:41:33 -0800 Subject: [PATCH] Page-align the read/write buffer. Unclear if this helps, but it certainly doesn't hurt. --- src/iperf.h | 3 ++- src/iperf_api.c | 12 +++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/iperf.h b/src/iperf.h index 225cd1a..fd344c9 100644 --- a/src/iperf.h +++ b/src/iperf.h @@ -84,7 +84,8 @@ struct iperf_stream struct iperf_stream_result *result; /* structure pointer to result */ Timer *send_timer; int udp_green_light; - char *buffer; /* data to send */ + char *buffer_malloc; /* data to send, malloced */ + char *buffer; /* data to send, page-aligned */ /* * for udp measurements - This can be a structure outside stream, and diff --git a/src/iperf_api.c b/src/iperf_api.c index f2e041e..6ce9d84 100644 --- a/src/iperf_api.c +++ b/src/iperf_api.c @@ -1673,7 +1673,7 @@ iperf_free_stream(struct iperf_stream *sp) struct iperf_interval_results *irp, *nirp; /* XXX: need to free interval list too! */ - free(sp->buffer); + free(sp->buffer_malloc); for (irp = TAILQ_FIRST(&sp->result->interval_results); irp != TAILQ_END(sp->result->interval_results); irp = nirp) { nirp = TAILQ_NEXT(irp, irlistentries); free(irp); @@ -1684,6 +1684,11 @@ iperf_free_stream(struct iperf_stream *sp) free(sp); } +#define PAGE 65536 +/* A guess - we should actually detect real page size. But as long as +** this is a multiple of the real one, it works for alignment purposes. +*/ + /**************************************************************************/ struct iperf_stream * iperf_new_stream(struct iperf_test *test, int s) @@ -1700,11 +1705,11 @@ iperf_new_stream(struct iperf_test *test, int s) memset(sp, 0, sizeof(struct iperf_stream)); sp->test = test; - sp->buffer = (char *) malloc(test->settings->blksize); + sp->buffer_malloc = (char *) malloc(test->settings->blksize + PAGE); sp->result = (struct iperf_stream_result *) malloc(sizeof(struct iperf_stream_result)); sp->settings = test->settings; - if (!sp->buffer) { + if (!sp->buffer_malloc) { i_errno = IECREATESTREAM; return NULL; } @@ -1717,6 +1722,7 @@ iperf_new_stream(struct iperf_test *test, int s) TAILQ_INIT(&sp->result->interval_results); /* Randomize the buffer */ + sp->buffer = (char*) (((uint64_t) sp->buffer_malloc / PAGE + 1 ) * PAGE); srandom(time(NULL)); for (i = 0; i < test->settings->blksize; ++i) sp->buffer[i] = random();