CNDP  22.08.0
cne_common.h File Reference
#include <stdint.h>
#include <stdlib.h>
#include <ctype.h>
#include <errno.h>
#include <limits.h>
#include <unistd.h>
#include <sys/syscall.h>
#include <linux/version.h>

Go to the source code of this file.

Macros

#define XDP_PKT_HEADROOM   256
 
#define CNE_DEFAULT_SET(x, y, z)
 
#define CNE_MAX_SET(x, z)
 
#define CNE_STD_C11   __extension__
 
#define cne_compiler_barrier()
 
#define __cne_aligned(a)   __attribute__((aligned(a)))
 
#define __cne_packed   __attribute__((__packed__))
 
#define __cne_weak   __attribute__((__weak__))
 
#define __cne_unused   __attribute__((__unused__))
 
#define CNE_SET_USED(x)   (void)(x)
 
#define CNE_INIT_PRIO(func, prio)    static void __attribute__((constructor(CNE_PRIO(prio)), used)) func(void)
 
#define CNE_INIT(func)   CNE_INIT_PRIO(func, LAST)
 
#define CNE_FINI_PRIO(func, prio)    static void __attribute__((destructor(CNE_PRIO(prio)), used)) func(void)
 
#define CNE_FINI(func)   CNE_FINI_PRIO(func, LAST)
 
#define __cne_always_inline   inline __attribute__((__always_inline__))
 
#define __cne_noinline   __attribute__((__noinline__))
 
#define CNE_PTR_CAST(ptr, x)   (x)((uintptr_t)(ptr))
 
#define CNE_PTR_ADD(ptr, x)   ((void *)((uintptr_t)(ptr) + (x)))
 
#define CNE_PTR_SUB(ptr, x)   ((void *)((uintptr_t)ptr - (x)))
 
#define CNE_PTR_DIFF(ptr1, ptr2)   ((uintptr_t)(ptr1) - (uintptr_t)(ptr2))
 
#define CNE_CAST_FIELD(var, field, type)    (*(type *)((uintptr_t)(var) + offsetof(typeof(*(var)), field)))
 
#define CNE_PTR_ALIGN_FLOOR(ptr, align)   ((typeof(ptr))CNE_ALIGN_FLOOR((uintptr_t)ptr, align))
 
#define CNE_ALIGN_FLOOR(val, align)   (typeof(val))((val) & (~((typeof(val))((align)-1))))
 
#define CNE_PTR_ALIGN_CEIL(ptr, align)    CNE_PTR_ALIGN_FLOOR((typeof(ptr))CNE_PTR_ADD(ptr, (align)-1), align)
 
#define CNE_ALIGN_CEIL(val, align)   CNE_ALIGN_FLOOR(((val) + ((typeof(val))(align)-1)), align)
 
#define CNE_PTR_ALIGN(ptr, align)   CNE_PTR_ALIGN_CEIL(ptr, align)
 
#define CNE_ALIGN(val, align)   CNE_ALIGN_CEIL(val, align)
 
#define CNE_ALIGN_MUL_CEIL(v, mul)    (((v + (typeof(v))(mul)-1) / ((typeof(v))(mul))) * (typeof(v))(mul))
 
#define CNE_ALIGN_MUL_FLOOR(v, mul)   ((v / ((typeof(v))(mul))) * (typeof(v))(mul))
 
#define CNE_ALIGN_MUL_NEAR(v, mul)
 
#define CNE_BUILD_BUG_ON(condition)   ((void)sizeof(char[1 - 2 * !!(condition)]))
 
#define CNE_CACHE_LINE_MASK   (CNE_CACHE_LINE_SIZE - 1)
 
#define CNE_CACHE_LINE_ROUNDUP(size)    (CNE_CACHE_LINE_SIZE * ((size + CNE_CACHE_LINE_SIZE - 1) / CNE_CACHE_LINE_SIZE))
 
#define CNE_CACHE_LINE_SIZE_LOG2   6
 
#define CNE_CACHE_LINE_MIN_SIZE   64
 
#define __cne_cache_aligned   __cne_aligned(CNE_CACHE_LINE_SIZE)
 
#define __cne_cache_min_aligned   __cne_aligned(CNE_CACHE_LINE_MIN_SIZE)
 
