aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Morey-Chaisemartin <nmorey@kalray.eu>2015-08-04 13:00:38 +0200
committerMaxim Uvarov <maxim.uvarov@linaro.org>2015-08-06 14:25:17 +0300
commitc02fbd7221acea2f40f76fafafff0e12181637d1 (patch)
treeec433047d78d40343edde0686f267bd6d41cc8c1
parent7f6daf2991a6f0994069ae2cb145ada9ec484c8f (diff)
performance: l2fwd: fix race condition between thread init and stat counter
Add a barrier between main and worker threads to be sure worker statistics are initialized Signed-off-by: Nicolas Morey-Chaisemartin <nmorey@kalray.eu> Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
-rw-r--r--test/performance/odp_l2fwd.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/test/performance/odp_l2fwd.c b/test/performance/odp_l2fwd.c
index 157df3b..b34df89 100644
--- a/test/performance/odp_l2fwd.c
+++ b/test/performance/odp_l2fwd.c
@@ -109,6 +109,8 @@ typedef struct {
/** Global pointer to args */
static args_t *gbl_args;
+/** Global barrier to synchronize main and workers */
+static odp_barrier_t barrier;
/* helper funcs */
static inline odp_queue_t lookup_dest_q(odp_packet_t pkt);
@@ -136,6 +138,7 @@ static void *pktio_queue_thread(void *arg)
thr = odp_thread_id();
printf("[%02i] QUEUE mode\n", thr);
+ odp_barrier_wait(&barrier);
/* Loop packets */
while (!exit_threads) {
@@ -219,6 +222,7 @@ static void *pktio_ifburst_thread(void *arg)
gbl_args->appl.if_names[src_idx],
gbl_args->appl.if_names[dst_idx],
odp_pktio_to_u64(pktio_src), odp_pktio_to_u64(pktio_dst));
+ odp_barrier_wait(&barrier);
/* Loop packets */
while (!exit_threads) {
@@ -323,6 +327,9 @@ static void print_speed_stats(int num_workers, stats_t **thr_stats,
int i, elapsed = 0;
int loop_forever = (duration == 0);
+ /* Wait for all threads to be ready*/
+ odp_barrier_wait(&barrier);
+
do {
pkts = 0;
drops = 0;
@@ -445,6 +452,8 @@ int main(int argc, char *argv[])
stats_t **stats = calloc(1, sizeof(stats_t) * num_workers);
+ odp_barrier_init(&barrier, num_workers + 1);
+
/* Create worker threads */
cpu = odp_cpumask_first(&cpumask);
for (i = 0; i < num_workers; ++i) {