rte_common.h(3)

๐Ÿ“ฆ
version 26.03 ยท 2 versions
, in nixos 26.05, nixpkgs unstable

rte_common.h ๐Ÿ’–

okay so this is the Library Functions Manual page for rte_common.h(3) โ€” literally the DPDK grab-bag of generic, commonly-used macro and inline function definitions. Utility-belt energy fr fr. ๐Ÿฆ‹


๐ŸŒธ NAME ๐ŸŒธ

rte_common.h


โœจ SYNOPSIS โœจ

First up, the includes โ€” bestie, they're giving "foundation stack" and we respect it:

#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

#define __rte_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)
#define __rte_format_printf(format_index,  first_arg)
#define __rte_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)
#define RTE_INIT(func)
#define RTE_FINI_PRIO(func,  prio)
#define RTE_FINI(func)
#define __rte_noreturn   __attribute__((noreturn))
#define __rte_unreachable()
#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)
#define __rte_no_asan
#define RTE_PTR_ADD(ptr,  x)
#define RTE_PTR_SUB(ptr,  x)
#define RTE_PTR_DIFF(ptr1,  ptr2)
#define RTE_PTR_UNQUAL(X)
#define RTE_CAST_PTR(type,  ptr)
#define RTE_CAST_FIELD(var,  field,  type)
#define RTE_PTR_ALIGN_FLOOR(ptr,  align)
#define RTE_ALIGN_FLOOR(val,  align)
#define RTE_PTR_ALIGN_CEIL(ptr,  align)
#define RTE_ALIGN_CEIL(val,  align)
#define RTE_PTR_ALIGN(ptr,  align)
#define RTE_ALIGN(val,  align)
#define RTE_ALIGN_MUL_CEIL(v,  mul)
#define RTE_ALIGN_MUL_FLOOR(v,  mul)
#define RTE_ALIGN_MUL_NEAR(v,  mul)
#define RTE_BUILD_BUG_ON(condition)
#define RTE_CACHE_LINE_MASK   (RTE_CACHE_LINE_SIZE-1)
#define RTE_CACHE_LINE_ROUNDUP(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(__LINE__)
#define RTE_MIN(a,  b)
#define RTE_MIN3(a,  b,  c)
#define RTE_MIN_T(a,  b,  t)
#define RTE_MAX(a,  b)
#define RTE_MAX3(a,  b,  c)
#define RTE_MAX_T(a,  b,  t)
#define offsetof(TYPE,  MEMBER)
#define container_of(ptr,  type,  member)
#define RTE_SWAP(a,  b)
#define RTE_SIZEOF_FIELD(type,  field)
#define RTE_STR(x)
#define RTE_FMT(fmt, ...)
#define RTE_LEN2MASK(ln,  tp)
#define RTE_DIM(a)

๐Ÿงธ 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)
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.

Definition in file rte_common.h.


๐Ÿ› ๏ธ Macro Definition Documentation ๐Ÿ› ๏ธ

__rte_aligned(a)

__attribute__((__aligned__(a)))

Force type alignment.

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.


__rte_packed

#define __rte_packed   (RTE_DEPRECATED(__rte_packed)
    __attribute__((__packed__)))
โš ๏ธ Deprecated โ€” bestie, this one is marked deprecated.

See also: __rte_packed_begin, __rte_packed_end.

Force a structure to be packed.

Definition at line 144 of file rte_common.h.


__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.


__rte_may_alias

__attribute__((__may_alias__))

Macro to mark a type that is not subject to type-based aliasing rules.

Definition at line 168 of file rte_common.h.


RTE_DEPRECATED(x)

Macro to mark macros and defines scheduled for removal.

Definition at line 188 of file rte_common.h.


__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.

Definition at line 196 of file rte_common.h.


__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.

Definition at line 208 of file rte_common.h.


__rte_weak

RTE_DEPRECATED(__rte_weak)
    __attribute__((__weak__))

Mark a function or variable to a weak reference.

Definition at line 219 of file rte_common.h.


__rte_pure

__attribute__((pure))

Mark a function to be pure.

Definition at line 228 of file rte_common.h.


__rte_used

__attribute__((used))

Force symbol to be generated even if it appears to be unused.

Definition at line 237 of file rte_common.h.


__rte_unused

__attribute__((__unused__))

short definition to mark a function parameter unused.

Definition at line 248 of file rte_common.h.


__rte_restrict

__restrict

Mark pointer as restricted with regard to pointer aliasing.

