FD.io VPP  v19.01.1-17-ge106252
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 <unistd.h>
47 
48 #include <rte_config.h>
49 
50 #include <rte_common.h>
51 #include <rte_log.h>
52 #include <rte_memory.h>
53 #include <rte_memzone.h>
54 #include <rte_tailq.h>
55 #include <rte_eal.h>
56 #include <rte_per_lcore.h>
57 #include <rte_launch.h>
58 #include <rte_atomic.h>
59 #include <rte_cycles.h>
60 #include <rte_prefetch.h>
61 #include <rte_lcore.h>
62 #include <rte_per_lcore.h>
63 #include <rte_branch_prediction.h>
64 #include <rte_interrupts.h>
65 #include <rte_vfio.h>
66 #include <rte_random.h>
67 #include <rte_debug.h>
68 #include <rte_ether.h>
69 #include <rte_ethdev.h>
70 #include <rte_ring.h>
71 #include <rte_mempool.h>
72 #include <rte_mbuf.h>
73 #include <rte_version.h>
74 
75 #include <vlib/vlib.h>
76 #include <vlib/unix/unix.h>
77 #include <vnet/vnet.h>
78 #include <dpdk/device/dpdk.h>
79 #include <dpdk/device/dpdk_priv.h>
80 
81 STATIC_ASSERT (VLIB_BUFFER_PRE_DATA_SIZE == RTE_PKTMBUF_HEADROOM,
82  "VLIB_BUFFER_PRE_DATA_SIZE must be equal to RTE_PKTMBUF_HEADROOM");
83 
84 typedef struct
85 {
86  CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
87  struct rte_mbuf **mbuf_alloc_list;
89 
90 typedef struct
91 {
95 
97 
100  int maybe_next)
101 {
102  struct rte_mbuf *mb;
103  u32 next, flags;
104 
105 next:
106  flags = b->flags;
107  next = b->next_buffer;
108  mb = rte_mbuf_from_vlib_buffer (b);
109 
110  if (PREDICT_FALSE (b->n_add_refs))
111  {
112  rte_mbuf_refcnt_update (mb, b->n_add_refs);
113  b->n_add_refs = 0;
114  }
115 
116  if ((mb = rte_pktmbuf_prefree_seg (mb)))
117  rte_mempool_put (mb->pool, mb);
118 
119  if (maybe_next && (flags & VLIB_BUFFER_NEXT_PRESENT))
120  {
121  b = vlib_get_buffer (vm, next);
122  goto next;
123  }
124 }
125 
126 #ifndef CLIB_MARCH_VARIANT
127 static void
129 {
130  u32 i;
131  vlib_buffer_t *b;
132  u32 thread_index = vlib_get_thread_index ();
133 
134  for (i = 0; i < vec_len (f->buffers); i++)
135  {
136  b = vlib_get_buffer (vm, f->buffers[i]);
137  dpdk_rte_pktmbuf_free (vm, thread_index, b, 1);
138  }
139 
140  vec_free (f->name);
141  vec_free (f->buffers);
142  /* Poison it. */
143  clib_memset (f, 0xab, sizeof (f[0]));
144 }
145 
146 /* Add buffer free list. */
147 static void
149  vlib_buffer_free_list_index_t free_list_index)
150 {
152  int i;
153 
154  ASSERT (vlib_get_thread_index () == 0);
155 
156  f = vlib_buffer_get_free_list (vm, free_list_index);
157 
158  del_free_list (vm, f);
159 
161 
162  for (i = 1; i < vec_len (vlib_mains); i++)
163  {
164  vlib_main_t *wvm = vlib_mains[i];
165  f = vlib_buffer_get_free_list (vlib_mains[i], free_list_index);
166  del_free_list (wvm, f);
168  }
169 }
170 #endif
171 
172 /* Make sure free list has at least given number of free buffers. */
173 uword
176  uword min_free_buffers)
177 {
178  dpdk_main_t *dm = &dpdk_main;
180  struct rte_mbuf **mb;
181  uword n_left, first;
182  word n_alloc;
183  unsigned socket_id = rte_socket_id ();
184  u32 thread_index = vlib_get_thread_index ();
185  dpdk_buffer_per_thread_data *d = vec_elt_at_index (dbm->ptd, thread_index);
186  struct rte_mempool *rmp = dm->pktmbuf_pools[socket_id];
187  dpdk_mempool_private_t *privp = rte_mempool_get_priv (rmp);
188  vlib_buffer_t bt;
189  u32 *bi;
190 
191  /* Too early? */
192  if (PREDICT_FALSE (rmp == 0))
193  return 0;
194 
195  /* Already have enough free buffers on free list? */
196  n_alloc = min_free_buffers - vec_len (fl->buffers);
197  if (n_alloc <= 0)
198  return min_free_buffers;
199 
200  /* Always allocate round number of buffers. */
201  n_alloc = round_pow2 (n_alloc, CLIB_CACHE_LINE_BYTES / sizeof (u32));
202 
203  /* Always allocate new buffers in reasonably large sized chunks. */
204  n_alloc = clib_max (n_alloc, fl->min_n_buffers_each_alloc);
205 
206  vec_validate_aligned (d->mbuf_alloc_list, n_alloc - 1,
208 
209  if (rte_mempool_get_bulk (rmp, (void *) d->mbuf_alloc_list, n_alloc) < 0)
210  return 0;
211 
212  clib_memset (&bt, 0, sizeof (vlib_buffer_t));
215 
216  _vec_len (d->mbuf_alloc_list) = n_alloc;
217 
218  first = vec_len (fl->buffers);
219  vec_resize_aligned (fl->buffers, n_alloc, CLIB_CACHE_LINE_BYTES);
220 
221  n_left = n_alloc;
222  mb = d->mbuf_alloc_list;
223  bi = fl->buffers + first;
224 
225  ASSERT (n_left % 8 == 0);
226 
227  while (n_left >= 8)
228  {
229  if (PREDICT_FALSE (n_left < 24))
230  goto no_prefetch;
231 
240 
241  no_prefetch:
242  vlib_get_buffer_indices_with_offset (vm, (void **) mb, bi, 8,
243  sizeof (struct rte_mbuf));
247  vlib_buffer_from_rte_mbuf (mb[3]), &bt);
251  vlib_buffer_from_rte_mbuf (mb[7]), &bt);
252 
253  n_left -= 8;
254  mb += 8;
255  bi += 8;
256  }
257 
258  if (fl->buffer_init_function)
259  fl->buffer_init_function (vm, fl, fl->buffers + first, n_alloc);
260 
261  fl->n_alloc += n_alloc;
262 
263  return n_alloc;
264 }
265 
268 {
269  struct rte_mbuf *mb;
270  mb = rte_mbuf_from_vlib_buffer (b);
271  CLIB_PREFETCH (mb, 2 * CLIB_CACHE_LINE_BYTES, LOAD);
273 }
274 
277  vlib_buffer_t * b)
278 {
279  u32 thread_index = vlib_get_thread_index ();
280 
281  dpdk_rte_pktmbuf_free (vm, thread_index, b, 1);
282 }
283 
286  u32 * buffers, u32 n_buffers, u32 follow_buffer_next)
287 {
289  vlib_buffer_t *bufp[n_buffers], **b = bufp;
290  u32 thread_index = vlib_get_thread_index ();
291  int i = 0;
292  u32 simple_mask = (VLIB_BUFFER_NON_DEFAULT_FREELIST |
293  VLIB_BUFFER_NEXT_PRESENT);
294  u32 n_left, *bi;
295  u32 (*cb) (vlib_main_t * vm, u32 * buffers, u32 n_buffers,
296  u32 follow_buffer_next);
297 
298  cb = bm->buffer_free_callback;
299 
300  if (PREDICT_FALSE (cb != 0))
301  n_buffers = (*cb) (vm, buffers, n_buffers, follow_buffer_next);
302 
303  if (!n_buffers)
304  return;
305 
306  n_left = n_buffers;
307  bi = buffers;
308  b = bufp;
309  vlib_get_buffers (vm, bi, b, n_buffers);
310 
311  while (n_left >= 4)
312  {
313  u32 or_flags;
314  vlib_buffer_t **p;
315 
316  if (n_left < 16)
317  goto no_prefetch;
318 
319  p = b + 12;
320  dpdk_prefetch_buffer (p[0]);
321  dpdk_prefetch_buffer (p[1]);
322  dpdk_prefetch_buffer (p[2]);
323  dpdk_prefetch_buffer (p[3]);
324  no_prefetch:
325 
326  for (i = 0; i < 4; i++)
328 
329  or_flags = b[0]->flags | b[1]->flags | b[2]->flags | b[3]->flags;
330 
331  if (or_flags & simple_mask)
332  {
333  recycle_or_free (vm, bm, bi[0], b[0]);
334  recycle_or_free (vm, bm, bi[1], b[1]);
335  recycle_or_free (vm, bm, bi[2], b[2]);
336  recycle_or_free (vm, bm, bi[3], b[3]);
337  }
338  else
339  {
340  dpdk_rte_pktmbuf_free (vm, thread_index, b[0], 0);
341  dpdk_rte_pktmbuf_free (vm, thread_index, b[1], 0);
342  dpdk_rte_pktmbuf_free (vm, thread_index, b[2], 0);
343  dpdk_rte_pktmbuf_free (vm, thread_index, b[3], 0);
344  }
345  bi += 4;
346  b += 4;
347  n_left -= 4;
348  }
349  while (n_left)
350  {
352  recycle_or_free (vm, bm, bi[0], b[0]);
353  bi += 1;
354  b += 1;
355  n_left -= 1;
356  }
357 }
358 
359 void
361  u32 n_buffers)
362 {
363  vlib_buffer_free_inline (vm, buffers, n_buffers, /* follow_buffer_next */
364  1);
365 }
366 
367 void
369  u32 n_buffers)
370 {
371  vlib_buffer_free_inline (vm, buffers, n_buffers, /* follow_buffer_next */
372  0);
373 }
374 
375 #ifndef CLIB_MARCH_VARIANT
376 clib_error_t *
377 dpdk_pool_create (vlib_main_t * vm, u8 * pool_name, u32 elt_size,
378  u32 num_elts, u32 pool_priv_size, u16 cache_size, u8 numa,
379  struct rte_mempool **_mp, u32 * map_index)
380 {
381  struct rte_mempool *mp;
382  enum rte_iova_mode iova_mode;
384  vlib_physmem_map_t *pm;
385  clib_error_t *error = 0;
386  size_t min_chunk_size, align;
387  int map_dma = 1;
388  u32 size;
389  i32 ret;
390  uword i;
391 
392  mp = rte_mempool_create_empty ((char *) pool_name, num_elts, elt_size,
393  512, pool_priv_size, numa, 0);
394  if (!mp)
395  return clib_error_return (0, "failed to create %s", pool_name);
396 
397  rte_mempool_set_ops_byname (mp, RTE_MBUF_DEFAULT_MEMPOOL_OPS, NULL);
398 
399  size = rte_mempool_op_calc_mem_size_default (mp, num_elts, 21,
400  &min_chunk_size, &align);
401 
402  if ((error = vlib_physmem_shared_map_create (vm, (char *) pool_name, size,
403  0, numa, map_index)))
404  {
405  rte_mempool_free (mp);
406  return error;
407  }
408  pm = vlib_physmem_get_map (vm, *map_index);
409 
410  /* Call the mempool priv initializer */
411  priv.mbp_priv.mbuf_data_room_size = VLIB_BUFFER_PRE_DATA_SIZE +
413  priv.mbp_priv.mbuf_priv_size = VLIB_BUFFER_HDR_SIZE;
414  rte_pktmbuf_pool_init (mp, &priv);
415 
416  if (rte_eth_dev_count_avail () == 0)
417  map_dma = 0;
418 
419  iova_mode = rte_eal_iova_mode ();
420  for (i = 0; i < pm->n_pages; i++)
421  {
422  size_t page_sz = 1ULL << pm->log2_page_size;
423  char *va = ((char *) pm->base) + i * page_sz;
424  uword pa = iova_mode == RTE_IOVA_VA ?
425  pointer_to_uword (va) : pm->page_table[i];
426  ret = rte_mempool_populate_iova (mp, va, pa, page_sz, 0, 0);
427  if (ret < 0)
428  {
429  rte_mempool_free (mp);
430  return clib_error_return (0, "failed to populate %s", pool_name);
431  }
432  /* -1 likely means there is no PCI devices assigned to vfio
433  container or noiommu mode is used so we stop trying */
434  if (map_dma && rte_vfio_dma_map (pointer_to_uword (va), pa, page_sz))
435  map_dma = 0;
436  }
437 
438  _mp[0] = mp;
439 
440  return 0;
441 }
442 
443 clib_error_t *
444 dpdk_buffer_pool_create (vlib_main_t * vm, unsigned num_mbufs,
445  unsigned socket_id)
446 {
447  dpdk_main_t *dm = &dpdk_main;
448  struct rte_mempool *rmp;
449  clib_error_t *error = 0;
450  u8 *pool_name;
451  u32 elt_size, i;
452  u32 map_index;
453 
455 
456  /* pool already exists, nothing to do */
457  if (dm->pktmbuf_pools[socket_id])
458  return 0;
459 
460  pool_name = format (0, "dpdk_mbuf_pool_socket%u%c", socket_id, 0);
461 
462  elt_size = sizeof (struct rte_mbuf) +
463  VLIB_BUFFER_HDR_SIZE /* priv size */ +
464  VLIB_BUFFER_PRE_DATA_SIZE + VLIB_BUFFER_DATA_SIZE; /*data room size */
465 
466  error = dpdk_pool_create (vm, pool_name, elt_size, num_mbufs,
467  sizeof (dpdk_mempool_private_t), 512, socket_id,
468  &rmp, &map_index);
469 
470  vec_free (pool_name);
471 
472  if (!error)
473  {
474  /* call the object initializers */
475  rte_mempool_obj_iter (rmp, rte_pktmbuf_init, 0);
476 
477  dpdk_mempool_private_t *privp = rte_mempool_get_priv (rmp);
478  privp->buffer_pool_index =
479  vlib_buffer_register_physmem_map (vm, map_index);
480 
481  dm->pktmbuf_pools[socket_id] = rmp;
482 
483  return 0;
484  }
485 
486  clib_error_report (error);
487 
488  /* no usable pool for this socket, try to use pool from another one */
489  for (i = 0; i < vec_len (dm->pktmbuf_pools); i++)
490  {
491  if (dm->pktmbuf_pools[i])
492  {
493  clib_warning ("WARNING: Failed to allocate mempool for CPU socket "
494  "%u. Threads running on socket %u will use socket %u "
495  "mempool.", socket_id, socket_id, i);
496  dm->pktmbuf_pools[socket_id] = dm->pktmbuf_pools[i];
497  return 0;
498  }
499  }
500 
501  return clib_error_return (0, "failed to allocate mempool on socket %u",
502  socket_id);
503 }
504 
505 #if CLIB_DEBUG > 0
506 
510 
511 static clib_error_t *
513 {
514  void *oldheap;
515 
517  mheap_alloc_with_lock (0, 10 << 20, 0 /* locked */ );
519 
523  clib_mem_set_heap (oldheap);
524  return 0;
525 }
526 
528 #endif
529 
530 #if CLI_DEBUG
531 struct dpdk_validate_buf_result
532 {
533  u32 invalid;
534  u32 uninitialized;
535 };
536 
537 #define DPDK_TRAJECTORY_POISON 31
538 
539 static void
540 dpdk_buffer_validate_trajectory (struct rte_mempool *mp, void *opaque,
541  void *obj, unsigned obj_idx)
542 {
543  vlib_buffer_t *b;
544  struct dpdk_validate_buf_result *counter = opaque;
545  b = vlib_buffer_from_rte_mbuf ((struct rte_mbuf *) obj);
546  if (b->pre_data[0] != 0)
547  {
548  if (b->pre_data[0] == DPDK_TRAJECTORY_POISON)
549  counter->uninitialized++;
550  else
551  counter->invalid++;
552  }
553 }
554 
555 int
556 dpdk_buffer_validate_trajectory_all (u32 * uninitialized)
557 {
558  dpdk_main_t *dm = &dpdk_main;
559  struct dpdk_validate_buf_result counter = { 0 };
560  int i;
561 
562  for (i = 0; i < vec_len (dm->pktmbuf_pools); i++)
563  rte_mempool_obj_iter (dm->pktmbuf_pools[i],
564  dpdk_buffer_validate_trajectory, &counter);
565  if (uninitialized)
566  *uninitialized = counter.uninitialized;
567  return counter.invalid;
568 }
569 
570 static void
571 dpdk_buffer_poison_trajectory (struct rte_mempool *mp, void *opaque,
572  void *obj, unsigned obj_idx)
573 {
574  vlib_buffer_t *b;
575  b = vlib_buffer_from_rte_mbuf ((struct rte_mbuf *) obj);
576  b->pre_data[0] = DPDK_TRAJECTORY_POISON;
577 }
578 
579 void
580 dpdk_buffer_poison_trajectory_all (void)
581 {
582  dpdk_main_t *dm = &dpdk_main;
583  int i;
584 
585  for (i = 0; i < vec_len (dm->pktmbuf_pools); i++)
586  rte_mempool_obj_iter (dm->pktmbuf_pools[i], dpdk_buffer_poison_trajectory,
587  0);
588 }
589 #endif
590 
591 static clib_error_t *
593 {
596 
597  vec_validate_aligned (dbm->ptd, tm->n_vlib_mains - 1,
599 
600  dbm->vfio_container_fd = -1;
601 
602  return 0;
603 }
604 
606 
607 /* *INDENT-OFF* */
608 VLIB_BUFFER_REGISTER_CALLBACKS (dpdk, static) = {
609  .vlib_buffer_fill_free_list_cb = &dpdk_buffer_fill_free_list,
610  .vlib_buffer_free_cb = &dpdk_buffer_free,
611  .vlib_buffer_free_no_next_cb = &dpdk_buffer_free_no_next,
612  .vlib_buffer_delete_free_list_cb = &dpdk_buffer_delete_free_list,
613 };
614 /* *INDENT-ON* */
615 
616 #if __x86_64__
623 
624 static void __clib_constructor
626 {
627  vlib_buffer_callbacks_t *cb = &__dpdk_buffer_callbacks;
628  if (dpdk_buffer_fill_free_list_avx512 && clib_cpu_supports_avx512f ())
629  {
633  }
634  else if (dpdk_buffer_fill_free_list_avx2 && clib_cpu_supports_avx2 ())
635  {
639  }
640 }
641 #endif
642 #endif
643 
644 /** @endcond */
645 /*
646  * fd.io coding-style-patch-verification: ON
647  *
648  * Local Variables:
649  * eval: (c-set-style "gnu")
650  * End:
651  */
#define vlib_buffer_from_rte_mbuf(x)
Definition: dpdk_priv.h:17
#define CLIB_CACHE_LINE_ALIGN_MARK(mark)
Definition: cache.h:60
u32 flags
Definition: vhost_user.h:115
dpdk_buffer_main_t dpdk_buffer_main
Definition: buffer.c:96
static clib_error_t * dpdk_buffer_init(vlib_main_t *vm)
Definition: buffer.c:592
dpdk_main_t dpdk_main
Definition: init.c:43
static_always_inline void dpdk_prefetch_buffer(vlib_buffer_t *b)
Definition: buffer.c:267
u8 vlib_buffer_register_physmem_map(vlib_main_t *vm, u32 physmem_map_index)
Definition: buffer.c:804
u32 * vlib_buffer_state_validation_lock
Definition: buffer.c:507
#define NULL
Definition: clib.h:58
vlib_buffer_free_cb_t __clib_weak dpdk_buffer_free_avx512
Definition: buffer.c:619
#define VLIB_BUFFER_PRE_DATA_SIZE
Definition: buffer.h:52
u8 buffer_pool_index
index of buffer pool this buffer belongs.
Definition: buffer.h:144
int i
static void dpdk_buffer_delete_free_list(vlib_main_t *vm, vlib_buffer_free_list_index_t free_list_index)
Definition: buffer.c:148
uword * page_table
Definition: physmem.h:51
clib_memset(h->entries, 0, sizeof(h->entries[0])*entries)
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:419
vlib_physmem_map_t * vlib_physmem_get_map(vlib_main_t *vm, u32 index)
Definition: physmem.c:87
#define vec_validate_aligned(V, I, A)
Make sure vector is long enough for given index (no header, specified alignment)
Definition: vec.h:450
void( vlib_buffer_free_cb_t)(struct vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Definition: buffer.h:400
vlib_main_t ** vlib_mains
Definition: buffer.c:310
unsigned char u8
Definition: types.h:56
vlib_buffer_fill_free_list_cb_t __clib_weak dpdk_buffer_fill_free_list_avx2
Definition: buffer.c:618
#define static_always_inline
Definition: clib.h:99
i64 word
Definition: types.h:111
uword * vlib_buffer_state_validation_hash
Definition: buffer.c:508
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:163
vlib_buffer_free_no_next_cb_t __clib_weak dpdk_buffer_free_no_next_avx512
Definition: buffer.c:621
#define vlib_prefetch_buffer_header(b, type)
Prefetch buffer metadata.
Definition: buffer.h:188
vlib_buffer_free_no_next_cb_t * vlib_buffer_free_no_next_cb
Definition: buffer.h:409
static void __clib_constructor dpdk_input_multiarch_select(void)
Definition: buffer.c:625
#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:168
unsigned int u32
Definition: types.h:88
#define fl(x, y)
static heap_elt_t * first(heap_header_t *h)
Definition: heap.c:59
#define rte_mbuf_from_vlib_buffer(x)
Definition: dpdk_priv.h:16
uword size
clib_error_t * dpdk_buffer_pool_create(vlib_main_t *vm, unsigned num_mbufs, unsigned socket_id)
Definition: buffer.c:444
clib_error_t * vlib_physmem_shared_map_create(vlib_main_t *vm, char *name, uword size, u32 log2_page_sz, u32 numa_node, u32 *map_index)
Definition: physmem.c:42
static clib_error_t * buffer_state_validation_init(vlib_main_t *vm)
Definition: buffer.c:512
static_always_inline void dpdk_rte_pktmbuf_free(vlib_main_t *vm, u32 thread_index, vlib_buffer_t *b, int maybe_next)
Definition: buffer.c:99
unsigned short u16
Definition: types.h:57
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:286
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:174
#define PREDICT_FALSE(x)
Definition: clib.h:111
vlib_buffer_free_list_t * buffer_free_list_pool
Definition: main.h:123
static_always_inline void vlib_get_buffer_indices_with_offset(vlib_main_t *vm, void **b, u32 *bi, uword count, i32 offset)
Translate array of buffer pointers into buffer indices with offset.
Definition: buffer_funcs.h:177
struct rte_pktmbuf_pool_private mbp_priv
Definition: dpdk_priv.h:58
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:407
static_always_inline void vlib_buffer_free_inline(vlib_main_t *vm, u32 *buffers, u32 n_buffers, u32 follow_buffer_next)
Definition: buffer.c:594
static_always_inline uword vlib_get_thread_index(void)
Definition: threads.h:212
u32(* buffer_free_callback)(struct vlib_main_t *vm, u32 *buffers, u32 n_buffers, u32 follow_buffer_next)
Definition: buffer.h:439
#define CLIB_PREFETCH(addr, size, type)
Definition: cache.h:79
vlib_main_t * vm
Definition: buffer.c:301
vlib_buffer_fill_free_list_cb_t __clib_weak dpdk_buffer_fill_free_list_avx512
Definition: buffer.c:617
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:341
static_always_inline void clib_memcpy64_x4(void *d0, void *d1, void *d2, void *d3, void *s)
Definition: string.h:224
static void * clib_mem_set_heap(void *heap)
Definition: mem.h:261
#define clib_warning(format, args...)
Definition: error.h:59
void CLIB_MULTIARCH_FN() dpdk_buffer_free_no_next(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Definition: buffer.c:368
static void del_free_list(vlib_main_t *vm, vlib_buffer_free_list_t *f)
Definition: buffer.c:128
static uword round_pow2(uword x, uword pow2)
Definition: clib.h:241
void * vlib_buffer_state_heap
Definition: buffer.c:509
#define VLIB_BUFFER_DATA_SIZE
Definition: buffer.h:51
#define VLIB_BUFFER_HDR_SIZE
Definition: buffer.h:179
void CLIB_MULTIARCH_FN() dpdk_buffer_free(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Definition: buffer.c:360
void( vlib_buffer_free_no_next_cb_t)(struct vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Definition: buffer.h:402
signed int i32
Definition: types.h:77
#define hash_create(elts, value_bytes)
Definition: hash.h:696
#define ASSERT(truth)
vlib_buffer_free_cb_t __clib_weak dpdk_buffer_free_avx2
Definition: buffer.c:620
vlib_buffer_free_cb_t * vlib_buffer_free_cb
Definition: buffer.h:408
int vfio_container_fd
Definition: buffer.c:92
void * mheap_alloc_with_lock(void *memory, uword size, int locked)
Definition: mem_dlmalloc.c:429
u32 next_buffer
Next buffer for this linked-list of buffers.
Definition: buffer.h:130
dpdk_buffer_per_thread_data * ptd
Definition: buffer.c:93
struct rte_mempool ** pktmbuf_pools
Definition: dpdk.h:447
#define clib_error_report(e)
Definition: error.h:113
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, u32 *map_index)
Definition: buffer.c:377
VLIB_BUFFER_REGISTER_CALLBACKS(dpdk, static)
static uword pointer_to_uword(const void *p)
Definition: types.h:131
u8 n_add_refs
Number of additional references to this buffer.
Definition: buffer.h:142
#define clib_max(x, y)
Definition: clib.h:288
static_always_inline void recycle_or_free(vlib_main_t *vm, vlib_buffer_main_t *bm, u32 bi, vlib_buffer_t *b, u32 follow_buffer_next)
Definition: buffer.c:566
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
#define VLIB_BUFFER_TRACE_TRAJECTORY_INIT(b)
Definition: buffer.h:495
u64 uword
Definition: types.h:112
static void vlib_buffer_init_for_free_list(vlib_buffer_t *dst, vlib_buffer_free_list_t *fl)
static vlib_thread_main_t * vlib_get_thread_main()
Definition: global_funcs.h:32
vlib_buffer_main_t buffer_main
Definition: buffer.c:56
u8 vlib_buffer_free_list_index_t
Definition: buffer.h:62
vlib_buffer_free_no_next_cb_t __clib_weak dpdk_buffer_free_no_next_avx2
Definition: buffer.c:622
static vlib_buffer_free_list_t * vlib_buffer_get_free_list(vlib_main_t *vm, vlib_buffer_free_list_index_t free_list_index)
Definition: buffer_funcs.h:657
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:397
static_always_inline void vlib_get_buffers(vlib_main_t *vm, u32 *bi, vlib_buffer_t **b, int count)
Translate array of buffer indices into buffer pointers.
Definition: buffer_funcs.h:145
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:59
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:117
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:62
struct rte_mbuf ** mbuf_alloc_list
Definition: buffer.c:87
#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:255