#define CNE_IS_POWER_OF_2(n)   ((n) && !(((n)-1) & (n)))
 
#define CNE_MIN(a, b)
 
#define CNE_MAX(a, b)
 
#define offsetof(TYPE, MEMBER)   __builtin_offsetof(TYPE, MEMBER)
 
#define container_of(ptr, type, member)
 
#define CNE_SIZEOF_FIELD(type, field)   (sizeof(((type *)0)->field))
 
#define CNE_STR(x)   _CNE_STR(x)
 
#define CNE_FMT(fmt, ...)   fmt "%.0s", __VA_ARGS__ ""
 
#define CNE_LEN2MASK(ln, tp)   ((tp)((uint64_t)-1 >> (sizeof(uint64_t) * CHAR_BIT - (ln))))
 
#define CNE_DIM(a)   (int)(sizeof(a) / sizeof((a)[0]))
 

Typedefs

typedef uint64_t phys_addr_t
 
typedef uint64_t cne_iova_t
 

Functions

static int cne_is_aligned (void *ptr, unsigned align)
 
static uint32_t cne_combine32ms1b (uint32_t x)
 
static uint64_t cne_combine64ms1b (uint64_t v)
 
static int cne_is_power_of_2 (uint32_t n)
 
static uint32_t cne_align32pow2 (uint32_t x)
 
static uint32_t cne_align32prevpow2 (uint32_t x)
 
static uint64_t cne_align64pow2 (uint64_t v)
 
static uint64_t cne_align64prevpow2 (uint64_t v)
 
static uint32_t cne_bsf32 (uint32_t v)
 
static int cne_bsf32_safe (uint64_t v, uint32_t *pos)
 
static uint32_t cne_log2_u32 (uint32_t v)
 
static int cne_fls_u32 (uint32_t x)
 
static int cne_bsf64 (uint64_t v)
 
static int cne_bsf64_safe (uint64_t v, uint32_t *pos)
 
static int cne_fls_u64 (uint64_t x)
 
static uint32_t cne_log2_u64 (uint64_t v)
 
static uint64_t cne_str_to_size (const char *str)
 

Variables

__extension__ typedef void * CNE_MARKER [0]
 
__extension__ typedef uint8_t CNE_MARKER8 [0]
 
__extension__ typedef uint16_t CNE_MARKER16 [0]
 
__extension__ typedef uint32_t CNE_MARKER32 [0]
 
__extension__ typedef uint64_t CNE_MARKER64 [0]
 

Detailed Description

Generic, commonly-used macro and inline function definitions for CNDP.

Definition in file cne_common.h.

Macro Definition Documentation

◆ XDP_PKT_HEADROOM

#define XDP_PKT_HEADROOM   256

Must mirror XDP_PACKET_HEADROOM

Definition at line 38 of file cne_common.h.

◆ CNE_DEFAULT_SET

#define CNE_DEFAULT_SET (   x,
  y,
 
)
Value:
do { \
if (x == y) \
x = z; \
} while ((0))

Enable the use of shared UMEM if the kernel version >= 5.10 and we detect in the top-level meson.build we have the correct libbpf version >= 0.3.0 <= 0.6.1 Helper routine to set a default value if x == y then x = z.

Parameters
xValue to set for default
yThe default value to be tested for, if equal then set x = z
zThe default value to be used
Returns
Sets the default value z, if x == y
Examples
examples/vpp-plugin/cndp/device.c.

Definition at line 67 of file cne_common.h.

◆ CNE_MAX_SET

#define CNE_MAX_SET (   x,
 
)
Value:
do { \
if (x > z) \
x = z; \
} while ((0))

Helper routine to set a max value if x > z then x = z.

Parameters
xValue to set
zThe Max value to be used
Returns
Sets the default value z, if x > z

Definition at line 83 of file cne_common.h.

◆ CNE_STD_C11

#define CNE_STD_C11   __extension__

C extension macro for environments lacking C11 features.

Definition at line 91 of file cne_common.h.

◆ cne_compiler_barrier

#define cne_compiler_barrier ( )
Value:
do { \
asm volatile("" : : : "memory"); \
} while (0)

Compiler barrier.

Guarantees that operation reordering does not occur at compile time for operations directly before and after the barrier.

Definition at line 116 of file cne_common.h.

