API Reference Manual  1.45.0
ODP THREAD

API Description

Thread types, masks and IDs.

Thread mask operations.

Data Structures

struct  odp_thrmask_t
 Thread mask. More...
 

Macros

#define ODP_THREAD_COUNT_MAX   256
 Maximum number of threads supported in build time. More...
 
#define ODP_THRMASK_STR_SIZE   ODP_CPUMASK_STR_SIZE
 Minimum size of output buffer for odp_thrmask_to_str() More...
 

Typedefs

typedef struct odp_thrmask_t odp_thrmask_t
 Thread mask. More...
 
typedef enum odp_thread_type_e odp_thread_type_t
 Thread type.
 

Enumerations

enum  odp_thread_type_e { ODP_THREAD_WORKER = 0 , ODP_THREAD_CONTROL }
 Thread type. More...
 

Functions

int odp_thread_id (void)
 Get thread identifier. More...
 
int odp_thread_count (void)
 Thread count. More...
 
int odp_thread_control_count (void)
 Control thread count. More...
 
int odp_thread_worker_count (void)
 Worker thread count. More...
 
int odp_thread_count_max (void)
 Maximum thread count. More...
 
int odp_thread_control_count_max (void)
 Maximum control thread count. More...
 
int odp_thread_worker_count_max (void)
 Maximum worker thread count. More...
 
odp_thread_type_t odp_thread_type (void)
 Thread type. More...
 
void odp_thrmask_from_str (odp_thrmask_t *mask, const char *str)
 Add thread mask bits from a string. More...
 
int32_t odp_thrmask_to_str (const odp_thrmask_t *mask, char *str, int32_t size)
 Format a string from thread mask. More...
 
void odp_thrmask_zero (odp_thrmask_t *mask)
 Clear entire thread mask. More...
 
void odp_thrmask_set (odp_thrmask_t *mask, int thr)
 Add thread to mask. More...
 
void odp_thrmask_setall (odp_thrmask_t *mask)
 Set all threads in mask. More...
 
void odp_thrmask_clr (odp_thrmask_t *mask, int thr)
 Remove thread from mask. More...
 
int odp_thrmask_isset (const odp_thrmask_t *mask, int thr)
 Test if thread is a member of mask. More...
 
int odp_thrmask_count (const odp_thrmask_t *mask)
 Count number of threads set in mask. More...
 
void odp_thrmask_and (odp_thrmask_t *dest, const odp_thrmask_t *src1, const odp_thrmask_t *src2)
 Member-wise AND over two thread masks. More...
 
void odp_thrmask_or (odp_thrmask_t *dest, const odp_thrmask_t *src1, const odp_thrmask_t *src2)
 Member-wise OR over two thread masks. More...
 
void odp_thrmask_xor (odp_thrmask_t *dest, const odp_thrmask_t *src1, const odp_thrmask_t *src2)
 Member-wise XOR over two thread masks. More...
 
int odp_thrmask_equal (const odp_thrmask_t *mask1, const odp_thrmask_t *mask2)
 Test if two thread masks contain the same threads. More...
 
void odp_thrmask_copy (odp_thrmask_t *dest, const odp_thrmask_t *src)
 Copy a thread mask. More...
 
int odp_thrmask_first (const odp_thrmask_t *mask)
 Find first set thread in mask. More...
 
int odp_thrmask_last (const odp_thrmask_t *mask)
 Find last set thread in mask. More...
 
int odp_thrmask_next (const odp_thrmask_t *mask, int thr)
 Find next set thread in mask. More...
 
int odp_thrmask_worker (odp_thrmask_t *mask)
 Worker thread mask. More...
 
int odp_thrmask_control (odp_thrmask_t *mask)
 Control thread mask. More...
 

Macro Definition Documentation

◆ ODP_THREAD_COUNT_MAX

#define ODP_THREAD_COUNT_MAX   256

Maximum number of threads supported in build time.

Use odp_thread_count_max() for maximum number of threads supported in run time, which depends on system configuration and may be lower than this number.

Examples
odp_atomic_perf.c, odp_icache_perf.c, odp_lock_perf.c, odp_mem_perf.c, odp_pool_perf.c, odp_queue_perf.c, odp_random.c, odp_sched_latency.c, odp_sched_perf.c, odp_simple_pipeline.c, odp_stash_perf.c, odp_stress.c, odp_sysinfo.c, and odp_timer_perf.c.

◆ ODP_THRMASK_STR_SIZE

#define ODP_THRMASK_STR_SIZE   ODP_CPUMASK_STR_SIZE

Minimum size of output buffer for odp_thrmask_to_str()

The maximum number of characters needed to record any thread mask as a string (output of odp_thrmask_to_str()).

Typedef Documentation

◆ odp_thrmask_t

typedef struct odp_thrmask_t odp_thrmask_t

Thread mask.

Don't access directly, use access functions.

Enumeration Type Documentation

