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 + \ 66 #ifdef RTE_ARCH_STRICT_ALIGN 71 typedef uint64_t unaligned_uint64_t;
72 typedef uint32_t unaligned_uint32_t;
73 typedef uint16_t unaligned_uint16_t;
79 #define __rte_aligned(a) __attribute__((__aligned__(a))) 84 #define __rte_packed __attribute__((__packed__)) 87 #define __rte_deprecated __attribute__((__deprecated__)) 92 #define __rte_weak __attribute__((__weak__)) 97 #define __rte_used __attribute__((used)) 104 #define __rte_unused __attribute__((__unused__)) 110 #define RTE_SET_USED(x) (void)(x) 112 #define RTE_PRIORITY_LOG 101 113 #define RTE_PRIORITY_BUS 110 114 #define RTE_PRIORITY_CLASS 120 115 #define RTE_PRIORITY_LAST 65535 117 #define RTE_PRIO(prio) \ 118 RTE_PRIORITY_ ## prio 129 #ifndef RTE_INIT_PRIO 130 #define RTE_INIT_PRIO(func, prio) \ 131 static void __attribute__((constructor(RTE_PRIO(prio)), used)) func(void) 142 #define RTE_INIT(func) \ 143 RTE_INIT_PRIO(func, LAST) 154 #ifndef RTE_FINI_PRIO 155 #define RTE_FINI_PRIO(func, prio) \ 156 static void __attribute__((destructor(RTE_PRIO(prio)), used)) func(void) 167 #define RTE_FINI(func) \ 168 RTE_FINI_PRIO(func, LAST) 173 #define __rte_always_inline inline __attribute__((always_inline)) 178 #define __rte_noinline __attribute__((noinline)) 183 #define __rte_hot __attribute__((hot)) 188 #define __rte_cold __attribute__((cold)) 195 #define RTE_PTR_ADD(ptr, x) ((void*)((uintptr_t)(ptr) + (x))) 200 #define RTE_PTR_SUB(ptr, x) ((void*)((uintptr_t)ptr - (x))) 207 #define RTE_PTR_DIFF(ptr1, ptr2) ((uintptr_t)(ptr1) - (uintptr_t)(ptr2)) 212 #define RTE_CAST_FIELD(var, field, type) \ 213 (*(type *)((uintptr_t)(var) + offsetof(typeof(*(var)), field))) 224 #define RTE_PTR_ALIGN_FLOOR(ptr, align) \ 225 ((typeof(ptr))RTE_ALIGN_FLOOR((uintptr_t)ptr, align)) 233 #define RTE_ALIGN_FLOOR(val, align) \ 234 (typeof(val))((val) & (~((typeof(val))((align) - 1)))) 242 #define RTE_PTR_ALIGN_CEIL(ptr, align) \ 243 RTE_PTR_ALIGN_FLOOR((typeof(ptr))RTE_PTR_ADD(ptr, (align) - 1), align) 251 #define RTE_ALIGN_CEIL(val, align) \ 252 RTE_ALIGN_FLOOR(((val) + ((typeof(val)) (align) - 1)), align) 261 #define RTE_PTR_ALIGN(ptr, align) RTE_PTR_ALIGN_CEIL(ptr, align) 270 #define RTE_ALIGN(val, align) RTE_ALIGN_CEIL(val, align) 277 #define RTE_ALIGN_MUL_CEIL(v, mul) \ 278 (((v + (typeof(v))(mul) - 1) / ((typeof(v))(mul))) * (typeof(v))(mul)) 285 #define RTE_ALIGN_MUL_FLOOR(v, mul) \ 286 ((v / ((typeof(v))(mul))) * (typeof(v))(mul)) 293 #define RTE_ALIGN_MUL_NEAR(v, mul) \ 295 typeof(v) ceil = RTE_ALIGN_MUL_CEIL(v, mul); \ 296 typeof(v) floor = RTE_ALIGN_MUL_FLOOR(v, mul); \ 297 (ceil - v) > (v - floor) ? floor : ceil; \ 322 #define RTE_BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)])) 327 #define RTE_CACHE_LINE_MASK (RTE_CACHE_LINE_SIZE-1) 330 #define RTE_CACHE_LINE_ROUNDUP(size) \ 331 (RTE_CACHE_LINE_SIZE * ((size + RTE_CACHE_LINE_SIZE - 1) / \ 332 RTE_CACHE_LINE_SIZE)) 335 #if RTE_CACHE_LINE_SIZE == 64 336 #define RTE_CACHE_LINE_SIZE_LOG2 6 337 #elif RTE_CACHE_LINE_SIZE == 128 338 #define RTE_CACHE_LINE_SIZE_LOG2 7 340 #error "Unsupported cache line size" 344 #define RTE_CACHE_LINE_MIN_SIZE 64 347 #define __rte_cache_aligned __rte_aligned(RTE_CACHE_LINE_SIZE) 350 #define __rte_cache_min_aligned __rte_aligned(RTE_CACHE_LINE_MIN_SIZE) 356 #define RTE_BAD_PHYS_ADDR ((phys_addr_t)-1) 366 #define RTE_BAD_IOVA ((rte_iova_t)-1) 379 static inline uint32_t
401 static inline uint64_t
419 #define RTE_IS_POWER_OF_2(n) ((n) && !(((n) - 1) & (n))) 430 return n && !(n & (n - 1));
442 static inline uint32_t
460 static inline uint32_t
477 static inline uint64_t
495 static inline uint64_t
508 #define RTE_MIN(a, b) \ 510 typeof (a) _a = (a); \ 511 typeof (b) _b = (b); \ 518 #define RTE_MAX(a, b) \ 520 typeof (a) _a = (a); \ 521 typeof (b) _b = (b); \ 538 static inline uint32_t
541 return (uint32_t)__builtin_ctz(v);
579 static inline uint32_t
603 return (x == 0) ? 0 : 32 - __builtin_clz(x);
620 return (uint32_t)__builtin_ctzll(v);
662 return (x == 0) ? 0 : 64 - __builtin_clzll(x);
676 static inline uint32_t
688 #define offsetof(TYPE, MEMBER) __builtin_offsetof (TYPE, MEMBER) 706 #define container_of(ptr, type, member) __extension__ ({ \ 707 const typeof(((type *)0)->member) *_ptr = (ptr); \ 708 __attribute__((unused)) type *_target_ptr = \ 710 (type *)(((uintptr_t)_ptr) - offsetof(type, member)); \ 724 #define RTE_SIZEOF_FIELD(type, field) (sizeof(((type *)0)->field)) 726 #define _RTE_STR(x) #x 728 #define RTE_STR(x) _RTE_STR(x) 735 #define RTE_FMT(fmt, ...) fmt "%.0s", __VA_ARGS__ "" 736 #define RTE_FMT_HEAD(fmt, ...) fmt 737 #define RTE_FMT_TAIL(fmt, ...) __VA_ARGS__ 740 #define RTE_LEN2MASK(ln, tp) \ 741 ((tp)((uint64_t)-1 >> (sizeof(uint64_t) * CHAR_BIT - (ln)))) 744 #define RTE_DIM(a) (sizeof (a) / sizeof ((a)[0])) 760 static inline uint64_t
764 unsigned long long size;
766 while (isspace((
int)*str))
772 size = strtoull(str, &endptr, 0);
780 case 'G':
case 'g': size *= 1024;
781 case 'M':
case 'm': size *= 1024;
782 case 'K':
case 'k': size *= 1024;
803 rte_exit(
int exit_code,
const char *format, ...)
804 __attribute__((noreturn))
805 __attribute__((format(printf, 2, 3)));
static int rte_is_aligned(void *ptr, unsigned align)
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 uint64_t rte_combine64ms1b(register uint64_t v)
static uint64_t rte_align64pow2(uint64_t v)
static uint32_t rte_log2_u32(uint32_t v)
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)
static int rte_fls_u64(uint64_t x)
#define RTE_PTR_ALIGN(ptr, align)
static int rte_is_power_of_2(uint32_t n)
void rte_exit(int exit_code, const char *format,...)
static int rte_bsf64(uint64_t v)
static uint32_t rte_align32prevpow2(uint32_t x)
static uint64_t rte_str_to_size(const char *str)
static uint32_t rte_combine32ms1b(register uint32_t x)