◆ __cne_aligned

#define __cne_aligned (   a)    __attribute__((aligned(a)))

Force alignment

Definition at line 124 of file cne_common.h.

◆ __cne_packed

struct cne_ipv6_fragment_ext __cne_packed   __attribute__((__packed__))

Force a structure to be packed

Definition at line 129 of file cne_common.h.

◆ __cne_weak

#define __cne_weak   __attribute__((__weak__))

Mark a function or variable to a weak reference.

Definition at line 137 of file cne_common.h.

◆ __cne_unused

◆ CNE_SET_USED

#define CNE_SET_USED (   x)    (void)(x)

definition to mark a variable or function parameter as used so as to avoid a compiler warning

Examples
examples/cli/main.c, and examples/dlb_test/dlb_test.c.

Definition at line 150 of file cne_common.h.

◆ CNE_INIT_PRIO

#define CNE_INIT_PRIO (   func,
  prio 
)     static void __attribute__((constructor(CNE_PRIO(prio)), used)) func(void)

Run function before main() with high priority.

Parameters
funcConstructor function.
prioPriority number must be above 100. Lowest number is the first to run.

Definition at line 177 of file cne_common.h.

◆ CNE_INIT

#define CNE_INIT (   func)    CNE_INIT_PRIO(func, LAST)

Run function before main() with low priority.

The constructor will be run after prioritized constructors.

Parameters
funcConstructor function.

Definition at line 189 of file cne_common.h.

◆ CNE_FINI_PRIO

#define CNE_FINI_PRIO (   func,
  prio 
)     static void __attribute__((destructor(CNE_PRIO(prio)), used)) func(void)

Run after main() with low priority.

Parameters
funcDestructor function name.
prioPriority number must be above 100. Lowest number is the last to run.

Definition at line 201 of file cne_common.h.

◆ CNE_FINI

#define CNE_FINI (   func)    CNE_FINI_PRIO(func, LAST)

Run after main() with high priority.

The destructor will be run before prioritized destructors.

Parameters
funcDestructor function name.

Definition at line 213 of file cne_common.h.

◆ __cne_always_inline

#define __cne_always_inline   inline __attribute__((__always_inline__))

Force a function to be inlined

Examples
examples/cndpfwd/main.c, and examples/vpp-plugin/cndp/device.c.

Definition at line 218 of file cne_common.h.

◆ __cne_noinline

#define __cne_noinline   __attribute__((__noinline__))

Force a function to be noinlined

Definition at line 223 of file cne_common.h.

◆ CNE_PTR_CAST

#define CNE_PTR_CAST (   ptr,
 
)    (x)((uintptr_t)(ptr))

Force type to a new type

Definition at line 228 of file cne_common.h.

◆ CNE_PTR_ADD

#define CNE_PTR_ADD (   ptr,
 
)    ((void *)((uintptr_t)(ptr) + (x)))

add a byte-value offset to a pointer

Examples
examples/cndpfwd/acl-func.c.

Definition at line 235 of file cne_common.h.

◆ CNE_PTR_SUB

#define CNE_PTR_SUB (   ptr,
 
)    ((void *)((uintptr_t)ptr - (x)))

subtract a byte-value offset from a pointer

Definition at line 240 of file cne_common.h.

◆ CNE_PTR_DIFF

#define CNE_PTR_DIFF (   ptr1,
  ptr2 
)    ((uintptr_t)(ptr1) - (uintptr_t)(ptr2))

get the difference between two pointer values, i.e. how far apart in bytes are the locations they point two. It is assumed that ptr1 is greater than ptr2.

Definition at line 247 of file cne_common.h.

◆ CNE_CAST_FIELD

#define CNE_CAST_FIELD (   var,
  field,
  type 
)     (*(type *)((uintptr_t)(var) + offsetof(typeof(*(var)), field)))

Workaround to cast a const field of a structure to non-const type.

Definition at line 252 of file cne_common.h.

◆ CNE_PTR_ALIGN_FLOOR

#define CNE_PTR_ALIGN_FLOOR (   ptr,
  align 
)    ((typeof(ptr))CNE_ALIGN_FLOOR((uintptr_t)ptr, align))

Macro to align a pointer to a given power-of-two. The resultant pointer will be a pointer of the same type as the first parameter, and point to an address no higher than the first parameter. Second parameter must be a power-of-two value.

