dpdk-input node packet trace intermittent on IP forwading path
[vpp.git] / src / plugins / dpdk / device / node.c
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 #include <vnet/vnet.h>
16 #include <vppinfra/vec.h>
17 #include <vppinfra/error.h>
18 #include <vppinfra/format.h>
19 #include <vppinfra/xxhash.h>
20
21 #include <vnet/ethernet/ethernet.h>
22 #include <dpdk/device/dpdk.h>
23 #include <vnet/classify/vnet_classify.h>
24 #include <vnet/mpls/packet.h>
25 #include <vnet/handoff.h>
26 #include <vnet/devices/devices.h>
27 #include <vnet/feature/feature.h>
28
29 #include <dpdk/device/dpdk_priv.h>
30
31 #ifndef CLIB_MULTIARCH_VARIANT
32 static char *dpdk_error_strings[] = {
33 #define _(n,s) s,
34   foreach_dpdk_error
35 #undef _
36 };
37 #endif
38
39 always_inline u32
40 dpdk_rx_next_from_etype (struct rte_mbuf *mb)
41 {
42   ethernet_header_t *h = rte_pktmbuf_mtod (mb, ethernet_header_t *);
43   if (PREDICT_TRUE (h->type == clib_host_to_net_u16 (ETHERNET_TYPE_IP4)))
44     {
45       if (PREDICT_TRUE ((mb->ol_flags & PKT_RX_IP_CKSUM_GOOD) != 0))
46         return VNET_DEVICE_INPUT_NEXT_IP4_NCS_INPUT;
47       else
48         return VNET_DEVICE_INPUT_NEXT_IP4_INPUT;
49     }
50   else if (PREDICT_TRUE (h->type == clib_host_to_net_u16 (ETHERNET_TYPE_IP6)))
51     return VNET_DEVICE_INPUT_NEXT_IP6_INPUT;
52   else
53     if (PREDICT_TRUE (h->type == clib_host_to_net_u16 (ETHERNET_TYPE_MPLS)))
54     return VNET_DEVICE_INPUT_NEXT_MPLS_INPUT;
55   else
56     return VNET_DEVICE_INPUT_NEXT_ETHERNET_INPUT;
57 }
58
59 always_inline void
60 dpdk_rx_error_from_mb (struct rte_mbuf *mb, u32 * next, u8 * error)
61 {
62   if (mb->ol_flags & PKT_RX_IP_CKSUM_BAD)
63     {
64       *error = DPDK_ERROR_IP_CHECKSUM_ERROR;
65       *next = VNET_DEVICE_INPUT_NEXT_DROP;
66     }
67   else
68     *error = DPDK_ERROR_NONE;
69 }
70
71 static_always_inline void
72 dpdk_add_trace (vlib_main_t * vm, vlib_node_runtime_t * node, u32 next,
73                 dpdk_device_t * xd, u16 queue_id,
74                 vlib_buffer_t * b, struct rte_mbuf *mb)
75 {
76   vlib_trace_buffer (vm, node, next, b, /* follow_chain */ 0);
77
78   dpdk_rx_dma_trace_t *t0 = vlib_add_trace (vm, node, b, sizeof t0[0]);
79   t0->queue_index = queue_id;
80   t0->device_index = xd->device_index;
81   t0->buffer_index = vlib_get_buffer_index (vm, b);
82
83   clib_memcpy (&t0->mb, mb, sizeof t0->mb);
84   clib_memcpy (&t0->buffer, b, sizeof b[0] - sizeof b->pre_data);
85   clib_memcpy (t0->buffer.pre_data, b->data, sizeof t0->buffer.pre_data);
86   clib_memcpy (&t0->data, mb->buf_addr + mb->data_off, sizeof t0->data);
87 }
88
89 static inline u32
90 dpdk_rx_burst (dpdk_main_t * dm, dpdk_device_t * xd, u16 queue_id)
91 {
92   u32 n_buffers;
93   u32 n_left;
94   u32 n_this_chunk;
95
96   n_left = VLIB_FRAME_SIZE;
97   n_buffers = 0;
98
99   if (PREDICT_TRUE (xd->flags & DPDK_DEVICE_FLAG_PMD))
100     {
101       while (n_left)
102         {
103           n_this_chunk = rte_eth_rx_burst (xd->device_index, queue_id,
104                                            xd->rx_vectors[queue_id] +
105                                            n_buffers, n_left);
106           n_buffers += n_this_chunk;
107           n_left -= n_this_chunk;
108
109           /* Empirically, DPDK r1.8 produces vectors w/ 32 or fewer elts */
110           if (n_this_chunk < 32)
111             break;
112         }
113     }
114   else
115     {
116       ASSERT (0);
117     }
118
119   return n_buffers;
120 }
121
122 static_always_inline void
123 dpdk_process_subseq_segs (vlib_main_t * vm, vlib_buffer_t * b,
124                           struct rte_mbuf *mb, vlib_buffer_free_list_t * fl)
125 {
126   u8 nb_seg = 1;
127   struct rte_mbuf *mb_seg = 0;
128   vlib_buffer_t *b_seg, *b_chain = 0;
129   mb_seg = mb->next;
130   b_chain = b;
131
132   if (mb->nb_segs < 2)
133     return;
134
135   b->flags |= VLIB_BUFFER_TOTAL_LENGTH_VALID;
136   b->total_length_not_including_first_buffer = 0;
137
138   while (nb_seg < mb->nb_segs)
139     {
140       ASSERT (mb_seg != 0);
141
142       b_seg = vlib_buffer_from_rte_mbuf (mb_seg);
143       vlib_buffer_init_for_free_list (b_seg, fl);
144
145       ASSERT ((b_seg->flags & VLIB_BUFFER_NEXT_PRESENT) == 0);
146       ASSERT (b_seg->current_data == 0);
147
148       /*
149        * The driver (e.g. virtio) may not put the packet data at the start
150        * of the segment, so don't assume b_seg->current_data == 0 is correct.
151        */
152       b_seg->current_data =
153         (mb_seg->buf_addr + mb_seg->data_off) - (void *) b_seg->data;
154
155       b_seg->current_length = mb_seg->data_len;
156       b->total_length_not_including_first_buffer += mb_seg->data_len;
157
158       b_chain->flags |= VLIB_BUFFER_NEXT_PRESENT;
159       b_chain->next_buffer = vlib_get_buffer_index (vm, b_seg);
160
161       b_chain = b_seg;
162       mb_seg = mb_seg->next;
163       nb_seg++;
164     }
165 }
166
167 static_always_inline void
168 dpdk_prefetch_buffer (struct rte_mbuf *mb)
169 {
170   vlib_buffer_t *b = vlib_buffer_from_rte_mbuf (mb);
171   CLIB_PREFETCH (mb, CLIB_CACHE_LINE_BYTES, LOAD);
172   CLIB_PREFETCH (b, CLIB_CACHE_LINE_BYTES, STORE);
173 }
174
175 static_always_inline void
176 dpdk_prefetch_ethertype (struct rte_mbuf *mb)
177 {
178   CLIB_PREFETCH (mb->buf_addr + mb->data_off +
179                  STRUCT_OFFSET_OF (ethernet_header_t, type),
180                  CLIB_CACHE_LINE_BYTES, LOAD);
181 }
182
183 /*
184  * This function is used when there are no worker threads.
185  * The main thread performs IO and forwards the packets.
186  */
187 static_always_inline u32
188 dpdk_device_input (dpdk_main_t * dm, dpdk_device_t * xd,
189                    vlib_node_runtime_t * node, u32 thread_index, u16 queue_id,
190                    int maybe_multiseg, u32 n_trace)
191 {
192   u32 n_buffers;
193   u32 next_index = VNET_DEVICE_INPUT_NEXT_ETHERNET_INPUT;
194   u32 n_left_to_next, *to_next;
195   u32 mb_index;
196   vlib_main_t *vm = vlib_get_main ();
197   uword n_rx_bytes = 0;
198   vlib_buffer_free_list_t *fl;
199   vlib_buffer_t *bt = vec_elt_at_index (dm->buffer_templates, thread_index);
200
201   if ((xd->flags & DPDK_DEVICE_FLAG_ADMIN_UP) == 0)
202     return 0;
203
204   n_buffers = dpdk_rx_burst (dm, xd, queue_id);
205
206   if (n_buffers == 0)
207     {
208       return 0;
209     }
210
211   fl = vlib_buffer_get_free_list (vm, VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX);
212
213   /* Update buffer template */
214   vnet_buffer (bt)->sw_if_index[VLIB_RX] = xd->vlib_sw_if_index;
215   bt->error = node->errors[DPDK_ERROR_NONE];
216   /* as DPDK is allocating empty buffers from mempool provided before interface
217      start for each queue, it is safe to store this in the template */
218   bt->buffer_pool_index = xd->buffer_pool_for_queue[queue_id];
219
220   mb_index = 0;
221
222   while (n_buffers > 0)
223     {
224       vlib_buffer_t *b0, *b1, *b2, *b3;
225       u32 bi0, next0;
226       u32 bi1, next1;
227       u32 bi2, next2;
228       u32 bi3, next3;
229       u8 error0, error1, error2, error3;
230       i16 offset0, offset1, offset2, offset3;
231       u64 or_ol_flags;
232
233       vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
234
235       while (n_buffers >= 12 && n_left_to_next >= 4)
236         {
237           struct rte_mbuf *mb0, *mb1, *mb2, *mb3;
238
239           /* prefetches are interleaved with the rest of the code to reduce
240              pressure on L1 cache */
241           dpdk_prefetch_buffer (xd->rx_vectors[queue_id][mb_index + 8]);
242           dpdk_prefetch_ethertype (xd->rx_vectors[queue_id][mb_index + 4]);
243
244           mb0 = xd->rx_vectors[queue_id][mb_index];
245           mb1 = xd->rx_vectors[queue_id][mb_index + 1];
246           mb2 = xd->rx_vectors[queue_id][mb_index + 2];
247           mb3 = xd->rx_vectors[queue_id][mb_index + 3];
248
249           ASSERT (mb0);
250           ASSERT (mb1);
251           ASSERT (mb2);
252           ASSERT (mb3);
253
254           if (maybe_multiseg)
255             {
256               if (PREDICT_FALSE (mb0->nb_segs > 1))
257                 dpdk_prefetch_buffer (mb0->next);
258               if (PREDICT_FALSE (mb1->nb_segs > 1))
259                 dpdk_prefetch_buffer (mb1->next);
260               if (PREDICT_FALSE (mb2->nb_segs > 1))
261                 dpdk_prefetch_buffer (mb2->next);
262               if (PREDICT_FALSE (mb3->nb_segs > 1))
263                 dpdk_prefetch_buffer (mb3->next);
264             }
265
266           b0 = vlib_buffer_from_rte_mbuf (mb0);
267           b1 = vlib_buffer_from_rte_mbuf (mb1);
268           b2 = vlib_buffer_from_rte_mbuf (mb2);
269           b3 = vlib_buffer_from_rte_mbuf (mb3);
270
271           dpdk_prefetch_buffer (xd->rx_vectors[queue_id][mb_index + 9]);
272           dpdk_prefetch_ethertype (xd->rx_vectors[queue_id][mb_index + 5]);
273
274           clib_memcpy64_x4 (b0, b1, b2, b3, bt);
275
276           dpdk_prefetch_buffer (xd->rx_vectors[queue_id][mb_index + 10]);
277           dpdk_prefetch_ethertype (xd->rx_vectors[queue_id][mb_index + 6]);
278
279           bi0 = vlib_get_buffer_index (vm, b0);
280           bi1 = vlib_get_buffer_index (vm, b1);
281           bi2 = vlib_get_buffer_index (vm, b2);
282           bi3 = vlib_get_buffer_index (vm, b3);
283
284           to_next[0] = bi0;
285           to_next[1] = bi1;
286           to_next[2] = bi2;
287           to_next[3] = bi3;
288           to_next += 4;
289           n_left_to_next -= 4;
290
291           if (PREDICT_FALSE (xd->per_interface_next_index != ~0))
292             {
293               next0 = next1 = next2 = next3 = xd->per_interface_next_index;
294             }
295           else
296             {
297               next0 = dpdk_rx_next_from_etype (mb0);
298               next1 = dpdk_rx_next_from_etype (mb1);
299               next2 = dpdk_rx_next_from_etype (mb2);
300               next3 = dpdk_rx_next_from_etype (mb3);
301             }
302
303           dpdk_prefetch_buffer (xd->rx_vectors[queue_id][mb_index + 11]);
304           dpdk_prefetch_ethertype (xd->rx_vectors[queue_id][mb_index + 7]);
305
306           or_ol_flags = (mb0->ol_flags | mb1->ol_flags |
307                          mb2->ol_flags | mb3->ol_flags);
308           if (PREDICT_FALSE (or_ol_flags & PKT_RX_IP_CKSUM_BAD))
309             {
310               dpdk_rx_error_from_mb (mb0, &next0, &error0);
311               dpdk_rx_error_from_mb (mb1, &next1, &error1);
312               dpdk_rx_error_from_mb (mb2, &next2, &error2);
313               dpdk_rx_error_from_mb (mb3, &next3, &error3);
314               b0->error = node->errors[error0];
315               b1->error = node->errors[error1];
316               b2->error = node->errors[error2];
317               b3->error = node->errors[error3];
318             }
319
320           offset0 = device_input_next_node_advance[next0];
321           b0->current_data = mb0->data_off + offset0 - RTE_PKTMBUF_HEADROOM;
322           b0->flags |= device_input_next_node_flags[next0];
323           vnet_buffer (b0)->l3_hdr_offset = b0->current_data;
324           vnet_buffer (b0)->l2_hdr_offset =
325             mb0->data_off - RTE_PKTMBUF_HEADROOM;
326           b0->current_length = mb0->data_len - offset0;
327           n_rx_bytes += mb0->pkt_len;
328
329           offset1 = device_input_next_node_advance[next1];
330           b1->current_data = mb1->data_off + offset1 - RTE_PKTMBUF_HEADROOM;
331           b1->flags |= device_input_next_node_flags[next1];
332           vnet_buffer (b1)->l3_hdr_offset = b1->current_data;
333           vnet_buffer (b1)->l2_hdr_offset =
334             mb1->data_off - RTE_PKTMBUF_HEADROOM;
335           b1->current_length = mb1->data_len - offset1;
336           n_rx_bytes += mb1->pkt_len;
337
338           offset2 = device_input_next_node_advance[next2];
339           b2->current_data = mb2->data_off + offset2 - RTE_PKTMBUF_HEADROOM;
340           b2->flags |= device_input_next_node_flags[next2];
341           vnet_buffer (b2)->l3_hdr_offset = b2->current_data;
342           vnet_buffer (b2)->l2_hdr_offset =
343             mb2->data_off - RTE_PKTMBUF_HEADROOM;
344           b2->current_length = mb2->data_len - offset2;
345           n_rx_bytes += mb2->pkt_len;
346
347           offset3 = device_input_next_node_advance[next3];
348           b3->current_data = mb3->data_off + offset3 - RTE_PKTMBUF_HEADROOM;
349           b3->flags |= device_input_next_node_flags[next3];
350           vnet_buffer (b3)->l3_hdr_offset = b3->current_data;
351           vnet_buffer (b3)->l2_hdr_offset =
352             mb3->data_off - RTE_PKTMBUF_HEADROOM;
353           b3->current_length = mb3->data_len - offset3;
354           n_rx_bytes += mb3->pkt_len;
355
356
357           /* Process subsequent segments of multi-segment packets */
358           if (maybe_multiseg)
359             {
360               dpdk_process_subseq_segs (vm, b0, mb0, fl);
361               dpdk_process_subseq_segs (vm, b1, mb1, fl);
362               dpdk_process_subseq_segs (vm, b2, mb2, fl);
363               dpdk_process_subseq_segs (vm, b3, mb3, fl);
364             }
365
366           /*
367            * Turn this on if you run into
368            * "bad monkey" contexts, and you want to know exactly
369            * which nodes they've visited... See main.c...
370            */
371           VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b0);
372           VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b1);
373           VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b2);
374           VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b3);
375
376           /* Do we have any driver RX features configured on the interface? */
377           vnet_feature_start_device_input_x4 (xd->vlib_sw_if_index,
378                                               &next0, &next1, &next2, &next3,
379                                               b0, b1, b2, b3);
380
381           vlib_validate_buffer_enqueue_x4 (vm, node, next_index,
382                                            to_next, n_left_to_next,
383                                            bi0, bi1, bi2, bi3,
384                                            next0, next1, next2, next3);
385           n_buffers -= 4;
386           mb_index += 4;
387
388           if (n_trace)
389             {
390               dpdk_add_trace (vm, node, next0, xd, queue_id, b0, mb0);
391               n_trace--;
392             }
393           if (n_trace)
394             {
395               dpdk_add_trace (vm, node, next1, xd, queue_id, b1, mb1);
396               n_trace--;
397             }
398           if (n_trace)
399             {
400               dpdk_add_trace (vm, node, next2, xd, queue_id, b2, mb2);
401               n_trace--;
402             }
403           if (n_trace)
404             {
405               dpdk_add_trace (vm, node, next3, xd, queue_id, b3, mb3);
406               n_trace--;
407             }
408         }
409       while (n_buffers > 0 && n_left_to_next > 0)
410         {
411           struct rte_mbuf *mb0 = xd->rx_vectors[queue_id][mb_index];
412
413           if (PREDICT_TRUE (n_buffers > 3))
414             {
415               dpdk_prefetch_buffer (xd->rx_vectors[queue_id][mb_index + 2]);
416               dpdk_prefetch_ethertype (xd->rx_vectors[queue_id]
417                                        [mb_index + 1]);
418             }
419
420           ASSERT (mb0);
421
422           b0 = vlib_buffer_from_rte_mbuf (mb0);
423
424           /* Prefetch one next segment if it exists. */
425           if (PREDICT_FALSE (mb0->nb_segs > 1))
426             dpdk_prefetch_buffer (mb0->next);
427
428           clib_memcpy (b0, bt, CLIB_CACHE_LINE_BYTES);
429
430           bi0 = vlib_get_buffer_index (vm, b0);
431
432           to_next[0] = bi0;
433           to_next++;
434           n_left_to_next--;
435
436           if (PREDICT_FALSE (xd->per_interface_next_index != ~0))
437             next0 = xd->per_interface_next_index;
438           else
439             next0 = dpdk_rx_next_from_etype (mb0);
440
441           dpdk_rx_error_from_mb (mb0, &next0, &error0);
442           b0->error = node->errors[error0];
443
444           offset0 = device_input_next_node_advance[next0];
445           b0->current_data = mb0->data_off + offset0 - RTE_PKTMBUF_HEADROOM;
446           b0->flags |= device_input_next_node_flags[next0];
447           vnet_buffer (b0)->l3_hdr_offset = b0->current_data;
448           vnet_buffer (b0)->l2_hdr_offset =
449             mb0->data_off - RTE_PKTMBUF_HEADROOM;
450           b0->current_length = mb0->data_len - offset0;
451           n_rx_bytes += mb0->pkt_len;
452
453           /* Process subsequent segments of multi-segment packets */
454           dpdk_process_subseq_segs (vm, b0, mb0, fl);
455
456           /*
457            * Turn this on if you run into
458            * "bad monkey" contexts, and you want to know exactly
459            * which nodes they've visited... See main.c...
460            */
461           VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b0);
462
463           /* Do we have any driver RX features configured on the interface? */
464           vnet_feature_start_device_input_x1 (xd->vlib_sw_if_index, &next0,
465                                               b0);
466
467           vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
468                                            to_next, n_left_to_next,
469                                            bi0, next0);
470           n_buffers--;
471           mb_index++;
472
473           if (n_trace)
474             {
475               dpdk_add_trace (vm, node, next0, xd, queue_id, b0, mb0);
476               n_trace--;
477             }
478         }
479       vlib_put_next_frame (vm, node, next_index, n_left_to_next);
480     }
481
482   vlib_increment_combined_counter
483     (vnet_get_main ()->interface_main.combined_sw_if_counters
484      + VNET_INTERFACE_COUNTER_RX,
485      thread_index, xd->vlib_sw_if_index, mb_index, n_rx_bytes);
486
487   vnet_device_increment_rx_packets (thread_index, mb_index);
488
489   return mb_index;
490 }
491
492 static_always_inline u32
493 dpdk_device_input_mseg (dpdk_main_t * dm, dpdk_device_t * xd,
494                         vlib_node_runtime_t * node, u32 thread_index,
495                         u16 queue_id, u32 n_trace)
496 {
497   if (xd->flags & DPDK_DEVICE_FLAG_MAYBE_MULTISEG)
498     return dpdk_device_input (dm, xd, node, thread_index, queue_id,
499                               /* maybe_multiseg */ 1, n_trace);
500   else
501     return dpdk_device_input (dm, xd, node, thread_index, queue_id,
502                               /* maybe_multiseg */ 0, n_trace);
503 }
504
505 static inline void
506 poll_rate_limit (dpdk_main_t * dm)
507 {
508   /* Limit the poll rate by sleeping for N msec between polls */
509   if (PREDICT_FALSE (dm->poll_sleep_usec != 0))
510     {
511       struct timespec ts, tsrem;
512
513       ts.tv_sec = 0;
514       ts.tv_nsec = 1000 * dm->poll_sleep_usec;
515
516       while (nanosleep (&ts, &tsrem) < 0)
517         {
518           ts = tsrem;
519         }
520     }
521 }
522
523 /** \brief Main DPDK input node
524     @node dpdk-input
525
526     This is the main DPDK input node: across each assigned interface,
527     call rte_eth_rx_burst(...) or similar to obtain a vector of
528     packets to process. Handle early packet discard. Derive @c
529     vlib_buffer_t metadata from <code>struct rte_mbuf</code> metadata,
530     Depending on the resulting metadata: adjust <code>b->current_data,
531     b->current_length </code> and dispatch directly to
532     ip4-input-no-checksum, or ip6-input. Trace the packet if required.
533
534     @param vm   vlib_main_t corresponding to the current thread
535     @param node vlib_node_runtime_t
536     @param f    vlib_frame_t input-node, not used.
537
538     @par Graph mechanics: buffer metadata, next index usage
539
540     @em Uses:
541     - <code>struct rte_mbuf mb->ol_flags</code>
542         - PKT_RX_IP_CKSUM_BAD
543     - <code> RTE_ETH_IS_xxx_HDR(mb->packet_type) </code>
544         - packet classification result
545
546     @em Sets:
547     - <code>b->error</code> if the packet is to be dropped immediately
548     - <code>b->current_data, b->current_length</code>
549         - adjusted as needed to skip the L2 header in  direct-dispatch cases
550     - <code>vnet_buffer(b)->sw_if_index[VLIB_RX]</code>
551         - rx interface sw_if_index
552     - <code>vnet_buffer(b)->sw_if_index[VLIB_TX] = ~0</code>
553         - required by ipX-lookup
554     - <code>b->flags</code>
555         - to indicate multi-segment pkts (VLIB_BUFFER_NEXT_PRESENT), etc.
556
557     <em>Next Nodes:</em>
558     - Static arcs to: error-drop, ethernet-input,
559       ip4-input-no-checksum, ip6-input, mpls-input
560     - per-interface redirection, controlled by
561       <code>xd->per_interface_next_index</code>
562 */
563
564 uword
565 CLIB_MULTIARCH_FN (dpdk_input) (vlib_main_t * vm, vlib_node_runtime_t * node,
566                                 vlib_frame_t * f)
567 {
568   dpdk_main_t *dm = &dpdk_main;
569   dpdk_device_t *xd;
570   uword n_rx_packets = 0;
571   vnet_device_input_runtime_t *rt = (void *) node->runtime_data;
572   vnet_device_and_queue_t *dq;
573   u32 thread_index = node->thread_index;
574
575   /*
576    * Poll all devices on this cpu for input/interrupts.
577    */
578   /* *INDENT-OFF* */
579   foreach_device_and_queue (dq, rt->devices_and_queues)
580     {
581       xd = vec_elt_at_index(dm->devices, dq->dev_instance);
582       if (PREDICT_FALSE (xd->flags & DPDK_DEVICE_FLAG_BOND_SLAVE))
583         continue;       /* Do not poll slave to a bonded interface */
584       u32 n_trace = vlib_get_trace_count (vm, node);
585       if (PREDICT_TRUE(n_trace == 0))
586         n_rx_packets += dpdk_device_input_mseg (dm, xd, node, thread_index,
587                                                 dq->queue_id, 0);
588       else
589         {
590           u32 n_tr_packets = dpdk_device_input_mseg (dm, xd, node, thread_index,
591                                                      dq->queue_id, n_trace);
592           n_rx_packets += n_tr_packets;
593           vlib_set_trace_count (vm, node,
594                                 n_trace - clib_min(n_trace, n_tr_packets));
595         }
596     }
597   /* *INDENT-ON* */
598
599   poll_rate_limit (dm);
600
601   return n_rx_packets;
602 }
603
604 #ifndef CLIB_MULTIARCH_VARIANT
605 /* *INDENT-OFF* */
606 VLIB_REGISTER_NODE (dpdk_input_node) = {
607   .function = dpdk_input,
608   .type = VLIB_NODE_TYPE_INPUT,
609   .name = "dpdk-input",
610   .sibling_of = "device-input",
611
612   /* Will be enabled if/when hardware is detected. */
613   .state = VLIB_NODE_STATE_DISABLED,
614
615   .format_buffer = format_ethernet_header_with_length,
616   .format_trace = format_dpdk_rx_dma_trace,
617
618   .n_errors = DPDK_N_ERROR,
619   .error_strings = dpdk_error_strings,
620 };
621 /* *INDENT-ON* */
622
623 vlib_node_function_t __clib_weak dpdk_input_avx512;
624 vlib_node_function_t __clib_weak dpdk_input_avx2;
625
626 #if __x86_64__
627 static void __clib_constructor
628 dpdk_input_multiarch_select (void)
629 {
630   if (dpdk_input_avx512 && clib_cpu_supports_avx512f ())
631     dpdk_input_node.function = dpdk_input_avx512;
632   else if (dpdk_input_avx2 && clib_cpu_supports_avx2 ())
633     dpdk_input_node.function = dpdk_input_avx2;
634 }
635 #endif
636 #endif
637
638 /*
639  * fd.io coding-style-patch-verification: ON
640  *
641  * Local Variables:
642  * eval: (c-set-style "gnu")
643  * End:
644  */