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