Definition at line 263 of file cne_common.h.

◆ CNE_ALIGN_FLOOR

#define CNE_ALIGN_FLOOR (   val,
  align 
)    (typeof(val))((val) & (~((typeof(val))((align)-1))))

Macro to align a value to a given power-of-two. The resultant value will be of the same type as the first parameter, and will be no bigger than the first parameter. Second parameter must be a power-of-two value.

Definition at line 271 of file cne_common.h.

◆ CNE_PTR_ALIGN_CEIL

#define CNE_PTR_ALIGN_CEIL (   ptr,
  align 
)     CNE_PTR_ALIGN_FLOOR((typeof(ptr))CNE_PTR_ADD(ptr, (align)-1), align)

Macro to align a pointer to a given power-of-two. The resultant pointer will be a pointer of the same type as the first parameter, and point to an address no lower than the first parameter. Second parameter must be a power-of-two value.

Definition at line 279 of file cne_common.h.

◆ CNE_ALIGN_CEIL

#define CNE_ALIGN_CEIL (   val,
  align 
)    CNE_ALIGN_FLOOR(((val) + ((typeof(val))(align)-1)), align)

Macro to align a value to a given power-of-two. The resultant value will be of the same type as the first parameter, and will be no lower than the first parameter. Second parameter must be a power-of-two value.

Definition at line 288 of file cne_common.h.

◆ CNE_PTR_ALIGN

#define CNE_PTR_ALIGN (   ptr,
  align 
)    CNE_PTR_ALIGN_CEIL(ptr, align)

Macro to align a pointer to a given power-of-two. The resultant pointer will be a pointer of the same type as the first parameter, and point to an address no lower than the first parameter. Second parameter must be a power-of-two value. This function is the same as CNE_PTR_ALIGN_CEIL

Definition at line 297 of file cne_common.h.

◆ CNE_ALIGN

#define CNE_ALIGN (   val,
  align 
)    CNE_ALIGN_CEIL(val, align)

Macro to align a value to a given power-of-two. The resultant value will be of the same type as the first parameter, and will be no lower than the first parameter. Second parameter must be a power-of-two value. This function is the same as CNE_ALIGN_CEIL

Definition at line 306 of file cne_common.h.

◆ CNE_ALIGN_MUL_CEIL

#define CNE_ALIGN_MUL_CEIL (   v,
  mul 
)     (((v + (typeof(v))(mul)-1) / ((typeof(v))(mul))) * (typeof(v))(mul))

Macro to align a value to the multiple of given value. The resultant value will be of the same type as the first parameter and will be no lower than the first parameter.

Definition at line 313 of file cne_common.h.

◆ CNE_ALIGN_MUL_FLOOR

#define CNE_ALIGN_MUL_FLOOR (   v,
  mul 
)    ((v / ((typeof(v))(mul))) * (typeof(v))(mul))

Macro to align a value to the multiple of given value. The resultant value will be of the same type as the first parameter and will be no higher than the first parameter.

Definition at line 321 of file cne_common.h.

◆ CNE_ALIGN_MUL_NEAR

#define CNE_ALIGN_MUL_NEAR (   v,
  mul 
)
Value:
({ \
typeof(v) ceil = CNE_ALIGN_MUL_CEIL(v, mul); \
typeof(v) floor = CNE_ALIGN_MUL_FLOOR(v, mul); \
(ceil - v) > (v - floor) ? floor : ceil; \
})
#define CNE_ALIGN_MUL_FLOOR(v, mul)
Definition: cne_common.h:321
#define CNE_ALIGN_MUL_CEIL(v, mul)
Definition: cne_common.h:313

Macro to align value to the nearest multiple of the given value. The resultant value might be greater than or less than the first parameter whichever difference is the lowest.

Definition at line 328 of file cne_common.h.

◆ CNE_BUILD_BUG_ON

#define CNE_BUILD_BUG_ON (   condition)    ((void)sizeof(char[1 - 2 * !!(condition)]))

Triggers an error at compilation time if the condition is true.

Definition at line 357 of file cne_common.h.

◆ CNE_CACHE_LINE_MASK

#define CNE_CACHE_LINE_MASK   (CNE_CACHE_LINE_SIZE - 1)

