API Reference Manual  1.45.1
ODP CPUMASK

API Description

CPU mask operations.

Data Structures

struct  odp_cpumask_t
 CPU mask. More...
 

Macros

#define ODP_CPUMASK_SIZE   (sizeof(cpu_set_t) * 8)
 Maximum cpumask size, this definition limits the number of individual CPUs that can be accessed in this system.
 
#define ODP_CPUMASK_STR_SIZE   ((ODP_CPUMASK_SIZE + 3) / 4 + 3)
 The maximum number of characters needed to record any CPU mask as a string (output of odp_cpumask_to_str()).
 

Typedefs

typedef struct odp_cpumask_t odp_cpumask_t
 CPU mask. More...
 

Functions

void odp_cpumask_from_str (odp_cpumask_t *mask, const char *str)
 Add CPU mask bits from a string. More...
 
int32_t odp_cpumask_to_str (const odp_cpumask_t *mask, char *str, int32_t size)
 Format a string from CPU mask. More...
 
void odp_cpumask_zero (odp_cpumask_t *mask)
 Clear entire CPU mask. More...
 
void odp_cpumask_set (odp_cpumask_t *mask, int cpu)
 Add CPU to mask. More...
 
void odp_cpumask_setall (odp_cpumask_t *mask)
 Set all CPUs in mask. More...
 
void odp_cpumask_clr (odp_cpumask_t *mask, int cpu)
 Remove CPU from mask. More...
 
int odp_cpumask_isset (const odp_cpumask_t *mask, int cpu)
 Test if CPU is a member of mask. More...
 
int odp_cpumask_count (const odp_cpumask_t *mask)
 Count number of CPUs set in mask. More...
 
void odp_cpumask_and (odp_cpumask_t *dest, const odp_cpumask_t *src1, const odp_cpumask_t *src2)
 Member-wise AND over two CPU masks. More...
 
void odp_cpumask_or (odp_cpumask_t *dest, const odp_cpumask_t *src1, const odp_cpumask_t *src2)
 Member-wise OR over two CPU masks. More...
 
void odp_cpumask_xor (odp_cpumask_t *dest, const odp_cpumask_t *src1, const odp_cpumask_t *src2)
 Member-wise XOR over two CPU masks. More...
 
int odp_cpumask_equal (const odp_cpumask_t *mask1, const odp_cpumask_t *mask2)
 Test if two CPU masks contain the same CPUs. More...
 
void odp_cpumask_copy (odp_cpumask_t *dest, const odp_cpumask_t *src)
 Copy a CPU mask. More...
 
int odp_cpumask_first (const odp_cpumask_t *mask)
 Find first set CPU in mask. More...
 
int odp_cpumask_last (const odp_cpumask_t *mask)
 Find last set CPU in mask. More...
 
int odp_cpumask_next (const odp_cpumask_t *mask, int cpu)
 Find next set CPU in mask. More...
 
int odp_cpumask_default_worker (odp_cpumask_t *mask, int num)
 Default CPU mask for worker threads. More...
 
int odp_cpumask_default_control (odp_cpumask_t *mask, int num)
 Default CPU mask for control threads. More...
 
int odp_cpumask_all_available (odp_cpumask_t *mask)
 Report all the available CPUs. More...
 

Typedef Documentation

◆ odp_cpumask_t

typedef struct odp_cpumask_t odp_cpumask_t

CPU mask.

Don't access directly, use access functions.

Function Documentation

◆ odp_cpumask_from_str()

void odp_cpumask_from_str ( odp_cpumask_t mask,
const char *  str 
)

Add CPU mask bits from a string.

Each bit set in the string represents a CPU 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). CPU #0 is located at the least significant bit (0x1).

Parameters
maskCPU mask to modify
strString of hexadecimal digits

◆ odp_cpumask_to_str()

int32_t odp_cpumask_to_str ( const odp_cpumask_t mask,
char *  str,
int32_t  size 
)

Format a string from CPU mask.

Output string format is defined in odp_cpumask_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
maskCPU mask
[out]strString pointer for output
sizeSize of output buffer. Buffer size ODP_CPUMASK_STR_SIZE or larger will have enough space for any CPU mask.
Returns
Number of characters written (including terminating null char)
Return values
<0on failure (e.g. buffer too small)
Examples
ipsec_api/odp_ipsec.c, ipsec_crypto/odp_ipsec.c, odp_bench_buffer.c, odp_bench_misc.c, odp_bench_packet.c, odp_bench_pktio_sp.c, odp_bench_timer.c, odp_classifier.c, odp_cpu_bench.c, odp_crypto.c, odp_ipfragreass.c, odp_ipsec.c, odp_l2fwd.c, odp_pktio.c, odp_pktio_ordered.c, odp_sched_latency.c, odp_sched_pktio.c, odp_switch.c, odp_sysinfo.c, and odp_timer_accuracy.c.

◆ odp_cpumask_zero()

void odp_cpumask_zero ( odp_cpumask_t mask)

◆ odp_cpumask_set()

void odp_cpumask_set ( odp_cpumask_t mask,
int  cpu 
)

◆ odp_cpumask_setall()

void odp_cpumask_setall ( odp_cpumask_t mask)

Set all CPUs in mask.

Set all possible CPUs in the mask. All CPUs from 0 to odp_cpumask_count() minus one are set, regardless of which CPUs are actually available to the application.

