DPDK: Data Plane Development Kit

18.02.0-rc0
rte_common.h File Reference
#include <stdint.h>
#include <stdlib.h>
#include <ctype.h>
#include <errno.h>
#include <limits.h>

Go to the source code of this file.

Macros

#define RTE_STD_C11   __extension__
#define __rte_aligned(a)   __attribute__((__aligned__(a)))
#define __rte_packed   __attribute__((__packed__))
#define __rte_unused   __attribute__((__unused__))
#define RTE_SET_USED(x)   (void)(x)
#define RTE_INIT(func)   static void __attribute__((constructor, used)) func(void)
#define RTE_INIT_PRIO(func, prio)   static void __attribute__((constructor(prio), used)) func(void)
#define __rte_always_inline   inline __attribute__((always_inline))
#define __rte_noinline   __attribute__((noinline))
#define RTE_PTR_ADD(ptr, x)   ((void*)((uintptr_t)(ptr) + (x)))
#define RTE_PTR_SUB(ptr, x)   ((void*)((uintptr_t)ptr - (x)))
#define RTE_PTR_DIFF(ptr1, ptr2)   ((uintptr_t)(ptr1) - (uintptr_t)(ptr2))
#define RTE_PTR_ALIGN_FLOOR(ptr, align)   ((typeof(ptr))RTE_ALIGN_FLOOR((uintptr_t)ptr, align))
#define RTE_ALIGN_FLOOR(val, align)   (typeof(val))((val) & (~((typeof(val))((align) - 1))))
#define RTE_PTR_ALIGN_CEIL(ptr, align)   RTE_PTR_ALIGN_FLOOR((typeof(ptr))RTE_PTR_ADD(ptr, (align) - 1), align)
#define RTE_ALIGN_CEIL(val, align)   RTE_ALIGN_FLOOR(((val) + ((typeof(val)) (align) - 1)), align)
#define RTE_PTR_ALIGN(ptr, align)   RTE_PTR_ALIGN_CEIL(ptr, align)
#define RTE_ALIGN(val, align)   RTE_ALIGN_CEIL(val, align)
#define RTE_BUILD_BUG_ON(condition)   ((void)sizeof(char[1 - 2*!!(condition)]))
#define RTE_MIN(a, b)
#define RTE_MAX(a, b)
#define offsetof(TYPE, MEMBER)   __builtin_offsetof (TYPE, MEMBER)
#define container_of(ptr, type, member)
#define RTE_STR(x)   _RTE_STR(x)
#define RTE_FMT(fmt,...)   fmt "%.0s", __VA_ARGS__ ""
#define RTE_LEN2MASK(ln, tp)   ((tp)((uint64_t)-1 >> (sizeof(uint64_t) * CHAR_BIT - (ln))))
#define RTE_DIM(a)   (sizeof (a) / sizeof ((a)[0]))

Typedefs

typedef uint64_t unaligned_uint64_t

Functions

static int rte_is_aligned (void *ptr, unsigned align)
static int rte_is_power_of_2 (uint32_t n)
static uint32_t rte_align32pow2 (uint32_t x)
static uint64_t rte_align64pow2 (uint64_t v)
static uint32_t rte_bsf32 (uint32_t v)
static uint32_t rte_log2_u32 (uint32_t v)
static uint64_t rte_str_to_size (const char *str)
void rte_exit (int exit_code, const char *format,...)

Detailed Description

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

Definition in file rte_common.h.

Macro Definition Documentation

#define RTE_STD_C11   __extension__

C extension macro for environments lacking C11 features.

Definition at line 64 of file rte_common.h.

#define __rte_aligned (   a)    __attribute__((__aligned__(a)))

Force alignment

Examples:
examples/ipsec-secgw/ipsec-secgw.c.

Definition at line 88 of file rte_common.h.

#define __rte_packed   __attribute__((__packed__))

Force a structure to be packed

Definition at line 93 of file rte_common.h.

#define __rte_unused   __attribute__((__unused__))

short definition to mark a function parameter unused