◆ odp_thread_type_e

Thread type.

Enumerator
ODP_THREAD_WORKER 

Worker thread.

Worker threads do most part of ODP application packet processing. These threads provide high packet and data rates, with low and predictable latency. Typically, worker threads are pinned to isolated CPUs and packets are processed in a run-to-completion loop with very low interference from the operating system.

ODP_THREAD_CONTROL 

Control thread.

Control threads do not participate the main packet flow through the system, but e.g. control or monitor the worker threads, or handle exceptions. These threads may perform general purpose processing, use system calls, share the CPU with other threads and be interrupt driven.

Definition at line 32 of file api/spec/thread_types.h.

Function Documentation

◆ odp_thread_id()

int odp_thread_id ( void  )

Get thread identifier.

Returns the ODP thread identifier of current thread. Thread IDs range from 0 to odp_thread_count_max() - 1 and are unique within an ODP instance.

Thread IDs are assigned by odp_init_local() and freed by odp_term_local(). IDs are assigned sequentially starting from 0 in the same order threads call odp_init_local(). Thread IDs freed by odp_term_local() may be reused by following odp_init_local() calls.

Returns
Thread identifier of the current thread
Examples
ipsec_api/odp_ipsec.c, ipsec_crypto/odp_ipsec.c, odp_bench_misc.c, odp_classifier.c, odp_dma_perf.c, odp_dmafwd.c, odp_icache_perf.c, odp_ipfragreass.c, odp_ipsecfwd.c, odp_l2fwd.c, odp_mem_perf.c, odp_packet_gen.c, odp_pktio.c, odp_pktio_perf.c, odp_pool_perf.c, odp_queue_perf.c, odp_sched_latency.c, odp_sched_perf.c, odp_stash_perf.c, odp_stress.c, odp_timer_accuracy.c, and odp_timer_perf.c.

◆ odp_thread_count()

int odp_thread_count ( void  )

Thread count.

Returns the current ODP thread count. This is the number of active threads of any type running in the ODP instance. Each odp_init_local() call increments and each odp_term_local() call decrements the count. The count is always between 1 and odp_thread_count_max().

Returns
Current thread count
Examples
odp_bench_misc.c.

◆ odp_thread_control_count()

int odp_thread_control_count ( void  )

Control thread count.

Otherwise like odp_thread_count(), but returns the number of active threads of type ODP_THREAD_CONTROL. The count is always between 0 and odp_thread_control_count_max().

Returns
Current control thread count

◆ odp_thread_worker_count()

int odp_thread_worker_count ( void  )

Worker thread count.

Otherwise like odp_thread_count(), but returns the number of active threads of type ODP_THREAD_WORKER. The count is always between 0 and odp_thread_worker_count_max().

Returns
Current worker thread count

◆ odp_thread_count_max()

int odp_thread_count_max ( void  )

Maximum thread count.

Returns the maximum number of threads of any type. This is a constant value and set in ODP initialization phase. The value may be lower than ODP_THREAD_COUNT_MAX.

Returns
Maximum thread count
Examples
odp_bench_misc.c, odp_dma_perf.c, odp_pktio_perf.c, and odp_sysinfo.c.

◆ odp_thread_control_count_max()

int odp_thread_control_count_max ( void  )

Maximum control thread count.

Otherwise like odp_thread_count_max(), but returns the maximum number of control threads (ODP_THREAD_CONTROL). The returned value is always <= odp_thread_count_max().

Returns
Maximum control thread count

◆ odp_thread_worker_count_max()

int odp_thread_worker_count_max ( void  )

Maximum worker thread count.

Otherwise like odp_thread_count_max(), but returns the maximum number of worker threads (ODP_THREAD_WORKER). The returned value is always <= odp_thread_count_max().

Returns
Maximum worker thread count

◆ odp_thread_type()

odp_thread_type_t odp_thread_type ( void  )

Thread type.

Returns the thread type of the current thread.

Returns
Thread type
Examples
odp_bench_misc.c.

◆ odp_thrmask_from_str()

void odp_thrmask_from_str ( odp_thrmask_t mask,
const char *  str 
)

Add thread mask bits from a string.

Each bit set in the string represents a thread ID to be added into the mask. The string is null terminated and consists of hexadecimal digits. It may be prepended with '0x' and may contain leading zeros (e.g. 0x0001, 0x1 or 1). Thread ID zero is located at the least significant bit (0x1).

Parameters
maskThread mask to modify
strString of hexadecimal digits

◆ odp_thrmask_to_str()

int32_t odp_thrmask_to_str ( const odp_thrmask_t mask,
char *  str,
int32_t  size 
)

Format a string from thread mask.

Output string format is defined in odp_thrmask_from_str() documentation, except that the string is always prepended with '0x' and does not have any leading zeros (e.g. outputs always 0x1 instead of 0x0001 or 1).