Cache line mask.

Definition at line 362 of file cne_common.h.

◆ CNE_CACHE_LINE_ROUNDUP

#define CNE_CACHE_LINE_ROUNDUP (   size)     (CNE_CACHE_LINE_SIZE * ((size + CNE_CACHE_LINE_SIZE - 1) / CNE_CACHE_LINE_SIZE))

Return the first cache-aligned value greater or equal to size.

Definition at line 365 of file cne_common.h.

◆ CNE_CACHE_LINE_SIZE_LOG2

#define CNE_CACHE_LINE_SIZE_LOG2   6

Cache line size in terms of log2

Definition at line 370 of file cne_common.h.

◆ CNE_CACHE_LINE_MIN_SIZE

#define CNE_CACHE_LINE_MIN_SIZE   64

Minimum Cache line size.

Definition at line 376 of file cne_common.h.

◆ __cne_cache_aligned

struct cne_node __cne_cache_aligned   __cne_aligned(CNE_CACHE_LINE_SIZE)

Force alignment to cache line.

Definition at line 379 of file cne_common.h.

◆ __cne_cache_min_aligned

struct pktdev_txq_info __cne_cache_min_aligned   __cne_aligned(CNE_CACHE_LINE_MIN_SIZE)

Force minimum cache line alignment.

Definition at line 382 of file cne_common.h.

◆ CNE_IS_POWER_OF_2

#define CNE_IS_POWER_OF_2 (   n)    ((n) && !(((n)-1) & (n)))

Macro to return 1 if n is a power of 2, 0 otherwise

Definition at line 461 of file cne_common.h.

◆ CNE_MIN

#define CNE_MIN (   a,
 
)
Value:
__extension__({ \
typeof(a) _a = (a); \
typeof(b) _b = (b); \
_a < _b ? _a : _b; \
})

Macro to return the minimum of two numbers

Examples
examples/cndpfwd/acl-func.c.

Definition at line 550 of file cne_common.h.

◆ CNE_MAX

#define CNE_MAX (   a,
 
)
Value:
__extension__({ \
typeof(a) _a = (a); \
typeof(b) _b = (b); \
_a > _b ? _a : _b; \
})

Macro to return the maximum of two numbers

Definition at line 560 of file cne_common.h.

◆ offsetof

#define offsetof (   TYPE,
  MEMBER 
)    __builtin_offsetof(TYPE, MEMBER)

Return the offset of a field in a structure.

Examples
examples/cnet-graph/cnet-graph.c, examples/cnet-quic/cnet-quic.c, and examples/l3fwd-graph/fwd.c.

Definition at line 723 of file cne_common.h.

◆ container_of

#define container_of (   ptr,
  type,
  member 
)
Value:
__extension__({ \
const typeof(((type *)0)->member) *_ptr = (ptr); \
__attribute__((unused)) type *_target_ptr = (type *)(ptr); \
(type *)(((uintptr_t)_ptr) - offsetof(type, member)); \
})
#define offsetof(TYPE, MEMBER)
Definition: cne_common.h:723

Return pointer to the wrapping struct instance.

Example:

struct wrapper { ... struct child c; ... };

struct child *x = obtain(...); struct wrapper *w = container_of(x, struct wrapper, c);

Definition at line 741 of file cne_common.h.

◆ CNE_SIZEOF_FIELD

#define CNE_SIZEOF_FIELD (   type,
  field 
)    (sizeof(((type *)0)->field))

Get the size of a field in a structure.

Parameters
typeThe type of the structure.
fieldThe field in the structure.
Returns
The size of the field in the structure, in bytes.

Definition at line 759 of file cne_common.h.

◆ CNE_STR

#define CNE_STR (   x)    _CNE_STR(x)

Take a macro value and get a string version of it

Definition at line 763 of file cne_common.h.

◆ CNE_FMT

#define CNE_FMT (   fmt,
  ... 
)    fmt "%.0s", __VA_ARGS__ ""

ISO C helpers to modify format strings using variadic macros. This is a replacement for the ", ## __VA_ARGS__" GNU extension. An empty s argument is appended to avoid a dangling comma.

Definition at line 770 of file cne_common.h.

◆ CNE_LEN2MASK