Examples:
examples/ethtool/ethtool-app/ethapp.c, examples/ethtool/lib/rte_ethtool.c, examples/ip_fragmentation/main.c, examples/ip_pipeline/pipeline/pipeline_common_be.c, examples/ip_pipeline/pipeline/pipeline_common_fe.c, examples/ip_pipeline/pipeline/pipeline_firewall.c, examples/ip_pipeline/pipeline/pipeline_firewall_be.c, examples/ip_pipeline/pipeline/pipeline_flow_actions.c, examples/ip_pipeline/pipeline/pipeline_flow_actions_be.c, examples/ip_pipeline/pipeline/pipeline_flow_classification.c, examples/ip_pipeline/pipeline/pipeline_flow_classification_be.c, examples/ip_pipeline/pipeline/pipeline_master_be.c, examples/ip_pipeline/pipeline/pipeline_passthrough_be.c, examples/ip_pipeline/pipeline/pipeline_routing.c, examples/ip_pipeline/pipeline/pipeline_routing_be.c, examples/ip_pipeline/thread_fe.c, examples/ipsec-secgw/parser.c, examples/ipv4_multicast/main.c, examples/kni/main.c, examples/l2fwd-jobstats/main.c, examples/l2fwd-keepalive/main.c, examples/l2fwd-keepalive/shm.c, examples/l3fwd-power/main.c, examples/l3fwd/l3fwd_em.c, examples/l3fwd/l3fwd_lpm.c, examples/multi_process/client_server_mp/mp_server/main.c, examples/multi_process/symmetric_mp/main.c, examples/netmap_compat/bridge/bridge.c, examples/netmap_compat/lib/compat_netmap.c, examples/packet_ordering/main.c, examples/performance-thread/common/arch/arm64/ctx.c, examples/performance-thread/common/lthread_cond.c, examples/performance-thread/common/lthread_mutex.c, examples/performance-thread/l3fwd-thread/main.c, examples/rxtx_callbacks/main.c, examples/server_node_efd/server/main.c, examples/tep_termination/main.c, examples/vhost/main.c, examples/vhost_scsi/scsi.c, and examples/vhost_scsi/vhost_scsi.c.

Definition at line 103 of file rte_common.h.

#define RTE_SET_USED (   x)    (void)(x)

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

Examples:
examples/eventdev_pipeline_sw_pmd/main.c, examples/link_status_interrupt/main.c, and examples/service_cores/main.c.

Definition at line 109 of file rte_common.h.

#define RTE_INIT (   func)    static void __attribute__((constructor, used)) func(void)

Run function before main() with low priority.

The constructor will be run after prioritized constructors.

Parameters
funcConstructor function.
Examples:
examples/performance-thread/common/lthread_diag.c, examples/performance-thread/common/lthread_sched.c, examples/performance-thread/common/lthread_tls.c, and examples/performance-thread/pthread_shim/pthread_shim.c.

Definition at line 119 of file rte_common.h.

#define RTE_INIT_PRIO (   func,
  prio 
)    static void __attribute__((constructor(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 131 of file rte_common.h.

#define __rte_noinline   __attribute__((noinline))

Force a function to be noinlined

Definition at line 142 of file rte_common.h.

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

add a byte-value offset from a pointer

Examples:
examples/ipsec-secgw/esp.c, examples/ipsec-secgw/ipsec-secgw.c, and examples/ipsec-secgw/sa.c.

Definition at line 149 of file rte_common.h.

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

subtract a byte-value offset from a pointer

Definition at line 154 of file rte_common.h.

#define RTE_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 161 of file rte_common.h.

#define RTE_PTR_ALIGN_FLOOR (   ptr,
  align 
)    ((typeof(ptr))RTE_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 172 of file rte_common.h.

#define RTE_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.

Examples:
examples/performance-thread/l3fwd-thread/main.c.

Definition at line 181 of file rte_common.h.

#define RTE_PTR_ALIGN_CEIL (   ptr,
  align 
)    RTE_PTR_ALIGN_FLOOR((typeof(ptr))RTE_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 190 of file rte_common.h.

#define RTE_ALIGN_CEIL (   val,
  align 
)    RTE_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.

Examples:
examples/ipsec-secgw/esp.c, and examples/netmap_compat/lib/compat_netmap.c.

Definition at line 199 of file rte_common.h.

#define RTE_PTR_ALIGN (   ptr,
  align 
)    RTE_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 RTE_PTR_ALIGN_CEIL

Definition at line 209 of file rte_common.h.

#define RTE_ALIGN (   val,
  align 
)    RTE_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 RTE_ALIGN_CEIL

Definition at line 218 of file rte_common.h.

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

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

Definition at line 243 of file rte_common.h.

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

Macro to return the maximum of two numbers

Examples:
examples/ip_reassembly/main.c, examples/l2fwd-cat/cat.c, examples/vhost/main.c, examples/vmdq/main.c, and examples/vmdq_dcb/main.c.

