diff options
Diffstat (limited to 'src/vlib')
-rw-r--r-- | src/vlib/buffer.c | 41 | ||||
-rw-r--r-- | src/vlib/buffer.h | 4 | ||||
-rw-r--r-- | src/vlib/buffer_funcs.h | 19 | ||||
-rw-r--r-- | src/vlib/unix/mc_socket.c | 8 |
4 files changed, 43 insertions, 29 deletions
diff --git a/src/vlib/buffer.c b/src/vlib/buffer.c index 345cd5c564b..a45b9bf2fc7 100644 --- a/src/vlib/buffer.c +++ b/src/vlib/buffer.c @@ -192,9 +192,9 @@ vlib_validate_buffer_helper (vlib_main_t * vm, if ((signed) b->current_data < (signed) -VLIB_BUFFER_PRE_DATA_SIZE) return format (0, "current data %d before pre-data", b->current_data); - if (b->current_data + b->current_length > VLIB_BUFFER_DATA_SIZE) + if (b->current_data + b->current_length > vlib_bufer_get_default_size (vm)) return format (0, "%d-%d beyond end of buffer %d", b->current_data, - b->current_length, VLIB_BUFFER_DATA_SIZE); + b->current_length, vlib_bufer_get_default_size (vm)); if (follow_buffer_next && (b->flags & VLIB_BUFFER_NEXT_PRESENT)) { @@ -407,7 +407,7 @@ vlib_buffer_add_data (vlib_main_t * vm, u32 * buffer_index, void *data, d = data; n_left = n_data_bytes; - n_buffer_bytes = VLIB_BUFFER_DATA_SIZE; + n_buffer_bytes = vlib_bufer_get_default_size (vm); b = vlib_get_buffer (vm, bi); b->flags &= ~VLIB_BUFFER_TOTAL_LENGTH_VALID; @@ -455,7 +455,7 @@ vlib_buffer_chain_append_data_with_alloc (vlib_main_t * vm, u16 data_len) { vlib_buffer_t *l = *last; - u32 n_buffer_bytes = VLIB_BUFFER_DATA_SIZE; + u32 n_buffer_bytes = vlib_bufer_get_default_size (vm); u16 copied = 0; ASSERT (n_buffer_bytes >= l->current_length + l->current_data); while (data_len) @@ -655,7 +655,7 @@ vlib_buffer_main_init_numa_node (struct vlib_main_t *vm, u32 numa_node) u32 buffers_per_numa; u32 buffer_size = CLIB_CACHE_LINE_ROUND (bm->ext_hdr_size + sizeof (vlib_buffer_t) + - VLIB_BUFFER_DATA_SIZE); + vlib_bufer_get_default_size (vm)); u8 *name; pagesize = clib_mem_get_default_hugepage_size (); @@ -690,7 +690,21 @@ retry: name = format (name, "default-numa-%d%c", numa_node, 0); return vlib_buffer_pool_create (vm, numa_node, (char *) name, - VLIB_BUFFER_DATA_SIZE, physmem_map_index); + vlib_bufer_get_default_size (vm), + physmem_map_index); +} + +void +vlib_buffer_main_alloc (vlib_main_t * vm) +{ + vlib_buffer_main_t *bm; + + if (vm->buffer_main) + return; + + vm->buffer_main = bm = clib_mem_alloc (sizeof (bm[0])); + clib_memset (vm->buffer_main, 0, sizeof (bm[0])); + bm->default_data_size = VLIB_BUFFER_DEFAULT_DATA_SIZE; } clib_error_t * @@ -701,11 +715,7 @@ vlib_buffer_main_init (struct vlib_main_t *vm) clib_bitmap_t *bmp = 0; u32 numa_node; - if (vm->buffer_main == 0) - { - vm->buffer_main = clib_mem_alloc (sizeof (bm[0])); - clib_memset (vm->buffer_main, 0, sizeof (bm[0])); - } + vlib_buffer_main_alloc (vm); bm = vm->buffer_main; bm->log_default = vlib_log_register_class ("buffer", 0); @@ -741,11 +751,7 @@ vlib_buffers_configure (vlib_main_t * vm, unformat_input_t * input) { vlib_buffer_main_t *bm; - if (vm->buffer_main == 0) - { - vm->buffer_main = clib_mem_alloc (sizeof (bm[0])); - clib_memset (vm->buffer_main, 0, sizeof (bm[0])); - } + vlib_buffer_main_alloc (vm); bm = vm->buffer_main; @@ -753,6 +759,9 @@ vlib_buffers_configure (vlib_main_t * vm, unformat_input_t * input) { if (unformat (input, "buffers-per-numa %u", &bm->buffers_per_numa)) ; + else if (unformat (input, "default data-size %u", + &bm->default_data_size)) + ; else return unformat_parse_error (input); } diff --git a/src/vlib/buffer.h b/src/vlib/buffer.h index 1adde73d4ee..31baf5fd21e 100644 --- a/src/vlib/buffer.h +++ b/src/vlib/buffer.h @@ -48,9 +48,10 @@ #include <vlib/error.h> /* for vlib_error_t */ #include <vlib/config.h> /* for __PRE_DATA_SIZE */ -#define VLIB_BUFFER_DATA_SIZE (2048) #define VLIB_BUFFER_PRE_DATA_SIZE __PRE_DATA_SIZE +#define VLIB_BUFFER_DEFAULT_DATA_SIZE (2048) + /* Minimum buffer chain segment size. Does not apply to last buffer in chain. Dataplane code can safely asume that specified amount of data is not split into 2 chained buffers */ @@ -413,6 +414,7 @@ typedef struct /* config */ u32 buffers_per_numa; u16 ext_hdr_size; + u32 default_data_size; /* logging */ vlib_log_class_t log_default; diff --git a/src/vlib/buffer_funcs.h b/src/vlib/buffer_funcs.h index 09ffd06428f..97b687b8cc6 100644 --- a/src/vlib/buffer_funcs.h +++ b/src/vlib/buffer_funcs.h @@ -56,16 +56,11 @@ vlib_buffer_validate (vlib_main_t * vm, vlib_buffer_t * b) /* reference count in allocated buffer always must be 1 or higher */ ASSERT (b->ref_count > 0); - /* verify that buffer pointer is from buffer memory range */ - ASSERT (pointer_to_uword (b) >= bm->buffer_mem_start); - ASSERT (pointer_to_uword (b) < bm->buffer_mem_start + bm->buffer_mem_size - - VLIB_BUFFER_DATA_SIZE); - /* verify that buffer pool index is valid */ bp = vec_elt_at_index (bm->buffer_pools, b->buffer_pool_index); ASSERT (pointer_to_uword (b) >= bp->start); ASSERT (pointer_to_uword (b) < bp->start + bp->size - - VLIB_BUFFER_DATA_SIZE); + (bp->data_size + sizeof (vlib_buffer_t))); } always_inline void * @@ -93,6 +88,12 @@ vlib_get_buffer (vlib_main_t * vm, u32 buffer_index) return b; } +static_always_inline u32 +vlib_bufer_get_default_size (vlib_main_t * vm) +{ + return vm->buffer_main->default_data_size; +} + static_always_inline void vlib_buffer_copy_indices (u32 * dst, u32 * src, u32 n_indices) { @@ -1161,7 +1162,7 @@ vlib_buffer_chain_append_data (vlib_main_t * vm, vlib_buffer_t * first, vlib_buffer_t * last, void *data, u16 data_len) { - u32 n_buffer_bytes = VLIB_BUFFER_DATA_SIZE; + u32 n_buffer_bytes = vlib_bufer_get_default_size (vm); ASSERT (n_buffer_bytes >= last->current_length + last->current_data); u16 len = clib_min (data_len, n_buffer_bytes - last->current_length - @@ -1236,7 +1237,7 @@ vlib_buffer_chain_compress (vlib_main_t * vm, } u32 want_first_size = clib_min (VLIB_BUFFER_CLONE_HEAD_SIZE, - VLIB_BUFFER_DATA_SIZE - + vlib_bufer_get_default_size (vm) - first->current_data); do { @@ -1283,7 +1284,7 @@ always_inline int vlib_buffer_chain_linearize (vlib_main_t * vm, vlib_buffer_t * first) { vlib_buffer_t *b = first; - u32 buf_len = VLIB_BUFFER_DATA_SIZE; + u32 buf_len = vlib_bufer_get_default_size (vm); // free buffer chain starting from the second buffer int free_count = (b->flags & VLIB_BUFFER_NEXT_PRESENT) != 0; u32 chain_to_free = b->next_buffer; diff --git a/src/vlib/unix/mc_socket.c b/src/vlib/unix/mc_socket.c index aaf73ae5e1e..d4f4a7fe7e3 100644 --- a/src/vlib/unix/mc_socket.c +++ b/src/vlib/unix/mc_socket.c @@ -165,7 +165,7 @@ recvmsg_helper (mc_socket_main_t * msm, vlib_main_t *vm = msm->mc_main.vlib_main; vlib_buffer_t *b; uword n_left, n_alloc, n_mtu, i, i_rx; - const uword buffer_size = VLIB_BUFFER_DATA_SIZE; + const uword buffer_size = vlib_bufer_get_default_size (vm); word n_bytes_left; /* Make sure we have at least a MTU worth of buffers. */ @@ -1011,8 +1011,10 @@ mc_socket_main_init (mc_socket_main_t * msm, char **intfc_probe_list, } msm->rx_mtu_n_bytes = mtu; - msm->rx_mtu_n_buffers = msm->rx_mtu_n_bytes / VLIB_BUFFER_DATA_SIZE; - msm->rx_mtu_n_buffers += (msm->rx_mtu_n_bytes % VLIB_BUFFER_DATA_SIZE) != 0; + msm->rx_mtu_n_buffers = + msm->rx_mtu_n_bytes / vlib_bufer_get_default_size (vm); + msm->rx_mtu_n_buffers += + (msm->rx_mtu_n_bytes % vlib_bufer_get_default_size (vm)) != 0; error = socket_setup (msm); if (error) |