24 #include <rte_config.h> 29 #ifndef RTE_TOOLCHAIN_MSVC 31 #define typeof __typeof__ 41 #ifdef RTE_TOOLCHAIN_MSVC 53 #define RTE_CC_IS_GNU 0 56 #elif defined __INTEL_COMPILER 58 #elif defined __GNUC__ 61 #define RTE_CC_IS_GNU 1 64 #define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + \ 80 #ifdef RTE_TOOLCHAIN_MSVC 81 #define __rte_aligned(a) __declspec(align(a)) 83 #define __rte_aligned(a) __attribute__((__aligned__(a))) 86 #ifdef RTE_ARCH_STRICT_ALIGN 91 typedef uint64_t unaligned_uint64_t;
92 typedef uint32_t unaligned_uint32_t;
93 typedef uint16_t unaligned_uint16_t;
99 #ifdef RTE_TOOLCHAIN_MSVC 102 #define __rte_packed __attribute__((__packed__)) 108 #ifdef RTE_TOOLCHAIN_MSVC 109 #define __rte_may_alias 111 #define __rte_may_alias __attribute__((__may_alias__)) 115 #ifdef RTE_TOOLCHAIN_MSVC 116 #define __rte_deprecated 117 #define __rte_deprecated_msg(msg) 119 #define __rte_deprecated __attribute__((__deprecated__)) 120 #define __rte_deprecated_msg(msg) __attribute__((__deprecated__(msg))) 126 #if defined(RTE_CC_GCC) || defined(RTE_CC_CLANG) 127 #define RTE_PRAGMA(x) _Pragma(#x) 128 #define RTE_PRAGMA_WARNING(w) RTE_PRAGMA(GCC warning #w) 129 #define RTE_DEPRECATED(x) RTE_PRAGMA_WARNING(#x is deprecated) 131 #define RTE_DEPRECATED(x) 137 #define __rte_weak __attribute__((__weak__)) 142 #ifdef RTE_TOOLCHAIN_MSVC 145 #define __rte_used __attribute__((used)) 153 #ifdef RTE_TOOLCHAIN_MSVC 156 #define __rte_unused __attribute__((__unused__)) 162 #if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L 163 #define __rte_restrict __restrict 165 #define __rte_restrict restrict 172 #define RTE_SET_USED(x) (void)(x) 181 #ifdef RTE_TOOLCHAIN_MSVC 182 #define __rte_format_printf(format_index, first_arg) 185 #define __rte_format_printf(format_index, first_arg) \ 186 __attribute__((format(gnu_printf, format_index, first_arg))) 188 #define __rte_format_printf(format_index, first_arg) \ 189 __attribute__((format(printf, format_index, first_arg))) 196 #ifdef RTE_TOOLCHAIN_MSVC 197 #define __rte_section(name) \ 198 __pragma(data_seg(name)) __declspec(allocate(name)) 200 #define __rte_section(name) \ 201 __attribute__((section(name))) 209 #if defined(RTE_CC_GCC) || defined(RTE_CC_CLANG) 210 #define __rte_alloc_size(...) \ 211 __attribute__((alloc_size(__VA_ARGS__))) 213 #define __rte_alloc_size(...) 216 #define RTE_PRIORITY_LOG 101 217 #define RTE_PRIORITY_BUS 110 218 #define RTE_PRIORITY_CLASS 120 219 #define RTE_PRIORITY_LAST 65535 221 #define RTE_PRIO(prio) \ 222 RTE_PRIORITY_ ## prio 233 #ifndef RTE_INIT_PRIO 234 #ifndef RTE_TOOLCHAIN_MSVC 235 #define RTE_INIT_PRIO(func, prio) \ 236 static void __attribute__((constructor(RTE_PRIO(prio)), used)) func(void) 239 typedef int(__cdecl *_PIFV)(void);
241 #define CTOR_SECTION_LOG ".CRT$XIB" 242 #define CTOR_SECTION_BUS ".CRT$XIC" 243 #define CTOR_SECTION_CLASS ".CRT$XID" 244 #define CTOR_SECTION_LAST ".CRT$XIY" 246 #define CTOR_PRIORITY_TO_SECTION(priority) CTOR_SECTION_ ## priority 248 #define RTE_INIT_PRIO(name, priority) \ 249 static void name(void); \ 250 static int __cdecl name ## _thunk(void) { name(); return 0; } \ 251 __pragma(const_seg(CTOR_PRIORITY_TO_SECTION(priority))) \ 252 __declspec(allocate(CTOR_PRIORITY_TO_SECTION(priority))) \ 253 _PIFV name ## _pointer = &name ## _thunk; \ 254 __pragma(const_seg()) \ 255 static void name(void) 267 #define RTE_INIT(func) \ 268 RTE_INIT_PRIO(func, LAST) 279 #ifndef RTE_FINI_PRIO 280 #ifndef RTE_TOOLCHAIN_MSVC 281 #define RTE_FINI_PRIO(func, prio) \ 282 static void __attribute__((destructor(RTE_PRIO(prio)), used)) func(void) 284 #define DTOR_SECTION_LOG "mydtor$B" 285 #define DTOR_SECTION_BUS "mydtor$C" 286 #define DTOR_SECTION_CLASS "mydtor$D" 287 #define DTOR_SECTION_LAST "mydtor$Y" 289 #define DTOR_PRIORITY_TO_SECTION(priority) DTOR_SECTION_ ## priority 291 #define RTE_FINI_PRIO(name, priority) \ 292 static void name(void); \ 293 __pragma(const_seg(DTOR_PRIORITY_TO_SECTION(priority))) \ 294 __declspec(allocate(DTOR_PRIORITY_TO_SECTION(priority))) name ## _pointer = &name; \ 295 __pragma(const_seg()) \ 296 static void name(void) 308 #define RTE_FINI(func) \ 309 RTE_FINI_PRIO(func, LAST) 314 #ifdef RTE_TOOLCHAIN_MSVC 315 #define __rte_noreturn 317 #define __rte_noreturn __attribute__((noreturn)) 343 #ifdef RTE_TOOLCHAIN_MSVC 344 #define __rte_warn_unused_result 346 #define __rte_warn_unused_result __attribute__((warn_unused_result)) 352 #ifdef RTE_TOOLCHAIN_MSVC 353 #define __rte_always_inline 355 #define __rte_always_inline inline __attribute__((always_inline)) 361 #define __rte_noinline __attribute__((noinline)) 366 #define __rte_hot __attribute__((hot)) 371 #ifdef RTE_TOOLCHAIN_MSVC 374 #define __rte_cold __attribute__((cold)) 380 #ifdef RTE_MALLOC_ASAN 382 #define __rte_no_asan __attribute__((no_sanitize("address", "hwaddress"))) 384 #define __rte_no_asan __attribute__((no_sanitize_address)) 387 #define __rte_no_asan 395 #define RTE_PTR_ADD(ptr, x) ((void*)((uintptr_t)(ptr) + (x))) 400 #define RTE_PTR_SUB(ptr, x) ((void *)((uintptr_t)(ptr) - (x))) 407 #define RTE_PTR_DIFF(ptr1, ptr2) ((uintptr_t)(ptr1) - (uintptr_t)(ptr2)) 412 #define RTE_CAST_FIELD(var, field, type) \ 413 (*(type *)((uintptr_t)(var) + offsetof(typeof(*(var)), field))) 424 #define RTE_PTR_ALIGN_FLOOR(ptr, align) \ 425 ((typeof(ptr))RTE_ALIGN_FLOOR((uintptr_t)(ptr), align)) 433 #define RTE_ALIGN_FLOOR(val, align) \ 434 (typeof(val))((val) & (~((typeof(val))((align) - 1)))) 442 #define RTE_PTR_ALIGN_CEIL(ptr, align) \ 443 RTE_PTR_ALIGN_FLOOR((typeof(ptr))RTE_PTR_ADD(ptr, (align) - 1), align) 451 #define RTE_ALIGN_CEIL(val, align) \ 452 RTE_ALIGN_FLOOR(((val) + ((typeof(val)) (align) - 1)), align) 461 #define RTE_PTR_ALIGN(ptr, align) RTE_PTR_ALIGN_CEIL(ptr, align) 470 #define RTE_ALIGN(val, align) RTE_ALIGN_CEIL(val, align) 477 #define RTE_ALIGN_MUL_CEIL(v, mul) \ 478 ((((v) + (typeof(v))(mul) - 1) / ((typeof(v))(mul))) * (typeof(v))(mul)) 485 #define RTE_ALIGN_MUL_FLOOR(v, mul) \ 486 (((v) / ((typeof(v))(mul))) * (typeof(v))(mul)) 493 #define RTE_ALIGN_MUL_NEAR(v, mul) \ 495 typeof(v) ceil = RTE_ALIGN_MUL_CEIL(v, mul); \ 496 typeof(v) floor = RTE_ALIGN_MUL_FLOOR(v, mul); \ 497 (ceil - (v)) > ((v) - floor) ? floor : ceil; \ 514 return ((uintptr_t)ptr & (align - 1)) == 0;
520 #if !defined(static_assert) && !defined(__cplusplus) 521 #define static_assert _Static_assert 530 #define RTE_BUILD_BUG_ON(condition) do { static_assert(!(condition), #condition); } while (0) 535 #define RTE_CACHE_LINE_MASK (RTE_CACHE_LINE_SIZE-1) 538 #define RTE_CACHE_LINE_ROUNDUP(size) RTE_ALIGN_CEIL(size, RTE_CACHE_LINE_SIZE) 541 #if RTE_CACHE_LINE_SIZE == 64 542 #define RTE_CACHE_LINE_SIZE_LOG2 6 543 #elif RTE_CACHE_LINE_SIZE == 128 544 #define RTE_CACHE_LINE_SIZE_LOG2 7 546 #error "Unsupported cache line size" 550 #define RTE_CACHE_LINE_MIN_SIZE 64 553 #define __rte_cache_aligned __rte_aligned(RTE_CACHE_LINE_SIZE) 556 #define __rte_cache_min_aligned __rte_aligned(RTE_CACHE_LINE_MIN_SIZE) 558 #define _RTE_CACHE_GUARD_HELPER2(unique) \ 559 alignas(RTE_CACHE_LINE_SIZE) \ 560 char cache_guard_ ## unique[RTE_CACHE_LINE_SIZE * RTE_CACHE_GUARD_LINES] 561 #define _RTE_CACHE_GUARD_HELPER1(unique) _RTE_CACHE_GUARD_HELPER2(unique) 569 #define RTE_CACHE_GUARD _RTE_CACHE_GUARD_HELPER1(__COUNTER__) 575 #define RTE_BAD_PHYS_ADDR ((phys_addr_t)-1) 585 #define RTE_BAD_IOVA ((rte_iova_t)-1) 589 #ifndef RTE_TOOLCHAIN_MSVC 609 #define RTE_MIN(a, b) \ 611 typeof (a) _a = (a); \ 612 typeof (b) _b = (b); \ 623 #define RTE_MIN_T(a, b, t) \ 624 ((t)(a) < (t)(b) ? (t)(a) : (t)(b)) 629 #define RTE_MAX(a, b) \ 631 typeof (a) _a = (a); \ 632 typeof (b) _b = (b); \ 643 #define RTE_MAX_T(a, b, t) \ 644 ((t)(a) > (t)(b) ? (t)(a) : (t)(b)) 650 #define offsetof(TYPE, MEMBER) __builtin_offsetof (TYPE, MEMBER) 668 #ifdef RTE_TOOLCHAIN_MSVC 669 #define container_of(ptr, type, member) \ 670 ((type *)((uintptr_t)(ptr) - offsetof(type, member))) 672 #define container_of(ptr, type, member) __extension__ ({ \ 673 const typeof(((type *)0)->member) *_ptr = (ptr); \ 674 __rte_unused type *_target_ptr = \ 676 (type *)(((uintptr_t)_ptr) - offsetof(type, member)); \ 682 #define RTE_SWAP(a, b) \ 699 #define RTE_SIZEOF_FIELD(type, field) (sizeof(((type *)0)->field)) 701 #define _RTE_STR(x) #x 703 #define RTE_STR(x) _RTE_STR(x) 710 #define RTE_FMT(fmt, ...) fmt "%.0s", __VA_ARGS__ "" 711 #define RTE_FMT_HEAD(fmt, ...) fmt 712 #define RTE_FMT_TAIL(fmt, ...) __VA_ARGS__ 715 #define RTE_LEN2MASK(ln, tp) \ 716 ((tp)((uint64_t)-1 >> (sizeof(uint64_t) * CHAR_BIT - (ln)))) 719 #define RTE_DIM(a) (sizeof (a) / sizeof ((a)[0])) 752 rte_exit(
int exit_code,
const char *format, ...)
__extension__ typedef uint8_t RTE_MARKER8[0]
__extension__ typedef void * RTE_MARKER[0]
__extension__ typedef uint64_t RTE_MARKER64[0]
uint64_t rte_str_to_size(const char *str)
#define __rte_format_printf(format_index, first_arg)
__extension__ typedef uint16_t RTE_MARKER16[0]
__extension__ typedef uint32_t RTE_MARKER32[0]
__rte_noreturn void rte_exit(int exit_code, const char *format,...) __rte_format_printf(2
static int rte_is_aligned(const void *const __rte_restrict ptr, const unsigned int align)