DPDK  24.11.0-rc3
Macros | Functions
rte_lcore_var.h File Reference
#include <stddef.h>
#include <stdalign.h>
#include <rte_common.h>
#include <rte_config.h>
#include <rte_lcore.h>

Go to the source code of this file.

Macros

#define RTE_LCORE_VAR_HANDLE_TYPE(type)   type *
 
#define RTE_LCORE_VAR_HANDLE(type, name)   RTE_LCORE_VAR_HANDLE_TYPE(type) name
 
#define RTE_LCORE_VAR_ALLOC_SIZE_ALIGN(handle, size, align)   handle = rte_lcore_var_alloc(size, align)
 
#define RTE_LCORE_VAR_ALLOC_SIZE(handle, size)   RTE_LCORE_VAR_ALLOC_SIZE_ALIGN(handle, size, 0)
 
#define RTE_LCORE_VAR_ALLOC(handle)
 
#define RTE_LCORE_VAR_INIT_SIZE_ALIGN(name, size, align)
 
#define RTE_LCORE_VAR_INIT_SIZE(name, size)   RTE_LCORE_VAR_INIT_SIZE_ALIGN(name, size, 0)
 
#define RTE_LCORE_VAR_INIT(name)
 
#define RTE_LCORE_VAR_LCORE(lcore_id, handle)   ((typeof(handle))rte_lcore_var_lcore(lcore_id, handle))
 
#define RTE_LCORE_VAR(handle)   RTE_LCORE_VAR_LCORE(rte_lcore_id(), handle)
 
#define RTE_LCORE_VAR_FOREACH(lcore_id, value, handle)
 

Functions

static void * rte_lcore_var_lcore (unsigned int lcore_id, void *handle)
 
__rte_experimental void * rte_lcore_var_alloc (size_t size, size_t align) __rte_alloc_size(1) __rte_alloc_align(2)
 

Detailed Description

Lcore variables

This API provides a mechanism to create and access per-lcore id variables in a space- and cycle-efficient manner.

Please refer to the lcore variables' programmer's guide for an overview of this API and its implementation.

EXPERIMENTAL: this API may change, or be removed, without prior notice.

Definition in file rte_lcore_var.h.

Macro Definition Documentation

◆ RTE_LCORE_VAR_HANDLE_TYPE

#define RTE_LCORE_VAR_HANDLE_TYPE (   type)    type *

Given the lcore variable type, produces the type of the lcore variable handle.

Definition at line 36 of file rte_lcore_var.h.

◆ RTE_LCORE_VAR_HANDLE

#define RTE_LCORE_VAR_HANDLE (   type,
  name 
)    RTE_LCORE_VAR_HANDLE_TYPE(type) name

Define an lcore variable handle.

This macro defines a variable which is used as a handle to access the various instances of a per-lcore id variable.

This macro clarifies that the declaration is an lcore handle, not a regular pointer.

Add static as a prefix in case the lcore variable is only to be accessed from a particular translation unit.

Definition at line 51 of file rte_lcore_var.h.

◆ RTE_LCORE_VAR_ALLOC_SIZE_ALIGN

#define RTE_LCORE_VAR_ALLOC_SIZE_ALIGN (   handle,
  size,
  align 
)    handle = rte_lcore_var_alloc(size, align)

Allocate space for an lcore variable, and initialize its handle.

The values of the lcore variable are initialized to zero.

Definition at line 59 of file rte_lcore_var.h.

◆ RTE_LCORE_VAR_ALLOC_SIZE

#define RTE_LCORE_VAR_ALLOC_SIZE (   handle,
  size 
)    RTE_LCORE_VAR_ALLOC_SIZE_ALIGN(handle, size, 0)

Allocate space for an lcore variable, and initialize its handle, with values aligned for any type of object.

The values of the lcore variable are initialized to zero.

Definition at line 68 of file rte_lcore_var.h.

◆ RTE_LCORE_VAR_ALLOC

#define RTE_LCORE_VAR_ALLOC (   handle)
Value:
RTE_LCORE_VAR_ALLOC_SIZE_ALIGN(handle, sizeof(*(handle)), \
alignof(typeof(*(handle))))
#define RTE_LCORE_VAR_ALLOC_SIZE_ALIGN(handle, size, align)
Definition: rte_lcore_var.h:59

Allocate space for an lcore variable of the size and alignment requirements suggested by the handle pointer type, and initialize its handle.

The values of the lcore variable are initialized to zero.

Definition at line 77 of file rte_lcore_var.h.

◆ RTE_LCORE_VAR_INIT_SIZE_ALIGN

