Go to the documentation of this file.
25 #include <rte_config.h>
31 #define typeof __typeof__
39 #if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 201112L
40 #define RTE_STD_C11 __extension__
46 #ifdef RTE_TOOLCHAIN_GCC
47 #define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + \
51 #ifdef RTE_ARCH_STRICT_ALIGN
53 typedef uint32_t unaligned_uint32_t __attribute__ ((aligned(1)));
54 typedef uint16_t unaligned_uint16_t __attribute__ ((aligned(1)));
57 typedef uint32_t unaligned_uint32_t;
58 typedef uint16_t unaligned_uint16_t;
64 #define __rte_aligned(a) __attribute__((__aligned__(a)))
69 #define __rte_packed __attribute__((__packed__))
72 #define __rte_deprecated __attribute__((__deprecated__))
77 #define __rte_weak __attribute__((__weak__))
84 #define __rte_unused __attribute__((__unused__))
90 #define RTE_SET_USED(x) (void)(x)
92 #define RTE_PRIORITY_LOG 101
93 #define RTE_PRIORITY_BUS 110
94 #define RTE_PRIORITY_CLASS 120
95 #define RTE_PRIORITY_LAST 65535
97 #define RTE_PRIO(prio) \
109 #ifndef RTE_INIT_PRIO
110 #if defined(__x86_64__) || defined(__i386__)
111 #define RTE_INIT_PRIO(func, prio) \
113 __attribute__((constructor(RTE_PRIO(prio)), used)) \
114 __attribute__((target ("sse2"))) \
115 __attribute__((target ("no-sse3"))) \
116 __attribute__((target ("no-sse4"))) \
119 #define RTE_INIT_PRIO(func, prio) \
121 __attribute__((constructor(RTE_PRIO(prio)), used)) \
134 #define RTE_INIT(func) \
135 RTE_INIT_PRIO(func, LAST)
146 #ifndef RTE_FINI_PRIO
147 #define RTE_FINI_PRIO(func, prio) \
148 static void __attribute__((destructor(RTE_PRIO(prio)), used)) func(void)
159 #define RTE_FINI(func) \
160 RTE_FINI_PRIO(func, LAST)
165 #define __rte_always_inline inline __attribute__((always_inline))
170 #define __rte_noinline __attribute__((noinline))
177 #define RTE_PTR_ADD(ptr, x) ((void*)((uintptr_t)(ptr) + (x)))
182 #define RTE_PTR_SUB(ptr, x) ((void*)((uintptr_t)ptr - (x)))
189 #define RTE_PTR_DIFF(ptr1, ptr2) ((uintptr_t)(ptr1) - (uintptr_t)(ptr2))
194 #define RTE_CAST_FIELD(var, field, type) \
195 (*(type *)((uintptr_t)(var) + offsetof(typeof(*(var)), field)))
206 #define RTE_PTR_ALIGN_FLOOR(ptr, align) \
207 ((typeof(ptr))RTE_ALIGN_FLOOR((uintptr_t)ptr, align))
215 #define RTE_ALIGN_FLOOR(val, align) \
216 (typeof(val))((val) & (~((typeof(val))((align) - 1))))
224 #define RTE_PTR_ALIGN_CEIL(ptr, align) \
225 RTE_PTR_ALIGN_FLOOR((typeof(ptr))RTE_PTR_ADD(ptr, (align) - 1), align)
233 #define RTE_ALIGN_CEIL(val, align) \
234 RTE_ALIGN_FLOOR(((val) + ((typeof(val)) (align) - 1)), align)
243 #define RTE_PTR_ALIGN(ptr, align) RTE_PTR_ALIGN_CEIL(ptr, align)
252 #define RTE_ALIGN(val, align) RTE_ALIGN_CEIL(val, align)
259 #define RTE_ALIGN_MUL_CEIL(v, mul) \
260 (((v + (typeof(v))(mul) - 1) / ((typeof(v))(mul))) * (typeof(v))(mul))
267 #define RTE_ALIGN_MUL_FLOOR(v, mul) \
268 ((v / ((typeof(v))(mul))) * (typeof(v))(mul))
275 #define RTE_ALIGN_MUL_NEAR(v, mul) \
277 typeof(v) ceil = RTE_ALIGN_MUL_CEIL(v, mul); \
278 typeof(v) floor = RTE_ALIGN_MUL_FLOOR(v, mul); \
279 (ceil - v) > (v - floor) ? floor : ceil; \
304 #define RTE_BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
309 #define RTE_CACHE_LINE_MASK (RTE_CACHE_LINE_SIZE-1)
312 #define RTE_CACHE_LINE_ROUNDUP(size) \
313 (RTE_CACHE_LINE_SIZE * ((size + RTE_CACHE_LINE_SIZE - 1) / \
314 RTE_CACHE_LINE_SIZE))
317 #if RTE_CACHE_LINE_SIZE == 64
318 #define RTE_CACHE_LINE_SIZE_LOG2 6
319 #elif RTE_CACHE_LINE_SIZE == 128
320 #define RTE_CACHE_LINE_SIZE_LOG2 7
322 #error "Unsupported cache line size"
326 #define RTE_CACHE_LINE_MIN_SIZE 64
329 #define __rte_cache_aligned __rte_aligned(RTE_CACHE_LINE_SIZE)
332 #define __rte_cache_min_aligned __rte_aligned(RTE_CACHE_LINE_MIN_SIZE)
338 #define RTE_BAD_PHYS_ADDR ((phys_addr_t)-1)
348 #define RTE_BAD_IOVA ((rte_iova_t)-1)
361 static inline uint32_t
383 static inline uint64_t
401 #define RTE_IS_POWER_OF_2(n) ((n) && !(((n) - 1) & (n)))
412 return n && !(n & (n - 1));
424 static inline uint32_t
442 static inline uint32_t
459 static inline uint64_t
477 static inline uint64_t
490 #define RTE_MIN(a, b) \
492 typeof (a) _a = (a); \
493 typeof (b) _b = (b); \
500 #define RTE_MAX(a, b) \
502 typeof (a) _a = (a); \
503 typeof (b) _b = (b); \
520 static inline uint32_t
523 return (uint32_t)__builtin_ctz(v);
561 static inline uint32_t
585 return (x == 0) ? 0 : 32 - __builtin_clz(x);
602 return (uint32_t)__builtin_ctzll(v);
644 return (x == 0) ? 0 : 64 - __builtin_clzll(x);
658 static inline uint32_t
670 #define offsetof(TYPE, MEMBER) __builtin_offsetof (TYPE, MEMBER)
688 #define container_of(ptr, type, member) __extension__ ({ \
689 const typeof(((type *)0)->member) *_ptr = (ptr); \
690 __attribute__((unused)) type *_target_ptr = \
692 (type *)(((uintptr_t)_ptr) - offsetof(type, member)); \
706 #define RTE_SIZEOF_FIELD(type, field) (sizeof(((type *)0)->field))
708 #define _RTE_STR(x) #x
710 #define RTE_STR(x) _RTE_STR(x)
717 #define RTE_FMT(fmt, ...) fmt "%.0s", __VA_ARGS__ ""
718 #define RTE_FMT_HEAD(fmt, ...) fmt
719 #define RTE_FMT_TAIL(fmt, ...) __VA_ARGS__
722 #define RTE_LEN2MASK(ln, tp) \
723 ((tp)((uint64_t)-1 >> (sizeof(uint64_t) * CHAR_BIT - (ln))))
726 #define RTE_DIM(a) (sizeof (a) / sizeof ((a)[0]))
742 static inline uint64_t
746 unsigned long long size;
748 while (isspace((
int)*str))
754 size = strtoull(str, &endptr, 0);
762 case 'G':
case 'g': size *= 1024;
763 case 'M':
case 'm': size *= 1024;
764 case 'K':
case 'k': size *= 1024;
786 __attribute__((noreturn))
787 __attribute__((format(printf, 2, 3)));
static uint64_t rte_str_to_size(const char *str)
static uint32_t rte_log2_u64(uint64_t v)
static uint32_t rte_log2_u32(uint32_t v)
static uint32_t rte_align32prevpow2(uint32_t x)
static int rte_is_power_of_2(uint32_t n)
static int rte_is_aligned(void *ptr, unsigned align)
static uint32_t rte_align32pow2(uint32_t x)
static uint64_t rte_align64pow2(uint64_t v)
static int rte_fls_u32(uint32_t x)
void rte_exit(int exit_code, const char *format,...)
static int rte_bsf32_safe(uint64_t v, uint32_t *pos)
uint64_t unaligned_uint64_t
#define RTE_PTR_ALIGN(ptr, align)
static uint64_t rte_combine64ms1b(uint64_t v)
static uint32_t rte_bsf32(uint32_t v)
static uint64_t rte_align64prevpow2(uint64_t v)
static int rte_bsf64_safe(uint64_t v, uint32_t *pos)
static uint32_t rte_combine32ms1b(uint32_t x)
static int rte_fls_u64(uint64_t x)
static int rte_bsf64(uint64_t v)