aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/dpdk
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2018-04-16 00:18:34 +0200
committerDave Barach <openvpp@barachs.net>2018-04-25 15:36:04 +0000
commitc576622667199db906efa3110ad25e552b3a0890 (patch)
treed6ffda4bf9b096f9ee1759d57e79d36dc51f27d0 /src/plugins/dpdk
parent4a6d02337b9058182172f19df894ad2e18e6ac68 (diff)
dpdk: complete rework of the dpdk-input node
Change-Id: If174d189de40e6f9ffae99997bba93a2519d9fda Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'src/plugins/dpdk')
-rw-r--r--src/plugins/dpdk/device/common.c2
-rw-r--r--src/plugins/dpdk/device/device.c6
-rw-r--r--src/plugins/dpdk/device/dpdk.h28
-rw-r--r--src/plugins/dpdk/device/dpdk_priv.h6
-rw-r--r--src/plugins/dpdk/device/format.c12
-rwxr-xr-xsrc/plugins/dpdk/device/init.c28
-rw-r--r--src/plugins/dpdk/device/node.c939
7 files changed, 556 insertions, 465 deletions
diff --git a/src/plugins/dpdk/device/common.c b/src/plugins/dpdk/device/common.c
index 77a7dee8a1b..1b043496256 100644
--- a/src/plugins/dpdk/device/common.c
+++ b/src/plugins/dpdk/device/common.c
@@ -43,7 +43,7 @@ dpdk_device_setup (dpdk_device_t * xd)
{
dpdk_main_t *dm = &dpdk_main;
vnet_main_t *vnm = vnet_get_main ();
- vnet_sw_interface_t *sw = vnet_get_sw_interface (vnm, xd->vlib_sw_if_index);
+ vnet_sw_interface_t *sw = vnet_get_sw_interface (vnm, xd->sw_if_index);
vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, xd->hw_if_index);
int rv;
int j;
diff --git a/src/plugins/dpdk/device/device.c b/src/plugins/dpdk/device/device.c
index c20a01b84eb..9ae3f9cbe6e 100644
--- a/src/plugins/dpdk/device/device.c
+++ b/src/plugins/dpdk/device/device.c
@@ -117,7 +117,7 @@ dpdk_tx_trace_buffer (dpdk_main_t * dm,
u16 queue_id, u32 buffer_index, vlib_buffer_t * buffer)
{
vlib_main_t *vm = vlib_get_main ();
- dpdk_tx_dma_trace_t *t0;
+ dpdk_tx_trace_t *t0;
struct rte_mbuf *mb;
mb = rte_mbuf_from_vlib_buffer (buffer);
@@ -608,7 +608,7 @@ CLIB_MULTIARCH_FN (dpdk_interface_tx) (vlib_main_t * vm,
cm = vec_elt_at_index (vnm->interface_main.sw_if_counters,
VNET_INTERFACE_COUNTER_TX_ERROR);
- vlib_increment_simple_counter (cm, my_cpu, xd->vlib_sw_if_index,
+ vlib_increment_simple_counter (cm, my_cpu, xd->sw_if_index,
n_packets);
vlib_error_count (vm, node->node_index, DPDK_TX_FUNC_ERROR_PKT_DROP,
@@ -787,7 +787,7 @@ VNET_DEVICE_CLASS (dpdk_device_class) = {
.tx_function_error_strings = dpdk_tx_func_error_strings,
.format_device_name = format_dpdk_device_name,
.format_device = format_dpdk_device,
- .format_tx_trace = format_dpdk_tx_dma_trace,
+ .format_tx_trace = format_dpdk_tx_trace,
.clear_counters = dpdk_clear_hw_interface_counters,
.admin_up_down_function = dpdk_interface_admin_up_down,
.subif_add_del_function = dpdk_subif_add_del_function,
diff --git a/src/plugins/dpdk/device/dpdk.h b/src/plugins/dpdk/device/dpdk.h
index 896617bd55f..bd442bd97af 100644
--- a/src/plugins/dpdk/device/dpdk.h
+++ b/src/plugins/dpdk/device/dpdk.h
@@ -181,14 +181,13 @@ typedef struct
dpdk_portid_t device_index;
u32 hw_if_index;
- u32 vlib_sw_if_index;
+ u32 sw_if_index;
/* next node index if we decide to steal the rx graph arc */
u32 per_interface_next_index;
/* dpdk rte_mbuf rx and tx vectors, VLIB_FRAME_SIZE */
struct rte_mbuf ***tx_vectors; /* one per worker thread */
- struct rte_mbuf ***rx_vectors;
dpdk_pmd_t pmd:8;
i8 cpu_socket;
@@ -350,19 +349,30 @@ typedef struct
extern dpdk_config_main_t dpdk_config_main;
+#define DPDK_RX_BURST_SZ VLIB_FRAME_SIZE
+
+typedef struct
+{
+ CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
+ struct rte_mbuf *mbufs[DPDK_RX_BURST_SZ];
+ u32 buffers[DPDK_RX_BURST_SZ];
+ u16 next[DPDK_RX_BURST_SZ];
+ u16 etype[DPDK_RX_BURST_SZ];
+ u8 flags[DPDK_RX_BURST_SZ];
+ vlib_buffer_t buffer_template;
+} dpdk_per_thread_data_t;
+
typedef struct
{
/* Devices */
dpdk_device_t *devices;
dpdk_device_and_queue_t **devices_by_hqos_cpu;
+ dpdk_per_thread_data_t *per_thread_data;
/* per-thread recycle lists */
u32 **recycle;
- /* per-thread buffer templates */
- vlib_buffer_t *buffer_templates;
-
/* buffer flags template, configurable to enable/disable tcp / udp cksum */
u32 buffer_flags_template;
@@ -416,7 +426,7 @@ typedef struct
/* Copy of VLIB buffer; packet data stored in pre_data. */
vlib_buffer_t buffer;
u8 data[256]; /* First 256 data bytes, used for hexdump */
-} dpdk_tx_dma_trace_t;
+} dpdk_tx_trace_t;
typedef struct
{
@@ -426,7 +436,7 @@ typedef struct
struct rte_mbuf mb;
vlib_buffer_t buffer; /* Copy of VLIB buffer; pkt data stored in pre_data. */
u8 data[256]; /* First 256 data bytes, used for hexdump */
-} dpdk_rx_dma_trace_t;
+} dpdk_rx_trace_t;
void dpdk_device_setup (dpdk_device_t * xd);
void dpdk_device_start (dpdk_device_t * xd);
@@ -467,8 +477,8 @@ void dpdk_update_link_state (dpdk_device_t * xd, f64 now);
format_function_t format_dpdk_device_name;
format_function_t format_dpdk_device;
format_function_t format_dpdk_device_errors;
-format_function_t format_dpdk_tx_dma_trace;
-format_function_t format_dpdk_rx_dma_trace;
+format_function_t format_dpdk_tx_trace;
+format_function_t format_dpdk_rx_trace;
format_function_t format_dpdk_rte_mbuf;
format_function_t format_dpdk_rx_rte_mbuf;
unformat_function_t unformat_dpdk_log_level;
diff --git a/src/plugins/dpdk/device/dpdk_priv.h b/src/plugins/dpdk/device/dpdk_priv.h
index 7c4091c1be5..cbc116e8dc2 100644
--- a/src/plugins/dpdk/device/dpdk_priv.h
+++ b/src/plugins/dpdk/device/dpdk_priv.h
@@ -106,7 +106,7 @@ dpdk_update_counters (dpdk_device_t * xd, f64 now)
cm = vec_elt_at_index (vnm->interface_main.sw_if_counters,
VNET_INTERFACE_COUNTER_RX_NO_BUF);
- vlib_increment_simple_counter (cm, thread_index, xd->vlib_sw_if_index,
+ vlib_increment_simple_counter (cm, thread_index, xd->sw_if_index,
xd->stats.rx_nombuf -
xd->last_stats.rx_nombuf);
}
@@ -117,7 +117,7 @@ dpdk_update_counters (dpdk_device_t * xd, f64 now)
cm = vec_elt_at_index (vnm->interface_main.sw_if_counters,
VNET_INTERFACE_COUNTER_RX_MISS);
- vlib_increment_simple_counter (cm, thread_index, xd->vlib_sw_if_index,
+ vlib_increment_simple_counter (cm, thread_index, xd->sw_if_index,
xd->stats.imissed -
xd->last_stats.imissed);
}
@@ -129,7 +129,7 @@ dpdk_update_counters (dpdk_device_t * xd, f64 now)
cm = vec_elt_at_index (vnm->interface_main.sw_if_counters,
VNET_INTERFACE_COUNTER_RX_ERROR);
- vlib_increment_simple_counter (cm, thread_index, xd->vlib_sw_if_index,
+ vlib_increment_simple_counter (cm, thread_index, xd->sw_if_index,
rxerrors - last_rxerrors);
}
diff --git a/src/plugins/dpdk/device/format.c b/src/plugins/dpdk/device/format.c
index af3ce63aed5..38090244f27 100644
--- a/src/plugins/dpdk/device/format.c
+++ b/src/plugins/dpdk/device/format.c
@@ -608,16 +608,16 @@ format_dpdk_device (u8 * s, va_list * args)
}
u8 *
-format_dpdk_tx_dma_trace (u8 * s, va_list * va)
+format_dpdk_tx_trace (u8 * s, va_list * va)
{
CLIB_UNUSED (vlib_main_t * vm) = va_arg (*va, vlib_main_t *);
CLIB_UNUSED (vlib_node_t * node) = va_arg (*va, vlib_node_t *);
CLIB_UNUSED (vnet_main_t * vnm) = vnet_get_main ();
- dpdk_tx_dma_trace_t *t = va_arg (*va, dpdk_tx_dma_trace_t *);
+ dpdk_tx_trace_t *t = va_arg (*va, dpdk_tx_trace_t *);
dpdk_main_t *dm = &dpdk_main;
dpdk_device_t *xd = vec_elt_at_index (dm->devices, t->device_index);
u32 indent = format_get_indent (s);
- vnet_sw_interface_t *sw = vnet_get_sw_interface (vnm, xd->vlib_sw_if_index);
+ vnet_sw_interface_t *sw = vnet_get_sw_interface (vnm, xd->sw_if_index);
s = format (s, "%U tx queue %d",
format_vnet_sw_interface_name, vnm, sw, t->queue_index);
@@ -638,17 +638,17 @@ format_dpdk_tx_dma_trace (u8 * s, va_list * va)
}
u8 *
-format_dpdk_rx_dma_trace (u8 * s, va_list * va)
+format_dpdk_rx_trace (u8 * s, va_list * va)
{
CLIB_UNUSED (vlib_main_t * vm) = va_arg (*va, vlib_main_t *);
CLIB_UNUSED (vlib_node_t * node) = va_arg (*va, vlib_node_t *);
CLIB_UNUSED (vnet_main_t * vnm) = vnet_get_main ();
- dpdk_rx_dma_trace_t *t = va_arg (*va, dpdk_rx_dma_trace_t *);
+ dpdk_rx_trace_t *t = va_arg (*va, dpdk_rx_trace_t *);
dpdk_main_t *dm = &dpdk_main;
dpdk_device_t *xd = vec_elt_at_index (dm->devices, t->device_index);
format_function_t *f;
u32 indent = format_get_indent (s);
- vnet_sw_interface_t *sw = vnet_get_sw_interface (vnm, xd->vlib_sw_if_index);
+ vnet_sw_interface_t *sw = vnet_get_sw_interface (vnm, xd->sw_if_index);
s = format (s, "%U rx queue %d",
format_vnet_sw_interface_name, vnm, sw, t->queue_index);
diff --git a/src/plugins/dpdk/device/init.c b/src/plugins/dpdk/device/init.c
index 17ae826e8b1..9ed3efdd49d 100755
--- a/src/plugins/dpdk/device/init.c
+++ b/src/plugins/dpdk/device/init.c
@@ -239,17 +239,17 @@ dpdk_lib_init (dpdk_main_t * dm)
| VNET_BUFFER_F_L4_CHECKSUM_COMPUTED);
/* vlib_buffer_t template */
- vec_validate_aligned (dm->buffer_templates, tm->n_vlib_mains - 1,
+ vec_validate_aligned (dm->per_thread_data, tm->n_vlib_mains - 1,
CLIB_CACHE_LINE_BYTES);
for (i = 0; i < tm->n_vlib_mains; i++)
{
vlib_buffer_free_list_t *fl;
- vlib_buffer_t *bt = vec_elt_at_index (dm->buffer_templates, i);
+ dpdk_per_thread_data_t *ptd = vec_elt_at_index (dm->per_thread_data, i);
fl = vlib_buffer_get_free_list (vm,
VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX);
- vlib_buffer_init_for_free_list (bt, fl);
- bt->flags = dm->buffer_flags_template;
- vnet_buffer (bt)->sw_if_index[VLIB_TX] = (u32) ~ 0;
+ vlib_buffer_init_for_free_list (&ptd->buffer_template, fl);
+ ptd->buffer_template.flags = dm->buffer_flags_template;
+ vnet_buffer (&ptd->buffer_template)->sw_if_index[VLIB_TX] = (u32) ~ 0;
}
for (i = 0; i < nports; i++)
@@ -546,15 +546,6 @@ dpdk_lib_init (dpdk_main_t * dm)
vec_reset_length (xd->tx_vectors[j]);
}
- vec_validate_aligned (xd->rx_vectors, xd->rx_q_used,
- CLIB_CACHE_LINE_BYTES);
- for (j = 0; j < xd->rx_q_used; j++)
- {
- vec_validate_aligned (xd->rx_vectors[j], VLIB_FRAME_SIZE - 1,
- CLIB_CACHE_LINE_BYTES);
- vec_reset_length (xd->rx_vectors[j]);
- }
-
/* count the number of descriptors used for this device */
nb_desc += xd->nb_rx_desc + xd->nb_tx_desc * xd->tx_q_used;
@@ -621,7 +612,7 @@ dpdk_lib_init (dpdk_main_t * dm)
xd->port_conf.rxmode.max_rx_pkt_len = max_rx_frame;
sw = vnet_get_hw_sw_interface (dm->vnet_main, xd->hw_if_index);
- xd->vlib_sw_if_index = sw->sw_if_index;
+ xd->sw_if_index = sw->sw_if_index;
vnet_hw_interface_set_input_node (dm->vnet_main, xd->hw_if_index,
dpdk_input_node.index);
@@ -1398,7 +1389,7 @@ dpdk_update_link_state (dpdk_device_t * xd, f64 now)
u8 new_link_state;
} *ed;
ed = ELOG_DATA (&vm->elog_main, e);
- ed->sw_if_index = xd->vlib_sw_if_index;
+ ed->sw_if_index = xd->sw_if_index;
ed->admin_up = (xd->flags & DPDK_DEVICE_FLAG_ADMIN_UP) != 0;
ed->old_link_state = (u8)
vnet_hw_interface_is_link_up (vnm, xd->hw_if_index);
@@ -1494,7 +1485,7 @@ dpdk_update_link_state (dpdk_device_t * xd, f64 now)
u32 flags;
} *ed;
ed = ELOG_DATA (&vm->elog_main, e);
- ed->sw_if_index = xd->vlib_sw_if_index;
+ ed->sw_if_index = xd->sw_if_index;
ed->flags = hw_flags;
}
vnet_hw_interface_set_flags (vnm, xd->hw_if_index, hw_flags);
@@ -1607,8 +1598,7 @@ dpdk_process (vlib_main_t * vm, vlib_node_runtime_t * rt, vlib_frame_t * f)
(bhi->bond_info, sdev->hw_if_index, 1);
/* Set MACs and slave link flags on slave interface */
shi = vnet_get_hw_interface (vnm, sdev->hw_if_index);
- ssi = vnet_get_sw_interface
- (vnm, sdev->vlib_sw_if_index);
+ ssi = vnet_get_sw_interface (vnm, sdev->sw_if_index);
sei = pool_elt_at_index
(em->interfaces, shi->hw_instance);
shi->bond_info = VNET_HW_INTERFACE_BOND_INFO_SLAVE;
diff --git a/src/plugins/dpdk/device/node.c b/src/plugins/dpdk/device/node.c
index e1674dcd88d..c2d66ae6f82 100644
--- a/src/plugins/dpdk/device/node.c
+++ b/src/plugins/dpdk/device/node.c
@@ -36,92 +36,46 @@ static char *dpdk_error_strings[] = {
};
#endif
-always_inline u32
-dpdk_rx_next_from_etype (struct rte_mbuf *mb)
-{
- ethernet_header_t *h = rte_pktmbuf_mtod (mb, ethernet_header_t *);
- if (PREDICT_TRUE (h->type == clib_host_to_net_u16 (ETHERNET_TYPE_IP4)))
- {
- if (PREDICT_TRUE ((mb->ol_flags & PKT_RX_IP_CKSUM_GOOD) != 0))
- return VNET_DEVICE_INPUT_NEXT_IP4_NCS_INPUT;
- else
- return VNET_DEVICE_INPUT_NEXT_IP4_INPUT;
- }
- else if (PREDICT_TRUE (h->type == clib_host_to_net_u16 (ETHERNET_TYPE_IP6)))
- return VNET_DEVICE_INPUT_NEXT_IP6_INPUT;
- else
- if (PREDICT_TRUE (h->type == clib_host_to_net_u16 (ETHERNET_TYPE_MPLS)))
- return VNET_DEVICE_INPUT_NEXT_MPLS_INPUT;
- else
- return VNET_DEVICE_INPUT_NEXT_ETHERNET_INPUT;
-}
+STATIC_ASSERT (VNET_DEVICE_INPUT_NEXT_IP4_INPUT - 1 ==
+ VNET_DEVICE_INPUT_NEXT_IP4_NCS_INPUT,
+ "IP4_INPUT must follow IP4_NCS_INPUT");
-always_inline void
-dpdk_rx_error_from_mb (struct rte_mbuf *mb, u32 * next, u8 * error)
+enum
{
- if (mb->ol_flags & PKT_RX_IP_CKSUM_BAD)
- {
- *error = DPDK_ERROR_IP_CHECKSUM_ERROR;
- *next = VNET_DEVICE_INPUT_NEXT_DROP;
- }
- else
- *error = DPDK_ERROR_NONE;
-}
-
-static_always_inline void
-dpdk_add_trace (vlib_main_t * vm, vlib_node_runtime_t * node, u32 next,
- dpdk_device_t * xd, u16 queue_id,
- vlib_buffer_t * b, struct rte_mbuf *mb)
-{
- vlib_trace_buffer (vm, node, next, b, /* follow_chain */ 0);
-
- dpdk_rx_dma_trace_t *t0 = vlib_add_trace (vm, node, b, sizeof t0[0]);
- t0->queue_index = queue_id;
- t0->device_index = xd->device_index;
- t0->buffer_index = vlib_get_buffer_index (vm, b);
+ DPDK_RX_F_CKSUM_GOOD = 7,
+ DPDK_RX_F_CKSUM_BAD = 4,
+ DPDK_RX_F_FDIR = 2,
+};
- clib_memcpy (&t0->mb, mb, sizeof t0->mb);
- clib_memcpy (&t0->buffer, b, sizeof b[0] - sizeof b->pre_data);
- clib_memcpy (t0->buffer.pre_data, b->data, sizeof t0->buffer.pre_data);
- clib_memcpy (&t0->data, mb->buf_addr + mb->data_off, sizeof t0->data);
-}
+/* currently we are just copying bit positions from DPDK, but that
+ might change in future, in case we strart to be interested in something
+ stored in upper bytes. Curently we store only lower byte for perf reasons */
+STATIC_ASSERT (1 << DPDK_RX_F_CKSUM_GOOD == PKT_RX_IP_CKSUM_GOOD, "");
+STATIC_ASSERT (1 << DPDK_RX_F_CKSUM_BAD == PKT_RX_IP_CKSUM_BAD, "");
+STATIC_ASSERT (1 << DPDK_RX_F_FDIR == PKT_RX_FDIR, "");
+STATIC_ASSERT ((PKT_RX_IP_CKSUM_GOOD | PKT_RX_IP_CKSUM_BAD | PKT_RX_FDIR) <
+ 256, "dpdk flags not un lower byte, fix needed");
-static inline u32
-dpdk_rx_burst (dpdk_main_t * dm, dpdk_device_t * xd, u16 queue_id)
+always_inline u32
+dpdk_rx_next (vlib_node_runtime_t * node, u16 etype, u8 flags)
{
- u32 n_buffers;
- u32 n_left;
- u32 n_this_chunk;
-
- n_left = VLIB_FRAME_SIZE;
- n_buffers = 0;
-
- if (PREDICT_TRUE (xd->flags & DPDK_DEVICE_FLAG_PMD))
+ if (PREDICT_TRUE (etype == clib_host_to_net_u16 (ETHERNET_TYPE_IP4)))
{
- while (n_left)
- {
- n_this_chunk = rte_eth_rx_burst (xd->device_index, queue_id,
- xd->rx_vectors[queue_id] +
- n_buffers, n_left);
- n_buffers += n_this_chunk;
- n_left -= n_this_chunk;
-
- /* Empirically, DPDK r1.8 produces vectors w/ 32 or fewer elts */
- if (n_this_chunk < 32)
- break;
- }
+ /* keep it branchless */
+ u32 is_good = (flags >> DPDK_RX_F_CKSUM_GOOD) & 1;
+ return VNET_DEVICE_INPUT_NEXT_IP4_INPUT - is_good;
}
+ else if (PREDICT_TRUE (etype == clib_host_to_net_u16 (ETHERNET_TYPE_IP6)))
+ return VNET_DEVICE_INPUT_NEXT_IP6_INPUT;
+ else if (PREDICT_TRUE (etype == clib_host_to_net_u16 (ETHERNET_TYPE_MPLS)))
+ return VNET_DEVICE_INPUT_NEXT_MPLS_INPUT;
else
- {
- ASSERT (0);
- }
-
- return n_buffers;
+ return VNET_DEVICE_INPUT_NEXT_ETHERNET_INPUT;
}
-static_always_inline void
+static_always_inline uword
dpdk_process_subseq_segs (vlib_main_t * vm, vlib_buffer_t * b,
- struct rte_mbuf *mb, vlib_buffer_free_list_t * fl)
+ struct rte_mbuf * mb, vlib_buffer_free_list_t * fl)
{
u8 nb_seg = 1;
struct rte_mbuf *mb_seg = 0;
@@ -130,7 +84,7 @@ dpdk_process_subseq_segs (vlib_main_t * vm, vlib_buffer_t * b,
b_chain = b;
if (mb->nb_segs < 2)
- return;
+ return 0;
b->flags |= VLIB_BUFFER_TOTAL_LENGTH_VALID;
b->total_length_not_including_first_buffer = 0;
@@ -162,346 +116,44 @@ dpdk_process_subseq_segs (vlib_main_t * vm, vlib_buffer_t * b,
mb_seg = mb_seg->next;
nb_seg++;
}
+ return b->total_length_not_including_first_buffer;
}
static_always_inline void
-dpdk_prefetch_buffer (struct rte_mbuf *mb)
+dpdk_prefetch_mbuf_x4 (struct rte_mbuf *mb[])
{
- vlib_buffer_t *b = vlib_buffer_from_rte_mbuf (mb);
- CLIB_PREFETCH (mb, CLIB_CACHE_LINE_BYTES, LOAD);
- CLIB_PREFETCH (b, CLIB_CACHE_LINE_BYTES, STORE);
+ CLIB_PREFETCH (mb[0], CLIB_CACHE_LINE_BYTES, LOAD);
+ CLIB_PREFETCH (mb[1], CLIB_CACHE_LINE_BYTES, LOAD);
+ CLIB_PREFETCH (mb[2], CLIB_CACHE_LINE_BYTES, LOAD);
+ CLIB_PREFETCH (mb[3], CLIB_CACHE_LINE_BYTES, LOAD);
}
static_always_inline void
-dpdk_prefetch_ethertype (struct rte_mbuf *mb)
+dpdk_prefetch_buffer_x4 (struct rte_mbuf *mb[])
{
- CLIB_PREFETCH (mb->buf_addr + mb->data_off +
- STRUCT_OFFSET_OF (ethernet_header_t, type),
- CLIB_CACHE_LINE_BYTES, LOAD);
+ vlib_buffer_t *b;
+ b = vlib_buffer_from_rte_mbuf (mb[0]);
+ CLIB_PREFETCH (b, CLIB_CACHE_LINE_BYTES, LOAD);
+ b = vlib_buffer_from_rte_mbuf (mb[1]);
+ CLIB_PREFETCH (b, CLIB_CACHE_LINE_BYTES, LOAD);
+ b = vlib_buffer_from_rte_mbuf (mb[2]);
+ CLIB_PREFETCH (b, CLIB_CACHE_LINE_BYTES, LOAD);
+ b = vlib_buffer_from_rte_mbuf (mb[3]);
+ CLIB_PREFETCH (b, CLIB_CACHE_LINE_BYTES, LOAD);
}
-/*
- * This function is used when there are no worker threads.
- * The main thread performs IO and forwards the packets.
- */
-static_always_inline u32
-dpdk_device_input (dpdk_main_t * dm, dpdk_device_t * xd,
- vlib_node_runtime_t * node, u32 thread_index, u16 queue_id,
- int maybe_multiseg, u32 n_trace)
-{
- u32 n_buffers;
- u32 next_index = VNET_DEVICE_INPUT_NEXT_ETHERNET_INPUT;
- u32 n_left_to_next, *to_next;
- u32 mb_index;
- vlib_main_t *vm = vlib_get_main ();
- uword n_rx_bytes = 0;
- vlib_buffer_free_list_t *fl;
- vlib_buffer_t *bt = vec_elt_at_index (dm->buffer_templates, thread_index);
-
- if ((xd->flags & DPDK_DEVICE_FLAG_ADMIN_UP) == 0)
- return 0;
-
- n_buffers = dpdk_rx_burst (dm, xd, queue_id);
-
- if (n_buffers == 0)
- {
- return 0;
- }
-
- fl = vlib_buffer_get_free_list (vm, VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX);
-
- /* Update buffer template */
- vnet_buffer (bt)->sw_if_index[VLIB_RX] = xd->vlib_sw_if_index;
- bt->error = node->errors[DPDK_ERROR_NONE];
- /* as DPDK is allocating empty buffers from mempool provided before interface
- start for each queue, it is safe to store this in the template */
- bt->buffer_pool_index = xd->buffer_pool_for_queue[queue_id];
-
- mb_index = 0;
-
- while (n_buffers > 0)
- {
- vlib_buffer_t *b0, *b1, *b2, *b3;
- u32 bi0, next0;
- u32 bi1, next1;
- u32 bi2, next2;
- u32 bi3, next3;
- u8 error0, error1, error2, error3;
- i16 offset0, offset1, offset2, offset3;
- u64 or_ol_flags;
-
- vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
-
- while (n_buffers >= 12 && n_left_to_next >= 4)
- {
- struct rte_mbuf *mb0, *mb1, *mb2, *mb3;
-
- /* prefetches are interleaved with the rest of the code to reduce
- pressure on L1 cache */
- dpdk_prefetch_buffer (xd->rx_vectors[queue_id][mb_index + 8]);
- dpdk_prefetch_ethertype (xd->rx_vectors[queue_id][mb_index + 4]);
-
- mb0 = xd->rx_vectors[queue_id][mb_index];
- mb1 = xd->rx_vectors[queue_id][mb_index + 1];
- mb2 = xd->rx_vectors[queue_id][mb_index + 2];
- mb3 = xd->rx_vectors[queue_id][mb_index + 3];
-
- ASSERT (mb0);
- ASSERT (mb1);
- ASSERT (mb2);
- ASSERT (mb3);
-
- if (maybe_multiseg)
- {
- if (PREDICT_FALSE (mb0->nb_segs > 1))
- dpdk_prefetch_buffer (mb0->next);
- if (PREDICT_FALSE (mb1->nb_segs > 1))
- dpdk_prefetch_buffer (mb1->next);
- if (PREDICT_FALSE (mb2->nb_segs > 1))
- dpdk_prefetch_buffer (mb2->next);
- if (PREDICT_FALSE (mb3->nb_segs > 1))
- dpdk_prefetch_buffer (mb3->next);
- }
-
- b0 = vlib_buffer_from_rte_mbuf (mb0);
- b1 = vlib_buffer_from_rte_mbuf (mb1);
- b2 = vlib_buffer_from_rte_mbuf (mb2);
- b3 = vlib_buffer_from_rte_mbuf (mb3);
-
- dpdk_prefetch_buffer (xd->rx_vectors[queue_id][mb_index + 9]);
- dpdk_prefetch_ethertype (xd->rx_vectors[queue_id][mb_index + 5]);
-
- clib_memcpy64_x4 (b0, b1, b2, b3, bt);
-
- dpdk_prefetch_buffer (xd->rx_vectors[queue_id][mb_index + 10]);
- dpdk_prefetch_ethertype (xd->rx_vectors[queue_id][mb_index + 6]);
-
- bi0 = vlib_get_buffer_index (vm, b0);
- bi1 = vlib_get_buffer_index (vm, b1);
- bi2 = vlib_get_buffer_index (vm, b2);
- bi3 = vlib_get_buffer_index (vm, b3);
-
- to_next[0] = bi0;
- to_next[1] = bi1;
- to_next[2] = bi2;
- to_next[3] = bi3;
- to_next += 4;
- n_left_to_next -= 4;
-
- if (PREDICT_FALSE (xd->per_interface_next_index != ~0))
- {
- next0 = next1 = next2 = next3 = xd->per_interface_next_index;
- }
- else
- {
- next0 = dpdk_rx_next_from_etype (mb0);
- next1 = dpdk_rx_next_from_etype (mb1);
- next2 = dpdk_rx_next_from_etype (mb2);
- next3 = dpdk_rx_next_from_etype (mb3);
-
- or_ol_flags = (mb0->ol_flags | mb1->ol_flags |
- mb2->ol_flags | mb3->ol_flags);
- if (PREDICT_FALSE (or_ol_flags & PKT_RX_IP_CKSUM_BAD))
- {
- dpdk_rx_error_from_mb (mb0, &next0, &error0);
- dpdk_rx_error_from_mb (mb1, &next1, &error1);
- dpdk_rx_error_from_mb (mb2, &next2, &error2);
- dpdk_rx_error_from_mb (mb3, &next3, &error3);
- b0->error = node->errors[error0];
- b1->error = node->errors[error1];
- b2->error = node->errors[error2];
- b3->error = node->errors[error3];
- }
- }
-
- dpdk_prefetch_buffer (xd->rx_vectors[queue_id][mb_index + 11]);
- dpdk_prefetch_ethertype (xd->rx_vectors[queue_id][mb_index + 7]);
-
- offset0 = device_input_next_node_advance[next0];
- b0->current_data = mb0->data_off + offset0 - RTE_PKTMBUF_HEADROOM;
- b0->flags |= device_input_next_node_flags[next0];
- vnet_buffer (b0)->l3_hdr_offset = b0->current_data;
- vnet_buffer (b0)->l2_hdr_offset =
- mb0->data_off - RTE_PKTMBUF_HEADROOM;
- b0->current_length = mb0->data_len - offset0;
- n_rx_bytes += mb0->pkt_len;
-
- offset1 = device_input_next_node_advance[next1];
- b1->current_data = mb1->data_off + offset1 - RTE_PKTMBUF_HEADROOM;
- b1->flags |= device_input_next_node_flags[next1];
- vnet_buffer (b1)->l3_hdr_offset = b1->current_data;
- vnet_buffer (b1)->l2_hdr_offset =
- mb1->data_off - RTE_PKTMBUF_HEADROOM;
- b1->current_length = mb1->data_len - offset1;
- n_rx_bytes += mb1->pkt_len;
-
- offset2 = device_input_next_node_advance[next2];
- b2->current_data = mb2->data_off + offset2 - RTE_PKTMBUF_HEADROOM;
- b2->flags |= device_input_next_node_flags[next2];
- vnet_buffer (b2)->l3_hdr_offset = b2->current_data;
- vnet_buffer (b2)->l2_hdr_offset =
- mb2->data_off - RTE_PKTMBUF_HEADROOM;
- b2->current_length = mb2->data_len - offset2;
- n_rx_bytes += mb2->pkt_len;
-
- offset3 = device_input_next_node_advance[next3];
- b3->current_data = mb3->data_off + offset3 - RTE_PKTMBUF_HEADROOM;
- b3->flags |= device_input_next_node_flags[next3];
- vnet_buffer (b3)->l3_hdr_offset = b3->current_data;
- vnet_buffer (b3)->l2_hdr_offset =
- mb3->data_off - RTE_PKTMBUF_HEADROOM;
- b3->current_length = mb3->data_len - offset3;
- n_rx_bytes += mb3->pkt_len;
-
-
- /* Process subsequent segments of multi-segment packets */
- if (maybe_multiseg)
- {
- dpdk_process_subseq_segs (vm, b0, mb0, fl);
- dpdk_process_subseq_segs (vm, b1, mb1, fl);
- dpdk_process_subseq_segs (vm, b2, mb2, fl);
- dpdk_process_subseq_segs (vm, b3, mb3, fl);
- }
-
- /*
- * Turn this on if you run into
- * "bad monkey" contexts, and you want to know exactly
- * which nodes they've visited... See main.c...
- */
- VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b0);
- VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b1);
- VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b2);
- VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b3);
-
- /* Do we have any driver RX features configured on the interface? */
- vnet_feature_start_device_input_x4 (xd->vlib_sw_if_index,
- &next0, &next1, &next2, &next3,
- b0, b1, b2, b3);
-
- vlib_validate_buffer_enqueue_x4 (vm, node, next_index,
- to_next, n_left_to_next,
- bi0, bi1, bi2, bi3,
- next0, next1, next2, next3);
- n_buffers -= 4;
- mb_index += 4;
-
- if (n_trace)
- {
- dpdk_add_trace (vm, node, next0, xd, queue_id, b0, mb0);
- n_trace--;
- }
- if (n_trace)
- {
- dpdk_add_trace (vm, node, next1, xd, queue_id, b1, mb1);
- n_trace--;
- }
- if (n_trace)
- {
- dpdk_add_trace (vm, node, next2, xd, queue_id, b2, mb2);
- n_trace--;
- }
- if (n_trace)
- {
- dpdk_add_trace (vm, node, next3, xd, queue_id, b3, mb3);
- n_trace--;
- }
- }
- while (n_buffers > 0 && n_left_to_next > 0)
- {
- struct rte_mbuf *mb0 = xd->rx_vectors[queue_id][mb_index];
-
- if (PREDICT_TRUE (n_buffers > 3))
- {
- dpdk_prefetch_buffer (xd->rx_vectors[queue_id][mb_index + 2]);
- dpdk_prefetch_ethertype (xd->rx_vectors[queue_id]
- [mb_index + 1]);
- }
-
- ASSERT (mb0);
-
- b0 = vlib_buffer_from_rte_mbuf (mb0);
-
- /* Prefetch one next segment if it exists. */
- if (PREDICT_FALSE (mb0->nb_segs > 1))
- dpdk_prefetch_buffer (mb0->next);
-
- clib_memcpy (b0, bt, CLIB_CACHE_LINE_BYTES);
-
- bi0 = vlib_get_buffer_index (vm, b0);
-
- to_next[0] = bi0;
- to_next++;
- n_left_to_next--;
-
- if (PREDICT_FALSE (xd->per_interface_next_index != ~0))
- next0 = xd->per_interface_next_index;
- else
- {
- next0 = dpdk_rx_next_from_etype (mb0);
-
- dpdk_rx_error_from_mb (mb0, &next0, &error0);
- b0->error = node->errors[error0];
- }
-
- offset0 = device_input_next_node_advance[next0];
- b0->current_data = mb0->data_off + offset0 - RTE_PKTMBUF_HEADROOM;
- b0->flags |= device_input_next_node_flags[next0];
- vnet_buffer (b0)->l3_hdr_offset = b0->current_data;
- vnet_buffer (b0)->l2_hdr_offset =
- mb0->data_off - RTE_PKTMBUF_HEADROOM;
- b0->current_length = mb0->data_len - offset0;
- n_rx_bytes += mb0->pkt_len;
-
- /* Process subsequent segments of multi-segment packets */
- dpdk_process_subseq_segs (vm, b0, mb0, fl);
-
- /*
- * Turn this on if you run into
- * "bad monkey" contexts, and you want to know exactly
- * which nodes they've visited... See main.c...
- */
- VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b0);
-
- /* Do we have any driver RX features configured on the interface? */
- vnet_feature_start_device_input_x1 (xd->vlib_sw_if_index, &next0,
- b0);
-
- vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
- to_next, n_left_to_next,
- bi0, next0);
- n_buffers--;
- mb_index++;
-
- if (n_trace)
- {
- dpdk_add_trace (vm, node, next0, xd, queue_id, b0, mb0);
- n_trace--;
- }
- }
- vlib_put_next_frame (vm, node, next_index, n_left_to_next);
- }
-
- vlib_increment_combined_counter
- (vnet_get_main ()->interface_main.combined_sw_if_counters
- + VNET_INTERFACE_COUNTER_RX,
- thread_index, xd->vlib_sw_if_index, mb_index, n_rx_bytes);
-
- vnet_device_increment_rx_packets (thread_index, mb_index);
-
- return mb_index;
-}
-
-static_always_inline u32
-dpdk_device_input_mseg (dpdk_main_t * dm, dpdk_device_t * xd,
- vlib_node_runtime_t * node, u32 thread_index,
- u16 queue_id, u32 n_trace)
+static_always_inline void
+dpdk_prefetch_buffer_data_x4 (struct rte_mbuf *mb[])
{
- if (xd->flags & DPDK_DEVICE_FLAG_MAYBE_MULTISEG)
- return dpdk_device_input (dm, xd, node, thread_index, queue_id,
- /* maybe_multiseg */ 1, n_trace);
- else
- return dpdk_device_input (dm, xd, node, thread_index, queue_id,
- /* maybe_multiseg */ 0, n_trace);
+ vlib_buffer_t *b;
+ b = vlib_buffer_from_rte_mbuf (mb[0]);
+ CLIB_PREFETCH (b->data, CLIB_CACHE_LINE_BYTES, LOAD);
+ b = vlib_buffer_from_rte_mbuf (mb[1]);
+ CLIB_PREFETCH (b->data, CLIB_CACHE_LINE_BYTES, LOAD);
+ b = vlib_buffer_from_rte_mbuf (mb[2]);
+ CLIB_PREFETCH (b->data, CLIB_CACHE_LINE_BYTES, LOAD);
+ b = vlib_buffer_from_rte_mbuf (mb[3]);
+ CLIB_PREFETCH (b->data, CLIB_CACHE_LINE_BYTES, LOAD);
}
static inline void
@@ -527,8 +179,8 @@ poll_rate_limit (dpdk_main_t * dm)
This is the main DPDK input node: across each assigned interface,
call rte_eth_rx_burst(...) or similar to obtain a vector of
- packets to process. Handle early packet discard. Derive @c
- vlib_buffer_t metadata from <code>struct rte_mbuf</code> metadata,
+ packets to process. Derive @c vlib_buffer_t metadata from
+ <code>struct rte_mbuf</code> metadata,
Depending on the resulting metadata: adjust <code>b->current_data,
b->current_length </code> and dispatch directly to
ip4-input-no-checksum, or ip6-input. Trace the packet if required.
@@ -542,8 +194,6 @@ poll_rate_limit (dpdk_main_t * dm)
@em Uses:
- <code>struct rte_mbuf mb->ol_flags</code>
- PKT_RX_IP_CKSUM_BAD
- - <code> RTE_ETH_IS_xxx_HDR(mb->packet_type) </code>
- - packet classification result
@em Sets:
- <code>b->error</code> if the packet is to be dropped immediately
@@ -563,7 +213,458 @@ poll_rate_limit (dpdk_main_t * dm)
<code>xd->per_interface_next_index</code>
*/
-uword
+static_always_inline void
+dpdk_mbuf_to_buffer_index_x4 (vlib_main_t * vm, struct rte_mbuf **mb,
+ u32 * buffers)
+{
+#ifdef CLIB_HAVE_VEC256
+ vlib_buffer_main_t *bm = &buffer_main;
+ u64x4 v = *(u64x4 *) mb;
+ u32x8 v2, mask = { 0, 2, 4, 6, 1, 3, 5, 7 };
+
+ /* load 4 pointers into 256-bit register */
+ v = u64x4_load_unaligned (mb);
+
+ /* vlib_buffer_t is straight after rte_mbuf so advance all 4
+ pointers for size of rte_mbuf */
+ v += u64x4_splat (sizeof (struct rte_mbuf));
+
+ /* calculate 4 buffer indices in paralled */
+ v = (v - u64x4_splat (bm->buffer_mem_start)) >> CLIB_LOG2_CACHE_LINE_BYTES;
+
+ /* permute 256-bit register so lower u32s of each buffer index are
+ * placed into lower 128-bits */
+ v2 = u32x8_permute ((u32x8) v, mask);
+
+ /* extract lower 128-bits and save them to the array of buffer indices */
+ u32x4_store_unaligned (u32x8_extract_lo (v2), buffers);
+#else
+ /* equivalent non-nector implementation */
+ buffers[0] = vlib_get_buffer_index (vm, vlib_buffer_from_rte_mbuf (mb[0]));
+ buffers[1] = vlib_get_buffer_index (vm, vlib_buffer_from_rte_mbuf (mb[1]));
+ buffers[2] = vlib_get_buffer_index (vm, vlib_buffer_from_rte_mbuf (mb[2]));
+ buffers[3] = vlib_get_buffer_index (vm, vlib_buffer_from_rte_mbuf (mb[3]));
+#endif
+}
+
+static_always_inline u8
+dpdk_ol_flags_extract (struct rte_mbuf **mb, u8 * flags, int count)
+{
+ u8 rv = 0;
+ int i;
+ for (i = 0; i < count; i++)
+ {
+ /* all flags we are interested in are in lower 8 bits but
+ that might change */
+ flags[i] = (u8) mb[i]->ol_flags;
+ rv |= flags[i];
+ }
+ return rv;
+}
+
+static_always_inline uword
+dpdk_process_rx_burst (vlib_main_t * vm, dpdk_per_thread_data_t * ptd,
+ uword n_rx_packets, int maybe_multiseg, u8 * or_flagsp)
+{
+ u32 n_left = n_rx_packets;
+ vlib_buffer_t *b[4];
+ vlib_buffer_free_list_t *fl;
+ struct rte_mbuf **mb = ptd->mbufs;
+ uword n_bytes = 0;
+ i16 off;
+ u8 *flags, or_flags = 0;
+ u16 *next;
+
+ fl = vlib_buffer_get_free_list (vm, VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX);
+
+ mb = ptd->mbufs;
+ flags = ptd->flags;
+ next = ptd->next;
+
+ while (n_left >= 8)
+ {
+ CLIB_PREFETCH (mb + 8, CLIB_CACHE_LINE_BYTES, LOAD);
+
+ dpdk_prefetch_buffer_x4 (mb + 4);
+
+ b[0] = vlib_buffer_from_rte_mbuf (mb[0]);
+ b[1] = vlib_buffer_from_rte_mbuf (mb[1]);
+ b[2] = vlib_buffer_from_rte_mbuf (mb[2]);
+ b[3] = vlib_buffer_from_rte_mbuf (mb[3]);
+
+ clib_memcpy64_x4 (b[0], b[1], b[2], b[3], &ptd->buffer_template);
+
+ dpdk_prefetch_mbuf_x4 (mb + 4);
+
+ or_flags |= dpdk_ol_flags_extract (mb, flags, 4);
+ flags += 4;
+
+ /* we temporary store relative offset of ethertype into next[x]
+ so we can prefetch and get it faster later */
+
+ off = mb[0]->data_off;
+ next[0] = off + STRUCT_OFFSET_OF (ethernet_header_t, type);
+ off -= RTE_PKTMBUF_HEADROOM;
+ vnet_buffer (b[0])->l2_hdr_offset = off;
+ b[0]->current_data = off;
+
+ off = mb[0]->data_off;
+ next[1] = off + STRUCT_OFFSET_OF (ethernet_header_t, type);
+ off -= RTE_PKTMBUF_HEADROOM;
+ vnet_buffer (b[1])->l2_hdr_offset = off;
+ b[1]->current_data = off;
+
+ off = mb[0]->data_off;
+ next[2] = off + STRUCT_OFFSET_OF (ethernet_header_t, type);
+ off -= RTE_PKTMBUF_HEADROOM;
+ vnet_buffer (b[2])->l2_hdr_offset = off;
+ b[2]->current_data = off;
+
+ off = mb[0]->data_off;
+ next[3] = off + STRUCT_OFFSET_OF (ethernet_header_t, type);
+ off -= RTE_PKTMBUF_HEADROOM;
+ vnet_buffer (b[3])->l2_hdr_offset = off;
+ b[3]->current_data = off;
+
+ b[0]->current_length = mb[0]->data_len;
+ b[1]->current_length = mb[1]->data_len;
+ b[2]->current_length = mb[2]->data_len;
+ b[3]->current_length = mb[3]->data_len;
+
+ n_bytes += mb[0]->data_len;
+ n_bytes += mb[1]->data_len;
+ n_bytes += mb[2]->data_len;
+ n_bytes += mb[3]->data_len;
+
+ if (maybe_multiseg)
+ {
+ n_bytes += dpdk_process_subseq_segs (vm, b[0], mb[0], fl);
+ n_bytes += dpdk_process_subseq_segs (vm, b[1], mb[1], fl);
+ n_bytes += dpdk_process_subseq_segs (vm, b[2], mb[2], fl);
+ n_bytes += dpdk_process_subseq_segs (vm, b[3], mb[3], fl);
+ }
+
+ VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b[0]);
+ VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b[1]);
+ VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b[2]);
+ VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b[3]);
+
+ /* next */
+ mb += 4;
+ n_left -= 4;
+ next += 4;
+ }
+
+ while (n_left)
+ {
+ b[0] = vlib_buffer_from_rte_mbuf (mb[0]);
+ clib_memcpy (b[0], &ptd->buffer_template, 64);
+ or_flags |= dpdk_ol_flags_extract (mb, flags, 1);
+ flags += 1;
+
+ off = mb[0]->data_off;
+ next[0] = off + STRUCT_OFFSET_OF (ethernet_header_t, type);
+ off -= RTE_PKTMBUF_HEADROOM;
+ vnet_buffer (b[0])->l2_hdr_offset = off;
+ b[0]->current_data = off;
+ b[0]->current_length = mb[0]->data_len;
+ n_bytes += mb[0]->data_len;
+ if (maybe_multiseg)
+ n_bytes += dpdk_process_subseq_segs (vm, b[0], mb[0], fl);
+ VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b[0]);
+
+ /* next */
+ mb += 1;
+ n_left -= 1;
+ next += 1;
+ }
+
+ *or_flagsp = or_flags;
+ return n_bytes;
+}
+
+static_always_inline void
+dpdk_set_next_from_etype (vlib_main_t * vm, vlib_node_runtime_t * node,
+ dpdk_per_thread_data_t * ptd, uword n_rx_packets)
+{
+ vlib_buffer_t *b[4];
+ i16 adv[4];
+ u16 etype[4];
+ struct rte_mbuf **mb = ptd->mbufs;
+ u8 *flags = ptd->flags;
+ u16 *next = ptd->next;
+ u32 n_left = n_rx_packets;
+
+ while (n_left >= 12)
+ {
+ dpdk_prefetch_buffer_data_x4 (mb + 8);
+ dpdk_prefetch_buffer_x4 (mb + 8);
+
+ b[0] = vlib_buffer_from_rte_mbuf (mb[0]);
+ b[1] = vlib_buffer_from_rte_mbuf (mb[1]);
+ b[2] = vlib_buffer_from_rte_mbuf (mb[2]);
+ b[3] = vlib_buffer_from_rte_mbuf (mb[3]);
+ etype[0] = *(u16 *) ((u8 *) mb[0] + next[0] + sizeof (vlib_buffer_t));
+ etype[1] = *(u16 *) ((u8 *) mb[1] + next[1] + sizeof (vlib_buffer_t));
+ etype[2] = *(u16 *) ((u8 *) mb[2] + next[2] + sizeof (vlib_buffer_t));
+ etype[3] = *(u16 *) ((u8 *) mb[3] + next[3] + sizeof (vlib_buffer_t));
+ next[0] = dpdk_rx_next (node, etype[0], flags[0]);
+ next[1] = dpdk_rx_next (node, etype[1], flags[1]);
+ next[2] = dpdk_rx_next (node, etype[2], flags[2]);
+ next[3] = dpdk_rx_next (node, etype[3], flags[3]);
+ adv[0] = device_input_next_node_advance[next[0]];
+ adv[1] = device_input_next_node_advance[next[1]];
+ adv[2] = device_input_next_node_advance[next[2]];
+ adv[3] = device_input_next_node_advance[next[3]];
+ b[0]->current_data += adv[0];
+ b[1]->current_data += adv[1];
+ b[2]->current_data += adv[2];
+ b[3]->current_data += adv[3];
+ b[0]->current_length -= adv[0];
+ b[1]->current_length -= adv[1];
+ b[2]->current_length -= adv[2];
+ b[3]->current_length -= adv[3];
+
+ /* next */
+ next += 4;
+ mb += 4;
+ n_left -= 4;
+ flags += 4;
+ }
+
+ while (n_left)
+ {
+ b[0] = vlib_buffer_from_rte_mbuf (mb[0]);
+ next[0] = *(u16 *) ((u8 *) mb[0] + next[0] + sizeof (vlib_buffer_t));
+ next[0] = dpdk_rx_next (node, next[0], flags[0]);
+ adv[0] = device_input_next_node_advance[next[0]];
+ b[0]->current_data += adv[0];
+ b[0]->current_length -= adv[0];
+
+ /* next */
+ next += 1;
+ mb += 1;
+ n_left -= 1;
+ flags += 1;
+ }
+}
+
+static_always_inline u32
+dpdk_device_input (vlib_main_t * vm, dpdk_main_t * dm, dpdk_device_t * xd,
+ vlib_node_runtime_t * node, u32 thread_index, u16 queue_id)
+{
+ uword n_rx_packets = 0, n_rx_bytes;
+ u32 n_left, n_trace;
+ u32 *buffers;
+ u32 next_index = VNET_DEVICE_INPUT_NEXT_ETHERNET_INPUT;
+ struct rte_mbuf **mb;
+ vlib_buffer_t *b0;
+ int known_next = 0;
+ u16 *next;
+ u8 or_flags;
+ u32 n;
+
+ dpdk_per_thread_data_t *ptd = vec_elt_at_index (dm->per_thread_data,
+ thread_index);
+ vlib_buffer_t *bt = &ptd->buffer_template;
+
+ if ((xd->flags & DPDK_DEVICE_FLAG_ADMIN_UP) == 0)
+ return 0;
+
+ /* get up to DPDK_RX_BURST_SZ buffers from PMD */
+ while (n_rx_packets < DPDK_RX_BURST_SZ)
+ {
+ n = rte_eth_rx_burst (xd->device_index, queue_id,
+ ptd->mbufs + n_rx_packets,
+ DPDK_RX_BURST_SZ - n_rx_packets);
+ n_rx_packets += n;
+
+ if (n < 32)
+ break;
+ }
+
+ if (n_rx_packets == 0)
+ return 0;
+
+ /* Update buffer template */
+ vnet_buffer (bt)->sw_if_index[VLIB_RX] = xd->sw_if_index;
+ bt->error = node->errors[DPDK_ERROR_NONE];
+ /* as DPDK is allocating empty buffers from mempool provided before interface
+ start for each queue, it is safe to store this in the template */
+ bt->buffer_pool_index = xd->buffer_pool_for_queue[queue_id];
+
+ /* receive burst of packets from DPDK PMD */
+ if (PREDICT_FALSE (xd->per_interface_next_index != ~0))
+ {
+ known_next = 1;
+ next_index = xd->per_interface_next_index;
+ }
+
+ /* as all packets belong to thr same interface feature arc lookup
+ can be don once and result stored in the buffer template */
+ if (PREDICT_FALSE (vnet_device_input_have_features (xd->sw_if_index)))
+ {
+ vnet_feature_start_device_input_x1 (xd->sw_if_index, &next_index, bt);
+ known_next = 1;
+ }
+
+ if (xd->flags & DPDK_DEVICE_FLAG_MAYBE_MULTISEG)
+ n_rx_bytes = dpdk_process_rx_burst (vm, ptd, n_rx_packets, 1, &or_flags);
+ else
+ n_rx_bytes = dpdk_process_rx_burst (vm, ptd, n_rx_packets, 0, &or_flags);
+
+ if (PREDICT_FALSE (known_next))
+ {
+ for (n = 0; n < n_rx_packets; n++)
+ ptd->next[n] = next_index;
+
+ bt->feature_arc_index = 0;
+ bt->current_config_index = 0;
+ }
+ else
+ dpdk_set_next_from_etype (vm, node, ptd, n_rx_packets);
+
+ /* is at least one packet marked as ip4 checksum bad? */
+ if (PREDICT_FALSE (or_flags & (1 << DPDK_RX_F_CKSUM_BAD)))
+ for (n = 0; n < n_rx_packets; n++)
+ {
+ if ((ptd->flags[n] & (1 << DPDK_RX_F_CKSUM_BAD)) == 0)
+ continue;
+ if (ptd->next[n] != VNET_DEVICE_INPUT_NEXT_IP4_INPUT)
+ continue;
+
+ b0 = vlib_buffer_from_rte_mbuf (ptd->mbufs[n]);
+ b0->error = node->errors[DPDK_ERROR_IP_CHECKSUM_ERROR];
+ ptd->next[n] = VNET_DEVICE_INPUT_NEXT_DROP;
+ }
+
+ /* enqueue buffers to the next node */
+ n_left = n_rx_packets;
+ next = ptd->next;
+ buffers = ptd->buffers;
+ mb = ptd->mbufs;
+ while (n_left)
+ {
+ u32 n_left_to_next;
+ u32 *to_next;
+ vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
+#ifdef CLIB_HAVE_VEC256
+ while (n_left >= 16 && n_left_to_next >= 16)
+ {
+ u16x16 next16 = u16x16_load_unaligned (next);
+ if (u16x16_is_all_equal (next16, next_index))
+ {
+ dpdk_mbuf_to_buffer_index_x4 (vm, mb, buffers);
+ dpdk_mbuf_to_buffer_index_x4 (vm, mb + 4, buffers + 4);
+ dpdk_mbuf_to_buffer_index_x4 (vm, mb + 8, buffers + 8);
+ dpdk_mbuf_to_buffer_index_x4 (vm, mb + 12, buffers + 12);
+ clib_memcpy (to_next, buffers, 16 * sizeof (u32));
+ to_next += 16;
+ n_left_to_next -= 16;
+ buffers += 16;
+ n_left -= 16;
+ next += 16;
+ mb += 16;
+ }
+ else
+ {
+ dpdk_mbuf_to_buffer_index_x4 (vm, mb, buffers);
+ clib_memcpy (to_next, buffers, 4 * sizeof (u32));
+ to_next += 4;
+ n_left_to_next -= 4;
+
+ vlib_validate_buffer_enqueue_x4 (vm, node, next_index, to_next,
+ n_left_to_next, buffers[0],
+ buffers[1], buffers[2],
+ buffers[3], next[0], next[1],
+ next[2], next[3]);
+ /* next */
+ buffers += 4;
+ n_left -= 4;
+ next += 4;
+ mb += 4;
+ }
+ }
+#endif
+ while (n_left >= 4 && n_left_to_next >= 4)
+ {
+ dpdk_mbuf_to_buffer_index_x4 (vm, mb, buffers);
+ clib_memcpy (to_next, buffers, 4 * sizeof (u32));
+ to_next += 4;
+ n_left_to_next -= 4;
+
+ vlib_validate_buffer_enqueue_x4 (vm, node, next_index, to_next,
+ n_left_to_next, buffers[0],
+ buffers[1], buffers[2], buffers[3],
+ next[0], next[1], next[2],
+ next[3]);
+ /* next */
+ buffers += 4;
+ n_left -= 4;
+ next += 4;
+ mb += 4;
+ }
+ while (n_left && n_left_to_next)
+ {
+ to_next[0] = buffers[0] =
+ vlib_get_buffer_index (vm, vlib_buffer_from_rte_mbuf (mb[0]));
+ to_next += 1;
+ n_left_to_next -= 1;
+ vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
+ n_left_to_next, buffers[0],
+ next[0]);
+ /* next */
+ buffers += 1;
+ n_left -= 1;
+ next += 1;
+ mb += 1;
+ }
+ vlib_put_next_frame (vm, node, next_index, n_left_to_next);
+ }
+
+ /* packet trace if enabled */
+ if ((n_trace = vlib_get_trace_count (vm, node)))
+ {
+ n_left = n_rx_packets;
+ buffers = ptd->buffers;
+ mb = ptd->mbufs;
+ next = ptd->next;
+ while (n_trace && n_left)
+ {
+ b0 = vlib_get_buffer (vm, buffers[0]);
+ vlib_trace_buffer (vm, node, next[0], b0, /* follow_chain */ 0);
+
+ dpdk_rx_trace_t *t0 = vlib_add_trace (vm, node, b0, sizeof t0[0]);
+ t0->queue_index = queue_id;
+ t0->device_index = xd->device_index;
+ t0->buffer_index = vlib_get_buffer_index (vm, b0);
+
+ clib_memcpy (&t0->mb, mb[0], sizeof t0->mb);
+ clib_memcpy (&t0->buffer, b0, sizeof b0[0] - sizeof b0->pre_data);
+ clib_memcpy (t0->buffer.pre_data, b0->data,
+ sizeof t0->buffer.pre_data);
+ clib_memcpy (&t0->data, mb[0]->buf_addr + mb[0]->data_off,
+ sizeof t0->data);
+ n_trace--;
+ n_left--;
+ buffers++;
+ mb++;
+ next++;
+ }
+ vlib_set_trace_count (vm, node, n_trace);
+ }
+
+ vlib_increment_combined_counter
+ (vnet_get_main ()->interface_main.combined_sw_if_counters
+ + VNET_INTERFACE_COUNTER_RX, thread_index, xd->sw_if_index,
+ n_rx_packets, n_rx_bytes);
+
+ vnet_device_increment_rx_packets (thread_index, n_rx_packets);
+
+ return n_rx_packets;
+}
+
+uword CLIB_CPU_OPTIMIZED
CLIB_MULTIARCH_FN (dpdk_input) (vlib_main_t * vm, vlib_node_runtime_t * node,
vlib_frame_t * f)
{
@@ -582,19 +683,9 @@ CLIB_MULTIARCH_FN (dpdk_input) (vlib_main_t * vm, vlib_node_runtime_t * node,
{
xd = vec_elt_at_index(dm->devices, dq->dev_instance);
if (PREDICT_FALSE (xd->flags & DPDK_DEVICE_FLAG_BOND_SLAVE))
- continue; /* Do not poll slave to a bonded interface */
- u32 n_trace = vlib_get_trace_count (vm, node);
- if (PREDICT_TRUE(n_trace == 0))
- n_rx_packets += dpdk_device_input_mseg (dm, xd, node, thread_index,
- dq->queue_id, 0);
- else
- {
- u32 n_tr_packets = dpdk_device_input_mseg (dm, xd, node, thread_index,
- dq->queue_id, n_trace);
- n_rx_packets += n_tr_packets;
- vlib_set_trace_count (vm, node,
- n_trace - clib_min(n_trace, n_tr_packets));
- }
+ continue; /* Do not poll slave to a bonded interface */
+ n_rx_packets += dpdk_device_input (vm, dm, xd, node, thread_index,
+ dq->queue_id);
}
/* *INDENT-ON* */
@@ -615,7 +706,7 @@ VLIB_REGISTER_NODE (dpdk_input_node) = {
.state = VLIB_NODE_STATE_DISABLED,
.format_buffer = format_ethernet_header_with_length,
- .format_trace = format_dpdk_rx_dma_trace,
+ .format_trace = format_dpdk_rx_trace,
.n_errors = DPDK_N_ERROR,
.error_strings = dpdk_error_strings,