FD.io VPP  v18.04-17-g3a0d853
Vector Packet Processing
dpdk_priv.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #define rte_mbuf_from_vlib_buffer(x) (((struct rte_mbuf *)x) - 1)
17 #define vlib_buffer_from_rte_mbuf(x) ((vlib_buffer_t *)(x+1))
18 
19 #define DPDK_NB_RX_DESC_DEFAULT 1024
20 #define DPDK_NB_TX_DESC_DEFAULT 1024
21 #define DPDK_NB_RX_DESC_VIRTIO 256
22 #define DPDK_NB_TX_DESC_VIRTIO 256
23 
24 #define I40E_DEV_ID_SFP_XL710 0x1572
25 #define I40E_DEV_ID_QSFP_A 0x1583
26 #define I40E_DEV_ID_QSFP_B 0x1584
27 #define I40E_DEV_ID_QSFP_C 0x1585
28 #define I40E_DEV_ID_10G_BASE_T 0x1586
29 #define I40E_DEV_ID_VF 0x154C
30 
31 /* These args appear by themselves */
32 #define foreach_eal_double_hyphen_predicate_arg \
33 _(no-shconf) \
34 _(no-hpet) \
35 _(no-huge) \
36 _(vmware-tsc-map)
37 
38 #define foreach_eal_single_hyphen_mandatory_arg \
39 _(coremask, c) \
40 _(nchannels, n) \
41 
42 #define foreach_eal_single_hyphen_arg \
43 _(blacklist, b) \
44 _(mem-alloc-request, m) \
45 _(force-ranks, r)
46 
47 /* These args are preceeded by "--" and followed by a single string */
48 #define foreach_eal_double_hyphen_arg \
49 _(huge-dir) \
50 _(proc-type) \
51 _(file-prefix) \
52 _(vdev)
53 
54 typedef struct
55 {
56  /* must be first */
57  struct rte_pktmbuf_pool_private mbp_priv;
60 
61 
62 static inline void
64 {
65  if (!(xd->flags & DPDK_DEVICE_FLAG_ADMIN_UP))
66  return;
67  int len;
68  if ((len = rte_eth_xstats_get (xd->device_index, NULL, 0)) > 0)
69  {
70  vec_validate (xd->xstats, len - 1);
71  vec_validate (xd->last_cleared_xstats, len - 1);
72 
73  len =
74  rte_eth_xstats_get (xd->device_index, xd->xstats,
75  vec_len (xd->xstats));
76 
77  ASSERT (vec_len (xd->xstats) == len);
78  ASSERT (vec_len (xd->last_cleared_xstats) == len);
79 
80  _vec_len (xd->xstats) = len;
81  _vec_len (xd->last_cleared_xstats) = len;
82 
83  }
84 }
85 
86 
87 static inline void
89 {
91  vnet_main_t *vnm = vnet_get_main ();
92  u32 thread_index = vlib_get_thread_index ();
93  u64 rxerrors, last_rxerrors;
94 
95  /* only update counters for PMD interfaces */
96  if ((xd->flags & DPDK_DEVICE_FLAG_PMD) == 0)
97  return;
98 
99  xd->time_last_stats_update = now ? now : xd->time_last_stats_update;
100  clib_memcpy (&xd->last_stats, &xd->stats, sizeof (xd->last_stats));
101  rte_eth_stats_get (xd->device_index, &xd->stats);
102 
103  /* maybe bump interface rx no buffer counter */
104  if (PREDICT_FALSE (xd->stats.rx_nombuf != xd->last_stats.rx_nombuf))
105  {
108 
109  vlib_increment_simple_counter (cm, thread_index, xd->vlib_sw_if_index,
110  xd->stats.rx_nombuf -
111  xd->last_stats.rx_nombuf);
112  }
113 
114  /* missed pkt counter */
115  if (PREDICT_FALSE (xd->stats.imissed != xd->last_stats.imissed))
116  {
119 
120  vlib_increment_simple_counter (cm, thread_index, xd->vlib_sw_if_index,
121  xd->stats.imissed -
122  xd->last_stats.imissed);
123  }
124  rxerrors = xd->stats.ierrors;
125  last_rxerrors = xd->last_stats.ierrors;
126 
127  if (PREDICT_FALSE (rxerrors != last_rxerrors))
128  {
131 
132  vlib_increment_simple_counter (cm, thread_index, xd->vlib_sw_if_index,
133  rxerrors - last_rxerrors);
134  }
135 
136  dpdk_get_xstats (xd);
137 }
138 
139 /*
140  * fd.io coding-style-patch-verification: ON
141  *
142  * Local Variables:
143  * eval: (c-set-style "gnu")
144  * End:
145  */
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
Definition: vec.h:434
vnet_main_t * vnet_get_main(void)
Definition: misc.c:47
struct rte_eth_stats last_stats
Definition: dpdk.h:226
vnet_interface_main_t interface_main
Definition: vnet.h:56
#define NULL
Definition: clib.h:55
u16 flags
Definition: dpdk.h:181
static void vlib_increment_simple_counter(vlib_simple_counter_main_t *cm, u32 thread_index, u32 index, u64 increment)
Increment a simple counter.
Definition: counter.h:78
struct rte_eth_xstat * last_cleared_xstats
Definition: dpdk.h:229
#define DPDK_DEVICE_FLAG_PMD
Definition: dpdk.h:184
struct rte_eth_stats stats
Definition: dpdk.h:225
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
unsigned long u64
Definition: types.h:89
A collection of simple counters.
Definition: counter.h:58
static void dpdk_get_xstats(dpdk_device_t *xd)
Definition: dpdk_priv.h:63
f64 time_last_stats_update
Definition: dpdk.h:230
u32 vlib_sw_if_index
Definition: dpdk.h:169
#define PREDICT_FALSE(x)
Definition: clib.h:105
vlib_simple_counter_main_t * sw_if_counters
Definition: interface.h:717
#define DPDK_DEVICE_FLAG_ADMIN_UP
Definition: dpdk.h:182
static_always_inline uword vlib_get_thread_index(void)
Definition: threads.h:221
static void dpdk_update_counters(dpdk_device_t *xd, f64 now)
Definition: dpdk_priv.h:88
#define clib_memcpy(a, b, c)
Definition: string.h:75
struct rte_eth_xstat * xstats
Definition: dpdk.h:228
#define ASSERT(truth)
unsigned int u32
Definition: types.h:88
dpdk_portid_t device_index
Definition: dpdk.h:166
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
double f64
Definition: types.h:142
unsigned char u8
Definition: types.h:56