#define CNE_LEN2MASK (   ln,
  tp 
)    ((tp)((uint64_t)-1 >> (sizeof(uint64_t) * CHAR_BIT - (ln))))

Mask value of type "tp" for the first "ln" bit set.

Definition at line 775 of file cne_common.h.

◆ CNE_DIM

#define CNE_DIM (   a)    (int)(sizeof(a) / sizeof((a)[0]))

Number of elements in the array.

Definition at line 778 of file cne_common.h.

Typedef Documentation

◆ phys_addr_t

typedef uint64_t phys_addr_t

Physical address

Definition at line 398 of file cne_common.h.

◆ cne_iova_t

typedef uint64_t cne_iova_t

IO virtual address type. When the physical addressing mode (IOVA as PA) is in use, the translation from an IO virtual address (IOVA) to a physical address is a direct mapping, i.e. the same value. Otherwise, in virtual mode (IOVA as VA), an IOMMU may do the translation.

Definition at line 408 of file cne_common.h.

Function Documentation

◆ cne_is_aligned()

static int cne_is_aligned ( void *  ptr,
unsigned  align 
)
inlinestatic

Checks if a pointer is aligned to a given power-of-two value

Parameters
ptrThe pointer whose alignment is to be checked
alignThe power-of-two value to which the ptr should be aligned
Returns
True(1) where the pointer is correctly aligned, false(0) otherwise

Definition at line 347 of file cne_common.h.

◆ cne_combine32ms1b()

static uint32_t cne_combine32ms1b ( uint32_t  x)
inlinestatic

Combines 32b inputs most significant set bits into the least significant bits to construct a value with the same MSBs as x but all 1's under it.

Parameters
xThe integer whose MSBs need to be combined with its LSBs
Returns
The combined value.

Definition at line 422 of file cne_common.h.

◆ cne_combine64ms1b()

static uint64_t cne_combine64ms1b ( uint64_t  v)
inlinestatic

Combines 64b inputs most significant set bits into the least significant bits to construct a value with the same MSBs as x but all 1's under it.

Parameters
vThe integer whose MSBs need to be combined with its LSBs
Returns
The combined value.

Definition at line 444 of file cne_common.h.

◆ cne_is_power_of_2()

static int cne_is_power_of_2 ( uint32_t  n)
inlinestatic

Returns true if n is a power of 2

Parameters
nNumber to check
Returns
1 if true, 0 otherwise

Definition at line 470 of file cne_common.h.

◆ cne_align32pow2()

static uint32_t cne_align32pow2 ( uint32_t  x)
inlinestatic

Aligns input parameter to the next power of 2

Parameters
xThe integer value to align
Returns
Input parameter aligned to the next power of 2

Definition at line 485 of file cne_common.h.

◆ cne_align32prevpow2()

static uint32_t cne_align32prevpow2 ( uint32_t  x)
inlinestatic

Aligns input parameter to the previous power of 2

Parameters
xThe integer value to align
Returns
Input parameter aligned to the previous power of 2

Definition at line 503 of file cne_common.h.

◆ cne_align64pow2()

static uint64_t cne_align64pow2 ( uint64_t  v)
inlinestatic

Aligns 64b input parameter to the next power of 2

Parameters
vThe 64b value to align
Returns
Input parameter aligned to the next power of 2
Examples
examples/cndpfwd/acl-func.c.

Definition at line 520 of file cne_common.h.

◆ cne_align64prevpow2()

static uint64_t cne_align64prevpow2 ( uint64_t  v)
inlinestatic

Aligns 64b input parameter to the previous power of 2

Parameters
vThe 64b value to align
Returns
Input parameter aligned to the previous power of 2

Definition at line 538 of file cne_common.h.

◆ cne_bsf32()

static uint32_t cne_bsf32 ( uint32_t  v)
inlinestatic

Searches the input parameter for the least significant set bit (starting from zero). If a least significant 1 bit is found, its bit index is returned. If the content of the input parameter is zero, then the content of the return value is undefined.

Parameters
vinput parameter, should not be zero.
Returns
least significant set bit in the input parameter.

Definition at line 581 of file cne_common.h.

◆ cne_bsf32_safe()

static int cne_bsf32_safe ( uint64_t  v,
uint32_t *  pos 
)
inlinestatic

Searches the input parameter for the least significant set bit (starting from zero). Safe version (checks for input parameter being zero).

