blob: 9312e8c0e479696e1d8ef7d14e42638e21436399 [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
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
Chris Luked4024f52016-09-06 09:32:36 -040040/**
Chris Luked4024f52016-09-06 09:32:36 -040041 * @file
42 *
43 * Allocate/free network buffers.
44 */
45
Damjan Marion910d3692019-01-21 11:48:34 +010046#include <vppinfra/linux/sysfs.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070047#include <vlib/vlib.h>
Damjan Marion374e2c52017-03-09 20:38:15 +010048#include <vlib/unix/unix.h>
Filip Tehlard2bbdef2019-02-22 05:05:53 -080049#include <vpp/stats/stat_segment.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070050
Damjan Marion910d3692019-01-21 11:48:34 +010051#define VLIB_BUFFER_DEFAULT_BUFFERS_PER_NUMA 16384
52#define VLIB_BUFFER_DEFAULT_BUFFERS_PER_NUMA_UNPRIV 8192
Damjan Marion901d16c2018-10-23 19:50:20 +020053
Damjan Marion910d3692019-01-21 11:48:34 +010054#ifdef CLIB_HAVE_VEC128
55/* Assumptions by vlib_buffer_free_inline: */
56STATIC_ASSERT_FITS_IN (vlib_buffer_t, flags, 16);
57STATIC_ASSERT_FITS_IN (vlib_buffer_t, ref_count, 16);
58STATIC_ASSERT_FITS_IN (vlib_buffer_t, buffer_pool_index, 16);
59#endif
Damjan Marion04a7f052017-07-10 15:06:17 +020060
Damjan Marion910d3692019-01-21 11:48:34 +010061/* Make sure that buffer template size is not accidentally changed */
62STATIC_ASSERT_OFFSET_OF (vlib_buffer_t, template_end, 64);
63
64u16 __vlib_buffer_external_hdr_size = 0;
Damjan Marion567e61d2018-10-24 17:08:26 +020065
Filip Tehlarb806d0e2019-02-28 04:36:10 -080066static void
67buffer_gauges_update_cached_fn (stat_segment_directory_entry_t * e,
68 u32 index);
69
70static void
71buffer_gauges_update_available_fn (stat_segment_directory_entry_t * e,
72 u32 index);
73
74static void
75buffer_gauges_update_used_fn (stat_segment_directory_entry_t * e, u32 index);
76
Dave Barach9b8ffd92016-07-08 08:13:45 -040077uword
78vlib_buffer_length_in_chain_slow_path (vlib_main_t * vm,
79 vlib_buffer_t * b_first)
Ed Warnickecb9cada2015-12-08 15:45:58 -070080{
Dave Barach9b8ffd92016-07-08 08:13:45 -040081 vlib_buffer_t *b = b_first;
Ed Warnickecb9cada2015-12-08 15:45:58 -070082 uword l_first = b_first->current_length;
83 uword l = 0;
84 while (b->flags & VLIB_BUFFER_NEXT_PRESENT)
85 {
86 b = vlib_get_buffer (vm, b->next_buffer);
87 l += b->current_length;
88 }
89 b_first->total_length_not_including_first_buffer = l;
90 b_first->flags |= VLIB_BUFFER_TOTAL_LENGTH_VALID;
91 return l + l_first;
92}
93
Dave Barach9b8ffd92016-07-08 08:13:45 -040094u8 *
95format_vlib_buffer (u8 * s, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -070096{
Dave Barach9b8ffd92016-07-08 08:13:45 -040097 vlib_buffer_t *b = va_arg (*args, vlib_buffer_t *);
Christophe Fontained3c008d2017-10-02 18:10:54 +020098 u32 indent = format_get_indent (s);
Damjan Mariondac03522018-02-01 15:30:13 +010099 u8 *a = 0;
Damjan Marion1cd8f3c2016-11-24 02:07:32 +0100100
Damjan Mariondac03522018-02-01 15:30:13 +0100101#define _(bit, name, v) \
102 if (v && (b->flags & VLIB_BUFFER_##name)) \
103 a = format (a, "%s ", v);
104 foreach_vlib_buffer_flag
105#undef _
Damjan Marion36eb7c22019-01-18 20:45:30 +0100106 s = format (s, "current data %d, length %d, buffer-pool %d, "
Damjan Marion910d3692019-01-21 11:48:34 +0100107 "ref-count %u", b->current_data, b->current_length,
108 b->buffer_pool_index, b->ref_count);
Damjan Marion1cd8f3c2016-11-24 02:07:32 +0100109
110 if (b->flags & VLIB_BUFFER_TOTAL_LENGTH_VALID)
111 s = format (s, ", totlen-nifb %d",
112 b->total_length_not_including_first_buffer);
113
114 if (b->flags & VLIB_BUFFER_IS_TRACED)
115 s = format (s, ", trace 0x%x", b->trace_index);
116
Damjan Mariondac03522018-02-01 15:30:13 +0100117 if (a)
118 s = format (s, "\n%U%v", format_white_space, indent, a);
119 vec_free (a);
120
Damjan Marion1cd8f3c2016-11-24 02:07:32 +0100121 while (b->flags & VLIB_BUFFER_NEXT_PRESENT)
122 {
123 vlib_main_t *vm = vlib_get_main ();
124 u32 next_buffer = b->next_buffer;
125 b = vlib_get_buffer (vm, next_buffer);
126
Damjan Marionc47ed032017-01-25 14:18:03 +0100127 s =
Damjan Marion910d3692019-01-21 11:48:34 +0100128 format (s, "\n%Unext-buffer 0x%x, segment length %d, ref-count %u",
Damjan Marionc47ed032017-01-25 14:18:03 +0100129 format_white_space, indent, next_buffer, b->current_length,
Damjan Marion910d3692019-01-21 11:48:34 +0100130 b->ref_count);
Damjan Marion1cd8f3c2016-11-24 02:07:32 +0100131 }
132
Ed Warnickecb9cada2015-12-08 15:45:58 -0700133 return s;
134}
135
Dave Barach9b8ffd92016-07-08 08:13:45 -0400136u8 *
137format_vlib_buffer_and_data (u8 * s, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700138{
Dave Barach9b8ffd92016-07-08 08:13:45 -0400139 vlib_buffer_t *b = va_arg (*args, vlib_buffer_t *);
140
Ed Warnickecb9cada2015-12-08 15:45:58 -0700141 s = format (s, "%U, %U",
142 format_vlib_buffer, b,
143 format_hex_bytes, vlib_buffer_get_current (b), 64);
144
145 return s;
146}
147
Dave Barach9b8ffd92016-07-08 08:13:45 -0400148static u8 *
149format_vlib_buffer_known_state (u8 * s, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700150{
151 vlib_buffer_known_state_t state = va_arg (*args, vlib_buffer_known_state_t);
Dave Barach9b8ffd92016-07-08 08:13:45 -0400152 char *t;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700153
154 switch (state)
155 {
156 case VLIB_BUFFER_UNKNOWN:
157 t = "unknown";
158 break;
159
160 case VLIB_BUFFER_KNOWN_ALLOCATED:
161 t = "known-allocated";
162 break;
163
164 case VLIB_BUFFER_KNOWN_FREE:
165 t = "known-free";
166 break;
167
168 default:
169 t = "invalid";
170 break;
171 }
172
173 return format (s, "%s", t);
174}
175
Dave Barach9b8ffd92016-07-08 08:13:45 -0400176u8 *
177format_vlib_buffer_contents (u8 * s, va_list * va)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700178{
Dave Barach9b8ffd92016-07-08 08:13:45 -0400179 vlib_main_t *vm = va_arg (*va, vlib_main_t *);
180 vlib_buffer_t *b = va_arg (*va, vlib_buffer_t *);
181
Ed Warnickecb9cada2015-12-08 15:45:58 -0700182 while (1)
183 {
Dave Barach9b8ffd92016-07-08 08:13:45 -0400184 vec_add (s, vlib_buffer_get_current (b), b->current_length);
185 if (!(b->flags & VLIB_BUFFER_NEXT_PRESENT))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700186 break;
187 b = vlib_get_buffer (vm, b->next_buffer);
188 }
189
190 return s;
191}
192
193static u8 *
194vlib_validate_buffer_helper (vlib_main_t * vm,
195 u32 bi,
Dave Barach9b8ffd92016-07-08 08:13:45 -0400196 uword follow_buffer_next, uword ** unique_hash)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700197{
Damjan Marion910d3692019-01-21 11:48:34 +0100198 vlib_buffer_main_t *bm = vm->buffer_main;
Dave Barach9b8ffd92016-07-08 08:13:45 -0400199 vlib_buffer_t *b = vlib_get_buffer (vm, bi);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700200
Damjan Marion910d3692019-01-21 11:48:34 +0100201 if (vec_len (bm->buffer_pools) <= b->buffer_pool_index)
202 return format (0, "unknown buffer pool 0x%x", b->buffer_pool_index);
203
Dave Barach9b8ffd92016-07-08 08:13:45 -0400204 if ((signed) b->current_data < (signed) -VLIB_BUFFER_PRE_DATA_SIZE)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700205 return format (0, "current data %d before pre-data", b->current_data);
Damjan Marion878c6092017-01-04 13:19:27 +0100206
Damjan Marion8934a042019-02-09 23:29:26 +0100207 if (b->current_data + b->current_length >
208 vlib_buffer_get_default_data_size (vm))
Damjan Marion910d3692019-01-21 11:48:34 +0100209 return format (0, "%d-%d beyond end of buffer %d", b->current_data,
Damjan Marion8934a042019-02-09 23:29:26 +0100210 b->current_length, vlib_buffer_get_default_data_size (vm));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700211
Dave Barach9b8ffd92016-07-08 08:13:45 -0400212 if (follow_buffer_next && (b->flags & VLIB_BUFFER_NEXT_PRESENT))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700213 {
214 vlib_buffer_known_state_t k;
Dave Barach9b8ffd92016-07-08 08:13:45 -0400215 u8 *msg, *result;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700216
Damjan Mariond50e3472019-01-20 00:03:56 +0100217 k = vlib_buffer_is_known (vm, b->next_buffer);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700218 if (k != VLIB_BUFFER_KNOWN_ALLOCATED)
219 return format (0, "next 0x%x: %U",
Dave Barach9b8ffd92016-07-08 08:13:45 -0400220 b->next_buffer, format_vlib_buffer_known_state, k);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700221
222 if (unique_hash)
223 {
224 if (hash_get (*unique_hash, b->next_buffer))
225 return format (0, "duplicate buffer 0x%x", b->next_buffer);
226
227 hash_set1 (*unique_hash, b->next_buffer);
228 }
229
230 msg = vlib_validate_buffer (vm, b->next_buffer, follow_buffer_next);
231 if (msg)
232 {
233 result = format (0, "next 0x%x: %v", b->next_buffer, msg);
234 vec_free (msg);
235 return result;
236 }
237 }
238
239 return 0;
240}
241
242u8 *
243vlib_validate_buffer (vlib_main_t * vm, u32 bi, uword follow_buffer_next)
Dave Barach9b8ffd92016-07-08 08:13:45 -0400244{
245 return vlib_validate_buffer_helper (vm, bi, follow_buffer_next,
246 /* unique_hash */ 0);
247}
Ed Warnickecb9cada2015-12-08 15:45:58 -0700248
249u8 *
250vlib_validate_buffers (vlib_main_t * vm,
251 u32 * buffers,
252 uword next_buffer_stride,
253 uword n_buffers,
254 vlib_buffer_known_state_t known_state,
255 uword follow_buffer_next)
256{
Dave Barach9b8ffd92016-07-08 08:13:45 -0400257 uword i, *hash;
258 u32 bi, *b = buffers;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700259 vlib_buffer_known_state_t k;
Dave Barach9b8ffd92016-07-08 08:13:45 -0400260 u8 *msg = 0, *result = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700261
262 hash = hash_create (0, 0);
263 for (i = 0; i < n_buffers; i++)
264 {
265 bi = b[0];
266 b += next_buffer_stride;
267
268 /* Buffer is not unique. */
269 if (hash_get (hash, bi))
270 {
271 msg = format (0, "not unique");
272 goto done;
273 }
274
Damjan Mariond50e3472019-01-20 00:03:56 +0100275 k = vlib_buffer_is_known (vm, bi);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700276 if (k != known_state)
277 {
278 msg = format (0, "is %U; expected %U",
279 format_vlib_buffer_known_state, k,
280 format_vlib_buffer_known_state, known_state);
281 goto done;
282 }
283
284 msg = vlib_validate_buffer_helper (vm, bi, follow_buffer_next, &hash);
285 if (msg)
286 goto done;
287
288 hash_set1 (hash, bi);
289 }
290
Dave Barach9b8ffd92016-07-08 08:13:45 -0400291done:
Ed Warnickecb9cada2015-12-08 15:45:58 -0700292 if (msg)
293 {
294 result = format (0, "0x%x: %v", bi, msg);
295 vec_free (msg);
296 }
297 hash_free (hash);
298 return result;
299}
300
Dave Barach80f54e22017-03-08 19:08:56 -0500301/*
302 * Hand-craft a static vector w/ length 1, so vec_len(vlib_mains) =1
303 * and vlib_mains[0] = &vlib_global_main from the beginning of time.
304 *
305 * The only place which should ever expand vlib_mains is start_workers()
306 * in threads.c. It knows about the bootstrap vector.
307 */
308/* *INDENT-OFF* */
309static struct
310{
311 vec_header_t h;
312 vlib_main_t *vm;
313} __attribute__ ((packed)) __bootstrap_vlib_main_vector
314 __attribute__ ((aligned (CLIB_CACHE_LINE_BYTES))) =
315{
316 .h.len = 1,
317 .vm = &vlib_global_main,
318};
319/* *INDENT-ON* */
320
321vlib_main_t **vlib_mains = &__bootstrap_vlib_main_vector.vm;
322
Ed Warnickecb9cada2015-12-08 15:45:58 -0700323
324/* When dubugging validate that given buffers are either known allocated
325 or known free. */
Damjan Marionc8a26c62017-11-24 20:15:23 +0100326void
Ed Warnickecb9cada2015-12-08 15:45:58 -0700327vlib_buffer_validate_alloc_free (vlib_main_t * vm,
328 u32 * buffers,
329 uword n_buffers,
330 vlib_buffer_known_state_t expected_state)
331{
Damjan Marion910d3692019-01-21 11:48:34 +0100332 vlib_buffer_main_t *bm = vm->buffer_main;
Dave Barach9b8ffd92016-07-08 08:13:45 -0400333 u32 *b;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700334 uword i, bi, is_free;
335
336 if (CLIB_DEBUG == 0)
337 return;
338
Ed Warnickecb9cada2015-12-08 15:45:58 -0700339 is_free = expected_state == VLIB_BUFFER_KNOWN_ALLOCATED;
340 b = buffers;
341 for (i = 0; i < n_buffers; i++)
342 {
343 vlib_buffer_known_state_t known;
Dave Barach9b8ffd92016-07-08 08:13:45 -0400344
Ed Warnickecb9cada2015-12-08 15:45:58 -0700345 bi = b[0];
346 b += 1;
Damjan Mariond50e3472019-01-20 00:03:56 +0100347 known = vlib_buffer_is_known (vm, bi);
Damjan Marion910d3692019-01-21 11:48:34 +0100348
349 if (known == VLIB_BUFFER_UNKNOWN &&
350 expected_state == VLIB_BUFFER_KNOWN_FREE)
351 known = VLIB_BUFFER_KNOWN_FREE;
352
Ed Warnickecb9cada2015-12-08 15:45:58 -0700353 if (known != expected_state)
354 {
Klement Sekerae82c73a2019-01-30 18:29:28 +0100355 clib_panic ("%s %U buffer 0x%x", is_free ? "freeing" : "allocating",
356 format_vlib_buffer_known_state, known, bi);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700357 }
358
Damjan Marion910d3692019-01-21 11:48:34 +0100359 clib_spinlock_lock (&bm->buffer_known_hash_lockp);
360 hash_set (bm->buffer_known_hash, bi, is_free ? VLIB_BUFFER_KNOWN_FREE :
361 VLIB_BUFFER_KNOWN_ALLOCATED);
362 clib_spinlock_unlock (&bm->buffer_known_hash_lockp);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700363 }
364}
Ed Warnickecb9cada2015-12-08 15:45:58 -0700365
Dave Barach9b8ffd92016-07-08 08:13:45 -0400366void
367vlib_packet_template_init (vlib_main_t * vm,
368 vlib_packet_template_t * t,
369 void *packet_data,
370 uword n_packet_data_bytes,
Damjan Mariond1274cb2018-03-13 21:32:17 +0100371 uword min_n_buffers_each_alloc, char *fmt, ...)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700372{
Damjan Marion1cd8f3c2016-11-24 02:07:32 +0100373 va_list va;
Damjan Marion1cd8f3c2016-11-24 02:07:32 +0100374
375 va_start (va, fmt);
Damjan Marion671e60e2018-12-30 18:09:59 +0100376 t->name = va_format (0, fmt, &va);
Damjan Marion1cd8f3c2016-11-24 02:07:32 +0100377 va_end (va);
378
379 vlib_worker_thread_barrier_sync (vm);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700380
Dave Barachb7b92992018-10-17 10:38:51 -0400381 clib_memset (t, 0, sizeof (t[0]));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700382
383 vec_add (t->packet_data, packet_data, n_packet_data_bytes);
Damjan Mariond1274cb2018-03-13 21:32:17 +0100384 t->min_n_buffers_each_alloc = min_n_buffers_each_alloc;
Damjan Marion878c6092017-01-04 13:19:27 +0100385 vlib_worker_thread_barrier_release (vm);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700386}
387
388void *
Dave Barach9b8ffd92016-07-08 08:13:45 -0400389vlib_packet_template_get_packet (vlib_main_t * vm,
390 vlib_packet_template_t * t, u32 * bi_result)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700391{
392 u32 bi;
Dave Barach9b8ffd92016-07-08 08:13:45 -0400393 vlib_buffer_t *b;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700394
395 if (vlib_buffer_alloc (vm, &bi, 1) != 1)
396 return 0;
397
398 *bi_result = bi;
399
400 b = vlib_get_buffer (vm, bi);
Dave Barach178cf492018-11-13 16:34:13 -0500401 clib_memcpy_fast (vlib_buffer_get_current (b),
402 t->packet_data, vec_len (t->packet_data));
Dave Barach9b8ffd92016-07-08 08:13:45 -0400403 b->current_length = vec_len (t->packet_data);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700404
405 return b->data;
406}
407
Ed Warnickecb9cada2015-12-08 15:45:58 -0700408/* Append given data to end of buffer, possibly allocating new buffers. */
Dave Barach3a63fc52019-01-07 09:15:47 -0500409int
Damjan Marionab9b7ec2019-01-18 20:24:44 +0100410vlib_buffer_add_data (vlib_main_t * vm, u32 * buffer_index, void *data,
411 u32 n_data_bytes)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700412{
413 u32 n_buffer_bytes, n_left, n_left_this_buffer, bi;
Dave Barach9b8ffd92016-07-08 08:13:45 -0400414 vlib_buffer_t *b;
415 void *d;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700416
Dave Barach3a63fc52019-01-07 09:15:47 -0500417 bi = *buffer_index;
Damjan Marionab9b7ec2019-01-18 20:24:44 +0100418 if (bi == ~0 && 1 != vlib_buffer_alloc (vm, &bi, 1))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700419 goto out_of_buffers;
420
421 d = data;
422 n_left = n_data_bytes;
Damjan Marion8934a042019-02-09 23:29:26 +0100423 n_buffer_bytes = vlib_buffer_get_default_data_size (vm);
Dave Barach9b8ffd92016-07-08 08:13:45 -0400424
Ed Warnickecb9cada2015-12-08 15:45:58 -0700425 b = vlib_get_buffer (vm, bi);
426 b->flags &= ~VLIB_BUFFER_TOTAL_LENGTH_VALID;
427
Dave Barach9b8ffd92016-07-08 08:13:45 -0400428 /* Get to the end of the chain before we try to append data... */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700429 while (b->flags & VLIB_BUFFER_NEXT_PRESENT)
430 b = vlib_get_buffer (vm, b->next_buffer);
431
432 while (1)
433 {
434 u32 n;
435
436 ASSERT (n_buffer_bytes >= b->current_length);
Dave Barach9b8ffd92016-07-08 08:13:45 -0400437 n_left_this_buffer =
438 n_buffer_bytes - (b->current_data + b->current_length);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700439 n = clib_min (n_left_this_buffer, n_left);
Dave Barach178cf492018-11-13 16:34:13 -0500440 clib_memcpy_fast (vlib_buffer_get_current (b) + b->current_length, d,
441 n);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700442 b->current_length += n;
443 n_left -= n;
444 if (n_left == 0)
445 break;
446
447 d += n;
Damjan Marionab9b7ec2019-01-18 20:24:44 +0100448 if (1 != vlib_buffer_alloc (vm, &b->next_buffer, 1))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700449 goto out_of_buffers;
450
451 b->flags |= VLIB_BUFFER_NEXT_PRESENT;
452
453 b = vlib_get_buffer (vm, b->next_buffer);
454 }
455
Dave Barach3a63fc52019-01-07 09:15:47 -0500456 *buffer_index = bi;
457 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700458
Dave Barach9b8ffd92016-07-08 08:13:45 -0400459out_of_buffers:
Dave Barach3a63fc52019-01-07 09:15:47 -0500460 clib_warning ("out of buffers");
461 return 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700462}
463
Pierre Pfister328e99b2016-02-12 13:18:42 +0000464u16
Dave Barach9b8ffd92016-07-08 08:13:45 -0400465vlib_buffer_chain_append_data_with_alloc (vlib_main_t * vm,
Dave Barach9b8ffd92016-07-08 08:13:45 -0400466 vlib_buffer_t * first,
Damjan Mariondac03522018-02-01 15:30:13 +0100467 vlib_buffer_t ** last, void *data,
468 u16 data_len)
Dave Barach9b8ffd92016-07-08 08:13:45 -0400469{
Pierre Pfister328e99b2016-02-12 13:18:42 +0000470 vlib_buffer_t *l = *last;
Damjan Marion8934a042019-02-09 23:29:26 +0100471 u32 n_buffer_bytes = vlib_buffer_get_default_data_size (vm);
Pierre Pfister328e99b2016-02-12 13:18:42 +0000472 u16 copied = 0;
Dave Barach9b8ffd92016-07-08 08:13:45 -0400473 ASSERT (n_buffer_bytes >= l->current_length + l->current_data);
474 while (data_len)
475 {
476 u16 max = n_buffer_bytes - l->current_length - l->current_data;
477 if (max == 0)
478 {
Damjan Marion910d3692019-01-21 11:48:34 +0100479 if (1 != vlib_buffer_alloc_from_pool (vm, &l->next_buffer, 1,
480 first->buffer_pool_index))
Dave Barach9b8ffd92016-07-08 08:13:45 -0400481 return copied;
Eyal Barib688fb12018-11-12 16:13:49 +0200482 *last = l = vlib_buffer_chain_buffer (vm, l, l->next_buffer);
Dave Barach9b8ffd92016-07-08 08:13:45 -0400483 max = n_buffer_bytes - l->current_length - l->current_data;
484 }
Pierre Pfister328e99b2016-02-12 13:18:42 +0000485
Dave Barach9b8ffd92016-07-08 08:13:45 -0400486 u16 len = (data_len > max) ? max : data_len;
Dave Barach178cf492018-11-13 16:34:13 -0500487 clib_memcpy_fast (vlib_buffer_get_current (l) + l->current_length,
488 data + copied, len);
Dave Barach9b8ffd92016-07-08 08:13:45 -0400489 vlib_buffer_chain_increase_length (first, l, len);
490 data_len -= len;
491 copied += len;
492 }
Pierre Pfister328e99b2016-02-12 13:18:42 +0000493 return copied;
494}
495
Damjan Marion910d3692019-01-21 11:48:34 +0100496clib_error_t *
497vlib_buffer_pool_create (vlib_main_t * vm, u8 index, char *name,
498 u32 data_size, u32 physmem_map_index)
Damjan Marion04a7f052017-07-10 15:06:17 +0200499{
Damjan Mariond50e3472019-01-20 00:03:56 +0100500 vlib_buffer_main_t *bm = vm->buffer_main;
Damjan Marion910d3692019-01-21 11:48:34 +0100501 vlib_buffer_pool_t *bp;
Damjan Marion68b4da62018-09-30 18:26:20 +0200502 vlib_physmem_map_t *m = vlib_physmem_get_map (vm, physmem_map_index);
503 uword start = pointer_to_uword (m->base);
Damjan Marion8e8d3c82018-10-23 22:54:40 +0200504 uword size = (uword) m->n_pages << m->log2_page_size;
Damjan Marion672ab692019-02-06 17:56:57 +0100505 uword i, j;
Damjan Marion910d3692019-01-21 11:48:34 +0100506 u32 alloc_size, n_alloc_per_page;;
507
508 vec_validate_aligned (bm->buffer_pools, index, CLIB_CACHE_LINE_BYTES);
509 bp = vec_elt_at_index (bm->buffer_pools, index);
510
511 if (bp->start)
512 return clib_error_return (0, "buffer with index %u already exists",
513 index);
514
515 if (index >= 255)
516 return clib_error_return (0, "buffer index must be < 255", index);
Damjan Marion04a7f052017-07-10 15:06:17 +0200517
518 if (bm->buffer_mem_size == 0)
519 {
520 bm->buffer_mem_start = start;
521 bm->buffer_mem_size = size;
522 }
523 else if (start < bm->buffer_mem_start)
524 {
525 bm->buffer_mem_size += bm->buffer_mem_start - start;
526 bm->buffer_mem_start = start;
527 if (size > bm->buffer_mem_size)
528 bm->buffer_mem_size = size;
529 }
530 else if (start > bm->buffer_mem_start)
531 {
532 uword new_size = start - bm->buffer_mem_start + size;
533 if (new_size > bm->buffer_mem_size)
534 bm->buffer_mem_size = new_size;
535 }
536
537 if ((u64) bm->buffer_mem_size >
538 ((u64) 1 << (32 + CLIB_LOG2_CACHE_LINE_BYTES)))
539 {
540 clib_panic ("buffer memory size out of range!");
541 }
Damjan Marion149ba772017-10-12 13:09:26 +0200542
Damjan Marion910d3692019-01-21 11:48:34 +0100543 bp->start = start;
544 bp->size = size;
545 bp->index = bp - bm->buffer_pools;
546 bp->buffer_template.buffer_pool_index = bp->index;
547 bp->buffer_template.ref_count = 1;
548 bp->physmem_map_index = physmem_map_index;
549 bp->name = format (0, "%s%c", name, 0);
550 bp->data_size = data_size;
551 bp->numa_node = m->numa_node;
Damjan Mariond1274cb2018-03-13 21:32:17 +0100552
Damjan Marion910d3692019-01-21 11:48:34 +0100553 vec_validate_aligned (bp->threads, vec_len (vlib_mains) - 1,
554 CLIB_CACHE_LINE_BYTES);
555
556 alloc_size = data_size + sizeof (vlib_buffer_t) + bm->ext_hdr_size;
557 n_alloc_per_page = (1ULL << m->log2_page_size) / alloc_size;
558
559 /* preallocate buffer indices memory */
560 vec_validate_aligned (bp->buffers, m->n_pages * n_alloc_per_page,
561 CLIB_CACHE_LINE_BYTES);
562 vec_reset_length (bp->buffers);
563
564 clib_spinlock_init (&bp->lock);
565
Damjan Marion672ab692019-02-06 17:56:57 +0100566 for (j = 0; j < m->n_pages; j++)
567 for (i = 0; i < n_alloc_per_page; i++)
568 {
569 u8 *p;
570 u32 bi;
Damjan Marion910d3692019-01-21 11:48:34 +0100571
Damjan Marion672ab692019-02-06 17:56:57 +0100572 p = m->base + (j << m->log2_page_size) + i * alloc_size;
573 p += bm->ext_hdr_size;
Damjan Marion910d3692019-01-21 11:48:34 +0100574
Damjan Marion672ab692019-02-06 17:56:57 +0100575 vlib_buffer_copy_template ((vlib_buffer_t *) p, &bp->buffer_template);
Damjan Marion910d3692019-01-21 11:48:34 +0100576
Damjan Marion672ab692019-02-06 17:56:57 +0100577 bi = vlib_get_buffer_index (vm, (vlib_buffer_t *) p);
Damjan Marion910d3692019-01-21 11:48:34 +0100578
Damjan Marion672ab692019-02-06 17:56:57 +0100579 vec_add1_aligned (bp->buffers, bi, CLIB_CACHE_LINE_BYTES);
580 vlib_get_buffer (vm, bi);
581 }
Damjan Marion910d3692019-01-21 11:48:34 +0100582
Damjan Marion672ab692019-02-06 17:56:57 +0100583 bp->n_buffers = vec_len (bp->buffers);
Damjan Marion910d3692019-01-21 11:48:34 +0100584
585 return 0;
Damjan Marion04a7f052017-07-10 15:06:17 +0200586}
Ed Warnickecb9cada2015-12-08 15:45:58 -0700587
Dave Barach9b8ffd92016-07-08 08:13:45 -0400588static u8 *
Damjan Marion910d3692019-01-21 11:48:34 +0100589format_vlib_buffer_pool (u8 * s, va_list * va)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700590{
Damjan Marion910d3692019-01-21 11:48:34 +0100591 vlib_main_t *vm = va_arg (*va, vlib_main_t *);
592 vlib_buffer_pool_t *bp = va_arg (*va, vlib_buffer_pool_t *);
593 vlib_buffer_pool_thread_t *bpt;
594 u32 cached = 0;
Damjan Marion1cd8f3c2016-11-24 02:07:32 +0100595
Damjan Marion910d3692019-01-21 11:48:34 +0100596 if (!bp)
597 return format (s, "%-20s%=6s%=6s%=6s%=11s%=6s%=8s%=8s%=8s",
598 "Pool Name", "Index", "NUMA", "Size", "Data Size",
599 "Total", "Avail", "Cached", "Used");
Damjan Marion1cd8f3c2016-11-24 02:07:32 +0100600
Damjan Marion910d3692019-01-21 11:48:34 +0100601 /* *INDENT-OFF* */
602 vec_foreach (bpt, bp->threads)
603 cached += vec_len (bpt->cached_buffers);
604 /* *INDENT-ON* */
Damjan Marion1cd8f3c2016-11-24 02:07:32 +0100605
Damjan Marion910d3692019-01-21 11:48:34 +0100606 s = format (s, "%-20s%=6d%=6d%=6u%=11u%=6u%=8u%=8u%=8u",
607 bp->name, bp->index, bp->numa_node, bp->data_size +
608 sizeof (vlib_buffer_t) + vm->buffer_main->ext_hdr_size,
609 bp->data_size, bp->n_buffers, vec_len (bp->buffers), cached,
610 bp->n_buffers - vec_len (bp->buffers) - cached);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700611
612 return s;
613}
614
615static clib_error_t *
616show_buffers (vlib_main_t * vm,
Dave Barach9b8ffd92016-07-08 08:13:45 -0400617 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700618{
Damjan Marion910d3692019-01-21 11:48:34 +0100619 vlib_buffer_main_t *bm = vm->buffer_main;
620 vlib_buffer_pool_t *bp;
Damjan Marion1cd8f3c2016-11-24 02:07:32 +0100621
Damjan Marion910d3692019-01-21 11:48:34 +0100622 vlib_cli_output (vm, "%U", format_vlib_buffer_pool, vm, 0);
Damjan Marion1cd8f3c2016-11-24 02:07:32 +0100623
Damjan Marion910d3692019-01-21 11:48:34 +0100624 /* *INDENT-OFF* */
625 vec_foreach (bp, bm->buffer_pools)
626 vlib_cli_output (vm, "%U", format_vlib_buffer_pool, vm, bp);
627 /* *INDENT-ON* */
Damjan Marion1cd8f3c2016-11-24 02:07:32 +0100628
Ed Warnickecb9cada2015-12-08 15:45:58 -0700629 return 0;
630}
631
Dave Barach9b8ffd92016-07-08 08:13:45 -0400632/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700633VLIB_CLI_COMMAND (show_buffers_command, static) = {
634 .path = "show buffers",
635 .short_help = "Show packet buffer allocation",
636 .function = show_buffers,
637};
Dave Barach9b8ffd92016-07-08 08:13:45 -0400638/* *INDENT-ON* */
639
Damjan Marion49d66f12017-07-20 18:10:35 +0200640clib_error_t *
Damjan Marion910d3692019-01-21 11:48:34 +0100641vlib_buffer_worker_init (vlib_main_t * vm)
Damjan Marion1cd8f3c2016-11-24 02:07:32 +0100642{
Damjan Marion910d3692019-01-21 11:48:34 +0100643 vlib_buffer_main_t *bm = vm->buffer_main;
644 vlib_buffer_pool_t *bp;
645
646 /* *INDENT-OFF* */
647 vec_foreach (bp, bm->buffer_pools)
648 {
649 clib_spinlock_lock (&bp->lock);
650 vec_validate_aligned (bp->threads, vec_len (vlib_mains) - 1,
651 CLIB_CACHE_LINE_BYTES);
652 clib_spinlock_unlock (&bp->lock);
653 }
654 /* *INDENT-ON* */
655
656 return 0;
657}
658
659VLIB_WORKER_INIT_FUNCTION (vlib_buffer_worker_init);
660
661static clib_error_t *
662vlib_buffer_main_init_numa_node (struct vlib_main_t *vm, u32 numa_node)
663{
664 vlib_buffer_main_t *bm = vm->buffer_main;
Damjan Marion49d66f12017-07-20 18:10:35 +0200665 clib_error_t *error;
Damjan Marion68b4da62018-09-30 18:26:20 +0200666 u32 physmem_map_index;
Damjan Marion910d3692019-01-21 11:48:34 +0100667 uword n_pages, pagesize;
668 u32 buffers_per_numa;
669 u32 buffer_size = CLIB_CACHE_LINE_ROUND (bm->ext_hdr_size +
670 sizeof (vlib_buffer_t) +
Damjan Marion8934a042019-02-09 23:29:26 +0100671 vlib_buffer_get_default_data_size
672 (vm));
Damjan Marion910d3692019-01-21 11:48:34 +0100673 u8 *name;
Damjan Marion567e61d2018-10-24 17:08:26 +0200674
Damjan Marion910d3692019-01-21 11:48:34 +0100675 pagesize = clib_mem_get_default_hugepage_size ();
676 name = format (0, "buffers-numa-%d%c", numa_node, 0);
Damjan Marion49d66f12017-07-20 18:10:35 +0200677
Damjan Marion910d3692019-01-21 11:48:34 +0100678 buffers_per_numa = bm->buffers_per_numa ? bm->buffers_per_numa :
679 VLIB_BUFFER_DEFAULT_BUFFERS_PER_NUMA;
Damjan Marion49d66f12017-07-20 18:10:35 +0200680
Damjan Marion567e61d2018-10-24 17:08:26 +0200681retry:
Damjan Marion910d3692019-01-21 11:48:34 +0100682 n_pages = (buffers_per_numa - 1) / (pagesize / buffer_size) + 1;
683 error = vlib_physmem_shared_map_create (vm, (char *) name,
684 n_pages * pagesize,
685 min_log2 (pagesize), numa_node,
Damjan Marion567e61d2018-10-24 17:08:26 +0200686 &physmem_map_index);
687
Damjan Marion910d3692019-01-21 11:48:34 +0100688 if (error && pagesize != clib_mem_get_page_size ())
Damjan Marion567e61d2018-10-24 17:08:26 +0200689 {
Damjan Marion910d3692019-01-21 11:48:34 +0100690 vlib_log_warn (bm->log_default, "%U", format_clib_error, error);
Damjan Marion567e61d2018-10-24 17:08:26 +0200691 clib_error_free (error);
Damjan Marion910d3692019-01-21 11:48:34 +0100692 vlib_log_warn (bm->log_default, "falling back to non-hugepage "
Damjan Marion567e61d2018-10-24 17:08:26 +0200693 "backed buffer pool");
Damjan Marion910d3692019-01-21 11:48:34 +0100694 pagesize = clib_mem_get_page_size ();
695 buffers_per_numa = bm->buffers_per_numa ? bm->buffers_per_numa :
696 VLIB_BUFFER_DEFAULT_BUFFERS_PER_NUMA_UNPRIV;
Damjan Marion567e61d2018-10-24 17:08:26 +0200697 goto retry;
698 }
699
700 if (error)
Damjan Marion68b4da62018-09-30 18:26:20 +0200701 return error;
Damjan Marion49d66f12017-07-20 18:10:35 +0200702
Damjan Marion910d3692019-01-21 11:48:34 +0100703 vec_reset_length (name);
704 name = format (name, "default-numa-%d%c", numa_node, 0);
Damjan Marion49d66f12017-07-20 18:10:35 +0200705
Damjan Marion910d3692019-01-21 11:48:34 +0100706 return vlib_buffer_pool_create (vm, numa_node, (char *) name,
Damjan Marion8934a042019-02-09 23:29:26 +0100707 vlib_buffer_get_default_data_size (vm),
Damjan Marion5de3fec2019-02-06 14:22:32 +0100708 physmem_map_index);
709}
710
711void
712vlib_buffer_main_alloc (vlib_main_t * vm)
713{
714 vlib_buffer_main_t *bm;
715
716 if (vm->buffer_main)
717 return;
718
719 vm->buffer_main = bm = clib_mem_alloc (sizeof (bm[0]));
720 clib_memset (vm->buffer_main, 0, sizeof (bm[0]));
721 bm->default_data_size = VLIB_BUFFER_DEFAULT_DATA_SIZE;
Damjan Marion910d3692019-01-21 11:48:34 +0100722}
723
Filip Tehlard2bbdef2019-02-22 05:05:53 -0800724static u32
725buffer_get_cached (vlib_buffer_pool_t * bp)
726{
727 u32 cached = 0;
728 vlib_buffer_pool_thread_t *bpt;
729
Filip Tehlarb806d0e2019-02-28 04:36:10 -0800730 clib_spinlock_lock (&bp->lock);
731
Filip Tehlard2bbdef2019-02-22 05:05:53 -0800732 /* *INDENT-OFF* */
733 vec_foreach (bpt, bp->threads)
734 cached += vec_len (bpt->cached_buffers);
735 /* *INDENT-ON* */
736
Filip Tehlarb806d0e2019-02-28 04:36:10 -0800737 clib_spinlock_unlock (&bp->lock);
738
Filip Tehlard2bbdef2019-02-22 05:05:53 -0800739 return cached;
740}
741
742static vlib_buffer_pool_t *
Ole Troan849cbe22019-02-26 13:10:56 +0100743buffer_get_by_index (vlib_buffer_main_t * bm, u32 index)
Filip Tehlard2bbdef2019-02-22 05:05:53 -0800744{
745 vlib_buffer_pool_t *bp;
Ole Troan849cbe22019-02-26 13:10:56 +0100746 if (!bm->buffer_pools || vec_len (bm->buffer_pools) < index)
747 return 0;
748 bp = vec_elt_at_index (bm->buffer_pools, index);
749 if (!bp)
750 return 0;
751 return bp;
Filip Tehlard2bbdef2019-02-22 05:05:53 -0800752}
753
754static void
Ole Troan849cbe22019-02-26 13:10:56 +0100755buffer_gauges_update_used_fn (stat_segment_directory_entry_t * e, u32 index)
Filip Tehlard2bbdef2019-02-22 05:05:53 -0800756{
757 vlib_main_t *vm = vlib_get_main ();
Ole Troan849cbe22019-02-26 13:10:56 +0100758 vlib_buffer_pool_t *bp = buffer_get_by_index (vm->buffer_main, index);
Filip Tehlard2bbdef2019-02-22 05:05:53 -0800759 if (!bp)
760 return;
761
762 e->value = bp->n_buffers - vec_len (bp->buffers) - buffer_get_cached (bp);
763}
764
765static void
Ole Troan849cbe22019-02-26 13:10:56 +0100766buffer_gauges_update_available_fn (stat_segment_directory_entry_t * e,
767 u32 index)
Filip Tehlard2bbdef2019-02-22 05:05:53 -0800768{
769 vlib_main_t *vm = vlib_get_main ();
Ole Troan849cbe22019-02-26 13:10:56 +0100770 vlib_buffer_pool_t *bp = buffer_get_by_index (vm->buffer_main, index);
Filip Tehlard2bbdef2019-02-22 05:05:53 -0800771 if (!bp)
772 return;
773
774 e->value = vec_len (bp->buffers);
775}
776
777static void
Ole Troan849cbe22019-02-26 13:10:56 +0100778buffer_gauges_update_cached_fn (stat_segment_directory_entry_t * e, u32 index)
Filip Tehlard2bbdef2019-02-22 05:05:53 -0800779{
780 vlib_main_t *vm = vlib_get_main ();
Ole Troan849cbe22019-02-26 13:10:56 +0100781 vlib_buffer_pool_t *bp = buffer_get_by_index (vm->buffer_main, index);
Filip Tehlard2bbdef2019-02-22 05:05:53 -0800782 if (!bp)
783 return;
784
785 e->value = buffer_get_cached (bp);
786}
787
Damjan Marion910d3692019-01-21 11:48:34 +0100788clib_error_t *
Filip Tehlard2bbdef2019-02-22 05:05:53 -0800789vlib_buffer_main_init (struct vlib_main_t * vm)
Damjan Marion910d3692019-01-21 11:48:34 +0100790{
791 vlib_buffer_main_t *bm;
792 clib_error_t *err;
793 clib_bitmap_t *bmp = 0;
794 u32 numa_node;
Filip Tehlard2bbdef2019-02-22 05:05:53 -0800795 vlib_buffer_pool_t *bp;
796 u8 *name;
Damjan Marion910d3692019-01-21 11:48:34 +0100797
Damjan Marion5de3fec2019-02-06 14:22:32 +0100798 vlib_buffer_main_alloc (vm);
Damjan Marion910d3692019-01-21 11:48:34 +0100799
800 bm = vm->buffer_main;
801 bm->log_default = vlib_log_register_class ("buffer", 0);
802 bm->ext_hdr_size = __vlib_buffer_external_hdr_size;
803
804 clib_spinlock_init (&bm->buffer_known_hash_lockp);
805
806 err = clib_sysfs_read ("/sys/devices/system/node/possible", "%U",
807 unformat_bitmap_list, &bmp);
808 if (err)
809 {
810 /* no info from sysfs, assuming that only numa 0 exists */
811 clib_error_free (err);
812 bmp = clib_bitmap_set (bmp, 0, 1);
813 }
814
815 /* *INDENT-OFF* */
816 clib_bitmap_foreach (numa_node, bmp, {
817 if ((err = vlib_buffer_main_init_numa_node(vm, numa_node)))
818 goto done;
819 });
820 /* *INDENT-ON* */
821
822 bm->n_numa_nodes = clib_bitmap_last_set (bmp) + 1;
823
Filip Tehlard2bbdef2019-02-22 05:05:53 -0800824 vec_foreach (bp, bm->buffer_pools)
825 {
Filip Tehlarb806d0e2019-02-28 04:36:10 -0800826 name = format (0, "/buffer-pools/%s/cached%c", bp->name, 0);
Ole Troan849cbe22019-02-26 13:10:56 +0100827 stat_segment_register_gauge (name, buffer_gauges_update_cached_fn,
828 bp - bm->buffer_pools);
Filip Tehlard2bbdef2019-02-22 05:05:53 -0800829 vec_free (name);
Filip Tehlarb806d0e2019-02-28 04:36:10 -0800830 name = format (0, "/buffer-pools/%s/used%c", bp->name, 0);
Ole Troan849cbe22019-02-26 13:10:56 +0100831 stat_segment_register_gauge (name, buffer_gauges_update_used_fn,
832 bp - bm->buffer_pools);
Filip Tehlard2bbdef2019-02-22 05:05:53 -0800833 vec_free (name);
Filip Tehlarb806d0e2019-02-28 04:36:10 -0800834 name = format (0, "/buffer-pools/%s/available%c", bp->name, 0);
Ole Troan849cbe22019-02-26 13:10:56 +0100835 stat_segment_register_gauge (name, buffer_gauges_update_available_fn,
836 bp - bm->buffer_pools);
Filip Tehlard2bbdef2019-02-22 05:05:53 -0800837 vec_free (name);
838 }
839
Damjan Marion910d3692019-01-21 11:48:34 +0100840done:
841 vec_free (bmp);
842 return err;
Damjan Marion878c6092017-01-04 13:19:27 +0100843}
Damjan Marion1cd8f3c2016-11-24 02:07:32 +0100844
Damjan Marion49d66f12017-07-20 18:10:35 +0200845static clib_error_t *
846vlib_buffers_configure (vlib_main_t * vm, unformat_input_t * input)
847{
Damjan Marion910d3692019-01-21 11:48:34 +0100848 vlib_buffer_main_t *bm;
849
Damjan Marion5de3fec2019-02-06 14:22:32 +0100850 vlib_buffer_main_alloc (vm);
Damjan Marion910d3692019-01-21 11:48:34 +0100851
852 bm = vm->buffer_main;
Damjan Marion49d66f12017-07-20 18:10:35 +0200853
854 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
855 {
Damjan Marion910d3692019-01-21 11:48:34 +0100856 if (unformat (input, "buffers-per-numa %u", &bm->buffers_per_numa))
857 ;
Damjan Marion5de3fec2019-02-06 14:22:32 +0100858 else if (unformat (input, "default data-size %u",
859 &bm->default_data_size))
860 ;
Damjan Marion49d66f12017-07-20 18:10:35 +0200861 else
862 return unformat_parse_error (input);
863 }
864
865 unformat_free (input);
866 return 0;
867}
868
869VLIB_EARLY_CONFIG_FUNCTION (vlib_buffers_configure, "buffers");
870
871
Chris Luked4024f52016-09-06 09:32:36 -0400872/** @endcond */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400873/*
874 * fd.io coding-style-patch-verification: ON
875 *
876 * Local Variables:
877 * eval: (c-set-style "gnu")
878 * End:
879 */