22 #include <rte_config.h> 27 #ifndef RTE_TOOLCHAIN_MSVC 29 #define typeof __typeof__ 39 #ifdef RTE_TOOLCHAIN_MSVC 49 #define RTE_CC_IS_GNU 0 52 #elif defined __INTEL_COMPILER 54 #elif defined __GNUC__ 57 #define RTE_CC_IS_GNU 1 60 #define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + \ 67 #ifdef RTE_TOOLCHAIN_MSVC 68 #define __rte_aligned(a) 70 #define __rte_aligned(a) __attribute__((__aligned__(a))) 73 #ifdef RTE_ARCH_STRICT_ALIGN 78 typedef uint64_t unaligned_uint64_t;
79 typedef uint32_t unaligned_uint32_t;
80 typedef uint16_t unaligned_uint16_t;
86 #ifdef RTE_TOOLCHAIN_MSVC 89 #define __rte_packed __attribute__((__packed__)) 95 #ifdef RTE_TOOLCHAIN_MSVC 96 #define __rte_may_alias 98 #define __rte_may_alias __attribute__((__may_alias__)) 102 #ifdef RTE_TOOLCHAIN_MSVC 103 #define __rte_deprecated 104 #define __rte_deprecated_msg(msg) 106 #define __rte_deprecated __attribute__((__deprecated__)) 107 #define __rte_deprecated_msg(msg) __attribute__((__deprecated__(msg))) 113 #if defined(RTE_CC_GCC) || defined(RTE_CC_CLANG) 114 #define RTE_PRAGMA(x) _Pragma(#x) 115 #define RTE_PRAGMA_WARNING(w) RTE_PRAGMA(GCC warning #w) 116 #define RTE_DEPRECATED(x) RTE_PRAGMA_WARNING(#x is deprecated) 118 #define RTE_DEPRECATED(x) 124 #define __rte_weak __attribute__((__weak__)) 129 #ifdef RTE_TOOLCHAIN_MSVC 132 #define __rte_used __attribute__((used)) 140 #ifdef RTE_TOOLCHAIN_MSVC 143 #define __rte_unused __attribute__((__unused__)) 149 #if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L 150 #define __rte_restrict __restrict 152 #define __rte_restrict restrict 159 #define RTE_SET_USED(x) (void)(x) 168 #ifdef RTE_TOOLCHAIN_MSVC 169 #define __rte_format_printf(format_index, first_arg) 172 #define __rte_format_printf(format_index, first_arg) \ 173 __attribute__((format(gnu_printf, format_index, first_arg))) 175 #define __rte_format_printf(format_index, first_arg) \ 176 __attribute__((format(printf, format_index, first_arg))) 185 #if defined(RTE_CC_GCC) || defined(RTE_CC_CLANG) 186 #define __rte_alloc_size(...) \ 187 __attribute__((alloc_size(__VA_ARGS__))) 189 #define __rte_alloc_size(...) 192 #define RTE_PRIORITY_LOG 101 193 #define RTE_PRIORITY_BUS 110 194 #define RTE_PRIORITY_CLASS 120 195 #define RTE_PRIORITY_LAST 65535 197 #define RTE_PRIO(prio) \ 198 RTE_PRIORITY_ ## prio 209 #ifndef RTE_INIT_PRIO 210 #ifndef RTE_TOOLCHAIN_MSVC 211 #if defined(__x86_64__) || defined(__i386__) 212 #define RTE_INIT_PRIO(func, prio) \ 214 __attribute__((constructor(RTE_PRIO(prio)), used)) \ 215 __attribute__((target ("sse2"))) \ 216 __attribute__((target ("no-sse3"))) \ 217 __attribute__((target ("no-sse4"))) \ 220 #define RTE_INIT_PRIO(func, prio) \ 222 __attribute__((constructor(RTE_PRIO(prio)), used)) \ 227 typedef int(__cdecl *_PIFV)(void);
229 #define CTOR_SECTION_LOG ".CRT$XIB" 230 #define CTOR_SECTION_BUS ".CRT$XIC" 231 #define CTOR_SECTION_CLASS ".CRT$XID" 232 #define CTOR_SECTION_LAST ".CRT$XIY" 234 #define CTOR_PRIORITY_TO_SECTION(priority) CTOR_SECTION_ ## priority 236 #define RTE_INIT_PRIO(name, priority) \ 237 static void name(void); \ 238 static int __cdecl name ## _thunk(void) { name(); return 0; } \ 239 __pragma(const_seg(CTOR_PRIORITY_TO_SECTION(priority))) \ 240 __declspec(allocate(CTOR_PRIORITY_TO_SECTION(priority))) \ 241 _PIFV name ## _pointer = &name ## _thunk; \ 242 __pragma(const_seg()) \ 243 static void name(void) 255 #define RTE_INIT(func) \ 256 RTE_INIT_PRIO(func, LAST) 267 #ifndef RTE_FINI_PRIO 268 #ifndef RTE_TOOLCHAIN_MSVC 269 #define RTE_FINI_PRIO(func, prio) \ 270 static void __attribute__((destructor(RTE_PRIO(prio)), used)) func(void) 272 #define DTOR_SECTION_LOG "mydtor$B" 273 #define DTOR_SECTION_BUS "mydtor$C" 274 #define DTOR_SECTION_CLASS "mydtor$D" 275 #define DTOR_SECTION_LAST "mydtor$Y" 277 #define DTOR_PRIORITY_TO_SECTION(priority) DTOR_SECTION_ ## priority 279 #define RTE_FINI_PRIO(name, priority) \ 280 static void name(void); \ 281 __pragma(const_seg(DTOR_PRIORITY_TO_SECTION(priority))) \ 282 __declspec(allocate(DTOR_PRIORITY_TO_SECTION(priority))) name ## _pointer = &name; \ 283 __pragma(const_seg()) \ 284 static void name(void) 296 #define RTE_FINI(func) \ 297 RTE_FINI_PRIO(func, LAST) 302 #ifdef RTE_TOOLCHAIN_MSVC 303 #define __rte_noreturn 305 #define __rte_noreturn __attribute__((noreturn)) 331 #ifdef RTE_TOOLCHAIN_MSVC 332 #define __rte_warn_unused_result 334 #define __rte_warn_unused_result __attribute__((warn_unused_result)) 340 #ifdef RTE_TOOLCHAIN_MSVC 341 #define __rte_always_inline 343 #define __rte_always_inline inline __attribute__((always_inline)) 349 #define __rte_noinline __attribute__((noinline)) 354 #define __rte_hot __attribute__((hot)) 359 #ifdef RTE_TOOLCHAIN_MSVC 362 #define __rte_cold __attribute__((cold)) 368 #ifdef RTE_MALLOC_ASAN 370 #define __rte_no_asan __attribute__((no_sanitize("address", "hwaddress"))) 372 #define __rte_no_asan __attribute__((no_sanitize_address)) 375 #define __rte_no_asan 383 #define RTE_PTR_ADD(ptr, x) ((void*)((uintptr_t)(ptr) + (x))) 388 #define RTE_PTR_SUB(ptr, x) ((void *)((uintptr_t)(ptr) - (x))) 395 #define RTE_PTR_DIFF(ptr1, ptr2) ((uintptr_t)(ptr1) - (uintptr_t)(ptr2)) 400 #define RTE_CAST_FIELD(var, field, type) \ 401 (*(type *)((uintptr_t)(var) + offsetof(typeof(*(var)), field))) 412 #define RTE_PTR_ALIGN_FLOOR(ptr, align) \ 413 ((typeof(ptr))RTE_ALIGN_FLOOR((uintptr_t)(ptr), align)) 421 #define RTE_ALIGN_FLOOR(val, align) \ 422 (typeof(val))((val) & (~((typeof(val))((align) - 1)))) 430 #define RTE_PTR_ALIGN_CEIL(ptr, align) \ 431 RTE_PTR_ALIGN_FLOOR((typeof(ptr))RTE_PTR_ADD(ptr, (align) - 1), align) 439 #define RTE_ALIGN_CEIL(val, align) \ 440 RTE_ALIGN_FLOOR(((val) + ((typeof(val)) (align) - 1)), align) 449 #define RTE_PTR_ALIGN(ptr, align) RTE_PTR_ALIGN_CEIL(ptr, align) 458 #define RTE_ALIGN(val, align) RTE_ALIGN_CEIL(val, align) 465 #define RTE_ALIGN_MUL_CEIL(v, mul) \ 466 ((((v) + (typeof(v))(mul) - 1) / ((typeof(v))(mul))) * (typeof(v))(mul)) 473 #define RTE_ALIGN_MUL_FLOOR(v, mul) \ 474 (((v) / ((typeof(v))(mul))) * (typeof(v))(mul)) 481 #define RTE_ALIGN_MUL_NEAR(v, mul) \ 483 typeof(v) ceil = RTE_ALIGN_MUL_CEIL(v, mul); \ 484 typeof(v) floor = RTE_ALIGN_MUL_FLOOR(v, mul); \ 485 (ceil - (v)) > ((v) - floor) ? floor : ceil; \ 502 return ((uintptr_t)ptr & (align - 1)) == 0;
510 #define RTE_BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)])) 515 #define RTE_CACHE_LINE_MASK (RTE_CACHE_LINE_SIZE-1) 518 #define RTE_CACHE_LINE_ROUNDUP(size) RTE_ALIGN_CEIL(size, RTE_CACHE_LINE_SIZE) 521 #if RTE_CACHE_LINE_SIZE == 64 522 #define RTE_CACHE_LINE_SIZE_LOG2 6 523 #elif RTE_CACHE_LINE_SIZE == 128 524 #define RTE_CACHE_LINE_SIZE_LOG2 7 526 #error "Unsupported cache line size" 530 #define RTE_CACHE_LINE_MIN_SIZE 64 533 #ifdef RTE_TOOLCHAIN_MSVC 534 #define __rte_cache_aligned 536 #define __rte_cache_aligned __rte_aligned(RTE_CACHE_LINE_SIZE) 540 #define __rte_cache_min_aligned __rte_aligned(RTE_CACHE_LINE_MIN_SIZE) 542 #define _RTE_CACHE_GUARD_HELPER2(unique) \ 543 char cache_guard_ ## unique[RTE_CACHE_LINE_SIZE * RTE_CACHE_GUARD_LINES] \ 545 #define _RTE_CACHE_GUARD_HELPER1(unique) _RTE_CACHE_GUARD_HELPER2(unique) 553 #define RTE_CACHE_GUARD _RTE_CACHE_GUARD_HELPER1(__COUNTER__) 559 #define RTE_BAD_PHYS_ADDR ((phys_addr_t)-1) 569 #define RTE_BAD_IOVA ((rte_iova_t)-1) 573 #ifndef RTE_TOOLCHAIN_MSVC 593 #define RTE_MIN(a, b) \ 595 typeof (a) _a = (a); \ 596 typeof (b) _b = (b); \ 603 #define RTE_MAX(a, b) \ 605 typeof (a) _a = (a); \ 606 typeof (b) _b = (b); \ 614 #define offsetof(TYPE, MEMBER) __builtin_offsetof (TYPE, MEMBER) 632 #ifdef RTE_TOOLCHAIN_MSVC 633 #define container_of(ptr, type, member) \ 634 ((type *)((uintptr_t)(ptr) - offsetof(type, member))) 636 #define container_of(ptr, type, member) __extension__ ({ \ 637 const typeof(((type *)0)->member) *_ptr = (ptr); \ 638 __rte_unused type *_target_ptr = \ 640 (type *)(((uintptr_t)_ptr) - offsetof(type, member)); \ 646 #define RTE_SWAP(a, b) \ 663 #define RTE_SIZEOF_FIELD(type, field) (sizeof(((type *)0)->field)) 665 #define _RTE_STR(x) #x 667 #define RTE_STR(x) _RTE_STR(x) 674 #define RTE_FMT(fmt, ...) fmt "%.0s", __VA_ARGS__ "" 675 #define RTE_FMT_HEAD(fmt, ...) fmt 676 #define RTE_FMT_TAIL(fmt, ...) __VA_ARGS__ 679 #define RTE_LEN2MASK(ln, tp) \ 680 ((tp)((uint64_t)-1 >> (sizeof(uint64_t) * CHAR_BIT - (ln)))) 683 #define RTE_DIM(a) (sizeof (a) / sizeof ((a)[0])) 716 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)