#define RTE_LCORE_VAR_INIT_SIZE_ALIGN (   name,
  size,
  align 
)
Value:
RTE_INIT(rte_lcore_var_init_ ## name) \
{ \
RTE_LCORE_VAR_ALLOC_SIZE_ALIGN(name, size, align); \
}
#define RTE_INIT(func)
Definition: rte_common.h:316

Allocate an explicitly-sized, explicitly-aligned lcore variable by means of a RTE_INIT constructor.

The values of the lcore variable are initialized to zero.

Definition at line 87 of file rte_lcore_var.h.

◆ RTE_LCORE_VAR_INIT_SIZE

#define RTE_LCORE_VAR_INIT_SIZE (   name,
  size 
)    RTE_LCORE_VAR_INIT_SIZE_ALIGN(name, size, 0)

Allocate an explicitly-sized lcore variable by means of a RTE_INIT constructor.

The values of the lcore variable are initialized to zero.

Definition at line 99 of file rte_lcore_var.h.

◆ RTE_LCORE_VAR_INIT

#define RTE_LCORE_VAR_INIT (   name)
Value:
RTE_INIT(rte_lcore_var_init_ ## name) \
{ \
RTE_LCORE_VAR_ALLOC(name); \
}
#define RTE_INIT(func)
Definition: rte_common.h:316

Allocate an lcore variable by means of a RTE_INIT constructor.

The values of the lcore variable are initialized to zero.

Definition at line 107 of file rte_lcore_var.h.

◆ RTE_LCORE_VAR_LCORE

#define RTE_LCORE_VAR_LCORE (   lcore_id,
  handle 
)    ((typeof(handle))rte_lcore_var_lcore(lcore_id, handle))

Get pointer to lcore variable instance with the specified lcore id.

Parameters
lcore_idThe lcore id specifying which of the RTE_MAX_LCORE value instances should be accessed. The lcore id need not be valid (e.g., may be LCORE_ID_ANY), but in such a case, the pointer is also not valid (and thus should not be dereferenced).
handleThe lcore variable handle.

Definition at line 143 of file rte_lcore_var.h.

◆ RTE_LCORE_VAR

#define RTE_LCORE_VAR (   handle)    RTE_LCORE_VAR_LCORE(rte_lcore_id(), handle)

Get pointer to lcore variable instance of the current thread.

May only be used by EAL threads and registered non-EAL threads.

Definition at line 151 of file rte_lcore_var.h.

◆ RTE_LCORE_VAR_FOREACH

#define RTE_LCORE_VAR_FOREACH (   lcore_id,
  value,
  handle 
)
Value:
for ((lcore_id) = \
(((value) = RTE_LCORE_VAR_LCORE(0, handle)), 0); \
(lcore_id) < RTE_MAX_LCORE; \
(lcore_id)++, (value) = RTE_LCORE_VAR_LCORE(lcore_id, \
handle))
#define RTE_LCORE_VAR_LCORE(lcore_id, handle)

Iterate over each lcore id's value for an lcore variable.

Parameters
lcore_idAn unsigned int variable successively set to the lcore id of every valid lcore id (up to RTE_MAX_LCORE).
valueA pointer variable successively set to point to lcore variable value instance of the current lcore id being processed.
handleThe lcore variable handle.

Definition at line 166 of file rte_lcore_var.h.

Function Documentation

◆ rte_lcore_var_lcore()

static void* rte_lcore_var_lcore ( unsigned int  lcore_id,
void *  handle 
)
inlinestatic

Get void pointer to lcore variable instance with the specified lcore id.

Parameters
lcore_idThe lcore id specifying which of the RTE_MAX_LCORE value instances should be accessed. The lcore id need not be valid (e.g., may be LCORE_ID_ANY), but in such a case, the pointer is also not valid (and thus should not be dereferenced).
handleThe lcore variable handle.

Definition at line 126 of file rte_lcore_var.h.

◆ rte_lcore_var_alloc()

__rte_experimental void* rte_lcore_var_alloc ( size_t  size,
size_t  align 
)

Allocate space in the per-lcore id buffers for an lcore variable.

The pointer returned is only an opaque identifier of the variable. To get an actual pointer to a particular instance of the variable, use RTE_LCORE_VAR or RTE_LCORE_VAR_LCORE.

The lcore variable values' memory is set to zero.

The allocation is always successful, barring a fatal exhaustion of the per-lcore id buffer space.

rte_lcore_var_alloc() is not multi-thread safe.

The allocated memory cannot be freed.

Parameters
sizeThe size (in bytes) of the variable's per-lcore id value. Must be > 0.
alignIf 0, the values will be suitably aligned for any kind of type (i.e., alignof(max_align_t)). Otherwise, the values will be aligned on a multiple of align, which must be a power of 2 and equal or less than RTE_CACHE_LINE_SIZE.
Returns
The variable's handle, stored in a void pointer value. The value is always non-NULL.