@@ -204,7 +204,7 @@ static void pack_udp_pkt(odp_buffer_t obuf)
ip->tot_len = odp_cpu_to_be_16(args->appl.payload + ODPH_UDPHDR_LEN +
ODPH_IPV4HDR_LEN);
ip->proto = ODPH_IPPROTO_UDP;
- seq = odp_atomic_fetch_add_u64(&counters.seq, 1) % 0xFFFF;
+ seq = odp_atomic_fetch_inc_u64(&counters.seq) % 0xFFFF;
ip->id = odp_cpu_to_be_16(seq);
ip->chksum = 0;
odph_ipv4_csum_update(pkt);
@@ -261,7 +261,7 @@ static void pack_icmp_pkt(odp_buffer_t obuf)
ip->tot_len = odp_cpu_to_be_16(args->appl.payload + ODPH_ICMPHDR_LEN +
ODPH_IPV4HDR_LEN);
ip->proto = ODPH_IPPROTO_ICMP;
- seq = odp_atomic_fetch_add_u64(&counters.seq, 1) % 0xffff;
+ seq = odp_atomic_fetch_inc_u64(&counters.seq) % 0xffff;
ip->id = odp_cpu_to_be_16(seq);
ip->chksum = 0;
odph_ipv4_csum_update(pkt);
@@ -338,11 +338,14 @@ static void *gen_send_thread(void *arg)
if (args->appl.interval != 0) {
printf(" [%02i] send pkt no:%ju seq %ju\n",
- thr, counters.seq, counters.seq%0xffff);
+ thr,
+ odp_atomic_load_u64(&counters.seq),
+ odp_atomic_load_u64(&counters.seq)%0xffff);
/* TODO use odp timer */
usleep(args->appl.interval * 1000);
}
- if (args->appl.number != -1 && counters.seq
+ if (args->appl.number != -1 &&
+ odp_atomic_load_u64(&counters.seq)
>= (unsigned int)args->appl.number) {
break;
}
@@ -351,7 +354,8 @@ static void *gen_send_thread(void *arg)
/* receive number of reply pks until timeout */
if (args->appl.mode == APPL_MODE_PING && args->appl.number > 0) {
while (args->appl.timeout >= 0) {
- if (counters.icmp >= (unsigned int)args->appl.number)
+ if (odp_atomic_load_u64(&counters.icmp) >=
+ (unsigned int)args->appl.number)
break;
/* TODO use odp timer */
sleep(1);
@@ -361,10 +365,12 @@ static void *gen_send_thread(void *arg)
/* print info */
if (args->appl.mode == APPL_MODE_UDP) {
- printf(" [%02i] total send: %ju\n", thr, counters.seq);
+ printf(" [%02i] total send: %ju\n",
+ thr, odp_atomic_load_u64(&counters.seq));
} else if (args->appl.mode == APPL_MODE_PING) {
printf(" [%02i] total send: %ju total receive: %ju\n",
- thr, counters.seq, counters.icmp);
+ thr, odp_atomic_load_u64(&counters.seq),
+ odp_atomic_load_u64(&counters.icmp));
}
return arg;
}
@@ -534,10 +540,10 @@ int main(int argc, char *argv[])
}
/* init counters */
- odp_atomic_init_u64(&counters.seq);
- odp_atomic_init_u64(&counters.ip);
- odp_atomic_init_u64(&counters.udp);
- odp_atomic_init_u64(&counters.icmp);
+ odp_atomic_init_u64(&counters.seq, 0);
+ odp_atomic_init_u64(&counters.ip, 0);
+ odp_atomic_init_u64(&counters.udp, 0);
+ odp_atomic_init_u64(&counters.icmp, 0);
/* Reserve memory for args from shared mem */
shm = odp_shm_reserve("shm_args", sizeof(args_t),
Signed-off-by: Ola Liljedahl <ola.liljedahl@linaro.org> --- example/generator/odp_generator.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-)