diff options
author | Damjan Marion <damarion@cisco.com> | 2017-07-10 15:06:17 +0200 |
---|---|---|
committer | Dave Barach <openvpp@barachs.net> | 2017-07-10 19:35:57 +0000 |
commit | 04a7f05e91e919f51eaecaee476435484076655b (patch) | |
tree | b7cbd12430c4a16b6289300b5b604835791bd780 /src/vlib/buffer.c | |
parent | 28160f38488743b8cee0a7bd62b432a9dd8f4bfd (diff) |
vlib: store buffer memory information in the buffer_main
Currently, buffer index is calculated as a offset to the physmem
region shifted by log2_cacheline size.
When DPDK is used we "hack" physmem data with information taken from
dpdk mempool. This makes physmem code not usable with DPDK.
This change makes buffer memory start and size independent of physmem
basically allowing physmem to be used when DPDK plugin is loaded.
Change-Id: Ieb399d398f147583b9baab467152a352d58c9c31
Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'src/vlib/buffer.c')
-rw-r--r-- | src/vlib/buffer.c | 57 |
1 files changed, 33 insertions, 24 deletions
diff --git a/src/vlib/buffer.c b/src/vlib/buffer.c index e50064ae622..b2a095cfb1a 100644 --- a/src/vlib/buffer.c +++ b/src/vlib/buffer.c @@ -46,6 +46,8 @@ #include <vlib/vlib.h> #include <vlib/unix/unix.h> +vlib_buffer_callbacks_t *vlib_buffer_callbacks = 0; + uword vlib_buffer_length_in_chain_slow_path (vlib_main_t * vm, vlib_buffer_t * b_first) @@ -584,11 +586,6 @@ alloc_from_free_list (vlib_main_t * vm, dst = alloc_buffers; - /* wait with buffer memory allocation as long as possible - in case external buffer manager takes over */ - if (PREDICT_FALSE (vm->os_physmem_alloc_aligned == 0)) - unix_physmem_init (vm, 0 /* fail_if_physical_memory_not_present */ ); - n_filled = fill_free_list (vm, free_list, n_alloc_buffers); if (n_filled == 0) return 0; @@ -944,6 +941,36 @@ vlib_buffer_chain_append_data_with_alloc (vlib_main_t * vm, return copied; } +void +vlib_buffer_add_mem_range (vlib_main_t * vm, uword start, uword size) +{ + vlib_buffer_main_t *bm = vm->buffer_main; + + if (bm->buffer_mem_size == 0) + { + bm->buffer_mem_start = start; + bm->buffer_mem_size = size; + } + else if (start < bm->buffer_mem_start) + { + bm->buffer_mem_size += bm->buffer_mem_start - start; + bm->buffer_mem_start = start; + if (size > bm->buffer_mem_size) + bm->buffer_mem_size = size; + } + else if (start > bm->buffer_mem_start) + { + uword new_size = start - bm->buffer_mem_start + size; + if (new_size > bm->buffer_mem_size) + bm->buffer_mem_size = new_size; + } + + if ((u64) bm->buffer_mem_size > + ((u64) 1 << (32 + CLIB_LOG2_CACHE_LINE_BYTES))) + { + clib_panic ("buffer memory size out of range!"); + } +} static u8 * format_vlib_buffer_free_list (u8 * s, va_list * va) @@ -1011,6 +1038,7 @@ void vlib_buffer_cb_init (struct vlib_main_t *vm) { vlib_buffer_main_t *bm = vm->buffer_main; + bm->cb.vlib_buffer_alloc_cb = &vlib_buffer_alloc_internal; bm->cb.vlib_buffer_alloc_from_free_list_cb = &vlib_buffer_alloc_from_free_list_internal; @@ -1018,25 +1046,6 @@ vlib_buffer_cb_init (struct vlib_main_t *vm) bm->cb.vlib_buffer_free_no_next_cb = &vlib_buffer_free_no_next_internal; bm->cb.vlib_buffer_delete_free_list_cb = &vlib_buffer_delete_free_list_internal; - bm->extern_buffer_mgmt = 0; -} - -int -vlib_buffer_cb_register (struct vlib_main_t *vm, vlib_buffer_callbacks_t * cb) -{ - vlib_buffer_main_t *bm = vm->buffer_main; - if (bm->extern_buffer_mgmt) - return -1; - -#define _(x) bm->cb.x = cb->x - _(vlib_buffer_alloc_cb); - _(vlib_buffer_alloc_from_free_list_cb); - _(vlib_buffer_free_cb); - _(vlib_buffer_free_no_next_cb); - _(vlib_buffer_delete_free_list_cb); -#undef _ - bm->extern_buffer_mgmt = 1; - return 0; } /** @endcond */ |