Definition at line 255 of file rte_common.h.


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 264 of file rte_common.h.


__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 280 of file rte_common.h.


__rte_section(name)

__attribute__((section(name)))

Specify data or function section/segment.

Definition at line 292 of file rte_common.h.


__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 305 of file rte_common.h.


__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.

Definition at line 318 of file rte_common.h.


__rte_malloc

Tells the compiler this is a function like malloc and that the pointer returned cannot alias any other pointer (ie new memory).

Definition at line 328 of file rte_common.h.


__rte_dealloc(dealloc, argno)

With recent GCC versions also able to track that proper deallocator function is used for this pointer.

Definition at line 339 of file rte_common.h.


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.


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.


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.


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.


__rte_noreturn

__attribute__((noreturn))

Hint never returning function.

Definition at line 443 of file rte_common.h.


__rte_unreachable()

__assume(0)

Hint point in program never reached.

Definition at line 452 of file rte_common.h.


__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.

__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

inline __attribute__((always_inline))

Force a function to be inlined.

Definition at line 490 of file rte_common.h.

๐Ÿ’… __rte_noinline โ€” __attribute__((noinline))

Bestie, this one is literally just "compiler, do NOT inline this function, I'm begging." It forces a function to be noinlined. That's it. That's the whole vibe.

Definition at line 499 of file rte_common.h.

๐Ÿซถ

๐Ÿ”ฅ __rte_hot โ€” __attribute__((hot))

A little hint to the compiler that this function lives in the hot path โ€” like, it's main character energy, it gets called all the time, optimize accordingly.

Definition at line 508 of file rte_common.h.

๐Ÿ’€ __rte_cold โ€” __attribute__((cold))

Opposite energy: hint function in the cold path. Like, barely anyone calls this, don't waste your precious optimization budget on it.

Definition at line 517 of file rte_common.h.

โญ __rte_assume( condition)

Value:

__assume(condition)

Hint precondition โ€” you're telling the compiler "trust me, condition is true," which is a whole mood.

โš ๏ธ Warning, and this is important bestie: depending on the compiler, any code in condition might actually be executed. This currently only occurs with GCC prior to version 13. So likeโ€ฆ don't put side effects in there, fr fr.

Definition at line 533 of file rte_common.h.

๐ŸŒธ __rte_no_asan

Disable AddressSanitizer on some code. Sometimes you gotta tell ASan to look away, y'know?

Definition at line 546 of file rte_common.h.


๐ŸŒˆ The pointer math girlies ๐Ÿ’…

๐ŸŽ€ RTE_PTR_ADD( ptr, x)

Value:

((void*)((uintptr_t)(ptr) + (x)))

Add a byte-value offset to a pointer. Clean, simple, iconic.

Definition at line 554 of file rte_common.h.

๐ŸŽ€ RTE_PTR_SUB( ptr, x)

Value:

((void *)((uintptr_t)(ptr) - (x)))

Subtract a byte-value offset from a pointer. The reverse slay.

Definition at line 559 of file rte_common.h.

๐Ÿฆ‹ RTE_PTR_DIFF( ptr1, ptr2)

Value:

