From 5f00065c549cb1187316bd7f43205be53649c6ac Mon Sep 17 00:00:00 2001 From: EunBong Song Date: Thu, 27 Apr 2017 14:17:14 +0900 Subject: [PATCH] apps/iperf: add iperf_api semaphore on reporter callback when iperf bi-directional test, freelist array value has been corrupted due to simultaneous access on it. - freelist array is used on __dtoa function called by snprintf - it causes data abort during a long-run test iperf reporter callback function is called by timer interrupt so, to guarantee completion of it we've added semaphore on reporter callback function. Change-Id: Ib0549de6c850008eb825a6d484205c0b84725b6d Signed-off-by: Jin-Seong Kim Signed-off-by: EunBong Song --- apps/examples/iperf/iperf.h | 4 ++++ apps/examples/iperf/iperf_api.c | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/apps/examples/iperf/iperf.h b/apps/examples/iperf/iperf.h index f1a55b7..6b8784a 100644 --- a/apps/examples/iperf/iperf.h +++ b/apps/examples/iperf/iperf.h @@ -59,6 +59,8 @@ #include #endif /* HAVE_CPUSET_SETAFFINITY */ +#include + #include "iperf_timer.h" #include "iperf_queue.h" #include "iperf_cjson.h" @@ -284,6 +286,8 @@ struct iperf_test { iperf_size_t blocks_sent; char cookie[COOKIE_SIZE]; // struct iperf_stream *streams; /* pointer to list of struct stream */ + + sem_t sem_iperf_api; SLIST_HEAD(slisthead, iperf_stream) streams; struct iperf_settings *settings; diff --git a/apps/examples/iperf/iperf_api.c b/apps/examples/iperf/iperf_api.c index b1d1450..5d7a012 100644 --- a/apps/examples/iperf/iperf_api.c +++ b/apps/examples/iperf/iperf_api.c @@ -77,6 +77,8 @@ #include #endif /* HAVE_CPUSET_SETAFFINITY */ +#include + #include "iperf_net.h" #include "iperf.h" #include "iperf_api.h" @@ -107,6 +109,11 @@ static int JSON_write(int fd, cJSON *json); static void print_interval_results(struct iperf_test *test, struct iperf_stream *sp, cJSON *json_interval_streams); static cJSON *JSON_read(int fd); +/************************** Iperf semaphore functions **************************/ +#define IPERF_UNLOCK(n) sem_post(n) +#define IPERF_LOCK(n) sem_wait(n) +/*******************************************************************************/ + /*************************** Print usage functions ****************************/ void iperf_usage(void) @@ -1755,6 +1762,10 @@ struct iperf_test *iperf_new_test(void) /* By default all output goes to stdout */ test->outfile = stdout; + if (sem_init(&(test->sem_iperf_api),0 ,1) != OK) { + printf("iperf_new_test : failed on sem_init\n"); + } + return test; } @@ -1989,6 +2000,7 @@ void iperf_free_test(struct iperf_test *test) // test->streams = NULL; test->stats_callback = NULL; test->reporter_callback = NULL; + sem_destroy(&test->sem_iperf_api); free(test); } @@ -2528,6 +2540,8 @@ static void iperf_print_results(struct iperf_test *test) */ void iperf_reporter_callback(struct iperf_test *test) { + IPERF_LOCK(&test->sem_iperf_api); + switch (test->state) { case TEST_RUNNING: case STREAM_RUNNING: @@ -2541,6 +2555,8 @@ void iperf_reporter_callback(struct iperf_test *test) break; } + IPERF_UNLOCK(&test->sem_iperf_api); + } /** -- 2.7.4