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 #define RTE_INIT_PRIO(func, prio) \ 212 static void __attribute__((constructor(RTE_PRIO(prio)), used)) func(void) 215 typedef int(__cdecl *_PIFV)(void);
217 #define CTOR_SECTION_LOG ".CRT$XIB" 218 #define CTOR_SECTION_BUS ".CRT$XIC" 219 #define CTOR_SECTION_CLASS ".CRT$XID" 220 #define CTOR_SECTION_LAST ".CRT$XIY" 222 #define CTOR_PRIORITY_TO_SECTION(priority) CTOR_SECTION_ ## priority 224 #define RTE_INIT_PRIO(name, priority) \ 225 static void name(void); \ 226 static int __cdecl name ## _thunk(void) { name(); return 0; } \ 227 __pragma(const_seg(CTOR_PRIORITY_TO_SECTION(priority))) \ 228 __declspec(allocate(CTOR_PRIORITY_TO_SECTION(priority))) \ 229 _PIFV name ## _pointer = &name ## _thunk; \ 230 __pragma(const_seg()) \ 231 static void name(void) 243 #define RTE_INIT(func) \ 244 RTE_INIT_PRIO(func, LAST) 255 #ifndef RTE_FINI_PRIO 256 #ifndef RTE_TOOLCHAIN_MSVC 257 #define RTE_FINI_PRIO(func, prio) \ 258 static void __attribute__((destructor(RTE_PRIO(prio)), used)) func(void) 260 #define DTOR_SECTION_LOG "mydtor$B" 261 #define DTOR_SECTION_BUS "mydtor$C" 262 #define DTOR_SECTION_CLASS "mydtor$D" 263 #define DTOR_SECTION_LAST "mydtor$Y" 265 #define DTOR_PRIORITY_TO_SECTION(priority) DTOR_SECTION_ ## priority 267 #define RTE_FINI_PRIO(name, priority) \ 268 static void name(void); \ 269 __pragma(const_seg(DTOR_PRIORITY_TO_SECTION(priority))) \ 270 __declspec(allocate(DTOR_PRIORITY_TO_SECTION(priority))) name ## _pointer = &name; \ 271 __pragma(const_seg()) \ 272 static void name(void) 284 #define RTE_FINI(func) \ 285 RTE_FINI_PRIO(func, LAST) 290 #ifdef RTE_TOOLCHAIN_MSVC 291 #define __rte_noreturn 293 #define __rte_noreturn __attribute__((noreturn)) 319 #ifdef RTE_TOOLCHAIN_MSVC 320 #define __rte_warn_unused_result 322 #define __rte_warn_unused_result __attribute__((warn_unused_result)) 328 #ifdef RTE_TOOLCHAIN_MSVC 329 #define __rte_always_inline 331 #define __rte_always_inline inline __attribute__((always_inline)) 337 #define __rte_noinline __attribute__((noinline)) 342 #define __rte_hot __attribute__((hot)) 347 #ifdef RTE_TOOLCHAIN_MSVC 350 #define __rte_cold __attribute__((cold)) 356 #ifdef RTE_MALLOC_ASAN 358 #define __rte_no_asan __attribute__((no_sanitize("address", "hwaddress"))) 360 #define __rte_no_asan __attribute__((no_sanitize_address)) 363 #define __rte_no_asan 371 #define RTE_PTR_ADD(ptr, x) ((void*)((uintptr_t)(ptr) + (x))) 376 #define RTE_PTR_SUB(ptr, x) ((void *)((uintptr_t)(ptr) - (x))) 383 #define RTE_PTR_DIFF(ptr1, ptr2) ((uintptr_t)(ptr1) - (uintptr_t)(ptr2)) 388 #define RTE_CAST_FIELD(var, field, type) \ 389 (*(type *)((uintptr_t)(var) + offsetof(typeof(*(var)), field))) 400 #define RTE_PTR_ALIGN_FLOOR(ptr, align) \ 401 ((typeof(ptr))RTE_ALIGN_FLOOR((uintptr_t)(ptr), align)) 409 #define RTE_ALIGN_FLOOR(val, align) \ 410 (typeof(val))((val) & (~((typeof(val))((align) - 1)))) 418 #define RTE_PTR_ALIGN_CEIL(ptr, align) \ 419 RTE_PTR_ALIGN_FLOOR((typeof(ptr))RTE_PTR_ADD(ptr, (align) - 1), align) 427 #define RTE_ALIGN_CEIL(val, align) \ 428 RTE_ALIGN_FLOOR(((val) + ((typeof(val)) (align) - 1)), align) 437 #define RTE_PTR_ALIGN(ptr, align) RTE_PTR_ALIGN_CEIL(ptr, align) 446 #define RTE_ALIGN(val, align) RTE_ALIGN_CEIL(val, align) 453 #define RTE_ALIGN_MUL_CEIL(v, mul) \ 454 ((((v) + (typeof(v))(mul) - 1) / ((typeof(v))(mul))) * (typeof(v))(mul)) 461 #define RTE_ALIGN_MUL_FLOOR(v, mul) \ 462 (((v) / ((typeof(v))(mul))) * (typeof(v))(mul)) 469 #define RTE_ALIGN_MUL_NEAR(v, mul) \ 471 typeof(v) ceil = RTE_ALIGN_MUL_CEIL(v, mul); \ 472 typeof(v) floor = RTE_ALIGN_MUL_FLOOR(v, mul); \ 473 (ceil - (v)) > ((v) - floor) ? floor : ceil; \ 490 return ((uintptr_t)ptr & (align - 1)) == 0;
498 #define RTE_BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)])) 503 #define RTE_CACHE_LINE_MASK (RTE_CACHE_LINE_SIZE-1) 506 #define RTE_CACHE_LINE_ROUNDUP(size) RTE_ALIGN_CEIL(size, RTE_CACHE_LINE_SIZE) 509 #if RTE_CACHE_LINE_SIZE == 64 510 #define RTE_CACHE_LINE_SIZE_LOG2 6 511 #elif RTE_CACHE_LINE_SIZE == 128 512 #define RTE_CACHE_LINE_SIZE_LOG2 7 514 #error "Unsupported cache line size" 518 #define RTE_CACHE_LINE_MIN_SIZE 64 521 #ifdef RTE_TOOLCHAIN_MSVC 522 #define __rte_cache_aligned 524 #define __rte_cache_aligned __rte_aligned(RTE_CACHE_LINE_SIZE) 528 #define __rte_cache_min_aligned __rte_aligned(RTE_CACHE_LINE_MIN_SIZE) 530 #define _RTE_CACHE_GUARD_HELPER2(unique) \ 531 char cache_guard_ ## unique[RTE_CACHE_LINE_SIZE * RTE_CACHE_GUARD_LINES] \ 533 #define _RTE_CACHE_GUARD_HELPER1(unique) _RTE_CACHE_GUARD_HELPER2(unique) 541 #define RTE_CACHE_GUARD _RTE_CACHE_GUARD_HELPER1(__COUNTER__) 547 #define RTE_BAD_PHYS_ADDR ((phys_addr_t)-1) 557 #define RTE_BAD_IOVA ((rte_iova_t)-1) 561 #ifndef RTE_TOOLCHAIN_MSVC 581 #define RTE_MIN(a, b) \ 583 typeof (a) _a = (a); \ 584 typeof (b) _b = (b); \ 591 #define RTE_MAX(a, b) \ 593 typeof (a) _a = (a); \ 594 typeof (b) _b = (b); \ 602 #define offsetof(TYPE, MEMBER) __builtin_offsetof (TYPE, MEMBER) 620 #ifdef RTE_TOOLCHAIN_MSVC 621 #define container_of(ptr, type, member) \ 622 ((type *)((uintptr_t)(ptr) - offsetof(type, member))) 624 #define container_of(ptr, type, member) __extension__ ({ \ 625 const typeof(((type *)0)->member) *_ptr = (ptr); \ 626 __rte_unused type *_target_ptr = \ 628 (type *)(((uintptr_t)_ptr) - offsetof(type, member)); \ 634 #define RTE_SWAP(a, b) \ 651 #define RTE_SIZEOF_FIELD(type, field) (sizeof(((type *)0)->field)) 653 #define _RTE_STR(x) #x 655 #define RTE_STR(x) _RTE_STR(x) 662 #define RTE_FMT(fmt, ...) fmt "%.0s", __VA_ARGS__ "" 663 #define RTE_FMT_HEAD(fmt, ...) fmt 664 #define RTE_FMT_TAIL(fmt, ...) __VA_ARGS__ 667 #define RTE_LEN2MASK(ln, tp) \ 668 ((tp)((uint64_t)-1 >> (sizeof(uint64_t) * CHAR_BIT - (ln)))) 671 #define RTE_DIM(a) (sizeof (a) / sizeof ((a)[0])) 704 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)