From 672ab690182f3d4941d2640c68bb6ced38880bc3 Mon Sep 17 00:00:00 2001 From: Damjan Marion Date: Wed, 6 Feb 2019 17:56:57 +0100 Subject: [PATCH] buffers: improve buffer init performance Change-Id: Ib59a3c32af754a898ade17c42e60a88f48b797ff Signed-off-by: Damjan Marion --- src/vlib/buffer.c | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/src/vlib/buffer.c b/src/vlib/buffer.c index 77602a61ac1..345cd5c564b 100644 --- a/src/vlib/buffer.c +++ b/src/vlib/buffer.c @@ -489,6 +489,7 @@ vlib_buffer_pool_create (vlib_main_t * vm, u8 index, char *name, vlib_physmem_map_t *m = vlib_physmem_get_map (vm, physmem_map_index); uword start = pointer_to_uword (m->base); uword size = (uword) m->n_pages << m->log2_page_size; + uword i, j; u32 alloc_size, n_alloc_per_page;; vec_validate_aligned (bm->buffer_pools, index, CLIB_CACHE_LINE_BYTES); @@ -549,28 +550,24 @@ vlib_buffer_pool_create (vlib_main_t * vm, u8 index, char *name, clib_spinlock_init (&bp->lock); - while (1) - { - u8 *p; - u32 bi; - - p = vlib_physmem_alloc_from_map (vm, bp->physmem_map_index, alloc_size, - CLIB_CACHE_LINE_BYTES); + for (j = 0; j < m->n_pages; j++) + for (i = 0; i < n_alloc_per_page; i++) + { + u8 *p; + u32 bi; - if (p == 0) - break; - - p += bm->ext_hdr_size; + p = m->base + (j << m->log2_page_size) + i * alloc_size; + p += bm->ext_hdr_size; - vlib_buffer_copy_template ((vlib_buffer_t *) p, &bp->buffer_template); + vlib_buffer_copy_template ((vlib_buffer_t *) p, &bp->buffer_template); - bi = vlib_get_buffer_index (vm, (vlib_buffer_t *) p); + bi = vlib_get_buffer_index (vm, (vlib_buffer_t *) p); - vec_add1_aligned (bp->buffers, bi, CLIB_CACHE_LINE_BYTES); - vlib_get_buffer (vm, bi); + vec_add1_aligned (bp->buffers, bi, CLIB_CACHE_LINE_BYTES); + vlib_get_buffer (vm, bi); + } - bp->n_buffers += 1; - } + bp->n_buffers = vec_len (bp->buffers); return 0; } -- 2.16.6