Parameters
maskThread mask
[out]strString pointer for output
sizeSize of output buffer. Buffer size ODP_THRMASK_STR_SIZE or larger will have enough space for any thread mask.
Returns
Number of characters written (including terminating null char)
Return values
<0on failure (e.g. buffer too small)

◆ odp_thrmask_zero()

void odp_thrmask_zero ( odp_thrmask_t mask)

Clear entire thread mask.

Parameters
maskThread mask to clear
Examples
odp_dma_perf.c, odp_l2fwd.c, odp_sched_latency.c, odp_sched_perf.c, odp_stress.c, and odp_timer_accuracy.c.

◆ odp_thrmask_set()

void odp_thrmask_set ( odp_thrmask_t mask,
int  thr 
)

Add thread to mask.

Parameters
maskThread mask to update
thrThread ID
Examples
odp_dma_perf.c, odp_l2fwd.c, odp_sched_latency.c, odp_sched_perf.c, odp_stress.c, and odp_timer_accuracy.c.

◆ odp_thrmask_setall()

void odp_thrmask_setall ( odp_thrmask_t mask)

Set all threads in mask.

Set all possible threads in the mask. All threads from 0 to odp_thread_count_max() minus one are set, regardless of which threads are actually active.

Parameters
maskThread mask to set

◆ odp_thrmask_clr()

void odp_thrmask_clr ( odp_thrmask_t mask,
int  thr 
)

Remove thread from mask.

Parameters
maskThread mask to update
thrThread ID

◆ odp_thrmask_isset()

int odp_thrmask_isset ( const odp_thrmask_t mask,
int  thr 
)

Test if thread is a member of mask.

Parameters
maskThread mask to test
thrThread ID
Returns
non-zero if set
Return values
0if not set

◆ odp_thrmask_count()

int odp_thrmask_count ( const odp_thrmask_t mask)

Count number of threads set in mask.

Parameters
maskThread mask
Returns
population count

◆ odp_thrmask_and()

void odp_thrmask_and ( odp_thrmask_t dest,
const odp_thrmask_t src1,
const odp_thrmask_t src2 
)

Member-wise AND over two thread masks.

Parameters
destDestination thread mask (may be one of the source masks)
src1Source thread mask 1
src2Source thread mask 2

◆ odp_thrmask_or()

void odp_thrmask_or ( odp_thrmask_t dest,
const odp_thrmask_t src1,
const odp_thrmask_t src2 
)

Member-wise OR over two thread masks.

Parameters
destDestination thread mask (may be one of the source masks)
src1Source thread mask 1
src2Source thread mask 2

◆ odp_thrmask_xor()

void odp_thrmask_xor ( odp_thrmask_t dest,
const odp_thrmask_t src1,
const odp_thrmask_t src2 
)

Member-wise XOR over two thread masks.

Parameters
destDestination thread mask (may be one of the source masks)
src1Source thread mask 1
src2Source thread mask 2

◆ odp_thrmask_equal()

int odp_thrmask_equal ( const odp_thrmask_t mask1,
const odp_thrmask_t mask2 
)

Test if two thread masks contain the same threads.

Parameters
mask1Thread mask 1
mask2Thread mask 2
Return values
non-zeroif thread masks equal
0if thread masks not equal

◆ odp_thrmask_copy()

void odp_thrmask_copy ( odp_thrmask_t dest,
const odp_thrmask_t src 
)

Copy a thread mask.

Parameters
destDestination thread mask
srcSource thread mask

◆ odp_thrmask_first()

int odp_thrmask_first ( const odp_thrmask_t mask)

Find first set thread in mask.

Parameters
maskthread mask
Returns
Thread ID
Return values
<0if no thread found

◆ odp_thrmask_last()

int odp_thrmask_last ( const odp_thrmask_t mask)

Find last set thread in mask.

Parameters
maskThread mask
Returns
Thread ID
Return values
<0if no thread found

◆ odp_thrmask_next()

int odp_thrmask_next ( const odp_thrmask_t mask,
int  thr 
)

Find next set thread in mask.

Finds the next thread in the thread mask, starting at the thread passed. Use with odp_thrmask_first to traverse a thread mask, e.g.

int thr = odp_thrmask_first(&mask); while (0 <= thr) { ... ... thr = odp_thrmask_next(&mask, thr); }

Parameters
maskThread mask
thrThread to start from
Returns
Thread ID
Return values
<0if no thread found
See also
odp_thrmask_first()

◆ odp_thrmask_worker()

int odp_thrmask_worker ( odp_thrmask_t mask)

Worker thread mask.

Initializes thread mask with current worker threads and returns the count set.

Parameters
[out]maskThread mask to initialize
Returns
Number of threads in the mask

◆ odp_thrmask_control()

int odp_thrmask_control ( odp_thrmask_t mask)

Control thread mask.

Initializes thread mask with current control threads and returns the count set.

Parameters
[out]maskThread mask to initialize
Returns
Number of threads in the mask