Warning
pos must be a valid pointer. It is not checked!
Parameters
vThe input parameter.
posIf v was not 0, this value will contain position of least significant bit within the input parameter.
Returns
Returns 0 if v was 0, otherwise returns 1.

Definition at line 601 of file cne_common.h.

◆ cne_log2_u32()

static uint32_t cne_log2_u32 ( uint32_t  v)
inlinestatic

Return the rounded-up log2 of a integer.

Parameters
vThe input parameter.
Returns
The rounded-up log2 of the input, or 0 if the input is 0.

Definition at line 619 of file cne_common.h.

◆ cne_fls_u32()

static int cne_fls_u32 ( uint32_t  x)
inlinestatic

Return the last (most-significant) bit set.

Note
The last (most significant) bit is at position 32.
cne_fls_u32(0) = 0, cne_fls_u32(1) = 1, cne_fls_u32(0x80000000) = 32
Parameters
xThe input parameter.
Returns
The last (most-significant) bit set, or 0 if the input is 0.

Definition at line 639 of file cne_common.h.

◆ cne_bsf64()

static int cne_bsf64 ( uint64_t  v)
inlinestatic

Searches the input parameter for the least significant set bit (starting from zero). If a least significant 1 bit is found, its bit index is returned. If the content of the input parameter is zero, then the content of the return value is undefined.

Parameters
vinput parameter, should not be zero.
Returns
least significant set bit in the input parameter.

Definition at line 656 of file cne_common.h.

◆ cne_bsf64_safe()

static int cne_bsf64_safe ( uint64_t  v,
uint32_t *  pos 
)
inlinestatic

Searches the input parameter for the least significant set bit (starting from zero). Safe version (checks for input parameter being zero).

Warning
pos must be a valid pointer. It is not checked!
Parameters
vThe input parameter.
posIf v was not 0, this value will contain position of least significant bit within the input parameter.
Returns
Returns 0 if v was 0, otherwise returns 1.

Definition at line 676 of file cne_common.h.

◆ cne_fls_u64()

static int cne_fls_u64 ( uint64_t  x)
inlinestatic

Return the last (most-significant) bit set.

Note
The last (most significant) bit is at position 64.
cne_fls_u64(0) = 0, cne_fls_u64(1) = 1, cne_fls_u64(0x8000000000000000) = 64
Parameters
xThe input parameter.
Returns
The last (most-significant) bit set, or 0 if the input is 0.

Definition at line 698 of file cne_common.h.

◆ cne_log2_u64()

static uint32_t cne_log2_u64 ( uint64_t  v)
inlinestatic

Return the rounded-up log2 of a 64-bit integer.

Parameters
vThe input parameter.
Returns
The rounded-up log2 of the input, or 0 if the input is 0.

Definition at line 712 of file cne_common.h.

◆ cne_str_to_size()

static uint64_t cne_str_to_size ( const char *  str)
inlinestatic

Converts a numeric string to the equivalent uint64_t value. As well as straight number conversion, also recognises the suffixes k, m and g for kilobytes, megabytes and gigabytes respectively.

If a negative number is passed in i.e. a string with the first non-black character being "-", zero is returned. Zero is also returned in the case of an error with the strtoull call in the function.

Parameters
strString containing number to convert.
Returns
Number.

Definition at line 796 of file cne_common.h.

Variable Documentation

◆ CNE_MARKER

__extension__ typedef void* CNE_MARKER[0]

Generic marker for any place in a structure.

Definition at line 385 of file cne_common.h.

◆ CNE_MARKER8

__extension__ typedef uint8_t CNE_MARKER8[0]

Marker for 1B alignment in a structure.

Definition at line 387 of file cne_common.h.

◆ CNE_MARKER16

__extension__ typedef uint16_t CNE_MARKER16[0]

Marker for 2B alignment in a structure.

Definition at line 389 of file cne_common.h.

◆ CNE_MARKER32

__extension__ typedef uint32_t CNE_MARKER32[0]

Marker for 4B alignment in a structure.

Definition at line 391 of file cne_common.h.

◆ CNE_MARKER64

__extension__ typedef uint64_t CNE_MARKER64[0]

Marker for 8B alignment in a structure.

Definition at line 393 of file cne_common.h.