Parameters
maskCPU mask to set

◆ odp_cpumask_clr()

void odp_cpumask_clr ( odp_cpumask_t mask,
int  cpu 
)

Remove CPU from mask.

Parameters
maskCPU mask to update
cpuCPU number
Examples
odp_packet_gen.c.

◆ odp_cpumask_isset()

int odp_cpumask_isset ( const odp_cpumask_t mask,
int  cpu 
)

Test if CPU is a member of mask.

Parameters
maskCPU mask to test
cpuCPU number
Returns
non-zero if set
Return values
0if not set

◆ odp_cpumask_count()

int odp_cpumask_count ( const odp_cpumask_t mask)

Count number of CPUs set in mask.

Parameters
maskCPU mask
Returns
population count
Examples
odp_pktio_perf.c.

◆ odp_cpumask_and()

void odp_cpumask_and ( odp_cpumask_t dest,
const odp_cpumask_t src1,
const odp_cpumask_t src2 
)

Member-wise AND over two CPU masks.

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

◆ odp_cpumask_or()

void odp_cpumask_or ( odp_cpumask_t dest,
const odp_cpumask_t src1,
const odp_cpumask_t src2 
)

Member-wise OR over two CPU masks.

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

◆ odp_cpumask_xor()

void odp_cpumask_xor ( odp_cpumask_t dest,
const odp_cpumask_t src1,
const odp_cpumask_t src2 
)

Member-wise XOR over two CPU masks.

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

◆ odp_cpumask_equal()

int odp_cpumask_equal ( const odp_cpumask_t mask1,
const odp_cpumask_t mask2 
)

Test if two CPU masks contain the same CPUs.

Parameters
mask1CPU mask 1
mask2CPU mask 2
Return values
non-zeroif CPU masks equal
0if CPU masks not equal

◆ odp_cpumask_copy()

void odp_cpumask_copy ( odp_cpumask_t dest,
const odp_cpumask_t src 
)

Copy a CPU mask.

Parameters
destDestination CPU mask
srcSource CPU mask

◆ odp_cpumask_first()

◆ odp_cpumask_last()

int odp_cpumask_last ( const odp_cpumask_t mask)

Find last set CPU in mask.

Parameters
maskCPU mask
Returns
cpu number
Return values
<0if no CPU found

◆ odp_cpumask_next()

int odp_cpumask_next ( const odp_cpumask_t mask,
int  cpu 
)

Find next set CPU in mask.

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

int cpu = odp_cpumask_first(&mask); while (0 <= cpu) { ... ... cpu = odp_cpumask_next(&mask, cpu); }

Parameters
maskCPU mask
cpuCPU to start from
Returns
cpu number
Return values
<0if no CPU found
See also
odp_cpumask_first()
Examples
odp_pktio_perf.c, odp_sched_pktio.c, and odp_simple_pipeline.c.

◆ odp_cpumask_default_worker()

int odp_cpumask_default_worker ( odp_cpumask_t mask,
int  num 
)

Default CPU mask for worker threads.

Initializes CPU mask with the default set of CPUs available for worker threads. It's system specific if other CPUs may be used for worker threads as well. Parameter 'num' defines the maximum number of CPUs to be returned. Use zero for all available CPUs. The mask pointer may be set to NULL when CPU mask is not required.

Returns the number of CPUs selected and written into the CPU mask (when not NULL).

Parameters
[out]maskCPU mask to initialize
numMaximum number of CPUs to return. Use zero for all available CPUs.
Returns
Number of selected CPUs
Examples
ipsec_api/odp_ipsec.c, ipsec_crypto/odp_ipsec.c, odp_atomic_perf.c, odp_bench_buffer.c, odp_bench_misc.c, odp_bench_packet.c, odp_bench_pktio_sp.c, odp_bench_timer.c, odp_classifier.c, odp_cpu_bench.c, odp_crypto.c, odp_dma_perf.c, odp_dmafwd.c, odp_icache_perf.c, odp_ipfragreass.c, odp_ipsec.c, odp_ipsecfwd.c, odp_l2fwd.c, odp_l2fwd_simple.c, odp_l3fwd.c, odp_lock_perf.c, odp_mem_perf.c, odp_packet_gen.c, odp_pktio.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_sysinfo.c, odp_timer_accuracy.c, and odp_timer_perf.c.

◆ odp_cpumask_default_control()

int odp_cpumask_default_control ( odp_cpumask_t mask,
int  num 
)

Default CPU mask for control threads.

Initializes CPU mask with the default set of CPUs available for control threads. It's system specific if other CPUs may be used for control threads as well. Parameter 'num' defines the maximum number of CPUs to be returned. Use zero for all available CPUs. The mask pointer may be set to NULL when CPU mask is not required.

Returns the number of CPUs selected and written into the CPU mask (when not NULL).

Parameters
[out]maskCPU mask to initialize
numMaximum number of CPUs to return. Use zero for all available CPUs.
Returns
Number of selected CPUs
Examples
odp_cli.c, and odp_sysinfo.c.

◆ odp_cpumask_all_available()

int odp_cpumask_all_available ( odp_cpumask_t mask)

Report all the available CPUs.

All the available CPUs include both worker CPUs and control CPUs

Parameters
[out]maskCPU mask to hold all available CPUs
Returns
cpu number of all available CPUs
Examples
odp_packet_gen.c, and odp_sysinfo.c.