OpenFastPath / ofp

OpenFastPath project
BSD 3-Clause "New" or "Revised" License
349 stars 126 forks source link

question about ofp_tcp_syncache #227

Open Nesyan opened 5 years ago

Nesyan commented 5 years ago

Hi, I want to define a variable for counting received packets in ofp_tcp_syncache.c file. how can I do that? Do I need to use a lock? how?

thanks in advance

MatiasElo commented 5 years ago

For counters you can use ODP atomics instead of locks.

E.g.

    odp_atomic_u64_t pkt_count;
    uint64_t cur_pkt_count;

    odp_atomic_init_u64(&pkt_count, 0);

    odp_atomic_inc_u64(&pkt_count);

    cur_pkt_count = odp_atomic_load_u64(&pkt_count);