API Reference Manual  1.45.0
ODP BARRIER

API Description

Thread execution and memory ordering barriers.

Thread execution barrier (odp_barrier_t)

Thread execution barrier synchronizes a group of threads to wait on the barrier until the entire group has reached the barrier.

Memory barriers

A memory barrier enforces the order between memory accesses (loads and/or stores) specified (in program order) before the barrier with those specified after the barrier. A barrier may affect both compiler optimizations and CPU out-of-order execution. Depending on the used HW platform and barrier types, heavy usage of barriers may cause significant performance degradation.

An application may use these memory barrier functions e.g. to build a synchronization mechanism between its threads in shared memory, or when it accesses memory mapped registers of a device.

An application does not need to use these memory barriers when using other ODP APIs for thread synchronization (execution barriers, spinlocks, etc.), or when exchanging data through ODP API mechanisms (queues, stashes, etc.). Those ODP calls include necessary (acquire and release) memory barriers to maintain coherency between data producers and consumers.

Some ODP atomic operations include a memory barrier - see for example odp_atomic_load_acq_u32() or odp_atomic_store_rel_u32(). Application may use also those (non-relaxed) atomic operations to enforce memory ordering while using atomic variables.

Typedefs

typedef struct odp_barrier_s odp_barrier_t
 ODP thread synchronization barrier.
 

Functions

void odp_barrier_init (odp_barrier_t *barr, int count)
 Initialize barrier with thread count. More...
 
void odp_barrier_wait (odp_barrier_t *barr)
 Synchronize thread execution on barrier. More...
 
void odp_mb_release (void)
 Memory barrier for release operations. More...
 
void odp_mb_acquire (void)
 Memory barrier for acquire operations. More...
 
void odp_mb_full (void)
 Full memory barrier. More...
 
void odp_mb_sync (void)
 Memory barrier for load and store synchronization. More...
 
void odp_mb_sync_load (void)
 Memory barrier for load synchronization. More...
 
void odp_mb_sync_store (void)
 Memory synchronization barrier for stores. More...
 

Function Documentation

◆ odp_barrier_init()

◆ odp_barrier_wait()

void odp_barrier_wait ( odp_barrier_t barr)

Synchronize thread execution on barrier.

Wait for all threads to arrive at the barrier until they are let loose again. Threads will block (spin) until the last thread has arrived at the barrier. All memory operations before the odp_barrier_wait() call will be visible to all threads when they leave the barrier.

Parameters
barrPointer to a barrier variable
Examples
ipsec_api/odp_ipsec.c, ipsec_crypto/odp_ipsec.c, odp_atomic_perf.c, odp_cpu_bench.c, odp_dma_perf.c, odp_dmafwd.c, odp_icache_perf.c, odp_ipfragreass.c, odp_ipsecfwd.c, odp_l2fwd.c, odp_l3fwd.c, odp_lock_perf.c, odp_mem_perf.c, odp_packet_gen.c, odp_pktio_ordered.c, odp_pktio_perf.c, odp_pool_latency.c, odp_pool_perf.c, odp_queue_perf.c, odp_random.c, odp_sched_latency.c, odp_sched_perf.c, odp_sched_pktio.c, odp_simple_pipeline.c, odp_stash_perf.c, odp_stress.c, odp_switch.c, odp_timer_accuracy.c, and odp_timer_perf.c.

◆ odp_mb_release()

void odp_mb_release ( void  )

Memory barrier for release operations.

This memory barrier has release semantics. It synchronizes with a pairing barrier for acquire operations. The releasing and acquiring threads synchronize through shared memory. The releasing thread must call this barrier before signaling the acquiring thread. After the acquiring thread receives the signal, it must call odp_mb_acquire() before it reads the memory written by the releasing thread.

This call is not needed when using ODP defined synchronization mechanisms.

See also
odp_mb_acquire()
Examples
odp_bench_misc.c.

◆ odp_mb_acquire()

void odp_mb_acquire ( void  )

Memory barrier for acquire operations.

This memory barrier has acquire semantics. It synchronizes with a pairing barrier for release operations. The releasing and acquiring threads synchronize through shared memory. The releasing thread must call odp_mb_release() before signaling the acquiring thread. After the acquiring thread receives the signal, it must call this barrier before it reads the memory written by the releasing thread.

This call is not needed when using ODP defined synchronization mechanisms.

See also
odp_mb_release()
Examples
odp_bench_misc.c.

◆ odp_mb_full()

void odp_mb_full ( void  )

Full memory barrier.

This is a full memory barrier. It guarantees that all load and store operations specified before it are visible to other threads before all load and store operations specified after it.

This call is not needed when using ODP defined synchronization mechanisms.

Examples
odp_bench_misc.c, odp_bench_packet.c, odp_cpu_bench.c, odp_l2fwd.c, odp_l2fwd_simple.c, odp_l3fwd.c, odp_sched_pktio.c, odp_switch.c, and odp_timer_accuracy.c.

◆ odp_mb_sync()

void odp_mb_sync ( void  )

Memory barrier for load and store synchronization.

This memory barrier ensures that all memory accesses (loads and stores) specified before the barrier (in program order) are complete prior to any memory access specified after the barrier begins execution.

This is a stronger barrier than odp_mb_full(), as in addition to visibility order also memory access completion is ensured. The barrier may be useful e.g. when synchronizing loads and stores into memory mapped registers of a device.

◆ odp_mb_sync_load()

void odp_mb_sync_load ( void  )

Memory barrier for load synchronization.

This memory barrier ensures that all memory loads specified before the barrier (in program order) are complete prior to any memory load specified after the barrier begins execution.

The barrier may be useful e.g. when synchronizing loads from memory mapped registers of a device.

◆ odp_mb_sync_store()

void odp_mb_sync_store ( void  )

Memory synchronization barrier for stores.

This memory barrier ensures that all memory stores specified before the barrier (in program order) are complete prior to any memory store specified after the barrier begins execution.

The barrier may be useful e.g. when synchronizing stores to memory mapped registers of a device.