diff options
author | Damjan Marion <damarion@cisco.com> | 2017-11-24 20:15:23 +0100 |
---|---|---|
committer | Dave Barach <openvpp@barachs.net> | 2017-11-27 14:53:23 +0000 |
commit | c8a26c6d239554bac96c481c840b3f5b3d8a17af (patch) | |
tree | 4ad52a5fd5bbbd7c3dd1ca976d5cd9e9b2c03cd5 /src/plugins/dpdk/buffer.c | |
parent | 8b9a5d198cc316d36b93f19fee7a351fc3922e4a (diff) |
vlib: make vlib_buffer_alloc inline function
Currently, every alloc involves callback function call. With this change
callback function is called only if there is no empty buffers on the
free list.
Change-Id: I2238c19ece7ce182c49ba0f2485add52f335f3b6
Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'src/plugins/dpdk/buffer.c')
-rw-r--r-- | src/plugins/dpdk/buffer.c | 84 |
1 files changed, 11 insertions, 73 deletions
diff --git a/src/plugins/dpdk/buffer.c b/src/plugins/dpdk/buffer.c index 3ac9c69a9d2..235a130d937 100644 --- a/src/plugins/dpdk/buffer.c +++ b/src/plugins/dpdk/buffer.c @@ -196,9 +196,10 @@ dpdk_buffer_delete_free_list (vlib_main_t * vm, u32 free_list_index) #endif /* Make sure free list has at least given number of free buffers. */ -static uword -fill_free_list (vlib_main_t * vm, - vlib_buffer_free_list_t * fl, uword min_free_buffers) +uword +CLIB_MULTIARCH_FN (dpdk_buffer_fill_free_list) (vlib_main_t * vm, + vlib_buffer_free_list_t * fl, + uword min_free_buffers) { dpdk_main_t *dm = &dpdk_main; vlib_buffer_t *b0, *b1, *b2, *b3; @@ -303,60 +304,6 @@ fill_free_list (vlib_main_t * vm, return n; } -static u32 -alloc_from_free_list (vlib_main_t * vm, - vlib_buffer_free_list_t * free_list, - u32 * alloc_buffers, u32 n_alloc_buffers) -{ - u32 *dst, *src; - uword len, n_filled; - - dst = alloc_buffers; - - n_filled = fill_free_list (vm, free_list, n_alloc_buffers); - if (n_filled == 0) - return 0; - - len = vec_len (free_list->buffers); - ASSERT (len >= n_alloc_buffers); - - src = free_list->buffers + len - n_alloc_buffers; - clib_memcpy (dst, src, n_alloc_buffers * sizeof (u32)); - - _vec_len (free_list->buffers) -= n_alloc_buffers; - - return n_alloc_buffers; -} - -/* Allocate a given number of buffers into given array. - Returns number actually allocated which will be either zero or - number requested. */ -u32 -CLIB_MULTIARCH_FN (dpdk_buffer_alloc) (vlib_main_t * vm, u32 * buffers, - u32 n_buffers) -{ - vlib_buffer_main_t *bm = vm->buffer_main; - - return alloc_from_free_list - (vm, - pool_elt_at_index (bm->buffer_free_list_pool, - VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX), - buffers, n_buffers); -} - - -u32 -CLIB_MULTIARCH_FN (dpdk_buffer_alloc_from_free_list) (vlib_main_t * vm, - u32 * buffers, - u32 n_buffers, - u32 free_list_index) -{ - vlib_buffer_main_t *bm = vm->buffer_main; - vlib_buffer_free_list_t *f; - f = pool_elt_at_index (bm->buffer_free_list_pool, free_list_index); - return alloc_from_free_list (vm, f, buffers, n_buffers); -} - static_always_inline void dpdk_prefetch_buffer_by_index (vlib_main_t * vm, u32 bi) { @@ -733,8 +680,7 @@ VLIB_INIT_FUNCTION (dpdk_buffer_init); /* *INDENT-OFF* */ VLIB_BUFFER_REGISTER_CALLBACKS (dpdk, static) = { - .vlib_buffer_alloc_cb = &dpdk_buffer_alloc, - .vlib_buffer_alloc_from_free_list_cb = &dpdk_buffer_alloc_from_free_list, + .vlib_buffer_fill_free_list_cb = &dpdk_buffer_fill_free_list, .vlib_buffer_free_cb = &dpdk_buffer_free, .vlib_buffer_free_no_next_cb = &dpdk_buffer_free_no_next, .vlib_packet_template_init_cb = &dpdk_packet_template_init, @@ -743,12 +689,8 @@ VLIB_BUFFER_REGISTER_CALLBACKS (dpdk, static) = { /* *INDENT-ON* */ #if __x86_64__ -vlib_buffer_alloc_cb_t __clib_weak dpdk_buffer_alloc_avx512; -vlib_buffer_alloc_cb_t __clib_weak dpdk_buffer_alloc_avx2; -vlib_buffer_alloc_from_free_list_cb_t __clib_weak - dpdk_buffer_alloc_from_free_list_avx512; -vlib_buffer_alloc_from_free_list_cb_t __clib_weak - dpdk_buffer_alloc_from_free_list_avx2; +vlib_buffer_fill_free_list_cb_t __clib_weak dpdk_buffer_fill_free_list_avx512; +vlib_buffer_fill_free_list_cb_t __clib_weak dpdk_buffer_fill_free_list_avx2; vlib_buffer_free_cb_t __clib_weak dpdk_buffer_free_avx512; vlib_buffer_free_cb_t __clib_weak dpdk_buffer_free_avx2; vlib_buffer_free_no_next_cb_t __clib_weak dpdk_buffer_free_no_next_avx512; @@ -758,19 +700,15 @@ static void __clib_constructor dpdk_input_multiarch_select (void) { vlib_buffer_callbacks_t *cb = &__dpdk_buffer_callbacks; - if (dpdk_buffer_alloc_avx512 && clib_cpu_supports_avx512f ()) + if (dpdk_buffer_fill_free_list_avx512 && clib_cpu_supports_avx512f ()) { - cb->vlib_buffer_alloc_cb = dpdk_buffer_alloc_avx512; - cb->vlib_buffer_alloc_from_free_list_cb = - dpdk_buffer_alloc_from_free_list_avx512; + cb->vlib_buffer_fill_free_list_cb = dpdk_buffer_fill_free_list_avx512; cb->vlib_buffer_free_cb = dpdk_buffer_free_avx512; cb->vlib_buffer_free_no_next_cb = dpdk_buffer_free_no_next_avx512; } - else if (dpdk_buffer_alloc_avx2 && clib_cpu_supports_avx2 ()) + else if (dpdk_buffer_fill_free_list_avx2 && clib_cpu_supports_avx2 ()) { - cb->vlib_buffer_alloc_cb = dpdk_buffer_alloc_avx2; - cb->vlib_buffer_alloc_from_free_list_cb = - dpdk_buffer_alloc_from_free_list_avx2; + cb->vlib_buffer_fill_free_list_cb = dpdk_buffer_fill_free_list_avx2; cb->vlib_buffer_free_cb = dpdk_buffer_free_avx2; cb->vlib_buffer_free_no_next_cb = dpdk_buffer_free_no_next_avx2; } |