NDN-DPDK
High-Speed Named Data Networking Forwarder
Loading...
Searching...
No Matches
common.h
Go to the documentation of this file.
1
6
7#ifndef NDNDPDK_CORE_COMMON_H
8#define NDNDPDK_CORE_COMMON_H
9
11
12#if __INTELLISENSE__
13// https://github.com/microsoft/vscode-cpptools/issues/4503
14#pragma diag_suppress 1094
15#endif
16
17#include <assert.h>
18#include <inttypes.h>
19#include <limits.h>
20#include <memory.h>
21#include <stdatomic.h>
22#include <stdbool.h>
23#include <stddef.h>
24#include <string.h>
25
26#define ALLOW_EXPERIMENTAL_API
27#include <rte_config.h>
28
29#include <rte_branch_prediction.h>
30#include <rte_common.h>
31
32#ifndef __BPF__
33
34#include <float.h>
35#include <math.h>
36#include <stdio.h>
37#include <stdlib.h>
38
39#include <urcu/list.h>
40
41#include <rte_bitops.h>
42#include <rte_byteorder.h>
43#include <rte_cycles.h>
44#include <rte_debug.h>
45#include <rte_errno.h>
46#include <rte_lcore_var.h>
47#include <rte_malloc.h>
48#include <rte_memcpy.h>
49
50#include <spdk/util.h>
51
52#ifdef NDEBUG
53#define NDNDPDK_ASSERT(x) \
54 do { \
55 if (__builtin_constant_p((x)) && !(x)) { \
56 __builtin_unreachable(); \
57 } \
58 } while (false)
59#else
60#define NDNDPDK_ASSERT(x) RTE_VERIFY((x))
61#endif
62
64#define LCORE_VAR_SAFE(handle) \
65 __extension__({ \
66 unsigned lc = rte_lcore_id(); \
67 RTE_LCORE_VAR_LCORE(lc == LCORE_ID_ANY ? RTE_MAX_LCORE - 1 : lc, handle); \
68 })
69
70#endif // __BPF__
71
72#define STATIC_ASSERT_FUNC_TYPE(typ, func) \
73 static_assert(__builtin_types_compatible_p(typ, typeof(&func)), "")
74
75#ifdef NDEBUG
76#define NULLize(x) RTE_SET_USED(x)
77#else
79#define NULLize(x) \
80 do { \
81 (x) = NULL; \
82 } while (false)
83#endif
84
85#ifdef NDNDPDK_POISON
86#define POISON_2_(x, size) memset(x, 0x99, size)
87#else
88#define POISON_2_(x, size) \
89 do { \
90 RTE_SET_USED(x); \
91 RTE_SET_USED(size); \
92 } while (false)
93#endif
94#define POISON_1_(x) POISON_2_((x), sizeof(*(x)))
95#define POISON_Arg3_(a1, a2, a3, ...) a3
96#define POISON_Choose_(...) POISON_Arg3_(__VA_ARGS__, POISON_2_, POISON_1_)
104#define POISON(...) POISON_Choose_(__VA_ARGS__)(__VA_ARGS__)
105
106#define CLAMP(x, lo, hi) RTE_MAX((lo), RTE_MIN((hi), (x)))
107
108#endif // NDNDPDK_CORE_COMMON_H