DPDK 22.11.5
|
#include <stdint.h>
#include <limits.h>
#include <rte_config.h>
#include <rte_os.h>
Go to the source code of this file.
Macros | |
#define | RTE_STD_C11 __extension__ |
#define | __rte_aligned(a) __attribute__((__aligned__(a))) |
#define | __rte_packed __attribute__((__packed__)) |
#define | __rte_may_alias __attribute__((__may_alias__)) |
#define | RTE_DEPRECATED(x) |
#define | __rte_weak __attribute__((__weak__)) |
#define | __rte_used __attribute__((used)) |
#define | __rte_unused __attribute__((__unused__)) |
#define | __rte_restrict __restrict |
#define | RTE_SET_USED(x) (void)(x) |
#define | __rte_format_printf(format_index, first_arg) __attribute__((format(printf, format_index, first_arg))) |
#define | __rte_alloc_size(...) |
#define | RTE_INIT_PRIO(func, prio) static void __attribute__((constructor(RTE_PRIO(prio)), used)) func(void) |
#define | RTE_INIT(func) RTE_INIT_PRIO(func, LAST) |
#define | RTE_FINI_PRIO(func, prio) static void __attribute__((destructor(RTE_PRIO(prio)), used)) func(void) |
#define | RTE_FINI(func) RTE_FINI_PRIO(func, LAST) |
#define | __rte_noreturn __attribute__((noreturn)) |
#define | __rte_warn_unused_result __attribute__((warn_unused_result)) |
#define | __rte_always_inline inline __attribute__((always_inline)) |
#define | __rte_noinline __attribute__((noinline)) |
#define | __rte_hot __attribute__((hot)) |
#define | __rte_cold __attribute__((cold)) |
#define | __rte_no_asan |
#define | RTE_PTR_ADD(ptr, x) ((void*)((uintptr_t)(ptr) + (x))) |
#define | RTE_PTR_SUB(ptr, x) ((void *)((uintptr_t)(ptr) - (x))) |
#define | RTE_PTR_DIFF(ptr1, ptr2) ((uintptr_t)(ptr1) - (uintptr_t)(ptr2)) |
#define | RTE_CAST_FIELD(var, field, type) (*(type *)((uintptr_t)(var) + offsetof(typeof(*(var)), field))) |
#define | RTE_PTR_ALIGN_FLOOR(ptr, align) ((typeof(ptr))RTE_ALIGN_FLOOR((uintptr_t)(ptr), align)) |
#define | RTE_ALIGN_FLOOR(val, align) (typeof(val))((val) & (~((typeof(val))((align) - 1)))) |
#define | RTE_PTR_ALIGN_CEIL(ptr, align) RTE_PTR_ALIGN_FLOOR((typeof(ptr))RTE_PTR_ADD(ptr, (align) - 1), align) |
#define | RTE_ALIGN_CEIL(val, align) RTE_ALIGN_FLOOR(((val) + ((typeof(val)) (align) - 1)), align) |
#define | RTE_PTR_ALIGN(ptr, align) RTE_PTR_ALIGN_CEIL(ptr, align) |
#define | RTE_ALIGN(val, align) RTE_ALIGN_CEIL(val, align) |
#define | RTE_ALIGN_MUL_CEIL(v, mul) ((((v) + (typeof(v))(mul) - 1) / ((typeof(v))(mul))) * (typeof(v))(mul)) |
#define | RTE_ALIGN_MUL_FLOOR(v, mul) (((v) / ((typeof(v))(mul))) * (typeof(v))(mul)) |
#define | RTE_ALIGN_MUL_NEAR(v, mul) |
#define | RTE_BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)])) |
#define | RTE_CACHE_LINE_MASK (RTE_CACHE_LINE_SIZE-1) |
#define | RTE_CACHE_LINE_ROUNDUP(size) RTE_ALIGN_CEIL(size, RTE_CACHE_LINE_SIZE) |
#define | RTE_CACHE_LINE_MIN_SIZE 64 |
#define | __rte_cache_aligned __rte_aligned(RTE_CACHE_LINE_SIZE) |
#define | __rte_cache_min_aligned __rte_aligned(RTE_CACHE_LINE_MIN_SIZE) |
#define | RTE_IS_POWER_OF_2(n) ((n) && !(((n) - 1) & (n))) |
#define | RTE_MIN(a, b) |
#define | RTE_MAX(a, b) |
#define | offsetof(TYPE, MEMBER) __builtin_offsetof (TYPE, MEMBER) |
#define | container_of(ptr, type, member) |
#define | RTE_SWAP(a, b) |
#define | RTE_SIZEOF_FIELD(type, field) (sizeof(((type *)0)->field)) |
#define | RTE_STR(x) _RTE_STR(x) |
#define | RTE_FMT(fmt, ...) fmt "%.0s", __VA_ARGS__ "" |
#define | RTE_LEN2MASK(ln, tp) ((tp)((uint64_t)-1 >> (sizeof(uint64_t) * CHAR_BIT - (ln)))) |
#define | RTE_DIM(a) (sizeof (a) / sizeof ((a)[0])) |
Typedefs | |
typedef uint64_t | phys_addr_t |
typedef uint64_t | rte_iova_t |
Functions | |
static int | rte_is_aligned (const void *const __rte_restrict ptr, const unsigned int align) |
static uint32_t | rte_combine32ms1b (uint32_t x) |
static uint64_t | rte_combine64ms1b (uint64_t v) |
static int | rte_is_power_of_2 (uint32_t n) |
static uint32_t | rte_align32pow2 (uint32_t x) |
static uint32_t | rte_align32prevpow2 (uint32_t x) |
static uint64_t | rte_align64pow2 (uint64_t v) |
static uint64_t | rte_align64prevpow2 (uint64_t v) |
static uint32_t | rte_bsf32 (uint32_t v) |
static int | rte_bsf32_safe (uint32_t v, uint32_t *pos) |
static uint32_t | rte_log2_u32 (uint32_t v) |
static uint32_t | rte_fls_u32 (uint32_t x) |
static uint32_t | rte_bsf64 (uint64_t v) |
static int | rte_bsf64_safe (uint64_t v, uint32_t *pos) |
static uint32_t | rte_fls_u64 (uint64_t x) |
static uint32_t | rte_log2_u64 (uint64_t v) |
uint64_t | rte_str_to_size (const char *str) |
__rte_noreturn void | rte_exit (int exit_code, const char *format,...) __rte_format_printf(2 |
Variables | |
__extension__ typedef void * | RTE_MARKER [0] |
__extension__ typedef uint8_t | RTE_MARKER8 [0] |
__extension__ typedef uint16_t | RTE_MARKER16 [0] |
__extension__ typedef uint32_t | RTE_MARKER32 [0] |
__extension__ typedef uint64_t | RTE_MARKER64 [0] |
Generic, commonly-used macro and inline function definitions for DPDK.
Definition in file rte_common.h.
#define RTE_STD_C11 __extension__ |
C extension macro for environments lacking C11 features.
Definition at line 39 of file rte_common.h.
#define __rte_aligned | ( | a | ) | __attribute__((__aligned__(a))) |
Force alignment
Definition at line 68 of file rte_common.h.
struct rte_vxlan_gpe_hdr __rte_packed __attribute__((__packed__)) |
Force a structure to be packed
Definition at line 83 of file rte_common.h.
#define __rte_may_alias __attribute__((__may_alias__)) |
Macro to mark a type that is not subject to type-based aliasing rules
Definition at line 88 of file rte_common.h.
#define RTE_DEPRECATED | ( | x | ) |
Macro to mark macros and defines scheduled for removal
Definition at line 102 of file rte_common.h.
#define __rte_weak __attribute__((__weak__)) |
Mark a function or variable to a weak reference.
Definition at line 108 of file rte_common.h.
#define __rte_used __attribute__((used)) |
Force symbol to be generated even if it appears to be unused.
Definition at line 113 of file rte_common.h.
#define __rte_unused __attribute__((__unused__)) |
short definition to mark a function parameter unused
Definition at line 120 of file rte_common.h.
#define __rte_restrict __restrict |
Mark pointer as restricted with regard to pointer aliasing.
Definition at line 126 of file rte_common.h.
#define RTE_SET_USED | ( | x | ) | (void)(x) |
definition to mark a variable or function parameter as used so as to avoid a compiler warning
Definition at line 135 of file rte_common.h.
#define __rte_format_printf | ( | format_index, | |
first_arg | |||
) | __attribute__((format(printf, format_index, first_arg))) |
Check format string and its arguments at compile-time.
GCC on Windows assumes MS-specific format string by default, even if the underlying stdio implementation is ANSI-compliant, so this must be overridden.
Definition at line 148 of file rte_common.h.
#define __rte_alloc_size | ( | ... | ) |
Tells compiler that the function returns a value that points to memory, where the size is given by the one or two arguments. Used by compiler to validate object size.
Definition at line 161 of file rte_common.h.
#define RTE_INIT_PRIO | ( | func, | |
prio | |||
) | static void __attribute__((constructor(RTE_PRIO(prio)), used)) func(void) |
Run function before main() with high priority.
func | Constructor function. |
prio | Priority number must be above 100. Lowest number is the first to run. |
Definition at line 182 of file rte_common.h.
#define RTE_INIT | ( | func | ) | RTE_INIT_PRIO(func, LAST) |
Run function before main() with low priority.
The constructor will be run after prioritized constructors.
func | Constructor function. |
Definition at line 194 of file rte_common.h.
#define RTE_FINI_PRIO | ( | func, | |
prio | |||
) | static void __attribute__((destructor(RTE_PRIO(prio)), used)) func(void) |
Run after main() with low priority.
func | Destructor function name. |
prio | Priority number must be above 100. Lowest number is the last to run. |
Definition at line 207 of file rte_common.h.
#define RTE_FINI | ( | func | ) | RTE_FINI_PRIO(func, LAST) |
Run after main() with high priority.
The destructor will be run before prioritized destructors.
func | Destructor function name. |
Definition at line 219 of file rte_common.h.
#define __rte_noreturn __attribute__((noreturn)) |
Hint never returning function
Definition at line 225 of file rte_common.h.
#define __rte_warn_unused_result __attribute__((warn_unused_result)) |
Issue a warning in case the function's return value is ignored.
The use of this attribute should be restricted to cases where ignoring the marked function's return value is almost always a bug. With GCC, some effort is required to make clear that ignoring the return value is intentional. The usual void-casting method to mark something unused as used does not suppress the warning with this compiler.
Definition at line 250 of file rte_common.h.
#define __rte_always_inline inline __attribute__((always_inline)) |
Force a function to be inlined
Definition at line 255 of file rte_common.h.
#define __rte_noinline __attribute__((noinline)) |
Force a function to be noinlined
Definition at line 260 of file rte_common.h.
#define __rte_hot __attribute__((hot)) |
Hint function in the hot path
Definition at line 265 of file rte_common.h.
#define __rte_cold __attribute__((cold)) |
Hint function in the cold path
Definition at line 270 of file rte_common.h.
#define __rte_no_asan |
Disable AddressSanitizer on some code
Definition at line 282 of file rte_common.h.
#define RTE_PTR_ADD | ( | ptr, | |
x | |||
) | ((void*)((uintptr_t)(ptr) + (x))) |
add a byte-value offset to a pointer
Definition at line 290 of file rte_common.h.
#define RTE_PTR_SUB | ( | ptr, | |
x | |||
) | ((void *)((uintptr_t)(ptr) - (x))) |
subtract a byte-value offset from a pointer
Definition at line 295 of file rte_common.h.
#define RTE_PTR_DIFF | ( | ptr1, | |
ptr2 | |||
) | ((uintptr_t)(ptr1) - (uintptr_t)(ptr2)) |
get the difference between two pointer values, i.e. how far apart in bytes are the locations they point two. It is assumed that ptr1 is greater than ptr2.
Definition at line 302 of file rte_common.h.
#define RTE_CAST_FIELD | ( | var, | |
field, | |||
type | |||
) | (*(type *)((uintptr_t)(var) + offsetof(typeof(*(var)), field))) |
Workaround to cast a const field of a structure to non-const type.
Definition at line 307 of file rte_common.h.
#define RTE_PTR_ALIGN_FLOOR | ( | ptr, | |
align | |||
) | ((typeof(ptr))RTE_ALIGN_FLOOR((uintptr_t)(ptr), align)) |
Macro to align a pointer to a given power-of-two. The resultant pointer will be a pointer of the same type as the first parameter, and point to an address no higher than the first parameter. Second parameter must be a power-of-two value.
Definition at line 319 of file rte_common.h.
#define RTE_ALIGN_FLOOR | ( | val, | |
align | |||
) | (typeof(val))((val) & (~((typeof(val))((align) - 1)))) |
Macro to align a value to a given power-of-two. The resultant value will be of the same type as the first parameter, and will be no bigger than the first parameter. Second parameter must be a power-of-two value.
Definition at line 328 of file rte_common.h.
#define RTE_PTR_ALIGN_CEIL | ( | ptr, | |
align | |||
) | RTE_PTR_ALIGN_FLOOR((typeof(ptr))RTE_PTR_ADD(ptr, (align) - 1), align) |
Macro to align a pointer to a given power-of-two. The resultant pointer will be a pointer of the same type as the first parameter, and point to an address no lower than the first parameter. Second parameter must be a power-of-two value.
Definition at line 337 of file rte_common.h.
#define RTE_ALIGN_CEIL | ( | val, | |
align | |||
) | RTE_ALIGN_FLOOR(((val) + ((typeof(val)) (align) - 1)), align) |
Macro to align a value to a given power-of-two. The resultant value will be of the same type as the first parameter, and will be no lower than the first parameter. Second parameter must be a power-of-two value.
Definition at line 346 of file rte_common.h.
#define RTE_PTR_ALIGN | ( | ptr, | |
align | |||
) | RTE_PTR_ALIGN_CEIL(ptr, align) |
Macro to align a pointer to a given power-of-two. The resultant pointer will be a pointer of the same type as the first parameter, and point to an address no lower than the first parameter. Second parameter must be a power-of-two value. This function is the same as RTE_PTR_ALIGN_CEIL
Definition at line 356 of file rte_common.h.
#define RTE_ALIGN | ( | val, | |
align | |||
) | RTE_ALIGN_CEIL(val, align) |
Macro to align a value to a given power-of-two. The resultant value will be of the same type as the first parameter, and will be no lower than the first parameter. Second parameter must be a power-of-two value. This function is the same as RTE_ALIGN_CEIL
Definition at line 365 of file rte_common.h.
#define RTE_ALIGN_MUL_CEIL | ( | v, | |
mul | |||
) | ((((v) + (typeof(v))(mul) - 1) / ((typeof(v))(mul))) * (typeof(v))(mul)) |
Macro to align a value to the multiple of given value. The resultant value will be of the same type as the first parameter and will be no lower than the first parameter.
Definition at line 372 of file rte_common.h.
#define RTE_ALIGN_MUL_FLOOR | ( | v, | |
mul | |||
) | (((v) / ((typeof(v))(mul))) * (typeof(v))(mul)) |
Macro to align a value to the multiple of given value. The resultant value will be of the same type as the first parameter and will be no higher than the first parameter.
Definition at line 380 of file rte_common.h.
#define RTE_ALIGN_MUL_NEAR | ( | v, | |
mul | |||
) |
Macro to align value to the nearest multiple of the given value. The resultant value might be greater than or less than the first parameter whichever difference is the lowest.
Definition at line 388 of file rte_common.h.
#define RTE_BUILD_BUG_ON | ( | condition | ) | ((void)sizeof(char[1 - 2*!!(condition)])) |
Triggers an error at compilation time if the condition is true.
Definition at line 417 of file rte_common.h.
#define RTE_CACHE_LINE_MASK (RTE_CACHE_LINE_SIZE-1) |
Cache line mask.
Definition at line 422 of file rte_common.h.
#define RTE_CACHE_LINE_ROUNDUP | ( | size | ) | RTE_ALIGN_CEIL(size, RTE_CACHE_LINE_SIZE) |
Return the first cache-aligned value greater or equal to size.
Definition at line 425 of file rte_common.h.
#define RTE_CACHE_LINE_MIN_SIZE 64 |
Cache line size in terms of log2 Minimum Cache line size.
Definition at line 437 of file rte_common.h.
struct rte_regexdev __rte_cache_aligned __rte_aligned(RTE_CACHE_LINE_SIZE) |
Force alignment to cache line.
Definition at line 440 of file rte_common.h.
struct rte_eth_txq_info __rte_cache_min_aligned __rte_aligned(RTE_CACHE_LINE_MIN_SIZE) |
Force minimum cache line alignment.
Definition at line 443 of file rte_common.h.
#define RTE_IS_POWER_OF_2 | ( | n | ) | ((n) && !(((n) - 1) & (n))) |
Macro to return 1 if n is a power of 2, 0 otherwise
Definition at line 524 of file rte_common.h.
#define RTE_MIN | ( | a, | |
b | |||
) |
Macro to return the minimum of two numbers
Definition at line 613 of file rte_common.h.
#define RTE_MAX | ( | a, | |
b | |||
) |
Macro to return the maximum of two numbers
Definition at line 623 of file rte_common.h.
#define offsetof | ( | TYPE, | |
MEMBER | |||
) | __builtin_offsetof (TYPE, MEMBER) |
Return the offset of a field in a structure.
Definition at line 793 of file rte_common.h.
#define container_of | ( | ptr, | |
type, | |||
member | |||
) |
Return pointer to the wrapping struct instance.
Example:
struct wrapper { ... struct child c; ... };
struct child *x = obtain(...); struct wrapper *w = container_of(x, struct wrapper, c);
Definition at line 811 of file rte_common.h.
#define RTE_SWAP | ( | a, | |
b | |||
) |
Swap two variables.
Definition at line 820 of file rte_common.h.
#define RTE_SIZEOF_FIELD | ( | type, | |
field | |||
) | (sizeof(((type *)0)->field)) |
Get the size of a field in a structure.
type | The type of the structure. |
field | The field in the structure. |
Definition at line 837 of file rte_common.h.
#define RTE_STR | ( | x | ) | _RTE_STR(x) |
Take a macro value and get a string version of it
Definition at line 841 of file rte_common.h.
#define RTE_FMT | ( | fmt, | |
... | |||
) | fmt "%.0s", __VA_ARGS__ "" |
ISO C helpers to modify format strings using variadic macros. This is a replacement for the ", ## __VA_ARGS__" GNU extension. An empty s argument is appended to avoid a dangling comma.
Definition at line 848 of file rte_common.h.
#define RTE_LEN2MASK | ( | ln, | |
tp | |||
) | ((tp)((uint64_t)-1 >> (sizeof(uint64_t) * CHAR_BIT - (ln)))) |
Mask value of type "tp" for the first "ln" bit set.
Definition at line 853 of file rte_common.h.
#define RTE_DIM | ( | a | ) | (sizeof (a) / sizeof ((a)[0])) |
Number of elements in the array.
Definition at line 857 of file rte_common.h.
typedef uint64_t phys_addr_t |
Physical address
Definition at line 448 of file rte_common.h.
typedef uint64_t rte_iova_t |
IO virtual address type. When the physical addressing mode (IOVA as PA) is in use, the translation from an IO virtual address (IOVA) to a physical address is a direct mapping, i.e. the same value. Otherwise, in virtual mode (IOVA as VA), an IOMMU may do the translation.
Definition at line 458 of file rte_common.h.
|
inlinestatic |
Checks if a pointer is aligned to a given power-of-two value
ptr | The pointer whose alignment is to be checked |
align | The power-of-two value to which the ptr should be aligned |
Definition at line 407 of file rte_common.h.
|
inlinestatic |
Combines 32b inputs most significant set bits into the least significant bits to construct a value with the same MSBs as x but all 1's under it.
x | The integer whose MSBs need to be combined with its LSBs |
Definition at line 485 of file rte_common.h.
|
inlinestatic |
Combines 64b inputs most significant set bits into the least significant bits to construct a value with the same MSBs as x but all 1's under it.
v | The integer whose MSBs need to be combined with its LSBs |
Definition at line 507 of file rte_common.h.
|
inlinestatic |
Returns true if n is a power of 2
n | Number to check |
Definition at line 533 of file rte_common.h.
|
inlinestatic |
Aligns input parameter to the next power of 2
x | The integer value to align |
Definition at line 548 of file rte_common.h.
|
inlinestatic |
Aligns input parameter to the previous power of 2
x | The integer value to align |
Definition at line 566 of file rte_common.h.
|
inlinestatic |
Aligns 64b input parameter to the next power of 2
v | The 64b value to align |
Definition at line 583 of file rte_common.h.
|
inlinestatic |
Aligns 64b input parameter to the previous power of 2
v | The 64b value to align |
Definition at line 601 of file rte_common.h.
|
inlinestatic |
Searches the input parameter for the least significant set bit (starting from zero). If a least significant 1 bit is found, its bit index is returned. If the content of the input parameter is zero, then the content of the return value is undefined.
v | input parameter, should not be zero. |
Definition at line 644 of file rte_common.h.
|
inlinestatic |
Searches the input parameter for the least significant set bit (starting from zero). Safe version (checks for input parameter being zero).
pos
must be a valid pointer. It is not checked!v | The input parameter. |
pos | If v was not 0, this value will contain position of least significant bit within the input parameter. |
v
was 0, otherwise returns 1. Definition at line 664 of file rte_common.h.
|
inlinestatic |
Return the rounded-up log2 of a integer.
v | The input parameter. |
Definition at line 685 of file rte_common.h.
|
inlinestatic |
Return the last (most-significant) bit set.
x | The input parameter. |
Definition at line 706 of file rte_common.h.
|
inlinestatic |
Searches the input parameter for the least significant set bit (starting from zero). If a least significant 1 bit is found, its bit index is returned. If the content of the input parameter is zero, then the content of the return value is undefined.
v | input parameter, should not be zero. |
Definition at line 723 of file rte_common.h.
|
inlinestatic |
Searches the input parameter for the least significant set bit (starting from zero). Safe version (checks for input parameter being zero).
pos
must be a valid pointer. It is not checked!v | The input parameter. |
pos | If v was not 0, this value will contain position of least significant bit within the input parameter. |
v
was 0, otherwise returns 1. Definition at line 743 of file rte_common.h.
|
inlinestatic |
Return the last (most-significant) bit set.
x | The input parameter. |
Definition at line 765 of file rte_common.h.
|
inlinestatic |
Return the rounded-up log2 of a 64-bit integer.
v | The input parameter. |
Definition at line 782 of file rte_common.h.
uint64_t rte_str_to_size | ( | const char * | str | ) |
Converts a numeric string to the equivalent uint64_t value. As well as straight number conversion, also recognises the suffixes k, m and g for kilobytes, megabytes and gigabytes respectively.
If a negative number is passed in i.e. a string with the first non-black character being "-", zero is returned. Zero is also returned in the case of an error with the strtoull call in the function.
str | String containing number to convert. |
__rte_noreturn void rte_exit | ( | int | exit_code, |
const char * | format, | ||
... | |||
) |
Function to terminate the application immediately, printing an error message and returning the exit_code back to the shell.
This function never returns
exit_code | The exit code to be returned by the application |
format | The format string to be used for printing the message. This can include printf format characters which will be expanded using any further parameters to the function. |
__extension__ typedef void* RTE_MARKER[0] |
Generic marker for any place in a structure.
Definition at line 464 of file rte_common.h.
__extension__ typedef uint8_t RTE_MARKER8[0] |
Marker for 1B alignment in a structure.
Definition at line 466 of file rte_common.h.
__extension__ typedef uint16_t RTE_MARKER16[0] |
Marker for 2B alignment in a structure.
Definition at line 468 of file rte_common.h.
__extension__ typedef uint32_t RTE_MARKER32[0] |
Marker for 4B alignment in a structure.
Definition at line 470 of file rte_common.h.
__extension__ typedef uint64_t RTE_MARKER64[0] |
Marker for 8B alignment in a structure.
Definition at line 472 of file rte_common.h.