FD.io VPP  v16.06
Vector Packet Processing
dpdk_buffer.c
Go to the documentation of this file.
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 /*
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 #include <rte_config.h>
41 
42 #include <rte_common.h>
43 #include <rte_log.h>
44 #include <rte_memory.h>
45 #include <rte_memzone.h>
46 #include <rte_tailq.h>
47 #include <rte_eal.h>
48 #include <rte_per_lcore.h>
49 #include <rte_launch.h>
50 #include <rte_atomic.h>
51 #include <rte_cycles.h>
52 #include <rte_prefetch.h>
53 #include <rte_lcore.h>
54 #include <rte_per_lcore.h>
55 #include <rte_branch_prediction.h>
56 #include <rte_interrupts.h>
57 #include <rte_pci.h>
58 #include <rte_random.h>
59 #include <rte_debug.h>
60 #include <rte_ether.h>
61 #include <rte_ethdev.h>
62 #include <rte_ring.h>
63 #include <rte_mempool.h>
64 #include <rte_mbuf.h>
65 
66 #include <vlib/vlib.h>
67 
68 #pragma weak rte_mem_virt2phy
69 #pragma weak rte_eal_has_hugepages
70 #pragma weak rte_socket_id
71 #pragma weak rte_pktmbuf_pool_create
72 
74 {
75  vlib_buffer_t * b = b_first;
76  uword l_first = b_first->current_length;
77  uword l = 0;
78  while (b->flags & VLIB_BUFFER_NEXT_PRESENT)
79  {
80  b = vlib_get_buffer (vm, b->next_buffer);
81  l += b->current_length;
82  }
85  return l + l_first;
86 }
87 
88 u8 * format_vlib_buffer (u8 * s, va_list * args)
89 {
90  vlib_buffer_t * b = va_arg (*args, vlib_buffer_t *);
91  uword indent = format_get_indent (s);
92 
93  s = format (s, "current data %d, length %d, free-list %d",
95  b->free_list_index);
96 
98  s = format (s, ", totlen-nifb %d",
100 
101  if (b->flags & VLIB_BUFFER_IS_TRACED)
102  s = format (s, ", trace 0x%x", b->trace_index);
103 
104  while (b->flags & VLIB_BUFFER_NEXT_PRESENT)
105  {
106  vlib_main_t * vm = vlib_get_main();
107  u32 next_buffer = b->next_buffer;
108  b = vlib_get_buffer(vm, next_buffer);
109 
110  s = format (s, "\n%Unext-buffer 0x%x, segment length %d",
111  format_white_space, indent, next_buffer, b->current_length);
112  }
113 
114 
115  return s;
116 }
117 
118 u8 * format_vlib_buffer_and_data (u8 * s, va_list * args)
119 {
120  vlib_buffer_t * b = va_arg (*args, vlib_buffer_t *);
121 
122  s = format (s, "%U, %U",
125 
126  return s;
127 }
128 
129 u8 * format_vlib_buffer_contents (u8 * s, va_list * va)
130 {
131  vlib_main_t * vm = va_arg (*va, vlib_main_t *);
132  vlib_buffer_t * b = va_arg (*va, vlib_buffer_t *);
133 
134  while (1)
135  {
137  b->current_length);
138  if (! (b->flags & VLIB_BUFFER_NEXT_PRESENT))
139  break;
140  b = vlib_get_buffer (vm, b->next_buffer);
141  }
142 
143  return s;
144 }
145 
147 
148 /* Aligned copy routine. */
149 void
150 vlib_aligned_memcpy (void * _dst, void * _src, int n_bytes)
151 {
152  vlib_copy_unit_t * dst = _dst;
153  vlib_copy_unit_t * src = _src;
154 
155  /* Arguments must be naturally aligned. */
156  ASSERT (pointer_to_uword (dst) % sizeof (dst[0]) == 0);
157  ASSERT (pointer_to_uword (src) % sizeof (src[0]) == 0);
158  ASSERT (n_bytes % sizeof (dst[0]) == 0);
159 
160  if (4 * sizeof (dst[0]) == CLIB_CACHE_LINE_BYTES)
161  {
162  CLIB_PREFETCH (dst + 0, 4 * sizeof (dst[0]), WRITE);
163  CLIB_PREFETCH (src + 0, 4 * sizeof (src[0]), READ);
164 
165  while (n_bytes >= 4 * sizeof (dst[0]))
166  {
167  dst += 4;
168  src += 4;
169  n_bytes -= 4 * sizeof (dst[0]);
170  CLIB_PREFETCH (dst, 4 * sizeof (dst[0]), WRITE);
171  CLIB_PREFETCH (src, 4 * sizeof (src[0]), READ);
172  dst[-4] = src[-4];
173  dst[-3] = src[-3];
174  dst[-2] = src[-2];
175  dst[-1] = src[-1];
176  }
177  }
178  else if (8 * sizeof (dst[0]) == CLIB_CACHE_LINE_BYTES)
179  {
180  CLIB_PREFETCH (dst + 0, 8 * sizeof (dst[0]), WRITE);
181  CLIB_PREFETCH (src + 0, 8 * sizeof (src[0]), READ);
182 
183  while (n_bytes >= 8 * sizeof (dst[0]))
184  {
185  dst += 8;
186  src += 8;
187  n_bytes -= 8 * sizeof (dst[0]);
188  CLIB_PREFETCH (dst, 8 * sizeof (dst[0]), WRITE);
189  CLIB_PREFETCH (src, 8 * sizeof (src[0]), READ);
190  dst[-8] = src[-8];
191  dst[-7] = src[-7];
192  dst[-6] = src[-6];
193  dst[-5] = src[-5];
194  dst[-4] = src[-4];
195  dst[-3] = src[-3];
196  dst[-2] = src[-2];
197  dst[-1] = src[-1];
198  }
199  }
200  else
201  /* Cache line size unknown: fall back to slow version. */;
202 
203  while (n_bytes > 0)
204  {
205  *dst++ = *src++;
206  n_bytes -= 1 * sizeof (dst[0]);
207  }
208 }
209 
210 #define BUFFERS_PER_COPY (sizeof (vlib_copy_unit_t) / sizeof (u32))
211 
212 /* Make sure we have at least given number of unaligned buffers. */
213 static void
215  vlib_buffer_free_list_t * free_list,
216  uword n_unaligned_buffers)
217 {
218  word la = vec_len (free_list->aligned_buffers);
219  word lu = vec_len (free_list->unaligned_buffers);
220 
221  /* Aligned come in aligned copy-sized chunks. */
222  ASSERT (la % BUFFERS_PER_COPY == 0);
223 
224  ASSERT (la >= n_unaligned_buffers);
225 
226  while (lu < n_unaligned_buffers)
227  {
228  /* Copy 4 buffers from end of aligned vector to unaligned vector. */
229  vec_add (free_list->unaligned_buffers,
230  free_list->aligned_buffers + la - BUFFERS_PER_COPY,
232  la -= BUFFERS_PER_COPY;
233  lu += BUFFERS_PER_COPY;
234  }
235  _vec_len (free_list->aligned_buffers) = la;
236 }
237 
238 /* After free aligned buffers may not contain even sized chunks. */
239 static void
241 {
242  uword l, n_trim;
243 
244  /* Add unaligned to aligned before trim. */
245  l = vec_len (f->unaligned_buffers);
246  if (l > 0)
247  {
249  /* align */ sizeof (vlib_copy_unit_t));
250 
251  _vec_len (f->unaligned_buffers) = 0;
252  }
253 
254  /* Remove unaligned buffers from end of aligned vector and save for next trim. */
255  l = vec_len (f->aligned_buffers);
256  n_trim = l % BUFFERS_PER_COPY;
257  if (n_trim)
258  {
259  /* Trim aligned -> unaligned. */
260  vec_add (f->unaligned_buffers, f->aligned_buffers + l - n_trim, n_trim);
261 
262  /* Remove from aligned. */
263  _vec_len (f->aligned_buffers) = l - n_trim;
264  }
265 }
266 
267 static void
270 {
271  uword l;
272  u32 * d;
273 
274  trim_aligned (src);
275  trim_aligned (dst);
276 
277  l = vec_len (src->aligned_buffers);
278  if (l > 0)
279  {
280  vec_add2_aligned (dst->aligned_buffers, d, l,
281  /* align */ sizeof (vlib_copy_unit_t));
282  vlib_aligned_memcpy (d, src->aligned_buffers, l * sizeof (d[0]));
283  vec_free (src->aligned_buffers);
284  }
285 
286  l = vec_len (src->unaligned_buffers);
287  if (l > 0)
288  {
291  }
292 }
293 
296 {
297  vlib_buffer_main_t * bm = vm->buffer_main;
298 
299  size = vlib_buffer_round_size (size);
300  uword * p = hash_get (bm->free_list_by_size, size);
301  return p ? p[0] : ~0;
302 }
303 
304 /* Add buffer free list. */
305 static u32
307  u32 n_data_bytes,
308  u32 is_public,
309  u32 is_default,
310  u8 * name)
311 {
312  vlib_buffer_main_t * bm = vm->buffer_main;
314 
315  if (! is_default && pool_elts (bm->buffer_free_list_pool) == 0)
316  {
317  u32 default_free_free_list_index;
318 
319  default_free_free_list_index =
321  /* default buffer size */ VLIB_BUFFER_DEFAULT_FREE_LIST_BYTES,
322  /* is_public */ 1,
323  /* is_default */ 1,
324  (u8 *) "default");
325  ASSERT (default_free_free_list_index == VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX);
326 
327  if (n_data_bytes == VLIB_BUFFER_DEFAULT_FREE_LIST_BYTES && is_public)
328  return default_free_free_list_index;
329  }
330 
332 
333  memset (f, 0, sizeof (f[0]));
334  f->index = f - bm->buffer_free_list_pool;
335  f->n_data_bytes = vlib_buffer_round_size (n_data_bytes);
337  f->name = clib_mem_is_heap_object (name) ? name : format (0, "%s", name);
338 
339  /* Setup free buffer template. */
341 
342  if (is_public)
343  {
345  if (! p)
347  }
348 
349  return f->index;
350 }
351 
353  char * fmt, ...)
354 {
355  va_list va;
356  u8 * name;
357 
358  va_start (va, fmt);
359  name = va_format (0, fmt, &va);
360  va_end (va);
361 
362  return vlib_buffer_create_free_list_helper (vm, n_data_bytes,
363  /* is_public */ 0,
364  /* is_default */ 0,
365  name);
366 }
367 
369  char * fmt, ...)
370 {
371  u32 i = vlib_buffer_get_free_list_with_size (vm, n_data_bytes);
372 
373  if (i == ~0)
374  {
375  va_list va;
376  u8 * name;
377 
378  va_start (va, fmt);
379  name = va_format (0, fmt, &va);
380  va_end (va);
381 
382  i = vlib_buffer_create_free_list_helper (vm, n_data_bytes,
383  /* is_public */ 1,
384  /* is_default */ 0,
385  name);
386  }
387 
388  return i;
389 }
390 
391 static void
393 {
394  u32 i;
395  struct rte_mbuf *mb;
396  vlib_buffer_t *b;
397 
398  for (i = 0; i < vec_len (f->unaligned_buffers); i++) {
399  b = vlib_get_buffer (vm, f->unaligned_buffers[i]);
400  mb = rte_mbuf_from_vlib_buffer(b);
401  ASSERT(rte_mbuf_refcnt_read(mb) == 1);
402  rte_pktmbuf_free (mb);
403  }
404  for (i = 0; i < vec_len (f->aligned_buffers); i++) {
405  b = vlib_get_buffer (vm, f->aligned_buffers[i]);
406  mb = rte_mbuf_from_vlib_buffer(b);
407  ASSERT(rte_mbuf_refcnt_read(mb) == 1);
408  rte_pktmbuf_free (mb);
409  }
410  vec_free (f->name);
413 }
414 
415 /* Add buffer free list. */
416 void vlib_buffer_delete_free_list (vlib_main_t * vm, u32 free_list_index)
417 {
418  vlib_buffer_main_t * bm = vm->buffer_main;
420  u32 merge_index;
421 
422  f = vlib_buffer_get_free_list (vm, free_list_index);
423 
424  merge_index = vlib_buffer_get_free_list_with_size (vm, f->n_data_bytes);
425  if (merge_index != ~0 && merge_index != free_list_index)
426  {
428  merge_index), f);
429  }
430 
431  del_free_list (vm, f);
432 
433  /* Poison it. */
434  memset (f, 0xab, sizeof (f[0]));
435 
437 }
438 
439 /* Make sure free list has at least given number of free buffers. */
440 static uword
443  uword min_free_buffers)
444 {
445  vlib_buffer_t * b;
446  int n, i;
447  u32 bi;
448  u32 n_remaining = 0, n_alloc = 0;
449  unsigned socket_id = rte_socket_id ? rte_socket_id() : 0;
450  struct rte_mempool *rmp = vm->buffer_main->pktmbuf_pools[socket_id];
451  struct rte_mbuf *mb;
452 
453  /* Too early? */
454  if (PREDICT_FALSE(rmp == 0))
455  return 0;
456 
457  trim_aligned (fl);
458 
459  /* Already have enough free buffers on free list? */
460  n = min_free_buffers - vec_len (fl->aligned_buffers);
461  if (n <= 0)
462  return min_free_buffers;
463 
464  /* Always allocate round number of buffers. */
465  n = round_pow2 (n, BUFFERS_PER_COPY);
466 
467  /* Always allocate new buffers in reasonably large sized chunks. */
469 
470  vec_validate (vm->mbuf_alloc_list, n-1);
471 
472  if (rte_mempool_get_bulk (rmp, vm->mbuf_alloc_list, n) < 0)
473  return 0;
474 
475  _vec_len (vm->mbuf_alloc_list) = n;
476 
477  for (i = 0; i < n; i++)
478  {
479  mb = vm->mbuf_alloc_list[i];
480 
481  ASSERT(rte_mbuf_refcnt_read(mb) == 0);
482  rte_mbuf_refcnt_set(mb, 1);
483  mb->next = NULL;
484  mb->data_off = RTE_PKTMBUF_HEADROOM;
485  mb->nb_segs = 1;
486 
487  b = vlib_buffer_from_rte_mbuf(mb);
488  bi = vlib_get_buffer_index (vm, b);
489 
491  n_alloc++;
492  n_remaining--;
493 
495 
496  if (fl->buffer_init_function)
497  fl->buffer_init_function (vm, fl, &bi, 1);
498  }
499 
500  fl->n_alloc += n;
501 
502  return n;
503 }
504 
507 { return (pointer_to_uword (x) / sizeof (x[0])) % BUFFERS_PER_COPY; }
508 
509 static u32
511  vlib_buffer_free_list_t * free_list,
512  u32 * alloc_buffers,
513  u32 n_alloc_buffers)
514 {
515  u32 * dst, * u_src;
516  uword u_len, n_left;
517  uword n_unaligned_start, n_unaligned_end, n_filled;
518 
519  n_left = n_alloc_buffers;
520  dst = alloc_buffers;
521  n_unaligned_start = ((BUFFERS_PER_COPY - copy_alignment (dst))
522  & (BUFFERS_PER_COPY - 1));
523 
524  n_filled = fill_free_list (vm, free_list, n_alloc_buffers);
525  if (n_filled == 0)
526  return 0;
527 
528  n_left = n_filled < n_left ? n_filled : n_left;
529  n_alloc_buffers = n_left;
530 
531  if (n_unaligned_start >= n_left)
532  {
533  n_unaligned_start = n_left;
534  n_unaligned_end = 0;
535  }
536  else
537  n_unaligned_end = copy_alignment (dst + n_alloc_buffers);
538 
539  fill_unaligned (vm, free_list, n_unaligned_start + n_unaligned_end);
540 
541  u_len = vec_len (free_list->unaligned_buffers);
542  u_src = free_list->unaligned_buffers + u_len - 1;
543 
544  if (n_unaligned_start)
545  {
546  uword n_copy = n_unaligned_start;
547  if (n_copy > n_left)
548  n_copy = n_left;
549  n_left -= n_copy;
550 
551  while (n_copy > 0)
552  {
553  *dst++ = *u_src--;
554  n_copy--;
555  u_len--;
556  }
557 
558  /* Now dst should be aligned. */
559  if (n_left > 0)
560  ASSERT (pointer_to_uword (dst) % sizeof (vlib_copy_unit_t) == 0);
561  }
562 
563  /* Aligned copy. */
564  {
565  vlib_copy_unit_t * d, * s;
566  uword n_copy;
567 
568  if (vec_len(free_list->aligned_buffers) < ((n_left/BUFFERS_PER_COPY)*BUFFERS_PER_COPY))
569  abort();
570 
571  n_copy = n_left / BUFFERS_PER_COPY;
572  n_left = n_left % BUFFERS_PER_COPY;
573 
574  /* Remove buffers from aligned free list. */
575  _vec_len (free_list->aligned_buffers) -= n_copy * BUFFERS_PER_COPY;
576 
577  s = (vlib_copy_unit_t *) vec_end (free_list->aligned_buffers);
578  d = (vlib_copy_unit_t *) dst;
579 
580  /* Fast path loop. */
581  while (n_copy >= 4)
582  {
583  d[0] = s[0];
584  d[1] = s[1];
585  d[2] = s[2];
586  d[3] = s[3];
587  n_copy -= 4;
588  s += 4;
589  d += 4;
590  }
591 
592  while (n_copy >= 1)
593  {
594  d[0] = s[0];
595  n_copy -= 1;
596  s += 1;
597  d += 1;
598  }
599 
600  dst = (void *) d;
601  }
602 
603  /* Unaligned copy. */
604  ASSERT (n_unaligned_end == n_left);
605  while (n_left > 0)
606  {
607  *dst++ = *u_src--;
608  n_left--;
609  u_len--;
610  }
611 
612  if (! free_list->unaligned_buffers)
613  ASSERT (u_len == 0);
614  else
615  _vec_len (free_list->unaligned_buffers) = u_len;
616 
617  return n_alloc_buffers;
618 }
619 
620 /* Allocate a given number of buffers into given array.
621  Returns number actually allocated which will be either zero or
622  number requested. */
623 u32 vlib_buffer_alloc (vlib_main_t * vm, u32 * buffers, u32 n_buffers)
624 {
625  vlib_buffer_main_t * bm = vm->buffer_main;
626 
627  return alloc_from_free_list
628  (vm,
631  buffers, n_buffers);
632 }
633 
635  u32 * buffers,
636  u32 n_buffers,
637  u32 free_list_index)
638 {
639  vlib_buffer_main_t * bm = vm->buffer_main;
641  f = pool_elt_at_index (bm->buffer_free_list_pool, free_list_index);
642  return alloc_from_free_list (vm, f, buffers, n_buffers);
643 }
644 
645 always_inline void
648  u32 buffer_index, u8 do_init)
649 {
650  vlib_buffer_t * b;
651  b = vlib_get_buffer (vm, buffer_index);
652  if (PREDICT_TRUE(do_init))
654  vec_add1_aligned (f->aligned_buffers, buffer_index, sizeof (vlib_copy_unit_t));
655 }
656 
659 {
660  vlib_buffer_main_t * bm = vm->buffer_main;
661  u32 i;
662 
663  *index = i = b->free_list_index;
665 }
666 
668 {
669  vlib_buffer_main_t * bm = vm->buffer_main;
670  void * rv = bm->buffer_free_callback;
671 
672  bm->buffer_free_callback = fp;
673  return rv;
674 }
675 
678  u32 * buffers,
679  u32 n_buffers,
680  u32 follow_buffer_next)
681 {
682  vlib_buffer_main_t * bm = vm->buffer_main;
684  u32 fi;
685  int i;
686  u32 (*cb)(vlib_main_t * vm, u32 * buffers, u32 n_buffers,
687  u32 follow_buffer_next);
688 
689  cb = bm->buffer_free_callback;
690 
691  if (PREDICT_FALSE (cb != 0))
692  n_buffers = (*cb)(vm, buffers, n_buffers, follow_buffer_next);
693 
694  if (! n_buffers)
695  return;
696 
697  for (i = 0; i < n_buffers; i++)
698  {
699  vlib_buffer_t * b;
700  struct rte_mbuf * mb;
701 
702  b = vlib_get_buffer (vm, buffers[i]);
703 
704  fl = buffer_get_free_list (vm, b, &fi);
705 
706  /* The only current use of this callback: multicast recycle */
708  {
709  int j;
710 
711  add_buffer_to_free_list (vm, fl, buffers[i], b->clone_count == 0);
712 
713  for (j = 0; j < vec_len (bm->announce_list); j++)
714  {
715  if (fl == bm->announce_list[j])
716  goto already_announced;
717  }
718  vec_add1 (bm->announce_list, fl);
719  already_announced:
720  ;
721  }
722  else
723  {
724  if (PREDICT_TRUE (b->clone_count == 0))
725  {
726  mb = rte_mbuf_from_vlib_buffer(b);
727  ASSERT(rte_mbuf_refcnt_read(mb) == 1);
728  rte_pktmbuf_free (mb);
729  }
730  }
731  }
732  if (vec_len(bm->announce_list))
733  {
735  for (i = 0; i < vec_len (bm->announce_list); i++)
736  {
737  fl = bm->announce_list[i];
739  }
740  _vec_len(bm->announce_list) = 0;
741  }
742 }
743 
745  u32 * buffers,
746  u32 n_buffers)
747 {
748  vlib_buffer_free_inline (vm, buffers, n_buffers, /* follow_buffer_next */ 1);
749 }
750 
752  u32 * buffers,
753  u32 n_buffers)
754 {
755  vlib_buffer_free_inline (vm, buffers, n_buffers, /* follow_buffer_next */ 0);
756 }
757 
758 /* Copy template packet data into buffers as they are allocated. */
759 __attribute__((unused)) static void
762  u32 * buffers,
763  u32 n_buffers)
764 {
767  uword i;
768 
769  for (i = 0; i < n_buffers; i++)
770  {
771  vlib_buffer_t * b = vlib_get_buffer (vm, buffers[i]);
774  }
775 }
776 
779  void * packet_data,
780  uword n_packet_data_bytes,
781  uword min_n_buffers_each_physmem_alloc,
782  char * fmt,
783  ...)
784 {
785  va_list va;
786  __attribute__((unused)) u8 * name;
787 
788  va_start (va, fmt);
789  name = va_format (0, fmt, &va);
790  va_end (va);
791 
793  memset (t, 0, sizeof (t[0]));
794 
795  vec_add (t->packet_data, packet_data, n_packet_data_bytes);
796 
798 }
799 
800 void *
803  u32 * bi_result)
804 {
805  u32 bi;
806  vlib_buffer_t * b;
807 
808  if (vlib_buffer_alloc (vm, &bi, 1) != 1)
809  return 0;
810 
811  *bi_result = bi;
812 
813  b = vlib_get_buffer (vm, bi);
817 
818  /* Fix up mbuf header length fields */
819  struct rte_mbuf * mb;
820  mb = rte_mbuf_from_vlib_buffer(b);
821  mb->data_len = b->current_length;
822  mb->pkt_len = b->current_length;
823 
824  return b->data;
825 }
826 
827 /* Append given data to end of buffer, possibly allocating new buffers. */
829  u32 free_list_index,
830  u32 buffer_index,
831  void * data, u32 n_data_bytes)
832 {
833  u32 n_buffer_bytes, n_left, n_left_this_buffer, bi;
834  vlib_buffer_t * b;
835  void * d;
836 
837  bi = buffer_index;
838  if (bi == 0
839  && 1 != vlib_buffer_alloc_from_free_list (vm, &bi, 1, free_list_index))
840  goto out_of_buffers;
841 
842  d = data;
843  n_left = n_data_bytes;
844  n_buffer_bytes = vlib_buffer_free_list_buffer_size (vm, free_list_index);
845 
846  b = vlib_get_buffer (vm, bi);
848 
849  /* Get to the end of the chain before we try to append data...*/
850  while (b->flags & VLIB_BUFFER_NEXT_PRESENT)
851  b = vlib_get_buffer (vm, b->next_buffer);
852 
853  while (1)
854  {
855  u32 n;
856 
857  ASSERT (n_buffer_bytes >= b->current_length);
858  n_left_this_buffer = n_buffer_bytes - (b->current_data + b->current_length);
859  n = clib_min (n_left_this_buffer, n_left);
861  b->current_length += n;
862  n_left -= n;
863  if (n_left == 0)
864  break;
865 
866  d += n;
867  if (1 != vlib_buffer_alloc_from_free_list (vm, &b->next_buffer, 1, free_list_index))
868  goto out_of_buffers;
869 
871 
872  b = vlib_get_buffer (vm, b->next_buffer);
873  }
874 
875  return bi;
876 
877  out_of_buffers:
878  clib_error ("out of buffers");
879  return bi;
880 }
881 
882 u16
884  u32 free_list_index,
887  void * data, u16 data_len) {
888  vlib_buffer_t *l = *last;
889  u32 n_buffer_bytes = vlib_buffer_free_list_buffer_size (vm, free_list_index);
890  u16 copied = 0;
891  ASSERT(n_buffer_bytes >= l->current_length + l->current_data);
892  while (data_len) {
893  u16 max = n_buffer_bytes - l->current_length - l->current_data;
894  if (max == 0) {
895  if (1 != vlib_buffer_alloc_from_free_list (vm, &l->next_buffer, 1, free_list_index))
896  return copied;
897  *last = l = vlib_buffer_chain_buffer(vm, first, l, l->next_buffer);
898  max = n_buffer_bytes - l->current_length - l->current_data;
899  }
900 
901  u16 len = (data_len > max)?max:data_len;
902  clib_memcpy(vlib_buffer_get_current (l) + l->current_length, data + copied, len);
903  vlib_buffer_chain_increase_length(first, l, len);
904  data_len -= len;
905  copied += len;
906  }
907  return copied;
908 }
909 
910 /*
911  * Fills in the required rte_mbuf fields for chained buffers given a VLIB chain.
912  */
914 {
915  vlib_buffer_t *b = b_first, *prev = b_first;
916  struct rte_mbuf *mb_prev, *mb, *mb_first;
917 
918  mb_first = rte_mbuf_from_vlib_buffer(b_first);
919 
920  mb_first->pkt_len = mb_first->data_len = b_first->current_length;
921  while (b->flags & VLIB_BUFFER_NEXT_PRESENT) {
922  b = vlib_get_buffer(vm, b->next_buffer);
923  mb = rte_mbuf_from_vlib_buffer(b);
924  mb_prev = rte_mbuf_from_vlib_buffer(prev);
925  mb_first->nb_segs++;
926  mb_first->pkt_len += b->current_length;
927  mb_prev->next = mb;
928  mb->data_len = b->current_length;
929  prev = b;
930  }
931 }
932 
933 clib_error_t *
934 vlib_buffer_pool_create(vlib_main_t * vm, unsigned num_mbufs,
935  unsigned socket_id)
936 {
937  vlib_buffer_main_t * bm = vm->buffer_main;
938  vlib_physmem_main_t * vpm = &vm->physmem_main;
939  struct rte_mempool * rmp;
940  uword new_start, new_size;
941  int i;
942 
943  if (!rte_pktmbuf_pool_create)
944  return clib_error_return (0, "not linked with DPDK");
945 
946  vec_validate_aligned(bm->pktmbuf_pools, socket_id, CLIB_CACHE_LINE_BYTES);
947 
948  /* pool already exists, nothing to do */
949  if (bm->pktmbuf_pools[socket_id])
950  return 0;
951 
952  u8 * pool_name = format(0, "mbuf_pool_socket%u%c",socket_id, 0);
953 
954  rmp = rte_pktmbuf_pool_create((char *) pool_name, /* pool name */
955  num_mbufs, /* number of mbufs */
956  512, /* cache size */
957  VLIB_BUFFER_HDR_SIZE, /* priv size */
959  + VLIB_BUFFER_DATA_SIZE, /* dataroom size */
960  socket_id); /* cpu socket */
961 
962  vec_free(pool_name);
963 
964  if (rmp)
965  {
966  new_start = pointer_to_uword(rmp);
967  new_size = rmp->elt_va_end - new_start;
968 
969  if (vpm->virtual.size > 0)
970  {
971  ASSERT(new_start != vpm->virtual.start);
972  if (new_start < vpm->virtual.start)
973  {
974  new_size = vpm->virtual.size + vpm->virtual.start - new_start;
975  }
976  else
977  {
978  new_size += new_start - vpm->virtual.start;
979  new_start = vpm->virtual.start;
980  }
981 
982  /* check if fits into buffer index range */
983  if (new_size > ( (uword) 1 << (32 + CLIB_LOG2_CACHE_LINE_BYTES)))
984  rmp = 0;
985  }
986  }
987 
988  if (rmp)
989  {
990  bm->pktmbuf_pools[socket_id] = rmp;
991  vpm->virtual.start = new_start;
992  vpm->virtual.size = new_size;
993  vpm->virtual.end = new_start + new_size;
994  return 0;
995  }
996 
997  /* no usable pool for this socket, try to use pool from another one */
998  for (i = 0; i < vec_len(bm->pktmbuf_pools); i++)
999  {
1000  if(bm->pktmbuf_pools[i])
1001  {
1002  clib_warning("WARNING: Failed to allocate mempool for CPU socket %u. "
1003  "Threads running on socket %u will use socket %u mempool.",
1004  socket_id, socket_id, i);
1005  bm->pktmbuf_pools[socket_id] = bm->pktmbuf_pools[i];
1006  return 0;
1007  }
1008  }
1009 
1010  return clib_error_return (0, "failed to allocate mempool on socket %u",
1011  socket_id);
1012 }
1013 
1014 
1016 {
1017  vlib_main_t * vm;
1019  uword n, n_bytes_to_write;
1020  vlib_buffer_t * last;
1021 
1022  n_bytes_to_write = s->current_buffer_index;
1024  vm = sm->vlib_main;
1025 
1026  ASSERT (sm->tx.max_n_data_bytes_per_chain > 0);
1028  || sm->tx.n_total_data_bytes + n_bytes_to_write > sm->tx.max_n_data_bytes_per_chain)
1029  {
1031 
1032  last = vlib_get_buffer (vm, sm->last_buffer);
1033  last->current_length = n_bytes_to_write;
1034 
1035  vlib_set_next_frame_buffer (vm, &p->node_runtime, sm->tx.next_index, sm->first_buffer);
1036 
1037  sm->first_buffer = sm->last_buffer = ~0;
1038  sm->tx.n_total_data_bytes = 0;
1039  }
1040 
1041  else if (n_bytes_to_write == 0 && s->n_buffer_bytes == 0)
1042  {
1043  ASSERT (sm->first_buffer == ~0);
1044  ASSERT (sm->last_buffer == ~0);
1045  n = vlib_buffer_alloc_from_free_list (vm, &sm->first_buffer, 1, sm->tx.free_list_index);
1046  if (n != 1)
1047  serialize_error (m, clib_error_create ("vlib_buffer_alloc_from_free_list fails"));
1048  sm->last_buffer = sm->first_buffer;
1049  s->n_buffer_bytes = vlib_buffer_free_list_buffer_size (vm, sm->tx.free_list_index);
1050  }
1051 
1052  if (n_bytes_to_write > 0)
1053  {
1054  vlib_buffer_t * prev = vlib_get_buffer (vm, sm->last_buffer);
1055  n = vlib_buffer_alloc_from_free_list (vm, &sm->last_buffer, 1, sm->tx.free_list_index);
1056  if (n != 1)
1057  serialize_error (m, clib_error_create ("vlib_buffer_alloc_from_free_list fails"));
1058  sm->tx.n_total_data_bytes += n_bytes_to_write;
1059  prev->current_length = n_bytes_to_write;
1060  prev->next_buffer = sm->last_buffer;
1062  }
1063 
1064  if (sm->last_buffer != ~0)
1065  {
1066  last = vlib_get_buffer (vm, sm->last_buffer);
1067  s->buffer = vlib_buffer_get_current (last);
1068  s->current_buffer_index = 0;
1070  }
1071 }
1072 
1074 {
1075  vlib_main_t * vm;
1077  vlib_buffer_t * last;
1078 
1080  vm = sm->vlib_main;
1081 
1083  return;
1084 
1085  if (sm->last_buffer != ~0)
1086  {
1087  last = vlib_get_buffer (vm, sm->last_buffer);
1088 
1089  if (last->flags & VLIB_BUFFER_NEXT_PRESENT)
1090  sm->last_buffer = last->next_buffer;
1091  else
1092  {
1093  vlib_buffer_free (vm, &sm->first_buffer, /* count */ 1);
1094  sm->first_buffer = sm->last_buffer = ~0;
1095  }
1096  }
1097 
1098  if (sm->last_buffer == ~0)
1099  {
1100  while (clib_fifo_elts (sm->rx.buffer_fifo) == 0)
1101  {
1102  sm->rx.ready_one_time_event = vlib_process_create_one_time_event (vm, vlib_current_process (vm), ~0);
1103  vlib_process_wait_for_one_time_event (vm, /* no event data */ 0, sm->rx.ready_one_time_event);
1104  }
1105 
1106  clib_fifo_sub1 (sm->rx.buffer_fifo, sm->first_buffer);
1107  sm->last_buffer = sm->first_buffer;
1108  }
1109 
1110  ASSERT (sm->last_buffer != ~0);
1111 
1112  last = vlib_get_buffer (vm, sm->last_buffer);
1113  s->current_buffer_index = 0;
1114  s->buffer = vlib_buffer_get_current (last);
1115  s->n_buffer_bytes = last->current_length;
1116 }
1117 
1118 static void
1120  vlib_main_t * vm,
1122  uword is_read)
1123 {
1124  /* Initialize serialize main but save overflow buffer for re-use between calls. */
1125  {
1126  u8 * save = m->stream.overflow_buffer;
1127  memset (m, 0, sizeof (m[0]));
1128  m->stream.overflow_buffer = save;
1129  if (save)
1130  _vec_len (save) = 0;
1131  }
1132 
1133  sm->first_buffer = sm->last_buffer = ~0;
1134  if (is_read)
1135  clib_fifo_reset (sm->rx.buffer_fifo);
1136  else
1137  sm->tx.n_total_data_bytes = 0;
1138  sm->vlib_main = vm;
1141 }
1142 
1144 { serialize_open_vlib_helper (m, vm, sm, /* is_read */ 0); }
1145 
1147 { serialize_open_vlib_helper (m, vm, sm, /* is_read */ 1); }
1148 
1150 {
1153  vlib_buffer_t * last;
1154  serialize_stream_t * s = &m->stream;
1155 
1156  last = vlib_get_buffer (sm->vlib_main, sm->last_buffer);
1158 
1159  if (vec_len (s->overflow_buffer) > 0)
1160  {
1161  sm->last_buffer
1162  = vlib_buffer_add_data (sm->vlib_main, sm->tx.free_list_index,
1163  sm->last_buffer == ~0 ? 0 : sm->last_buffer,
1164  s->overflow_buffer,
1165  vec_len (s->overflow_buffer));
1166  _vec_len (s->overflow_buffer) = 0;
1167  }
1168 
1169  return sm->first_buffer;
1170 }
1171 
1173 {
1176  if (sm->first_buffer != ~0)
1178  clib_fifo_reset (sm->rx.buffer_fifo);
1179  if (m->stream.overflow_buffer)
1180  _vec_len (m->stream.overflow_buffer) = 0;
1181 }
1182 
1183 static u8 * format_vlib_buffer_free_list (u8 * s, va_list * va)
1184 {
1185  vlib_buffer_free_list_t * f = va_arg (*va, vlib_buffer_free_list_t *);
1186  u32 threadnum= va_arg (*va, u32);
1187  uword bytes_alloc, bytes_free, n_free, size;
1188 
1189  if (! f)
1190  return format (s, "%=7s%=30s%=12s%=12s%=12s%=12s%=12s%=12s",
1191  "Thread", "Name", "Index", "Size", "Alloc", "Free", "#Alloc", "#Free");
1192 
1193  size = sizeof (vlib_buffer_t) + f->n_data_bytes;
1194  n_free = vec_len (f->aligned_buffers) + vec_len (f->unaligned_buffers);
1195  bytes_alloc = size * f->n_alloc;
1196  bytes_free = size * n_free;
1197 
1198  s = format (s, "%7d%30s%12d%12d%=12U%=12U%=12d%=12d",
1199  threadnum,
1200  f->name, f->index, f->n_data_bytes,
1201  format_memory_size, bytes_alloc,
1202  format_memory_size, bytes_free,
1203  f->n_alloc, n_free);
1204 
1205  return s;
1206 }
1207 
1208 static clib_error_t *
1210  unformat_input_t * input,
1211  vlib_cli_command_t * cmd)
1212 {
1213  vlib_buffer_main_t * bm;
1215  vlib_main_t *curr_vm;
1216  u32 vm_index = 0;
1217 
1219 
1220  do {
1221  curr_vm = vec_len(vlib_mains) ? vlib_mains[vm_index] : vm;
1222  bm = curr_vm->buffer_main;
1223 
1225  vlib_cli_output (vm, "%U", format_vlib_buffer_free_list, f, vm_index);
1226  }));
1227 
1228  vm_index++;
1229  } while (vm_index < vec_len(vlib_mains));
1230 
1231  return 0;
1232 }
1233 
1234 VLIB_CLI_COMMAND (show_buffers_command, static) = {
1235  .path = "show buffers",
1236  .short_help = "Show packet buffer allocation",
1237  .function = show_buffers,
1238 };
1239 
1240 #if CLIB_DEBUG > 0
1241 
1245 
1246 static clib_error_t *
1248 {
1249  void * oldheap;
1250 
1251  vlib_buffer_state_heap = mheap_alloc (0, 10<<20);
1252 
1254 
1258  clib_mem_set_heap (oldheap);
1259  return 0;
1260 }
1261 
1263 #endif
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
Definition: vec.h:394
void vlib_buffer_chain_validate(vlib_main_t *vm, vlib_buffer_t *b_first)
Definition: dpdk_buffer.c:913
uword * vlib_buffer_state_validation_hash
Definition: dpdk_buffer.c:1243
always_inline uword round_pow2(uword x, uword pow2)
Definition: clib.h:255
#define hash_set(h, key, value)
Definition: hash.h:237
sll srl srl sll sra u16x4 i
Definition: vector_sse2.h:267
#define clib_min(x, y)
Definition: clib.h:295
always_inline uword vlib_process_create_one_time_event(vlib_main_t *vm, uword node_index, uword with_type_opaque)
Definition: node_funcs.h:593
vlib_node_runtime_t node_runtime
Definition: node.h:450
u32 free_list_index
Buffer free list that this buffer was allocated from and will be freed to.
Definition: buffer.h:102
#define PREDICT_TRUE(x)
Definition: clib.h:98
vlib_physmem_main_t physmem_main
Definition: main.h:105
void * mheap_alloc(void *memory, uword size)
Definition: mheap.c:908
void * vlib_buffer_state_heap
Definition: dpdk_buffer.c:1244
serialize_main_header_t header
Definition: serialize.h:137
#define NULL
Definition: clib.h:55
#define vec_add2_aligned(V, P, N, A)
Add N elements to end of vector V, return pointer to new elements in P.
Definition: vec.h:531
vlib_buffer_t buffer_init_template
Definition: buffer.h:241
struct vlib_main_t * vlib_main
Definition: buffer.h:319
void vlib_buffer_free_no_next(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Free buffers, does not free the buffer chain for each buffer.
Definition: dpdk_buffer.c:751
#define clib_error(format, args...)
Definition: error.h:62
#define CLIB_LOG2_CACHE_LINE_BYTES
Definition: cache.h:49
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:480
static void fill_unaligned(vlib_main_t *vm, vlib_buffer_free_list_t *free_list, uword n_unaligned_buffers)
Definition: dpdk_buffer.c:214
vlib_buffer_main_t * buffer_main
Definition: main.h:103
always_inline vlib_buffer_t * vlib_buffer_chain_buffer(vlib_main_t *vm, vlib_buffer_t *first, vlib_buffer_t *last, u32 next_bi)
Definition: buffer_funcs.h:435
always_inline uword copy_alignment(u32 *x)
Definition: dpdk_buffer.c:506
static u32 vlib_buffer_create_free_list_helper(vlib_main_t *vm, u32 n_data_bytes, u32 is_public, u32 is_default, u8 *name)
Definition: dpdk_buffer.c:306
u32 min_n_buffers_each_physmem_alloc
Definition: buffer.h:251
#define vec_validate_aligned(V, I, A)
Make sure vector is long enough for given index (no header, specified alignment)
Definition: vec.h:405
static_always_inline void vlib_buffer_free_inline(vlib_main_t *vm, u32 *buffers, u32 n_buffers, u32 follow_buffer_next)
Definition: dpdk_buffer.c:677
always_inline void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
Definition: buffer.h:184
always_inline u32 vlib_buffer_free_list_buffer_size(vlib_main_t *vm, u32 free_list_index)
Definition: buffer_funcs.h:346
always_inline vlib_main_t * vlib_get_main(void)
Definition: global_funcs.h:23
struct vlib_serialize_buffer_main_t::@27::@30 rx
#define vec_add(V, E, N)
Add N elements to end of vector V (no header, unspecified alignment)
Definition: vec.h:557
#define vec_add1_aligned(V, E, A)
Add 1 element to end of vector (alignment specified).
Definition: vec.h:490
void(* buffers_added_to_freelist_function)(struct vlib_main_t *vm, struct vlib_buffer_free_list_t *fl)
Definition: buffer.h:279
i16 current_data
signed offset in data[], pre_data[] that we are currently processing.
Definition: buffer.h:77
#define static_always_inline
Definition: clib.h:85
void unserialize_open_vlib_buffer(serialize_main_t *m, vlib_main_t *vm, vlib_serialize_buffer_main_t *sm)
Definition: dpdk_buffer.c:1146
#define pool_foreach(VAR, POOL, BODY)
Definition: pool.h:328
always_inline heap_elt_t * last(heap_header_t *h)
Definition: heap.c:51
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:109
#define always_inline
Definition: clib.h:84
u8 * format_white_space(u8 *s, va_list *va)
Definition: std-formats.c:107
#define BUFFERS_PER_COPY
Definition: dpdk_buffer.c:210
static void trim_aligned(vlib_buffer_free_list_t *f)
Definition: dpdk_buffer.c:240
u8 * format_hex_bytes(u8 *s, va_list *va)
Definition: std-formats.c:79
always_inline uword pool_elts(void *v)
Definition: pool.h:97
always_inline uword clib_fifo_elts(void *v)
Definition: fifo.h:63
#define clib_warning(format, args...)
Definition: error.h:59
always_inline vlib_buffer_free_list_t * vlib_buffer_get_free_list(vlib_main_t *vm, u32 free_list_index)
Definition: buffer_funcs.h:332
#define vec_end(v)
End (last data address) of vector.
void serialize_open_vlib_buffer(serialize_main_t *m, vlib_main_t *vm, vlib_serialize_buffer_main_t *sm)
Definition: dpdk_buffer.c:1143
u8 * format_vlib_buffer_contents(u8 *s, va_list *va)
Definition: dpdk_buffer.c:129
u8 * format_vlib_buffer(u8 *s, va_list *args)
Definition: dpdk_buffer.c:88
static uword pointer_to_uword(const void *p)
Definition: types.h:131
#define VLIB_BUFFER_NEXT_PRESENT
Definition: buffer.h:93
always_inline void serialize_error(serialize_main_header_t *m, clib_error_t *error)
Definition: serialize.h:100
always_inline heap_elt_t * first(heap_header_t *h)
Definition: heap.c:54
vlib_buffer_free_list_t ** announce_list
Definition: buffer.h:310
always_inline u32 vlib_buffer_get_free_list_with_size(vlib_main_t *vm, u32 size)
Definition: dpdk_buffer.c:295
vlib_main_t ** vlib_mains
Definition: dpdk_buffer.c:146
#define VLIB_BUFFER_PRE_DATA_SIZE
Definition: buffer.h:56
always_inline void vlib_buffer_free_one(vlib_main_t *vm, u32 buffer_index)
Free one buffer Shorthand to free a single buffer chain.
Definition: buffer_funcs.h:319
static void vlib_packet_template_buffer_init(vlib_main_t *vm, vlib_buffer_free_list_t *fl, u32 *buffers, u32 n_buffers)
Definition: dpdk_buffer.c:760
#define hash_get(h, key)
Definition: hash.h:231
always_inline uword serialize_stream_is_end_of_stream(serialize_stream_t *s)
Definition: serialize.h:83
#define pool_elt_at_index(p, i)
Definition: pool.h:346
always_inline void vlib_buffer_chain_increase_length(vlib_buffer_t *first, vlib_buffer_t *last, i32 len)
Definition: buffer_funcs.h:466
static void vlib_serialize_rx(serialize_main_header_t *m, serialize_stream_t *s)
Definition: dpdk_buffer.c:1073
uword vlib_buffer_length_in_chain_slow_path(vlib_main_t *vm, vlib_buffer_t *b_first)
Definition: dpdk_buffer.c:73
always_inline void clib_fifo_reset(void *v)
Definition: fifo.h:83
#define clib_fifo_sub1(f, e)
Definition: fifo.h:219
#define VLIB_BUFFER_DEFAULT_FREE_LIST_BYTES
Definition: buffer.h:297
u32 serialize_close_vlib_buffer(serialize_main_t *m)
Definition: dpdk_buffer.c:1149
u16 current_length
Nbytes between current data and the end of this buffer.
Definition: buffer.h:81
void vlib_aligned_memcpy(void *_dst, void *_src, int n_bytes)
Definition: dpdk_buffer.c:150
static clib_error_t * show_buffers(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: dpdk_buffer.c:1209
#define pool_put(P, E)
Definition: pool.h:200
always_inline uword vlib_process_wait_for_one_time_event(vlib_main_t *vm, uword **data_vector, uword with_type_index)
Definition: node_funcs.h:503
#define PREDICT_FALSE(x)
Definition: clib.h:97
#define clib_error_create(args...)
Definition: error.h:109
always_inline void * clib_mem_set_heap(void *heap)
Definition: mem.h:190
u32 vlib_buffer_get_or_create_free_list(vlib_main_t *vm, u32 n_data_bytes, char *fmt,...)
Definition: dpdk_buffer.c:368
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:538
static void vlib_serialize_tx(serialize_main_header_t *m, serialize_stream_t *s)
Definition: dpdk_buffer.c:1015
u16 vlib_buffer_chain_append_data_with_alloc(vlib_main_t *vm, u32 free_list_index, vlib_buffer_t *first, vlib_buffer_t **last, void *data, u16 data_len)
Definition: dpdk_buffer.c:883
clib_error_t * vlib_buffer_pool_create(vlib_main_t *vm, unsigned num_mbufs, unsigned socket_id)
Definition: dpdk_buffer.c:934
#define uword_to_pointer(u, type)
Definition: types.h:134
#define pool_get_aligned(P, E, A)
Definition: pool.h:155
#define vec_add_aligned(V, E, N, A)
Add N elements to end of vector V (no header, specified alignment)
Definition: vec.h:567
serialize_stream_t stream
Definition: serialize.h:138
u32 current_buffer_index
Definition: serialize.h:61
u32(* buffer_free_callback)(struct vlib_main_t *vm, u32 *buffers, u32 n_buffers, u32 follow_buffer_next)
Definition: buffer.h:287
#define CLIB_PREFETCH(addr, size, type)
Definition: cache.h:82
u8 * va_format(u8 *s, char *fmt, va_list *va)
Definition: format.c:374
u8 * format_vlib_buffer_and_data(u8 *s, va_list *args)
Definition: dpdk_buffer.c:118
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:298
always_inline void add_buffer_to_free_list(vlib_main_t *vm, vlib_buffer_free_list_t *f, u32 buffer_index, u8 do_init)
Definition: dpdk_buffer.c:646
void vlib_buffer_delete_free_list(vlib_main_t *vm, u32 free_list_index)
Definition: dpdk_buffer.c:416
void unserialize_close_vlib_buffer(serialize_main_t *m)
Definition: dpdk_buffer.c:1172
#define clib_memcpy(a, b, c)
Definition: string.h:63
u32 * vlib_buffer_state_validation_lock
Definition: dpdk_buffer.c:1242
serialize_data_function_t * data_function
Definition: serialize.h:90
#define VLIB_BUFFER_TOTAL_LENGTH_VALID
Definition: buffer.h:95
static u8 * format_vlib_buffer_free_list(u8 *s, va_list *va)
Definition: dpdk_buffer.c:1183
uword data_function_opaque
Definition: serialize.h:73
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:150
u8 * format_memory_size(u8 *s, va_list *va)
Definition: std-formats.c:185
#define VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX
Definition: buffer.h:296
#define hash_create(elts, value_bytes)
Definition: hash.h:615
#define ASSERT(truth)
void vlib_worker_thread_barrier_sync(vlib_main_t *vm)
Definition: threads.c:1100
unsigned int u32
Definition: types.h:88
#define VLIB_BUFFER_HDR_SIZE
Definition: buffer.h:153
u8 * format(u8 *s, char *fmt,...)
Definition: format.c:405
static u32 alloc_from_free_list(vlib_main_t *vm, vlib_buffer_free_list_t *free_list, u32 *alloc_buffers, u32 n_alloc_buffers)
Definition: dpdk_buffer.c:510
void vlib_packet_template_init(vlib_main_t *vm, vlib_packet_template_t *t, void *packet_data, uword n_packet_data_bytes, uword min_n_buffers_each_physmem_alloc, char *fmt,...)
Definition: dpdk_buffer.c:777
u32 size
Definition: vhost-user.h:74
u32 next_buffer
Next buffer for this linked-list of buffers.
Definition: buffer.h:112
u64 vlib_copy_unit_t
Definition: buffer.h:62
u32 clone_count
Specifies whether this buffer should be reinitialized when freed.
Definition: buffer.h:121
static uword fill_free_list(vlib_main_t *vm, vlib_buffer_free_list_t *fl, uword min_free_buffers)
Definition: dpdk_buffer.c:441
void vlib_worker_thread_barrier_release(vlib_main_t *vm)
Definition: threads.c:1131
void vlib_buffer_free(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Free buffers Frees the entire buffer chain for each buffer.
Definition: dpdk_buffer.c:744
#define VLIB_BUFFER_IS_TRACED
Definition: buffer.h:91
#define clib_max(x, y)
Definition: clib.h:288
always_inline void vlib_buffer_init_for_free_list(vlib_buffer_t *_dst, vlib_buffer_free_list_t *fl)
Definition: buffer_funcs.h:591
always_inline uword format_get_indent(u8 *s)
Definition: format.h:72
u64 uword
Definition: types.h:112
u32 total_length_not_including_first_buffer
Only valid for first buffer in chain.
Definition: buffer.h:106
void ** mbuf_alloc_list
Definition: main.h:161
always_inline vlib_buffer_free_list_t * buffer_get_free_list(vlib_main_t *vm, vlib_buffer_t *b, u32 *index)
Definition: dpdk_buffer.c:658
unsigned short u16
Definition: types.h:57
i64 word
Definition: types.h:111
always_inline uword clib_mem_is_heap_object(void *p)
Definition: mem.h:133
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
unsigned char u8
Definition: types.h:56
static void del_free_list(vlib_main_t *vm, vlib_buffer_free_list_t *f)
Definition: dpdk_buffer.c:392
void(* buffer_init_function)(struct vlib_main_t *vm, struct vlib_buffer_free_list_t *fl, u32 *buffers, u32 n_buffers)
Definition: buffer.h:272
u32 vlib_buffer_alloc_from_free_list(vlib_main_t *vm, u32 *buffers, u32 n_buffers, u32 free_list_index)
Allocate buffers from specific freelist into supplied array.
Definition: dpdk_buffer.c:634
vlib_buffer_free_list_t * buffer_free_list_pool
Definition: buffer.h:295
always_inline void vlib_set_next_frame_buffer(vlib_main_t *vm, vlib_node_runtime_t *node, u32 next_index, u32 buffer_index)
Definition: node_funcs.h:292
#define VLIB_BUFFER_DATA_SIZE
Definition: buffer.h:55
void * vlib_set_buffer_free_callback(vlib_main_t *vm, void *fp)
Definition: dpdk_buffer.c:667
always_inline uword vlib_current_process(vlib_main_t *vm)
Definition: node_funcs.h:317
vlib_physmem_region_t virtual
Definition: physmem.h:48
u8 data[0]
Packet data.
Definition: buffer.h:150
always_inline vlib_process_t * vlib_get_current_process(vlib_main_t *vm)
Definition: node_funcs.h:306
void * vlib_packet_template_get_packet(vlib_main_t *vm, vlib_packet_template_t *t, u32 *bi_result)
Definition: dpdk_buffer.c:801
always_inline u32 vlib_buffer_round_size(u32 size)
Definition: buffer_funcs.h:269
u32 vlib_buffer_add_data(vlib_main_t *vm, u32 free_list_index, u32 buffer_index, void *data, u32 n_data_bytes)
Definition: dpdk_buffer.c:828
uword buffer_init_function_opaque
Definition: buffer.h:282
#define clib_error_return(e, args...)
Definition: error.h:112
struct _unformat_input_t unformat_input_t
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:67
static clib_error_t * buffer_state_validation_init(vlib_main_t *vm)
Definition: dpdk_buffer.c:1247
u32 flags
buffer flags: VLIB_BUFFER_IS_TRACED: trace this buffer.
Definition: buffer.h:84
always_inline vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:69
u32 vlib_buffer_alloc(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Allocate buffers into supplied array.
Definition: dpdk_buffer.c:623
always_inline u32 vlib_get_buffer_index(vlib_main_t *vm, void *p)
Translate buffer pointer into buffer index.
Definition: buffer_funcs.h:82
u32 trace_index
Specifies index into trace buffer if VLIB_PACKET_IS_TRACED flag is set.
Definition: buffer.h:116
uword * free_list_by_size
Definition: buffer.h:301
static void merge_free_lists(vlib_buffer_free_list_t *dst, vlib_buffer_free_list_t *src)
Definition: dpdk_buffer.c:268
struct vlib_serialize_buffer_main_t::@27::@29 tx
u32 vlib_buffer_create_free_list(vlib_main_t *vm, u32 n_data_bytes, char *fmt,...)
Definition: dpdk_buffer.c:352
static void serialize_open_vlib_helper(serialize_main_t *m, vlib_main_t *vm, vlib_serialize_buffer_main_t *sm, uword is_read)
Definition: dpdk_buffer.c:1119