From: Grigore Ion <ion.grig...@freescale.com> The counters.seq counter is used to check if the configured number of packets was processed. There is a race condition between the counter incrementation time and its value testing time. If code is running on multiple CPUs it is possible the application send more packets than expected (with number of CPUs - 1). A separate counter must be used for the processed packets.
Signed-off-by: Grigore Ion <ion.grig...@freescale.com> --- example/generator/odp_generator.c | 20 +++++++++++--------- 1 files changed, 11 insertions(+), 9 deletions(-) diff --git a/example/generator/odp_generator.c b/example/generator/odp_generator.c index e281b27..34df8b3 100644 --- a/example/generator/odp_generator.c +++ b/example/generator/odp_generator.c @@ -66,6 +66,7 @@ static struct { odp_atomic_u64_t ip; /**< ip packets */ odp_atomic_u64_t udp; /**< udp packets */ odp_atomic_u64_t icmp; /**< icmp packets */ + odp_atomic_u64_t cnt; /**< sent packets*/ } counters; /** * Thread specific arguments @@ -395,6 +396,12 @@ static void *gen_send_thread(void *arg) for (;;) { int err; + if (args->appl.number != -1 && + odp_atomic_fetch_add_u64(&counters.cnt, 1) >= + (unsigned int)args->appl.number) { + break; + } + if (args->appl.mode == APPL_MODE_UDP) pkt = pack_udp_pkt(thr_args->pool); else if (args->appl.mode == APPL_MODE_PING) @@ -426,11 +433,6 @@ static void *gen_send_thread(void *arg) thr_args->tmo_ev); } - if (args->appl.number != -1 && - odp_atomic_load_u64(&counters.seq) - >= (unsigned int)args->appl.number) { - break; - } } /* receive number of reply pks until timeout */ @@ -450,11 +452,10 @@ static void *gen_send_thread(void *arg) /* print info */ if (args->appl.mode == APPL_MODE_UDP) { - printf(" [%02i] total send: %ju\n", - thr, odp_atomic_load_u64(&counters.seq)); + printf(" [%02i] total send: %d\n", thr, args->appl.number); } else if (args->appl.mode == APPL_MODE_PING) { - printf(" [%02i] total send: %ju total receive: %ju\n", - thr, odp_atomic_load_u64(&counters.seq), + printf(" [%02i] total send: %d total receive: %ju\n", + thr, args->appl.number, odp_atomic_load_u64(&counters.icmp)); } return arg; @@ -610,6 +611,7 @@ int main(int argc, char *argv[]) odp_atomic_init_u64(&counters.ip, 0); odp_atomic_init_u64(&counters.udp, 0); odp_atomic_init_u64(&counters.icmp, 0); + odp_atomic_init_u64(&counters.cnt, 0); /* Reserve memory for args from shared mem */ shm = odp_shm_reserve("shm_args", sizeof(args_t), -- 1.7.3.4 _______________________________________________ lng-odp mailing list lng-odp@lists.linaro.org https://lists.linaro.org/mailman/listinfo/lng-odp