rte_common.h(3)
๐ซ rte_common.h โ DPDK's Bestie Manual ๐ซ
okay so this is the rte_common.h(3) page from the DPDK manual and honestly? it's giving foundational. it's the header that holds all the generic, commonly-used macro and inline function definitions for DPDK. like, the building blocks. the main character energy of headers, fr fr.
Definition in file rte_common.h.
โจ SYNOPSIS โจ
so first you gotta include all these, bestie. no skipping:
#include <assert.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdalign.h>
#include <rte_compat.h>
#include <rte_config.h>
#include <rte_os.h>
๐ Macros ๐
okay this is the big list and it's honestly iconic. every single one, here we go:
#define __rte_aligned(a) __attribute__((__aligned__(a)))
#define __rte_packed (RTE_DEPRECATED(__rte_packed)
__attribute__((__packed__)))
#define __rte_packed_begin
#define __rte_may_alias __attribute__((__may_alias__))
#define RTE_DEPRECATED(x)
#define __rte_diagnostic_push _Pragma('GCC diagnostic push')
#define __rte_diagnostic_ignored_wcast_qual _Pragma('GCC diagnostic
ignored ยด-Wcast-qualยด')
#define __rte_weak RTE_DEPRECATED(__rte_weak)
__attribute__((__weak__))
#define __rte_pure __attribute__((pure))
#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_section(name) __attribute__((section(name)))
#define __rte_alloc_size(...)
#define __rte_alloc_align(argno)
#define __rte_malloc
#define __rte_dealloc(dealloc, argno)
#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_unreachable() __assume(0)
#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_assume(condition) __assume(condition)
#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_PTR_UNQUAL(X) ((void *)(uintptr_t)(X))
#define RTE_CAST_PTR(type, ptr) ((type)(uintptr_t)(ptr))
#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) do { static_assert(!(condition),
#condition); } while (0)
#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_CACHE_GUARD _RTE_CACHE_GUARD_HELPER1(__COUNTER__)
#define RTE_MIN(a, b)
#define RTE_MIN_T(a, b, t) ((t)(a) < (t)(b) ? (t)(a) : (t)(b))
#define RTE_MAX(a, b)
#define RTE_MAX_T(a, b, t) ((t)(a) > (t)(b) ? (t)(a) : (t)(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_ttypedef uint64_t rte_iova_t
๐ฆ Functions ๐ฆ
static int rte_is_aligned (const void *const __rte_restrict ptr, const unsigned int align)uint64_t rte_str_to_size (const char *str)__rte_experimental char * rte_size_to_str (char *buf, int buf_size, uint64_t count, bool use_iec, const char *unit)__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]
๐ Detailed Description ๐
Generic, commonly-used macro and inline function definitions for DPDK. like, it's the whole vibe. everything foundational lives here.
Definition in file rte_common.h.
๐ฅ Macro Definition Documentation ๐ฅ
#define __rte_aligned(a) __attribute__((__aligned__(a)))
Force type alignment, bestie. ๐
This macro should be used when alignment of a struct or union type is required. For toolchain compatibility it should appear between the {struct,union} keyword and tag. e.g.
struct __rte_aligned(8) tag { ... };
If alignment of an object/variable is required then this macro should not be used, instead prefer C11 alignas(a).
Definition at line 121 of file rte_common.h.
#define __rte_packed (RTE_DEPRECATED(__rte_packed) __attribute__((__packed__)))
Deprecated! no cap, this one's on the way out. ๐ซถ
See also __rte_packed_begin, __rte_packed_end
Force a structure to be packed.
Definition at line 144 of file rte_common.h.
#define __rte_packed_begin
Force a structure to be packed. Usage: struct __rte_packed_begin mystruct { ... } __rte_packed_end; union __rte_packed_begin myunion { ... } __rte_packed_end; Note: alignment attributes when present should precede __rte_packed_begin.
Definition at line 158 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. it's giving "i do what i want" energy. โจ
Definition at line 168 of file rte_common.h.
#define RTE_DEPRECATED(x)
Macro to mark macros and defines scheduled for removal. rip but also necessary. ๐
Definition at line 188 of file rte_common.h.
#define __rte_diagnostic_push _Pragma('GCC diagnostic push')
Macros to cause the compiler to remember the state of the diagnostics as of each push, and restore to that point at each pop. so organized, honestly obsessed. ๐
Definition at line 196 of file rte_common.h.
#define __rte_diagnostic_ignored_wcast_qual _Pragma('GCC diagnostic ignored ยด-Wcast-qualยด')
Macro to disable compiler warnings about removing a type qualifier from the target type. sometimes you just gotta do what you gotta do, yk? ๐
Definition at line 208 of file rte_common.h.
#define __rte_weak RTE_DEPRECATED(__rte_weak) __attribute__((__weak__))
Mark a function or variable to a weak reference. deprecated bestie, but still here for now. ๐
Definition at line 219 of file rte_common.h.
#define __rte_pure __attribute__((pure))
Mark a function to be pure. iconic behavior only. โจ
Definition at line 228 of file rte_common.h.
#define __rte_used __attribute__((used))
Force symbol to be generated even if it appears to be unused. it's like "i'm still here, don't forget me" vibes. ๐ฆ
Definition at line 237 of file rte_common.h.
#define __rte_unused __attribute__((__unused__))
short definition to mark a function parameter unused. literally just chilling. no drama. ๐
Definition at line 248 of file rte_common.h.
#define __rte_restrict __restrict
Mark pointer as restricted with regard to pointer aliasing.
Definition at line 255 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. classic move fr fr. ๐
Definition at line 264 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. windows being windows, smh. ๐ซ
Definition at line 280 of file rte_common.h.
#define __rte_section(name) __attribute__((section(name)))
Specify data or function section/segment. giving it a specific home. ๐
Definition at line 292 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. so helpful, we love a helpful compiler. โจ
Definition at line 305 of file rte_common.h.
#define __rte_alloc_align(argno)
Tells the compiler that the function returns a value that points to memory aligned by a function argument.
Note: not enabled on Clang because it warns if align argument is zero. clang being a little dramatic, we respect it tho. ๐ญ
Definition at line 318 of file rte_common.h.
#define __rte_malloc
Tells the compiler this is a function like malloc and that the pointer returned cannot alias any other pointer (ie new memory). fresh allocation, who dis. ๐
Definition at line 328 of file rte_common.h.
#define __rte_dealloc(dealloc, argno)
With recent GCC versions also able to track that proper deallocator function is used for this pointer. it's giving accountability. ๐ธ
Definition at line 339 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.
Parameters:
- func โ Constructor function.
- prio โ Priority number must be above
100. Lowest number is the first to run.
Definition at line 361 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.
Parameters:
- func โ Constructor function.
Definition at line 393 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.
Parameters:
- func โ Destructor function name.
- prio โ Priority number must be above
100. Lowest number is the last to run.
Definition at line 407 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.
Parameters:
- func โ Destructor function name.
Definition at line 434 of file rte_common.h.
okay that's part 1 bestie, there's more coming so don't go anywhere ๐โจ
__rte_noreturn โ bestie, this is the โshe is literally never coming backโ hint for a function. Compiler gets told it never returns, periodt.
#define __rte_noreturn __attribute__((noreturn))
Definition at line 443 of file rte_common.h.
__rte_unreachable() โ the โthis point in the program is never ever reachedโ hint. Main character energy for dead code, ngl.
#define __rte_unreachable() __assume(0)
Definition at line 452 of file rte_common.h.
__rte_warn_unused_result โ screams a warning if the functionโs return value gets ignored. Lowkey only use this when ignoring that result is almost always a bug. With GCC, you gotta put in some effort to show that ignoring it is intentional. The usual void-casting trick does not suppress the warning with this compiler. ๐
__rte_warn_unused_result int foo();
void ignore_foo_result(void) {
foo(); // generates a warning with all compilers
(void)foo(); // still generates the warning with GCC (but not clang)
int unused __rte_unused;
unused = foo(); // does the trick with all compilers
}
Definition at line 481 of file rte_common.h.
__rte_always_inline โ forces a function to be inlined. No cap, the compiler is being told to make it happen.
#define __rte_always_inline inline __attribute__((always_inline))
Definition at line 490 of file rte_common.h.
__rte_noinline โ forces a function to be noinlined. The opposite vibe of always-inline, and honestly iconic for when you need it.
#define __rte_noinline __attribute__((noinline))
Definition at line 499 of file rte_common.h.
__rte_hot โ hints that the function lives in the hot path. Sheโs popular, sheโs getting called a lot.
#define __rte_hot __attribute__((hot))
Definition at line 508 of file rte_common.h.
__rte_cold โ hints that the function lives in the cold path. Not every function gets to be main character.
#define __rte_cold __attribute__((cold))
Definition at line 517 of file rte_common.h.
__rte_assume(condition) โ a precondition hint. Very โtrust me bestieโ energy.
โ ๏ธ Warning: depending on the compiler, any code in condition might be executed. This currently only occurs with GCC prior to version 13. So yeah, donโt put your whole personality in there assuming it wonโt run.
#define __rte_assume(condition) __assume(condition)
Definition at line 533 of file rte_common.h.
__rte_no_asan โ disables AddressSanitizer on some code. Letting that one specific code snippet have a little quiet time.
#define __rte_no_asan
Definition at line 546 of file rte_common.h.
RTE_PTR_ADD(ptr, x) โ adds a byte-value offset to a pointer. Pointer math, but make it byte-y.
#define RTE_PTR_ADD(ptr, x) ((void*)((uintptr_t)(ptr) + (x)))
Definition at line 554 of file rte_common.h.
RTE_PTR_SUB(ptr, x) โ subtracts a byte-value offset from a pointer. Same energy, opposite direction.
#define RTE_PTR_SUB(ptr, x) ((void *)((uintptr_t)(ptr) - (x)))
Definition at line 559 of file rte_common.h.
RTE_PTR_DIFF(ptr1, ptr2) โ gets the difference between two pointer values, i.e. how far apart in bytes the locations they point to are. It assumes that ptr1 is greater than ptr2.
#define RTE_PTR_DIFF(ptr1, ptr2) ((uintptr_t)(ptr1) - (uintptr_t)(ptr2))
Definition at line 566 of file rte_common.h.
RTE_PTR_UNQUAL(X) โ discards qualifiers like const, volatile, and restrict from a pointer, without the compiler emitting a warning. The โtake off the qualifiers, bestieโ macro.
#define RTE_PTR_UNQUAL(X) ((void *)(uintptr_t)(X))
Definition at line 574 of file rte_common.h.
RTE_CAST_PTR(type, ptr) โ casts a pointer to a specific type without the compiler emitting a warning about discarding qualifiers. Convenient, but read the warning, okay?
โ ๏ธ Warning: when casting a pointer to point to a larger type, the resulting pointer may be misaligned, which results in undefined behavior. E.g.:
struct s { uint16_t a; uint8_t b; uint8_t c; uint8_t d; } v; uint16_t *
p = RTE_CAST_PTR(uint16_t *, &v.c); // 'p' is not 16 bit aligned!
Definition at line 593 of file rte_common.h.
RTE_CAST_FIELD(var, field, type) โ a workaround to cast a const field of a structure to a non-const type. Yes, sheโs a little sneaky, but thatโs the assignment.
#define RTE_CAST_FIELD(var, field, type) (*(type *)((uintptr_t)(var) + offsetof(typeof(*(var)), field)))
Definition at line 598 of file rte_common.h.
RTE_PTR_ALIGN_FLOOR(ptr, align) โ aligns a pointer to a given power-of-two. The resulting pointer is the same type as the first parameter, and points to an address no higher than the first parameter. Second parameter must be a power-of-two value.
#define RTE_PTR_ALIGN_FLOOR(ptr, align) ((typeof(ptr))RTE_ALIGN_FLOOR((uintptr_t)(ptr), align))
Definition at line 610 of file rte_common.h.
RTE_ALIGN_FLOOR(val, align) โ aligns a value to a given power-of-two. Result has the same type as the first parameter and is no bigger than the first parameter. Second parameter must be a power-of-two value.
#define RTE_ALIGN_FLOOR(val, align) (typeof(val))((val) & (~((typeof(val))((align) - 1))))
Definition at line 619 of file rte_common.h.
RTE_PTR_ALIGN_CEIL(ptr, align) โ aligns a pointer to a given power-of-two. Result is the same pointer type as the first parameter and points to an address no lower than the first parameter. Second parameter must be a power-of-two value.
#define RTE_PTR_ALIGN_CEIL(ptr, align) RTE_PTR_ALIGN_FLOOR((typeof(ptr))RTE_PTR_ADD(ptr, (align) - 1), align)
Definition at line 628 of file rte_common.h.
RTE_ALIGN_CEIL(val, align) โ aligns a value to a given power-of-two. Result has the same type as the first parameter and is no lower than the first parameter. Second parameter must be a power-of-two value.
#define RTE_ALIGN_CEIL(val, align) RTE_ALIGN_FLOOR(((val) + ((typeof(val)) (align) - 1)), align)
Definition at line 637 of file rte_common.h.
RTE_PTR_ALIGN(ptr, align) โ aligns a pointer to a given power-of-two. Result is the same pointer type as the first parameter and points 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.
#define RTE_PTR_ALIGN(ptr, align) RTE_PTR_ALIGN_CEIL(ptr, align)
Definition at line 647 of file rte_common.h.
RTE_ALIGN(val, align) โ aligns a value to a given power-of-two. Result has the same type as the first parameter and is no lower than the first parameter. Second parameter must be a power-of-two value. This function is the same as RTE_ALIGN_CEIL.
#define RTE_ALIGN(val, align) RTE_ALIGN_CEIL(val, align)
Definition at line 656 of file rte_common.h.
RTE_ALIGN_MUL_CEIL(v, mul) โ aligns a value to the multiple of a given value. Result has the same type as the first parameter and is no lower than the first parameter.
#define RTE_ALIGN_MUL_CEIL(v, mul) ((((v) + (typeof(v))(mul) - 1) / ((typeof(v))(mul))) * (typeof(v))(mul))
Definition at line 663 of file rte_common.h.
RTE_ALIGN_MUL_FLOOR(v, mul) โ aligns a value to the multiple of a given value. Result has the same type as the first parameter and is no higher than the first parameter.
#define RTE_ALIGN_MUL_FLOOR(v, mul) (((v) / ((typeof(v))(mul))) * (typeof(v))(mul))
Definition at line 671 of file rte_common.h.
RTE_ALIGN_MUL_NEAR(v, mul) โ aligns a value to the nearest multiple of the given value. Result might be greater than or less than the first parameter, whichever difference is the lowest. Itโs giving โclosest match winsโ โจ
#define RTE_ALIGN_MUL_NEAR(v, mul)
__extension__ ({ typeof(v) ceil = RTE_ALIGN_MUL_CEIL(v, mul); typeof(v) floor = RTE_ALIGN_MUL_FLOOR(v, mul); (ceil - (v)) > ((v) - floor) ? floor : ceil; })
Definition at line 679 of file rte_common.h.
RTE_BUILD_BUG_ON(condition) โ triggers an error at compilation time if the condition is true. Tiny time bomb, but make it compile-time and cute.
The do { } while(0) is there to work around a bug in clang (#55821) where it would not handle _Static_assert in a switch case.
#define RTE_BUILD_BUG_ON(condition) do { static_assert(!(condition), #condition); } while (0)
Definition at line 716 of file rte_common.h.
RTE_CACHE_LINE_MASK โ cache line mask. Thatโs the whole assignment, bestie.
#define RTE_CACHE_LINE_MASK (RTE_CACHE_LINE_SIZE-1)
Definition at line 721 of file rte_common.h.
RTE_CACHE_LINE_ROUNDUP(size) โ returns the first cache-aligned value greater than or equal to size. Rounding up, but make it cache-line coded.
#define RTE_CACHE_LINE_ROUNDUP(size) RTE_ALIGN_CEIL(size, RTE_CACHE_LINE_SIZE)
Definition at line 724 of file rte_common.h.
RTE_CACHE_LINE_MIN_SIZE โ cache line size in terms of log2 minimum cache line size. Yes, that is the sentence. We keep the sentence.
#define RTE_CACHE_LINE_MIN_SIZE 64
Definition at line 736 of file rte_common.h.
__rte_cache_aligned โ forces alignment to cache line. Sheโs aligned and she knows it.
#define __rte_cache_aligned __rte_aligned(RTE_CACHE_LINE_SIZE)
Definition at line 739 of file rte_common.h.
__rte_cache_min_aligned โ forces minimum cache line alignment. Still aligned, just with minimum energy.
#define __rte_cache_min_aligned __rte_aligned(RTE_CACHE_LINE_MIN_SIZE)
Definition at line 742 of file rte_common.h.
RTE_CACHE_GUARD โ empty cache lines, guarding against false sharing-like effects on systems with a next-N-lines hardware prefetcher. Use it as spacing between data accessed by different lcores, so you prevent cache thrashing on hardware with speculative prefetching. Protective force field, but for cache lines ๐ก๏ธ
#define RTE_CACHE_GUARD _RTE_CACHE_GUARD_HELPER1(__COUNTER__)
Definition at line 755 of file rte_common.h.
RTE_MIN(a, b) โ returns the minimum of two numbers. Little one wins, no cap.
#define RTE_MIN(a, b)
__extension__ ({ typeof (a) _a = (a); typeof (b) _b = (b); _a < _b ? _a : _b; })
Definition at line 795 of file rte_common.h.
RTE_MIN_T(a, b, t) โ returns the minimum of two numbers, but typed.
As opposed to RTE_MIN, it does not use temporary variables, so it is not safe if a or b is an expression. Yet it is guaranteed to be constant for use in static_assert(). Tradeoff queen.
#define RTE_MIN_T(a, b, t) ((t)(a) < (t)(b) ? (t)(a) : (t)(b))
Definition at line 809 of file rte_common.h.
RTE_MAX(a, b) โ returns the maximum of two numbers. Big one wins, periodt.
#define RTE_MAX(a, b)
__extension__ ({ typeof (a) _a = (a); typeof (b) _b = (b); _a > _b ? _a : _b; })
Definition at line 815 of file rte_common.h.
RTE_MAX_T(a, b, t) โ returns the maximum of two numbers, but typed.
As opposed to RTE_MAX, it does not use temporary variables, so it is not safe if a or b is an expression. Yet it is guaranteed to be constant for use in static_assert(). Same caveat, maximum vibe.
#define RTE_MAX_T(a, b, t) ((t)(a) > (t)(b) ? (t)(a) : (t)(b))
Definition at line 829 of file rte_common.h.
offsetof(TYPE, MEMBER) โ returns the offset of a field in a structure. The classic โwhere exactly does this member liveโ check.
#define offsetof(TYPE, MEMBER) __builtin_offsetof (TYPE, MEMBER)
Definition at line 836 of file rte_common.h.
container_of(ptr, type, member) โ returns a pointer to the wrapping struct instance. You got a pointer to the child, now find the parent. Obsessed with this one, honestly.
Example:
struct wrapper { ... struct child c; ... };
struct child *x = obtain(...); struct wrapper *w = container_of(x, struct wrapper, c);
#define container_of(ptr, type, member)
__extension__ ({ const typeof(((type *)0)->member) *_ptr = (ptr); __rte_unused type *_target_ptr = (type *)(ptr); (type *)(((uintptr_t)_ptr) - offsetof(type, member)); })
Definition at line 858 of file rte_common.h.
RTE_SWAP(a, b) โ swaps two variables. They trade places, no drama.
#define RTE_SWAP(a, b)
__extension__ ({ typeof (a) _a = a; a = b; b = _a; })
Definition at line 868 of file rte_common.h.
RTE_SIZEOF_FIELD(type, field) โ gets the size of a field in a structure. Tiny ruler for one specific member.
Parameters:
- type โ the type of the structure.
- field โ the field in the structure.
Returns the size of the field in the structure, in bytes.
#define RTE_SIZEOF_FIELD(type, field) (sizeof(((type *)0)->field))
Definition at line 885 of file rte_common.h.
RTE_STR(x) โ takes a macro value and gets a string version of it. Macro value โ string, bestie.
#define RTE_STR(x) _RTE_STR(x)
#define RTE_FMT(fmt, ...)โfmt '%.0s', __VA_ARGS__ ''โ the ISO C helper squad for editing format strings with variadic macros ๐ it's a glow-up replacement for the', ## __VA_ARGS__'GNU extension, and an emptysargument gets tacked on the end so you never end up with a dangling comma. no dangling commas in this house ๐ซ
Definition at line 889 of file rte_common.h.
#define RTE_LEN2MASK(ln, tp)โ((tp)((uint64_t)-1 >> (sizeof(uint64_t) * CHAR_BIT - (ln))))โ slaps together a mask value of typetpfor the firstlnbits being set. literally just "gimme the bits" energy โจ
Definition at line 896 of file rte_common.h.
#define RTE_DIM(a)โ(sizeof (a) / sizeof ((a)[0]))โ the number of elements in the array ๐ข the OG "how many are in there" macro, obsessed.
Definition at line 901 of file rte_common.h.
๐ Typedef Documentation ๐
typedef uint64_t phys_addr_tโ a physical address. that's it, that's the whole vibe ๐ซถ
Definition at line 760 of file rte_common.h.
typedef uint64_t rte_iova_tโ your IO virtual address type ๐ ok so here's the tea: 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. literally the same value, no thoughts head empty. but in virtual mode (IOVA as VA), an IOMMU may do the translating for you ๐ฆ
Definition at line 770 of file rte_common.h.
๐ Function Documentation ๐
static int rte_is_aligned (const void *const __rte_restrict ptr, const unsigned int align) [inline], [static]
Checks if your pointer is aligned to a given power-of-two value. vibe check for alignment, fr fr ๐ฅ
Parameters
ptrโ the pointer whose alignment is being checked ๐alignโ the power-of-two value thatptrshould be aligned to
Returns
True (1) when the pointer is correctly aligned, false (0) otherwise. iconic binary moment ๐
Definition at line 698 of file rte_common.h.
uint64_t rte_str_to_size (const char * str)
Converts a numeric string into the equivalent uint64_t value ๐งฎ and it's not just plain numbers โ it also recognises the suffixes k, m and g for kilobytes, megabytes and gigabytes respectively, which is kind of a slay ngl.
โ ๏ธ If a negative number gets passed in โ like, a string where the first non-blank character is'-'โ you get zero back. Zero also comes back when there's an error with thestrtoullcall inside the function. so like, zero is the "nope" of return values ๐
Parameters
strโ string containing the number to convert.
Returns
Number. that's the return value. number. ๐
__rte_experimental char* rte_size_to_str (char * buf, int buf_size, uint64_t count, bool use_iec, const char * unit)
Warning: EXPERIMENTAL โ this API may change without prior notice ๐ญ so don't get too attached bestie.
Converts the uint64_t value you give it into a human-readable string ๐ธ It null-terminates the string, truncating the data if needed. You can also hand it an optional unit (like 'B') as a string โ it gets appended to the number, and a space gets inserted before the unit if needed. polite little space insertion, we love to see it ๐
Sample outputs: (1) 'use_iec' disabled, (2) 'use_iec' enabled, (3) 'use_iec' enabled and 'B' as unit:
0 : '0', '0', '0 B'
700 : '700', '700', '700 B'
1000 : '1.00 k', '1000', '1000 B'
1024 : '1.02 k', '1.00 ki', '1.00 kiB'
21474836480 : '21.5 G', '20.0 Gi', '20.0 GiB'
109951162777600 : '110 T', '100 Ti', '100 TiB'
Parameters
bufโ buffer to write the string to.buf_sizeโ size of the buffer.countโ number to convert.use_iecโ if true, use IEC units (1024-based), otherwise use SI units (1000-based).unitโ unit to append to the string (like'B'for bytes). can beNULL.
Returns
buf on success, NULL if the buffer is too small ๐ (buffer said "no room, bestie").
__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 ๐ dramatic exit, main character energy, we respect it.
This function never returns. like. ever. it's gone. bye ๐
Parameters
exit_codeโ the exit code to be returned by the application.formatโ the format string used for printing the message. This can includeprintfformat characters, which will be expanded using any further parameters to the function ๐
๐ Variable Documentation ๐
__extension__ typedef void* RTE_MARKER[0]โ generic marker for any place in a structure ๐
Definition at line 778 of file rte_common.h.
__extension__ typedef uint8_t RTE_MARKER8[0]โ marker for1Balignment in a structure โจ
Definition at line 780 of file rte_common.h.
__extension__ typedef uint16_t RTE_MARKER16[0]โ marker for2Balignment in a structure โจ
Definition at line 782 of file rte_common.h.
__extension__ typedef uint32_t RTE_MARKER32[0]โ marker for4Balignment in a structure โจ
Definition at line 784 of file rte_common.h.
__extension__ typedef uint64_t RTE_MARKER64[0]โ marker for8Balignment in a structure โจ big marker, big alignment, big slay.
Definition at line 786 of file rte_common.h.
๐ฆ Author ๐ฆ
Generated automatically by Doxygen for DPDK from the source code ๐ค (not a human wrote this one, it's the robot bestie doing its thing).
okay and that's the whole page!! ๐ this was Version 25.11.0, dated Fri Jan 30 2026 โ screenshot it, frame it, put it on the fridge, rte_common.h(3) forever ๐๐
๐ซถ
๐ฆ where this page comes from
- centos-stream 9: dpdk-devel 2:25.11-1.el9 ยท BSD and LGPLv2 and GPLv2
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms