25 #include <rte_config.h> 31 #define typeof __typeof__ 39 #if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 201112L 40 #define RTE_STD_C11 __extension__ 51 #define RTE_CC_IS_GNU 0 54 #elif defined __INTEL_COMPILER 56 #elif defined __GNUC__ 59 #define RTE_CC_IS_GNU 1 62 #define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + \ 69 #define __rte_aligned(a) __attribute__((__aligned__(a))) 71 #ifdef RTE_ARCH_STRICT_ALIGN 76 typedef uint64_t unaligned_uint64_t;
77 typedef uint32_t unaligned_uint32_t;
78 typedef uint16_t unaligned_uint16_t;
84 #define __rte_packed __attribute__((__packed__)) 87 #define __rte_deprecated __attribute__((__deprecated__)) 88 #define __rte_deprecated_msg(msg) __attribute__((__deprecated__(msg))) 93 #if defined(RTE_CC_GCC) || defined(RTE_CC_CLANG) 94 #define RTE_PRAGMA(x) _Pragma(#x) 95 #define RTE_PRAGMA_WARNING(w) RTE_PRAGMA(GCC warning #w) 96 #define RTE_DEPRECATED(x) RTE_PRAGMA_WARNING(#x is deprecated) 98 #define RTE_DEPRECATED(x) 104 #define __rte_weak __attribute__((__weak__)) 109 #define __rte_used __attribute__((used)) 116 #define __rte_unused __attribute__((__unused__)) 121 #if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L 122 #define __rte_restrict __restrict 124 #define __rte_restrict restrict 131 #define RTE_SET_USED(x) (void)(x) 141 #define __rte_format_printf(format_index, first_arg) \ 142 __attribute__((format(gnu_printf, format_index, first_arg))) 144 #define __rte_format_printf(format_index, first_arg) \ 145 __attribute__((format(printf, format_index, first_arg))) 153 #if defined(RTE_CC_GCC) || defined(RTE_CC_CLANG) 154 #define __rte_alloc_size(...) \ 155 __attribute__((alloc_size(__VA_ARGS__))) 157 #define __rte_alloc_size(...) 160 #define RTE_PRIORITY_LOG 101 161 #define RTE_PRIORITY_BUS 110 162 #define RTE_PRIORITY_CLASS 120 163 #define RTE_PRIORITY_LAST 65535 165 #define RTE_PRIO(prio) \ 166 RTE_PRIORITY_ ## prio 177 #ifndef RTE_INIT_PRIO 178 #define RTE_INIT_PRIO(func, prio) \ 179 static void __attribute__((constructor(RTE_PRIO(prio)), used)) func(void) 190 #define RTE_INIT(func) \ 191 RTE_INIT_PRIO(func, LAST) 202 #ifndef RTE_FINI_PRIO 203 #define RTE_FINI_PRIO(func, prio) \ 204 static void __attribute__((destructor(RTE_PRIO(prio)), used)) func(void) 215 #define RTE_FINI(func) \ 216 RTE_FINI_PRIO(func, LAST) 221 #define __rte_noreturn __attribute__((noreturn)) 226 #define __rte_always_inline inline __attribute__((always_inline)) 231 #define __rte_noinline __attribute__((noinline)) 236 #define __rte_hot __attribute__((hot)) 241 #define __rte_cold __attribute__((cold)) 248 #define RTE_PTR_ADD(ptr, x) ((void*)((uintptr_t)(ptr) + (x))) 253 #define RTE_PTR_SUB(ptr, x) ((void*)((uintptr_t)ptr - (x))) 260 #define RTE_PTR_DIFF(ptr1, ptr2) ((uintptr_t)(ptr1) - (uintptr_t)(ptr2)) 265 #define RTE_CAST_FIELD(var, field, type) \ 266 (*(type *)((uintptr_t)(var) + offsetof(typeof(*(var)), field))) 277 #define RTE_PTR_ALIGN_FLOOR(ptr, align) \ 278 ((typeof(ptr))RTE_ALIGN_FLOOR((uintptr_t)ptr, align)) 286 #define RTE_ALIGN_FLOOR(val, align) \ 287 (typeof(val))((val) & (~((typeof(val))((align) - 1)))) 295 #define RTE_PTR_ALIGN_CEIL(ptr, align) \ 296 RTE_PTR_ALIGN_FLOOR((typeof(ptr))RTE_PTR_ADD(ptr, (align) - 1), align) 304 #define RTE_ALIGN_CEIL(val, align) \ 305 RTE_ALIGN_FLOOR(((val) + ((typeof(val)) (align) - 1)), align) 314 #define RTE_PTR_ALIGN(ptr, align) RTE_PTR_ALIGN_CEIL(ptr, align) 323 #define RTE_ALIGN(val, align) RTE_ALIGN_CEIL(val, align) 330 #define RTE_ALIGN_MUL_CEIL(v, mul) \ 331 ((((v) + (typeof(v))(mul) - 1) / ((typeof(v))(mul))) * (typeof(v))(mul)) 338 #define RTE_ALIGN_MUL_FLOOR(v, mul) \ 339 (((v) / ((typeof(v))(mul))) * (typeof(v))(mul)) 346 #define RTE_ALIGN_MUL_NEAR(v, mul) \ 348 typeof(v) ceil = RTE_ALIGN_MUL_CEIL(v, mul); \ 349 typeof(v) floor = RTE_ALIGN_MUL_FLOOR(v, mul); \ 350 (ceil - (v)) > ((v) - floor) ? floor : ceil; \ 375 #define RTE_BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)])) 380 #define RTE_CACHE_LINE_MASK (RTE_CACHE_LINE_SIZE-1) 383 #define RTE_CACHE_LINE_ROUNDUP(size) \ 384 (RTE_CACHE_LINE_SIZE * ((size + RTE_CACHE_LINE_SIZE - 1) / \ 385 RTE_CACHE_LINE_SIZE)) 388 #if RTE_CACHE_LINE_SIZE == 64 389 #define RTE_CACHE_LINE_SIZE_LOG2 6 390 #elif RTE_CACHE_LINE_SIZE == 128 391 #define RTE_CACHE_LINE_SIZE_LOG2 7 393 #error "Unsupported cache line size" 397 #define RTE_CACHE_LINE_MIN_SIZE 64 400 #define __rte_cache_aligned __rte_aligned(RTE_CACHE_LINE_SIZE) 403 #define __rte_cache_min_aligned __rte_aligned(RTE_CACHE_LINE_MIN_SIZE) 409 #define RTE_BAD_PHYS_ADDR ((phys_addr_t)-1) 419 #define RTE_BAD_IOVA ((rte_iova_t)-1) 444 static inline uint32_t
466 static inline uint64_t
484 #define RTE_IS_POWER_OF_2(n) ((n) && !(((n) - 1) & (n))) 495 return n && !(n & (n - 1));
507 static inline uint32_t
525 static inline uint32_t
542 static inline uint64_t
560 static inline uint64_t
573 #define RTE_MIN(a, b) \ 575 typeof (a) _a = (a); \ 576 typeof (b) _b = (b); \ 583 #define RTE_MAX(a, b) \ 585 typeof (a) _a = (a); \ 586 typeof (b) _b = (b); \ 603 static inline uint32_t
606 return (uint32_t)__builtin_ctz(v);
644 static inline uint32_t
668 return (x == 0) ? 0 : 32 - __builtin_clz(x);
685 return (uint32_t)__builtin_ctzll(v);
727 return (x == 0) ? 0 : 64 - __builtin_clzll(x);
741 static inline uint32_t
753 #define offsetof(TYPE, MEMBER) __builtin_offsetof (TYPE, MEMBER) 771 #define container_of(ptr, type, member) __extension__ ({ \ 772 const typeof(((type *)0)->member) *_ptr = (ptr); \ 773 __rte_unused type *_target_ptr = \ 775 (type *)(((uintptr_t)_ptr) - offsetof(type, member)); \ 789 #define RTE_SIZEOF_FIELD(type, field) (sizeof(((type *)0)->field)) 791 #define _RTE_STR(x) #x 793 #define RTE_STR(x) _RTE_STR(x) 800 #define RTE_FMT(fmt, ...) fmt "%.0s", __VA_ARGS__ "" 801 #define RTE_FMT_HEAD(fmt, ...) fmt 802 #define RTE_FMT_TAIL(fmt, ...) __VA_ARGS__ 805 #define RTE_LEN2MASK(ln, tp) \ 806 ((tp)((uint64_t)-1 >> (sizeof(uint64_t) * CHAR_BIT - (ln)))) 809 #define RTE_DIM(a) (sizeof (a) / sizeof ((a)[0])) 825 static inline uint64_t
829 unsigned long long size;
831 while (isspace((
int)*str))
837 size = strtoull(str, &endptr, 0);
845 case 'G':
case 'g': size *= 1024;
846 case 'M':
case 'm': size *= 1024;
847 case 'K':
case 'k': size *= 1024;
868 rte_exit(
int exit_code,
const char *format, ...)
static int rte_is_aligned(void *ptr, unsigned align)
static uint64_t rte_combine64ms1b(uint64_t v)
static int rte_bsf32_safe(uint64_t v, uint32_t *pos)
static int rte_fls_u32(uint32_t x)
static uint32_t rte_log2_u64(uint64_t v)
static uint32_t rte_combine32ms1b(uint32_t x)
static uint64_t rte_align64pow2(uint64_t v)
static uint32_t rte_log2_u32(uint32_t v)
__extension__ typedef uint8_t RTE_MARKER8[0]
__extension__ typedef void * RTE_MARKER[0]
static uint32_t rte_bsf32(uint32_t v)
static uint64_t rte_align64prevpow2(uint64_t v)
static uint32_t rte_align32pow2(uint32_t x)
static int rte_bsf64_safe(uint64_t v, uint32_t *pos)
__extension__ typedef uint64_t RTE_MARKER64[0]
#define __rte_format_printf(format_index, first_arg)
static int rte_fls_u64(uint64_t x)
#define RTE_PTR_ALIGN(ptr, align)
static int rte_is_power_of_2(uint32_t n)
__extension__ typedef uint16_t RTE_MARKER16[0]
static int rte_bsf64(uint64_t v)
__extension__ typedef uint32_t RTE_MARKER32[0]
static uint32_t rte_align32prevpow2(uint32_t x)
static uint64_t rte_str_to_size(const char *str)
__rte_noreturn void rte_exit(int exit_code, const char *format,...) __rte_format_printf(2