((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. (Yes, "point two" โ€” the source said it, I'm not gonna pretend otherwise ๐Ÿ˜ญ.) It is assumed that ptr1 is greater than ptr2, so like, respect the ordering bestie.

Definition at line 566 of file rte_common.h.

โœจ RTE_PTR_UNQUAL( X)

Value:

((void *)(uintptr_t)(X))

Macro to discard qualifiers (such as const, volatile, restrict) from a pointer, without the compiler emitting a warning. It's giving "I know what I'm doing, mind your business, gcc."

Definition at line 574 of file rte_common.h.

๐Ÿ‘‘ RTE_CAST_PTR( type, ptr)

Value:

((type)(uintptr_t)(ptr))

Macro to cast a pointer to a specific type, without the compiler emitting a warning about discarding qualifiers. So convenient. So dangerous. Both can be true.

โš ๏ธ Warning: when casting a pointer to point to a larger type, the resulting pointer may be misaligned, which results in undefined behavior. Like, no cap, actual UB. E.g.: c 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!

That comment is in the original and it is screaming at you. Listen to it. ๐Ÿ’€

Definition at line 593 of file rte_common.h.

๐Ÿงš RTE_CAST_FIELD( var, field, type)

Value:

(*(type *)((uintptr_t)(var) + offsetof(typeof(*(var)), field)))

Workaround to cast a const field of a structure to non-const type. It's a workaround, it says so itself, and honestly? We respect the honesty.

Definition at line 598 of file rte_common.h.


๐ŸŽฏ Alignment era โœจ (power-of-two only, bestie)

๐Ÿ“ RTE_PTR_ALIGN_FLOOR( ptr, align)

Value:

((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. (Say it with me: power-of-two. The whole squad.)

Definition at line 610 of file rte_common.h.

๐Ÿ“ RTE_ALIGN_FLOOR( val, align)

Value:

(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 619 of file rte_common.h.

๐ŸŒธ RTE_PTR_ALIGN_CEIL( ptr, align)

Value:

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 628 of file rte_common.h.

๐ŸŒธ RTE_ALIGN_CEIL( val, align)

Value:

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 637 of file rte_common.h.

๐Ÿซถ RTE_PTR_ALIGN( ptr, align)

Value:

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. Same girl, different name. ๐Ÿ’…

Definition at line 647 of file rte_common.h.

๐Ÿซถ RTE_ALIGN( val, align)

Value:

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 656 of file rte_common.h.


๐ŸŒผ Multiple-of alignment (different vibe, same energy)

๐Ÿ’œ RTE_ALIGN_MUL_CEIL( v, mul)

Value:

((((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. Note: multiple, not power-of-two โ€” different rulebook, bestie.

Definition at line 663 of file rte_common.h.

๐Ÿ’œ RTE_ALIGN_MUL_FLOOR( v, mul)

Value:

(((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 671 of file rte_common.h.

โญ RTE_ALIGN_MUL_NEAR( v, mul)

Value:

__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;    \
})

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. It's picking the closer one, like choosing which friend's house is a shorter walk. ๐Ÿšถโ€โ™€๏ธ

Definition at line 679 of file rte_common.h.


๐Ÿ›‘ Build-time chaos & cache things

๐ŸŒˆ RTE_BUILD_BUG_ON( condition)

Value:

do { static_assert(!(condition), #condition); } while (0)

Triggers an error at compilation time if the condition is true. Catch it early, queen. ๐Ÿ‘‘

The do { } while(0) exists to workaround a bug in clang (#55821) where it would not handle _Static_assert in a switch case. So it's not just aesthetic โ€” it's load-bearing.

Definition at line 716 of file rte_common.h.

๐ŸŽ€ RTE_CACHE_LINE_MASK โ€” (RTE_CACHE_LINE_SIZE-1)

Cache line mask. That's the whole description, she's mysterious like that. โœจ

Definition at line 721 of file rte_common.h.

๐ŸŽ€ RTE_CACHE_LINE_ROUNDUP( size)

Value:

RTE_ALIGN_CEIL(size, RTE_CACHE_LINE_SIZE)

Return the first cache-aligned value greater or equal to size. Round up, always.

Definition at line 724 of file rte_common.h.

๐ŸŒธ RTE_CACHE_LINE_MIN_SIZE โ€” 64

Cache line size in terms of log2 Minimum Cache line size. (Yes, that's what it says. I'm reporting faithfully, bestie.)

Definition at line 736 of file rte_common.h.

๐Ÿ”ฅ __rte_cache_aligned โ€” __rte_aligned(RTE_CACHE_LINE_SIZE)

Force alignment to cache line. For when your struct needs to sit pretty on a cache line boundary.

Definition at line 739 of file rte_common.h.

๐Ÿ”ฅ __rte_cache_min_aligned โ€” __rte_aligned(RTE_CACHE_LINE_MIN_SIZE)

Force minimum cache line alignment. The budget version of the above, still slaying.

Definition at line 742 of file rte_common.h.

๐Ÿฆ‹ RTE_CACHE_GUARD โ€” _RTE_CACHE_GUARD_HELPER1(__LINE__)

Empty cache lines, to guard against false sharing-like effects on systems with a next-N-lines hardware prefetcher.

Use as spacing between data accessed by different lcores, to prevent cache thrashing on hardware with speculative prefetching.

๐Ÿ“Œ Note: although COUNTER would be better for uniqueness, it is not yet (March 2026) part of the C standard, so compilation would fail when building in pedantic mode.

Like, they wanted to be fancy but the standard said no. Respect the constraint. ๐Ÿ˜ญ

Definition at line 759 of file rte_common.h.


๐Ÿ‘‘ MIN / MAX supremacy (the classics)

๐Ÿ’– RTE_MIN( a, b)

Value:

__extension__ ({ \
    typeof (a) _a_min = (a); \
    typeof (b) _b_min = (b); \
    _a_min < _b_min ? _a_min : _b_min; \
})

Macro to return the minimum of two numbers. Uses temp variables so your expressions get evaluated exactly once. Very considerate. ๐Ÿซถ

Definition at line 799 of file rte_common.h.

๐Ÿ’– RTE_MIN3( a, b, c)

Value:

__extension__ ({ \
    typeof (a) _a_min3 = (a); \
    typeof (b) _b_min3 = (b); \
    typeof (c) _c_min3 = (c); \
    _a_min3 < _b_min3 ? \
        (_a_min3 < _c_min3 ? _a_min3 : _c_min3) : \
        (_b_min3 < _c_min3 ? _b_min3 : _c_min3); \
})

Macro to return the minimum of three numbers. Three! The trio we didn't know we needed.

Definition at line 809 of file rte_common.h.

โญ RTE_MIN_T( a, b, t)

Value:

((t)(a) < (t)(b) ? (t)(a) : (t)(b))

Macro to return 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(). Trade-off, bestie. Choose wisely. โš–๏ธ

Definition at line 826 of file rte_common.h.

๐Ÿ’– RTE_MAX( a, b)

Value:

__extension__ ({ \
    typeof (a) _a_max = (a); \
    typeof (b) _b_max = (b); \
    _a_max > _b_max ? _a_max : _b_max; \
})

Macro to return the maximum of two numbers. Flip the sign, same slay.

Definition at line 832 of file rte_common.h.

๐Ÿ’– RTE_MAX3( a, b, c)

Value:

__extension__ ({ \
    typeof (a) _a_max3 = (a); \
    typeof (b) _b_max3 = (b); \
    typeof (c) _c_max3 = (c); \
    _a_max3 > _b_max3 ? \
        (_a_max3 > _c_max3 ? _a_max3 : _c_max3) : \
        (_b_max3 > _c_max3 ? _b_max3 : _c_max3); \
})

Macro to return the maximum of three numbers. The big three. ๐ŸŒˆ

Definition at line 842 of file rte_common.h.

โญ RTE_MAX_T( a, b, t)

Value:

((t)(a) > (t)(b) ? (t)(a) : (t)(b))

Macro to return the maximum of two numbers, 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 deal as RTE_MIN_T. ๐Ÿค

Definition at line 859 of file rte_common.h.


๐ŸŽ€ Struct girlies

๐Ÿงš offsetof( TYPE, MEMBER)

Value:

__builtin_offsetof (TYPE, MEMBER)

Return the offset of a field in a structure. Classic, dependable, never misses.

Definition at line 866 of file rte_common.h.

๐Ÿ‘‘ container_of( ptr, type, member)

Value:

    __extension__ ({        \
    const typeof(((type *)0)->member) *_ptr = (ptr); \
    __rte_unused type *_target_ptr =    \
        (type *)(ptr);              \
    (type *)(((uintptr_t)_ptr) - offsetof(type, member)); \
})

Return pointer to the wrapping struct instance. Like, you have a pointer to a member field and you're like "okay but who's your parent?" This finds out. Iconic.

Example:

struct wrapper { ... struct child c; ... };

struct child *x = obtain(...); struct wrapper *w = container_of(x, struct wrapper, c);

Definition at line 888 of file rte_common.h.

๐Ÿฆ‹ RTE_SWAP( a, b)

Value:

__extension__ ({ \
    typeof (a) _a = a; \
    a = b; \
    b = _a; \
})

Swap two variables. The original "you take my snack, I take yours" maneuver. ๐Ÿ“

Definition at line 898 of file rte_common.h.

๐Ÿ“ RTE_SIZEOF_FIELD( type, field)

Value:

(sizeof(((type *)0)->field))

Get the size of a field in a structure. No actual dereference of that 0 pointer, don't worry โ€” sizeof is doing compile-time magic. โœจ

Parameters:

  • type โ€” the type of the structure.
  • field โ€” the field in the structure.

And that's where the original page cuts off on this one โ€” no definition line listed, so I'm not gonna invent one. ๐Ÿ’…

Returns โ€” the size of the field in the structure, in bytes. that's it, that's the whole vibe ๐Ÿ’–

Definition at line 915 of file rte_common.h.

  • #define RTE_STR( x) โ€” value: _RTE_STR(x). take a macro value and get a string version of it โœจ (yes it's literally just the one-liner you think it is, and that's why we love it)

Definition at line 919 of file rte_common.h.

  • #define RTE_FMT( fmt, ...) โ€” value:
fmt "%.0s", __VA_ARGS__ ""

ISO C helpers to modify format strings using variadic macros ๐Ÿ”ฅ this is the replacement for the ", ## __VA_ARGS__" GNU extension. an empty s argument gets appended so you don't end up with a dangling comma โ€” no cap, that's the whole trick

Definition at line 926 of file rte_common.h.

  • #define RTE_LEN2MASK( ln, tp) โ€” value:
((tp)((uint64_t)-1 >> (sizeof(uint64_t) * CHAR_BIT - (ln))))

mask value of type tp for the first ln bits set ๐ŸŽ€

Definition at line 931 of file rte_common.h.

  • #define RTE_DIM( a) โ€” value:
(sizeof (a) / sizeof ((a)[0]))

number of elements in the array ๐Ÿฆ‹ classic move, unmatched energy

Definition at line 935 of file rte_common.h.


โœจ Typedef Documentation โœจ

  • typedef uint64_t phys_addr_t โ€” physical address ๐Ÿ’…

Definition at line 764 of file rte_common.h.

  • typedef uint64_t rte_iova_t โ€” IO virtual address type. okay so this one has lore: 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 774 of file rte_common.h.


๐ŸŒธ Function Documentation ๐ŸŒธ

int rte_is_aligned (const void *const __rte_restrict ptr, const unsigned int align) โ€” inline, static

checks if a pointer is aligned to a given power-of-two value ๐Ÿ’ซ

Parameters

  • ptr โ€” the pointer whose alignment is to be checked
  • align โ€” the power-of-two value to which the ptr should be aligned

Returns โ€” true (1) where the pointer is correctly aligned, false (0) otherwise. bestie it's a yes-or-no situation and it will tell you ๐Ÿ˜Œ

Definition at line 698 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, it also recognises the suffixes k, m and g for kilobytes, megabytes and gigabytes respectively ๐Ÿ”ฅ

real talk though, the caveat: if a negative number is passed in โ€” i.e. a string with the first non-blank character being "-" โ€” zero is returned. zero is also returned in the case of an error with the strtoull call in the function. so like, zero can mean "zero" or "it went sideways", iykyk ๐Ÿ˜ญ

Parameters

  • str โ€” string containing number to convert.

Returns โ€” 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. ๐Ÿ‘€ consider yourself warned bestie

converts the uint64_t value provided to a human-readable string ๐Ÿ’– it null-terminates the string, truncating the data if needed. an optional unit (like "B") can be provided as a string โ€” it will be appended to the number, and a space will be inserted before the unit if needed.

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). pick your fighter โš”๏ธ
  • unit โ€” unit to append to the string (like "B" for bytes). can be NULL.

Returns โ€” buf on success, NULL if the buffer is too small. so like, size your buffer correctly or get nothing, no in-between ๐Ÿ™ˆ


__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. not "usually doesn't", not "might not" โ€” never. periodt.

Parameters

  • 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.

๐Ÿฆ‹ Variable Documentation ๐Ÿฆ‹

  • __extension__ typedef void* RTE_MARKER[0] โ€” generic marker for any place in a structure ๐Ÿซถ

Definition at line 782 of file rte_common.h.

  • __extension__ typedef uint8_t RTE_MARKER8[0] โ€” marker for 1B alignment in a structure โœจ

Definition at line 784 of file rte_common.h.

  • __extension__ typedef uint16_t RTE_MARKER16[0] โ€” marker for 2B alignment in a structure โœจ

Definition at line 786 of file rte_common.h.

  • __extension__ typedef uint32_t RTE_MARKER32[0] โ€” marker for 4B alignment in a structure โœจ

Definition at line 788 of file rte_common.h.

  • __extension__ typedef uint64_t RTE_MARKER64[0] โ€” marker for 8B alignment in a structure โœจ

Definition at line 790 of file rte_common.h.


๐Ÿ‘‘ Author ๐Ÿ‘‘

generated automatically by Doxygen for DPDK from the source code. not me writing an author bio, the robots did it ๐Ÿค–๐Ÿ’œ


that's the whole page bestie, you ate it UP ๐ŸŒˆโญ this was DPDK, Version 26.03.0, page rte_common.h(3) โ€” go forth and align your pointers ๐Ÿ’…๐ŸŽ€

๐Ÿ“ฆ where this page comes from