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__))
74 #define __rte_may_alias __attribute__((__may_alias__))
77 #define __rte_deprecated __attribute__((__deprecated__))
82 #define __rte_weak __attribute__((__weak__))
89 #define __rte_unused __attribute__((__unused__))
95 #define RTE_SET_USED(x) (void)(x)
97 #define RTE_PRIORITY_LOG 101
98 #define RTE_PRIORITY_BUS 110
99 #define RTE_PRIORITY_CLASS 120
100 #define RTE_PRIORITY_LAST 65535
102 #define RTE_PRIO(prio) \
103 RTE_PRIORITY_ ## prio
114 #ifndef RTE_INIT_PRIO
115 #define RTE_INIT_PRIO(func, prio) \
116 static void __attribute__((constructor(RTE_PRIO(prio)), used)) func(void)
127 #define RTE_INIT(func) \
128 RTE_INIT_PRIO(func, LAST)
139 #ifndef RTE_FINI_PRIO
140 #define RTE_FINI_PRIO(func, prio) \
141 static void __attribute__((destructor(RTE_PRIO(prio)), used)) func(void)
152 #define RTE_FINI(func) \
153 RTE_FINI_PRIO(func, LAST)
158 #define __rte_always_inline inline __attribute__((always_inline))
163 #define __rte_noinline __attribute__((noinline))
170 #define RTE_PTR_ADD(ptr, x) ((void*)((uintptr_t)(ptr) + (x)))
175 #define RTE_PTR_SUB(ptr, x) ((void*)((uintptr_t)ptr - (x)))
182 #define RTE_PTR_DIFF(ptr1, ptr2) ((uintptr_t)(ptr1) - (uintptr_t)(ptr2))
187 #define RTE_CAST_FIELD(var, field, type) \
188 (*(type *)((uintptr_t)(var) + offsetof(typeof(*(var)), field)))
199 #define RTE_PTR_ALIGN_FLOOR(ptr, align) \
200 ((typeof(ptr))RTE_ALIGN_FLOOR((uintptr_t)ptr, align))
208 #define RTE_ALIGN_FLOOR(val, align) \
209 (typeof(val))((val) & (~((typeof(val))((align) - 1))))
217 #define RTE_PTR_ALIGN_CEIL(ptr, align) \
218 RTE_PTR_ALIGN_FLOOR((typeof(ptr))RTE_PTR_ADD(ptr, (align) - 1), align)
226 #define RTE_ALIGN_CEIL(val, align) \
227 RTE_ALIGN_FLOOR(((val) + ((typeof(val)) (align) - 1)), align)
236 #define RTE_PTR_ALIGN(ptr, align) RTE_PTR_ALIGN_CEIL(ptr, align)
245 #define RTE_ALIGN(val, align) RTE_ALIGN_CEIL(val, align)
252 #define RTE_ALIGN_MUL_CEIL(v, mul) \
253 ((((v) + (typeof(v))(mul) - 1) / ((typeof(v))(mul))) * (typeof(v))(mul))
260 #define RTE_ALIGN_MUL_FLOOR(v, mul) \
261 (((v) / ((typeof(v))(mul))) * (typeof(v))(mul))
268 #define RTE_ALIGN_MUL_NEAR(v, mul) \
270 typeof(v) ceil = RTE_ALIGN_MUL_CEIL(v, mul); \
271 typeof(v) floor = RTE_ALIGN_MUL_FLOOR(v, mul); \
272 (ceil - (v)) > ((v) - floor) ? floor : ceil; \
297 #define RTE_BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
302 #define RTE_CACHE_LINE_MASK (RTE_CACHE_LINE_SIZE-1)
305 #define RTE_CACHE_LINE_ROUNDUP(size) \
306 (RTE_CACHE_LINE_SIZE * ((size + RTE_CACHE_LINE_SIZE - 1) / \
307 RTE_CACHE_LINE_SIZE))
310 #if RTE_CACHE_LINE_SIZE == 64
311 #define RTE_CACHE_LINE_SIZE_LOG2 6
312 #elif RTE_CACHE_LINE_SIZE == 128
313 #define RTE_CACHE_LINE_SIZE_LOG2 7
315 #error "Unsupported cache line size"
319 #define RTE_CACHE_LINE_MIN_SIZE 64
322 #define __rte_cache_aligned __rte_aligned(RTE_CACHE_LINE_SIZE)
325 #define __rte_cache_min_aligned __rte_aligned(RTE_CACHE_LINE_MIN_SIZE)
331 #define RTE_BAD_PHYS_ADDR ((phys_addr_t)-1)
341 #define RTE_BAD_IOVA ((rte_iova_t)-1)
354 static inline uint32_t
376 static inline uint64_t
394 #define RTE_IS_POWER_OF_2(n) ((n) && !(((n) - 1) & (n)))
405 return n && !(n & (n - 1));
417 static inline uint32_t
435 static inline uint32_t
452 static inline uint64_t
470 static inline uint64_t
483 #define RTE_MIN(a, b) \
485 typeof (a) _a = (a); \
486 typeof (b) _b = (b); \
493 #define RTE_MAX(a, b) \
495 typeof (a) _a = (a); \
496 typeof (b) _b = (b); \
513 static inline uint32_t
516 return (uint32_t)__builtin_ctz(v);
554 static inline uint32_t
578 return (x == 0) ? 0 : 32 - __builtin_clz(x);
595 return (uint32_t)__builtin_ctzll(v);
637 return (x == 0) ? 0 : 64 - __builtin_clzll(x);
651 static inline uint32_t
663 #define offsetof(TYPE, MEMBER) __builtin_offsetof (TYPE, MEMBER)
681 #define container_of(ptr, type, member) __extension__ ({ \
682 const typeof(((type *)0)->member) *_ptr = (ptr); \
683 __attribute__((unused)) type *_target_ptr = \
685 (type *)(((uintptr_t)_ptr) - offsetof(type, member)); \
699 #define RTE_SIZEOF_FIELD(type, field) (sizeof(((type *)0)->field))
701 #define _RTE_STR(x) #x
703 #define RTE_STR(x) _RTE_STR(x)
710 #define RTE_FMT(fmt, ...) fmt "%.0s", __VA_ARGS__ ""
711 #define RTE_FMT_HEAD(fmt, ...) fmt
712 #define RTE_FMT_TAIL(fmt, ...) __VA_ARGS__
715 #define RTE_LEN2MASK(ln, tp) \
716 ((tp)((uint64_t)-1 >> (sizeof(uint64_t) * CHAR_BIT - (ln))))
719 #define RTE_DIM(a) (sizeof (a) / sizeof ((a)[0]))
735 static inline uint64_t
739 unsigned long long size;
741 while (isspace((
int)*str))
747 size = strtoull(str, &endptr, 0);
755 case 'G':
case 'g': size *= 1024;
756 case 'M':
case 'm': size *= 1024;
757 case 'K':
case 'k': size *= 1024;
778 rte_exit(
int exit_code,
const char *format, ...)
779 __attribute__((noreturn))
780 __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)