Definition at line 327 of file rte_common.h.

#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)); \
})

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 390 of file rte_common.h.

#define RTE_STR (   x)    _RTE_STR(x)

Take a macro value and get a string version of it

Definition at line 400 of file rte_common.h.

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

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

Definition at line 407 of file rte_common.h.

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

Typedef Documentation

typedef uint64_t unaligned_uint64_t

Define GCC_VERSION

Definition at line 80 of file rte_common.h.

Function Documentation

static int rte_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 232 of file rte_common.h.

static int rte_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
Examples:
examples/ip_pipeline/config_check.c, and examples/ip_pipeline/pipeline/pipeline_passthrough_be.c.

Definition at line 262 of file rte_common.h.

static uint32_t rte_align32pow2 ( uint32_t  x)
inlinestatic

Aligns input parameter to the next power of 2

Parameters
xThe integer value to algin
Returns
Input parameter aligned to the next power of 2
Examples:
examples/ip_pipeline/pipeline/pipeline_flow_classification_be.c, examples/ip_pipeline/pipeline/pipeline_routing_be.c, and examples/netmap_compat/lib/compat_netmap.c.

Definition at line 277 of file rte_common.h.

static uint64_t rte_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

Definition at line 299 of file rte_common.h.

static uint32_t rte_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 348 of file rte_common.h.

static uint32_t rte_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 362 of file rte_common.h.

static uint64_t rte_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 433 of file rte_common.h.

void rte_exit ( int  exit_code,
const char *  format,
  ... 
)

Function to terminate the application immediately, printing an error message and returning the exit_code back to the shell.

This function never returns

Parameters
exit_codeThe exit code to be returned by the application
formatThe format string to be used for printing the message. This can include printf format characters which will be expanded using any further parameters to the function.
Examples:
examples/bond/main.c, examples/distributor/main.c, examples/ethtool/ethtool-app/main.c, examples/eventdev_pipeline_sw_pmd/main.c, examples/flow_classify/flow_classify.c, examples/flow_filtering/main.c, examples/ip_fragmentation/main.c, examples/ip_pipeline/config_parse.c, examples/ip_pipeline/config_parse_tm.c, examples/ip_pipeline/pipeline/pipeline_master_be.c, examples/ip_reassembly/main.c, examples/ipsec-secgw/ipsec-secgw.c, examples/ipsec-secgw/rt.c, examples/ipsec-secgw/sa.c, examples/ipsec-secgw/sp4.c, examples/ipsec-secgw/sp6.c, examples/ipv4_multicast/main.c, examples/kni/main.c, examples/l2fwd-cat/l2fwd-cat.c, examples/l2fwd-crypto/main.c, examples/l2fwd-jobstats/main.c, examples/l2fwd-keepalive/main.c, examples/l2fwd/main.c, examples/l3fwd-acl/main.c, examples/l3fwd-power/main.c, examples/l3fwd-vf/main.c, examples/l3fwd/l3fwd_em.c, examples/l3fwd/l3fwd_lpm.c, examples/l3fwd/main.c, examples/link_status_interrupt/main.c, examples/multi_process/client_server_mp/mp_client/client.c, examples/multi_process/client_server_mp/mp_server/init.c, examples/multi_process/l2fwd_fork/main.c, examples/multi_process/simple_mp/main.c, examples/multi_process/symmetric_mp/main.c, examples/netmap_compat/bridge/bridge.c, examples/packet_ordering/main.c, examples/performance-thread/l3fwd-thread/main.c, examples/performance-thread/pthread_shim/main.c, examples/ptpclient/ptpclient.c, examples/qos_meter/main.c, examples/qos_sched/cfg_file.c, examples/qos_sched/init.c, examples/quota_watermark/qw/args.c, examples/quota_watermark/qw/init.c, examples/quota_watermark/qw/main.c, examples/quota_watermark/qwctl/qwctl.c, examples/rxtx_callbacks/main.c, examples/server_node_efd/node/node.c, examples/server_node_efd/server/init.c, examples/service_cores/main.c, examples/skeleton/basicfwd.c, examples/tep_termination/main.c, examples/tep_termination/vxlan_setup.c, examples/vhost/main.c, examples/vhost_scsi/vhost_scsi.c, examples/vm_power_manager/main.c, examples/vmdq/main.c, and examples/vmdq_dcb/main.c.