FD.io VPP  v18.01-8-g0eacf49
Vector Packet Processing
buffer.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 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  * buffer.c: allocate/free network buffers.
17  *
18  * Copyright (c) 2008 Eliot Dresselhaus
19  *
20  * Permission is hereby granted, free of charge, to any person obtaining
21  * a copy of this software and associated documentation files (the
22  * "Software"), to deal in the Software without restriction, including
23  * without limitation the rights to use, copy, modify, merge, publish,
24  * distribute, sublicense, and/or sell copies of the Software, and to
25  * permit persons to whom the Software is furnished to do so, subject to
26  * the following conditions:
27  *
28  * The above copyright notice and this permission notice shall be
29  * included in all copies or substantial portions of the Software.
30  *
31  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
32  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
33  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
34  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
35  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
36  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
37  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38  */
39 
40 /**
41  * @file
42  *
43  * Allocate/free network buffers.
44  */
45 
46 #include <rte_config.h>
47 
48 #include <rte_common.h>
49 #include <rte_log.h>
50 #include <rte_memory.h>
51 #include <rte_memzone.h>
52 #include <rte_tailq.h>
53 #include <rte_eal.h>
54 #include <rte_per_lcore.h>
55 #include <rte_launch.h>
56 #include <rte_atomic.h>
57 #include <rte_cycles.h>
58 #include <rte_prefetch.h>
59 #include <rte_lcore.h>
60 #include <rte_per_lcore.h>
61 #include <rte_branch_prediction.h>
62 #include <rte_interrupts.h>
63 #include <rte_pci.h>
64 #include <rte_random.h>
65 #include <rte_debug.h>
66 #include <rte_ether.h>
67 #include <rte_ethdev.h>
68 #include <rte_ring.h>
69 #include <rte_mempool.h>
70 #include <rte_mbuf.h>
71 #include <rte_version.h>
72 
73 #include <vlib/vlib.h>
74 #include <vnet/vnet.h>
75 #include <dpdk/device/dpdk.h>
76 #include <dpdk/device/dpdk_priv.h>
77 
78 
79 STATIC_ASSERT (VLIB_BUFFER_PRE_DATA_SIZE == RTE_PKTMBUF_HEADROOM,
80  "VLIB_BUFFER_PRE_DATA_SIZE must be equal to RTE_PKTMBUF_HEADROOM");
81 
82 typedef struct
83 {
84  CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
85  struct rte_mbuf ***mbuf_pending_free_list;
86 
87  /* cached last pool */
88  struct rte_mempool *last_pool;
91 
92 typedef struct
93 {
96 
98 
101 {
102  vlib_buffer_t *hb = b;
104  dpdk_buffer_per_thread_data *d = vec_elt_at_index (dbm->ptd, thread_index);
105  struct rte_mbuf *mb;
106  u32 next, flags;
107  mb = rte_mbuf_from_vlib_buffer (hb);
108 
109 next:
110  flags = b->flags;
111  next = b->next_buffer;
112  mb = rte_mbuf_from_vlib_buffer (b);
113 
114  if (PREDICT_FALSE (b->n_add_refs))
115  {
116  rte_mbuf_refcnt_update (mb, b->n_add_refs);
117  b->n_add_refs = 0;
118  }
119 
120  mb = rte_pktmbuf_prefree_seg (mb);
121  if (mb)
122  {
123  if (mb->pool != d->last_pool)
124  {
125  d->last_pool = mb->pool;
126  dpdk_mempool_private_t *privp = rte_mempool_get_priv (d->last_pool);
131  }
133  }
134 
135  if (flags & VLIB_BUFFER_NEXT_PRESENT)
136  {
137  b = vlib_get_buffer (vm, next);
138  goto next;
139  }
140 }
141 
142 #ifndef CLIB_MULTIARCH_VARIANT
143 static void
145 {
146  u32 i;
147  vlib_buffer_t *b;
148  u32 thread_index = vlib_get_thread_index ();
149 
150  for (i = 0; i < vec_len (f->buffers); i++)
151  {
152  b = vlib_get_buffer (vm, f->buffers[i]);
153  dpdk_rte_pktmbuf_free (vm, thread_index, b);
154  }
155 
156  vec_free (f->name);
157  vec_free (f->buffers);
158 }
159 
160 /* Add buffer free list. */
161 static void
163 {
166  u32 merge_index;
167  int i;
168 
169  ASSERT (vlib_get_thread_index () == 0);
170 
171  f = vlib_buffer_get_free_list (vm, free_list_index);
172 
173  merge_index = vlib_buffer_get_free_list_with_size (vm, f->n_data_bytes);
174  if (merge_index != ~0 && merge_index != free_list_index)
175  {
177  (bm->buffer_free_list_pool, merge_index),
178  f);
179  }
180 
181  del_free_list (vm, f);
182 
183  /* Poison it. */
184  memset (f, 0xab, sizeof (f[0]));
185 
187 
188  for (i = 1; i < vec_len (vlib_mains); i++)
189  {
190  bm = vlib_mains[i]->buffer_main;
191  f = vlib_buffer_get_free_list (vlib_mains[i], free_list_index);;
192  memset (f, 0xab, sizeof (f[0]));
194  }
195 }
196 #endif
197 
198 /* Make sure free list has at least given number of free buffers. */
199 uword
202  uword min_free_buffers)
203 {
204  dpdk_main_t *dm = &dpdk_main;
205  vlib_buffer_t *b0, *b1, *b2, *b3;
206  int n, i;
207  u32 bi0, bi1, bi2, bi3;
208  unsigned socket_id = rte_socket_id ();
209  struct rte_mempool *rmp = dm->pktmbuf_pools[socket_id];
210  dpdk_mempool_private_t *privp = rte_mempool_get_priv (rmp);
211  struct rte_mbuf *mb0, *mb1, *mb2, *mb3;
212  vlib_buffer_t bt;
213 
214  /* Too early? */
215  if (PREDICT_FALSE (rmp == 0))
216  return 0;
217 
218  /* Already have enough free buffers on free list? */
219  n = min_free_buffers - vec_len (fl->buffers);
220  if (n <= 0)
221  return min_free_buffers;
222 
223  /* Always allocate round number of buffers. */
224  n = round_pow2 (n, CLIB_CACHE_LINE_BYTES / sizeof (u32));
225 
226  /* Always allocate new buffers in reasonably large sized chunks. */
227  n = clib_max (n, fl->min_n_buffers_each_physmem_alloc);
228 
230 
231  if (rte_mempool_get_bulk (rmp, vm->mbuf_alloc_list, n) < 0)
232  return 0;
233 
234  memset (&bt, 0, sizeof (vlib_buffer_t));
237 
238  _vec_len (vm->mbuf_alloc_list) = n;
239 
240  i = 0;
241  int f = vec_len (fl->buffers);
243 
244  while (i < (n - 7))
245  {
247  (vm->mbuf_alloc_list[i + 4]), STORE);
249  (vm->mbuf_alloc_list[i + 5]), STORE);
251  (vm->mbuf_alloc_list[i + 6]), STORE);
253  (vm->mbuf_alloc_list[i + 7]), STORE);
254 
255  mb0 = vm->mbuf_alloc_list[i];
256  mb1 = vm->mbuf_alloc_list[i + 1];
257  mb2 = vm->mbuf_alloc_list[i + 2];
258  mb3 = vm->mbuf_alloc_list[i + 3];
259 
260  b0 = vlib_buffer_from_rte_mbuf (mb0);
261  b1 = vlib_buffer_from_rte_mbuf (mb1);
262  b2 = vlib_buffer_from_rte_mbuf (mb2);
263  b3 = vlib_buffer_from_rte_mbuf (mb3);
264 
265  bi0 = vlib_get_buffer_index (vm, b0);
266  bi1 = vlib_get_buffer_index (vm, b1);
267  bi2 = vlib_get_buffer_index (vm, b2);
268  bi3 = vlib_get_buffer_index (vm, b3);
269 
270  fl->buffers[f++] = bi0;
271  fl->buffers[f++] = bi1;
272  fl->buffers[f++] = bi2;
273  fl->buffers[f++] = bi3;
274 
275  clib_memcpy64_x4 (b0, b1, b2, b3, &bt);
276 
277  if (fl->buffer_init_function)
278  {
279  fl->buffer_init_function (vm, fl, &bi0, 1);
280  fl->buffer_init_function (vm, fl, &bi1, 1);
281  fl->buffer_init_function (vm, fl, &bi2, 1);
282  fl->buffer_init_function (vm, fl, &bi3, 1);
283  }
284  i += 4;
285  }
286 
287  while (i < n)
288  {
289  mb0 = vm->mbuf_alloc_list[i];
290 
291  b0 = vlib_buffer_from_rte_mbuf (mb0);
292  bi0 = vlib_get_buffer_index (vm, b0);
293 
294  fl->buffers[f++] = bi0;
295  clib_memcpy (b0, &bt, sizeof (vlib_buffer_t));
296 
297  if (fl->buffer_init_function)
298  fl->buffer_init_function (vm, fl, &bi0, 1);
299  i++;
300  }
301 
302  fl->n_alloc += n;
303 
304  return n;
305 }
306 
309 {
310  vlib_buffer_t *b;
311  struct rte_mbuf *mb;
312  b = vlib_get_buffer (vm, bi);
313  mb = rte_mbuf_from_vlib_buffer (b);
314  CLIB_PREFETCH (mb, 2 * CLIB_CACHE_LINE_BYTES, STORE);
316 }
317 
320  vlib_buffer_t * b)
321 {
323  u32 thread_index = vlib_get_thread_index ();
324  u32 fi;
325  fl = vlib_buffer_get_buffer_free_list (vm, b, &fi);
326 
327  /* The only current use of this callback: multicast recycle */
329  {
330  int j;
331 
332  vlib_buffer_add_to_free_list (vm, fl, bi,
333  (b->flags & VLIB_BUFFER_RECYCLE) == 0);
334 
335  for (j = 0; j < vec_len (bm->announce_list); j++)
336  {
337  if (fl == bm->announce_list[j])
338  goto already_announced;
339  }
340  vec_add1 (bm->announce_list, fl);
341  already_announced:
342  ;
343  }
344  else
345  {
346  if (PREDICT_TRUE ((b->flags & VLIB_BUFFER_RECYCLE) == 0))
347  dpdk_rte_pktmbuf_free (vm, thread_index, b);
348  }
349 }
350 
353  u32 * buffers, u32 n_buffers, u32 follow_buffer_next)
354 {
357  vlib_buffer_t *b0, *b1, *b2, *b3;
358  u32 thread_index = vlib_get_thread_index ();
359  dpdk_buffer_per_thread_data *d = vec_elt_at_index (dbm->ptd, thread_index);
360  int i = 0;
361  u32 (*cb) (vlib_main_t * vm, u32 * buffers, u32 n_buffers,
362  u32 follow_buffer_next);
363 
364  cb = bm->buffer_free_callback;
365 
366  if (PREDICT_FALSE (cb != 0))
367  n_buffers = (*cb) (vm, buffers, n_buffers, follow_buffer_next);
368 
369  if (!n_buffers)
370  return;
371 
372  while (i + 7 < n_buffers)
373  {
374  dpdk_prefetch_buffer_by_index (vm, buffers[i + 4]);
375  dpdk_prefetch_buffer_by_index (vm, buffers[i + 5]);
376  dpdk_prefetch_buffer_by_index (vm, buffers[i + 6]);
377  dpdk_prefetch_buffer_by_index (vm, buffers[i + 7]);
378 
379  b0 = vlib_get_buffer (vm, buffers[i]);
380  b1 = vlib_get_buffer (vm, buffers[i + 1]);
381  b2 = vlib_get_buffer (vm, buffers[i + 2]);
382  b3 = vlib_get_buffer (vm, buffers[i + 3]);
383 
388 
389  recycle_or_free (vm, bm, buffers[i], b0);
390  recycle_or_free (vm, bm, buffers[i + 1], b1);
391  recycle_or_free (vm, bm, buffers[i + 2], b2);
392  recycle_or_free (vm, bm, buffers[i + 3], b3);
393 
394  i += 4;
395  }
396  while (i < n_buffers)
397  {
398  b0 = vlib_get_buffer (vm, buffers[i]);
400  recycle_or_free (vm, bm, buffers[i], b0);
401  i++;
402  }
403  if (vec_len (bm->announce_list))
404  {
406  for (i = 0; i < vec_len (bm->announce_list); i++)
407  {
408  fl = bm->announce_list[i];
410  }
411  _vec_len (bm->announce_list) = 0;
412  }
413 
415  {
416  int len = vec_len (d->mbuf_pending_free_list[i]);
417  if (len)
418  {
419  rte_mempool_put_bulk (d->mbuf_pending_free_list[i][len - 1]->pool,
420  (void *) d->mbuf_pending_free_list[i], len);
422  }
423  }
424 }
425 
426 void
428  u32 n_buffers)
429 {
430  vlib_buffer_free_inline (vm, buffers, n_buffers, /* follow_buffer_next */
431  1);
432 }
433 
434 void
436  u32 n_buffers)
437 {
438  vlib_buffer_free_inline (vm, buffers, n_buffers, /* follow_buffer_next */
439  0);
440 }
441 
442 #ifndef CLIB_MULTIARCH_VARIANT
443 static void
445  void *vt,
446  void *packet_data,
447  uword n_packet_data_bytes,
448  uword min_n_buffers_each_physmem_alloc, u8 * name)
449 {
451 
453  memset (t, 0, sizeof (t[0]));
454 
455  vec_add (t->packet_data, packet_data, n_packet_data_bytes);
456 
458 }
459 
460 clib_error_t *
461 dpdk_pool_create (vlib_main_t * vm, u8 * pool_name, u32 elt_size,
462  u32 num_elts, u32 pool_priv_size, u16 cache_size, u8 numa,
463  struct rte_mempool **_mp, vlib_physmem_region_index_t * pri)
464 {
465  struct rte_mempool *mp;
467  clib_error_t *error = 0;
468  u32 size, obj_size;
469  i32 ret;
470 
471  obj_size = rte_mempool_calc_obj_size (elt_size, 0, 0);
472 #if RTE_VERSION < RTE_VERSION_NUM(17, 11, 0, 0)
473  size = rte_mempool_xmem_size (num_elts, obj_size, 21);
474 #else
475  size = rte_mempool_xmem_size (num_elts, obj_size, 21, 0);
476 #endif
477 
478  error =
479  vlib_physmem_region_alloc (vm, (i8 *) pool_name, size, numa, 0, pri);
480  if (error)
481  return error;
482 
483  pr = vlib_physmem_get_region (vm, pri[0]);
484 
485  mp =
486  rte_mempool_create_empty ((i8 *) pool_name, num_elts, elt_size,
487  512, pool_priv_size, numa, 0);
488  if (!mp)
489  return clib_error_return (0, "failed to create %s", pool_name);
490 
491  rte_mempool_set_ops_byname (mp, RTE_MBUF_DEFAULT_MEMPOOL_OPS, NULL);
492 
493 #if RTE_VERSION < RTE_VERSION_NUM(17, 11, 0, 0)
494  ret =
495  rte_mempool_populate_phys_tab (mp, pr->mem, pr->page_table, pr->n_pages,
496  pr->log2_page_size, NULL, NULL);
497 #else
498  ret =
499  rte_mempool_populate_iova_tab (mp, pr->mem, pr->page_table, pr->n_pages,
500  pr->log2_page_size, NULL, NULL);
501 #endif
502  if (ret != (i32) mp->size)
503  {
504  rte_mempool_free (mp);
505  return clib_error_return (0, "failed to populate %s", pool_name);
506  }
507 
508  _mp[0] = mp;
509 
510  return 0;
511 }
512 
513 clib_error_t *
514 dpdk_buffer_pool_create (vlib_main_t * vm, unsigned num_mbufs,
515  unsigned socket_id)
516 {
517  dpdk_main_t *dm = &dpdk_main;
518  struct rte_mempool *rmp;
521  clib_error_t *error = 0;
522  u8 *pool_name;
523  u32 elt_size, i;
524 
526 
527  /* pool already exists, nothing to do */
528  if (dm->pktmbuf_pools[socket_id])
529  return 0;
530 
531  pool_name = format (0, "dpdk_mbuf_pool_socket%u%c", socket_id, 0);
532 
533  elt_size = sizeof (struct rte_mbuf) +
534  VLIB_BUFFER_HDR_SIZE /* priv size */ +
535  VLIB_BUFFER_PRE_DATA_SIZE + VLIB_BUFFER_DATA_SIZE; /*data room size */
536 
537  error =
538  dpdk_pool_create (vm, pool_name, elt_size, num_mbufs,
539  sizeof (dpdk_mempool_private_t), 512, socket_id,
540  &rmp, &pri);
541 
542  vec_free (pool_name);
543 
544  if (!error)
545  {
546  priv.mbp_priv.mbuf_data_room_size = VLIB_BUFFER_PRE_DATA_SIZE +
548  priv.mbp_priv.mbuf_priv_size = VLIB_BUFFER_HDR_SIZE;
549 
550  /* call the mempool priv initializer */
551  rte_pktmbuf_pool_init (rmp, &priv);
552 
553  /* call the object initializers */
554  rte_mempool_obj_iter (rmp, rte_pktmbuf_init, 0);
555 
556  dpdk_mempool_private_t *privp = rte_mempool_get_priv (rmp);
558 
559  dm->pktmbuf_pools[socket_id] = rmp;
560 
561  return 0;
562  }
563 
564  clib_error_report (error);
565 
566  /* no usable pool for this socket, try to use pool from another one */
567  for (i = 0; i < vec_len (dm->pktmbuf_pools); i++)
568  {
569  if (dm->pktmbuf_pools[i])
570  {
571  clib_warning ("WARNING: Failed to allocate mempool for CPU socket "
572  "%u. Threads running on socket %u will use socket %u "
573  "mempool.", socket_id, socket_id, i);
574  dm->pktmbuf_pools[socket_id] = dm->pktmbuf_pools[i];
575  return 0;
576  }
577  }
578 
579  return clib_error_return (0, "failed to allocate mempool on socket %u",
580  socket_id);
581 }
582 
583 #if CLIB_DEBUG > 0
584 
588 
589 static clib_error_t *
591 {
592  void *oldheap;
593 
594  vlib_buffer_state_heap = mheap_alloc (0, 10 << 20);
595 
597 
601  clib_mem_set_heap (oldheap);
602  return 0;
603 }
604 
606 #endif
607 
608 #if CLI_DEBUG
609 struct dpdk_validate_buf_result
610 {
611  u32 invalid;
612  u32 uninitialized;
613 };
614 
615 #define DPDK_TRAJECTORY_POISON 31
616 
617 static void
618 dpdk_buffer_validate_trajectory (struct rte_mempool *mp, void *opaque,
619  void *obj, unsigned obj_idx)
620 {
621  vlib_buffer_t *b;
622  struct dpdk_validate_buf_result *counter = opaque;
623  b = vlib_buffer_from_rte_mbuf ((struct rte_mbuf *) obj);
624  if (b->pre_data[0] != 0)
625  {
626  if (b->pre_data[0] == DPDK_TRAJECTORY_POISON)
627  counter->uninitialized++;
628  else
629  counter->invalid++;
630  }
631 }
632 
633 int
634 dpdk_buffer_validate_trajectory_all (u32 * uninitialized)
635 {
636  dpdk_main_t *dm = &dpdk_main;
637  struct dpdk_validate_buf_result counter = { 0 };
638  int i;
639 
640  for (i = 0; i < vec_len (dm->pktmbuf_pools); i++)
641  rte_mempool_obj_iter (dm->pktmbuf_pools[i],
642  dpdk_buffer_validate_trajectory, &counter);
643  if (uninitialized)
644  *uninitialized = counter.uninitialized;
645  return counter.invalid;
646 }
647 
648 static void
649 dpdk_buffer_poison_trajectory (struct rte_mempool *mp, void *opaque,
650  void *obj, unsigned obj_idx)
651 {
652  vlib_buffer_t *b;
653  b = vlib_buffer_from_rte_mbuf ((struct rte_mbuf *) obj);
654  b->pre_data[0] = DPDK_TRAJECTORY_POISON;
655 }
656 
657 void
658 dpdk_buffer_poison_trajectory_all (void)
659 {
660  dpdk_main_t *dm = &dpdk_main;
661  int i;
662 
663  for (i = 0; i < vec_len (dm->pktmbuf_pools); i++)
664  rte_mempool_obj_iter (dm->pktmbuf_pools[i], dpdk_buffer_poison_trajectory,
665  0);
666 }
667 #endif
668 
669 static clib_error_t *
671 {
674  vec_validate_aligned (dbm->ptd, tm->n_vlib_mains - 1,
676  return 0;
677 }
678 
680 
681 /* *INDENT-OFF* */
682 VLIB_BUFFER_REGISTER_CALLBACKS (dpdk, static) = {
683  .vlib_buffer_fill_free_list_cb = &dpdk_buffer_fill_free_list,
684  .vlib_buffer_free_cb = &dpdk_buffer_free,
685  .vlib_buffer_free_no_next_cb = &dpdk_buffer_free_no_next,
686  .vlib_packet_template_init_cb = &dpdk_packet_template_init,
687  .vlib_buffer_delete_free_list_cb = &dpdk_buffer_delete_free_list,
688 };
689 /* *INDENT-ON* */
690 
691 #if __x86_64__
698 
699 static void __clib_constructor
701 {
702  vlib_buffer_callbacks_t *cb = &__dpdk_buffer_callbacks;
703  if (dpdk_buffer_fill_free_list_avx512 && clib_cpu_supports_avx512f ())
704  {
708  }
709  else if (dpdk_buffer_fill_free_list_avx2 && clib_cpu_supports_avx2 ())
710  {
714  }
715 }
716 #endif
717 #endif
718 
719 /** @endcond */
720 /*
721  * fd.io coding-style-patch-verification: ON
722  *
723  * Local Variables:
724  * eval: (c-set-style "gnu")
725  * End:
726  */
#define vec_foreach_index(var, v)
Iterate over vector indices.
#define vlib_buffer_from_rte_mbuf(x)
Definition: dpdk_priv.h:17
#define CLIB_CACHE_LINE_ALIGN_MARK(mark)
Definition: cache.h:68
sll srl srl sll sra u16x4 i
Definition: vector_sse2.h:337
void vlib_buffer_merge_free_lists(vlib_buffer_free_list_t *dst, vlib_buffer_free_list_t *src)
Definition: buffer.c:336
dpdk_buffer_main_t dpdk_buffer_main
Definition: buffer.c:97
static clib_error_t * dpdk_buffer_init(vlib_main_t *vm)
Definition: buffer.c:670
#define VLIB_BUFFER_RECYCLE
Definition: buffer.h:99
dpdk_main_t dpdk_main
Definition: init.c:39
#define PREDICT_TRUE(x)
Definition: clib.h:106
void * mheap_alloc(void *memory, uword size)
Definition: mheap.c:947
u32 * vlib_buffer_state_validation_lock
Definition: buffer.c:585
#define NULL
Definition: clib.h:55
vlib_buffer_free_cb_t __clib_weak dpdk_buffer_free_avx512
Definition: buffer.c:694
#define VLIB_BUFFER_PRE_DATA_SIZE
Definition: buffer.h:52
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:518
u8 buffer_pool_index
index of buffer pool this buffer belongs.
Definition: buffer.h:126
static clib_error_t * vlib_physmem_region_alloc(vlib_main_t *vm, char *name, u32 size, u8 numa_node, u32 flags, vlib_physmem_region_index_t *idx)
vlib_buffer_main_t * buffer_main
Definition: main.h:106
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:419
struct rte_mempool * last_pool
Definition: buffer.c:88
#define vec_validate_aligned(V, I, A)
Make sure vector is long enough for given index (no header, specified alignment)
Definition: vec.h:443
void( vlib_buffer_free_cb_t)(struct vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Definition: buffer.h:386
vlib_main_t ** vlib_mains
Definition: buffer.c:292
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
#define vlib_worker_thread_barrier_sync(X)
Definition: threads.h:212
#define vec_add(V, E, N)
Add N elements to end of vector V (no header, unspecified alignment)
Definition: vec.h:595
vlib_buffer_fill_free_list_cb_t __clib_weak dpdk_buffer_fill_free_list_avx2
Definition: buffer.c:693
#define VLIB_BUFFER_NEXT_PRESENT
Definition: buffer.h:95
#define static_always_inline
Definition: clib.h:93
uword * vlib_buffer_state_validation_hash
Definition: buffer.c:586
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:111
vlib_buffer_free_no_next_cb_t __clib_weak dpdk_buffer_free_no_next_avx512
Definition: buffer.c:696
int i32
Definition: types.h:81
#define vlib_prefetch_buffer_header(b, type)
Prefetch buffer metadata.
Definition: buffer.h:171
vlib_buffer_free_no_next_cb_t * vlib_buffer_free_no_next_cb
Definition: buffer.h:395
static void __clib_constructor dpdk_input_multiarch_select(void)
Definition: buffer.c:700
char i8
Definition: types.h:45
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
#define clib_error_return(e, args...)
Definition: error.h:99
u8 pre_data[VLIB_BUFFER_PRE_DATA_SIZE]
Space for inserting data before buffer start.
Definition: buffer.h:151
static u32 vlib_get_buffer_index(vlib_main_t *vm, void *p)
Translate buffer pointer into buffer index.
Definition: buffer_funcs.h:74
#define fl(x, y)
static vlib_physmem_region_t * vlib_physmem_get_region(vlib_main_t *vm, u8 index)
Definition: physmem_funcs.h:44
vlib_buffer_free_list_t ** announce_list
Definition: buffer.h:449
#define rte_mbuf_from_vlib_buffer(x)
Definition: dpdk_priv.h:16
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:459
clib_error_t * dpdk_buffer_pool_create(vlib_main_t *vm, unsigned num_mbufs, unsigned socket_id)
Definition: buffer.c:514
static clib_error_t * buffer_state_validation_init(vlib_main_t *vm)
Definition: buffer.c:590
static u32 vlib_buffer_get_free_list_with_size(vlib_main_t *vm, u32 size)
Definition: buffer_funcs.h:430
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:271
uword CLIB_MULTIARCH_FN() dpdk_buffer_fill_free_list(vlib_main_t *vm, vlib_buffer_free_list_t *fl, uword min_free_buffers)
Definition: buffer.c:200
#define PREDICT_FALSE(x)
Definition: clib.h:105
static void vlib_buffer_add_to_free_list(vlib_main_t *vm, vlib_buffer_free_list_t *f, u32 buffer_index, u8 do_init)
Definition: buffer_funcs.h:848
static_always_inline void recycle_or_free(vlib_main_t *vm, vlib_buffer_main_t *bm, u32 bi, vlib_buffer_t *b)
Definition: buffer.c:319
clib_error_t * dpdk_pool_create(vlib_main_t *vm, u8 *pool_name, u32 elt_size, u32 num_elts, u32 pool_priv_size, u16 cache_size, u8 numa, struct rte_mempool **_mp, vlib_physmem_region_index_t *pri)
Definition: buffer.c:461
struct rte_pktmbuf_pool_private mbp_priv
Definition: dpdk_priv.h:57
STATIC_ASSERT(VLIB_BUFFER_PRE_DATA_SIZE==RTE_PKTMBUF_HEADROOM,"VLIB_BUFFER_PRE_DATA_SIZE must be equal to RTE_PKTMBUF_HEADROOM")
vlib_buffer_fill_free_list_cb_t * vlib_buffer_fill_free_list_cb
Definition: buffer.h:393
static_always_inline void vlib_buffer_free_inline(vlib_main_t *vm, u32 *buffers, u32 n_buffers, u32 follow_buffer_next)
Definition: buffer.c:613
static_always_inline uword vlib_get_thread_index(void)
Definition: threads.h:221
u8 vlib_buffer_add_physmem_region(vlib_main_t *vm, vlib_physmem_region_index_t pri)
Definition: buffer.c:912
u32(* buffer_free_callback)(struct vlib_main_t *vm, u32 *buffers, u32 n_buffers, u32 follow_buffer_next)
Definition: buffer.h:426
#define CLIB_PREFETCH(addr, size, type)
Definition: cache.h:82
vlib_main_t * vm
Definition: buffer.c:283
vlib_buffer_fill_free_list_cb_t __clib_weak dpdk_buffer_fill_free_list_avx512
Definition: buffer.c:692
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:336
static_always_inline void clib_memcpy64_x4(void *d0, void *d1, void *d2, void *d3, void *s)
Definition: string.h:89
static void * clib_mem_set_heap(void *heap)
Definition: mem.h:226
#define clib_warning(format, args...)
Definition: error.h:59
#define clib_memcpy(a, b, c)
Definition: string.h:75
void CLIB_MULTIARCH_FN() dpdk_buffer_free_no_next(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Definition: buffer.c:435
static void del_free_list(vlib_main_t *vm, vlib_buffer_free_list_t *f)
Definition: buffer.c:144
void(* buffers_added_to_freelist_function)(struct vlib_main_t *vm, struct vlib_buffer_free_list_t *fl)
Definition: buffer.h:378
static uword round_pow2(uword x, uword pow2)
Definition: clib.h:286
void * vlib_buffer_state_heap
Definition: buffer.c:587
static void dpdk_buffer_delete_free_list(vlib_main_t *vm, u32 free_list_index)
Definition: buffer.c:162
#define VLIB_BUFFER_DATA_SIZE
Definition: buffer.h:51
#define VLIB_BUFFER_HDR_SIZE
Definition: buffer.h:162
void CLIB_MULTIARCH_FN() dpdk_buffer_free(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Definition: buffer.c:427
void( vlib_buffer_free_no_next_cb_t)(struct vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Definition: buffer.h:388
#define hash_create(elts, value_bytes)
Definition: hash.h:681
#define ASSERT(truth)
unsigned int u32
Definition: types.h:88
vlib_buffer_free_cb_t __clib_weak dpdk_buffer_free_avx2
Definition: buffer.c:695
vlib_buffer_free_cb_t * vlib_buffer_free_cb
Definition: buffer.h:394
u64 size
Definition: vhost-user.h:76
static vlib_buffer_free_list_t * vlib_buffer_get_buffer_free_list(vlib_main_t *vm, vlib_buffer_t *b, u32 *index)
Definition: buffer_funcs.h:440
u32 next_buffer
Next buffer for this linked-list of buffers.
Definition: buffer.h:109
dpdk_buffer_per_thread_data * ptd
Definition: buffer.c:94
struct rte_mempool ** pktmbuf_pools
Definition: dpdk.h:398
#define clib_error_report(e)
Definition: error.h:113
struct rte_mbuf *** mbuf_pending_free_list
Definition: buffer.c:85
VLIB_BUFFER_REGISTER_CALLBACKS(dpdk, static)
u8 n_add_refs
Number of additional references to this buffer.
Definition: buffer.h:124
#define clib_max(x, y)
Definition: clib.h:333
u64 uword
Definition: types.h:112
void ** mbuf_alloc_list
Definition: main.h:175
unsigned short u16
Definition: types.h:57
static_always_inline void dpdk_prefetch_buffer_by_index(vlib_main_t *vm, u32 bi)
Definition: buffer.c:308
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
unsigned char u8
Definition: types.h:56
#define VLIB_BUFFER_TRACE_TRAJECTORY_INIT(b)
Definition: buffer.h:534
vlib_buffer_free_list_t * buffer_free_list_pool
Definition: buffer.h:433
static void vlib_buffer_init_for_free_list(vlib_buffer_t *dst, vlib_buffer_free_list_t *fl)
Definition: buffer_funcs.h:809
void vlib_worker_thread_barrier_release(vlib_main_t *vm)
Definition: threads.c:1491
static vlib_thread_main_t * vlib_get_thread_main()
Definition: global_funcs.h:32
static void dpdk_packet_template_init(vlib_main_t *vm, void *vt, void *packet_data, uword n_packet_data_bytes, uword min_n_buffers_each_physmem_alloc, u8 *name)
Definition: buffer.c:444
vlib_buffer_free_no_next_cb_t __clib_weak dpdk_buffer_free_no_next_avx2
Definition: buffer.c:697
static vlib_buffer_free_list_t * vlib_buffer_get_free_list(vlib_main_t *vm, u32 free_list_index)
Definition: buffer_funcs.h:451
uword( vlib_buffer_fill_free_list_cb_t)(struct vlib_main_t *vm, vlib_buffer_free_list_t *fl, uword min_free_buffers)
Definition: buffer.h:383
u32 flags
Definition: vhost-user.h:77
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:67
static_always_inline void dpdk_rte_pktmbuf_free(vlib_main_t *vm, u32 thread_index, vlib_buffer_t *b)
Definition: buffer.c:100
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index, VLIB_BUFFER_IS_TRACED: trace this buffer.
Definition: buffer.h:75
u8 vlib_physmem_region_index_t
Definition: physmem.h:43
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:57
#define CLIB_MULTIARCH_FN(fn)
Definition: cpu.h:59
#define vec_resize_aligned(V, N, A)
Resize a vector (no header, alignment specified).
Definition: vec.h:250