aboutsummaryrefslogtreecommitdiff
path: root/example
diff options
context:
space:
mode:
authorGrigore Ion <ion.grigore@freescale.com>2015-10-22 12:57:05 +0300
committerMaxim Uvarov <maxim.uvarov@linaro.org>2015-10-27 13:40:26 +0300
commit4894e98c380201bb641a771e374cf74359bdddef (patch)
tree2b53b6dd80eab46edaf6edeed723af154e8635c9 /example
parent68f260816f0968335a1d5da29a3fc6a47c3aa6e8 (diff)
example:generator : Fix data race condition
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.grigore@freescale.com> Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
Diffstat (limited to 'example')
-rw-r--r--example/generator/odp_generator.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/example/generator/odp_generator.c b/example/generator/odp_generator.c
index 5dc28b8e..68f38e62 100644
--- a/example/generator/odp_generator.c
+++ b/example/generator/odp_generator.c
@@ -68,6 +68,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
@@ -407,6 +408,11 @@ 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)
@@ -438,11 +444,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 */
@@ -597,7 +598,7 @@ static void print_global_stats(int num_workers)
while (odp_thrmask_worker(&thrd_mask) == num_workers) {
if (args->appl.number != -1 &&
- odp_atomic_load_u64(&counters.seq) >=
+ odp_atomic_load_u64(&counters.cnt) >=
(unsigned int)args->appl.number) {
break;
}
@@ -669,6 +670,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),