summaryrefslogtreecommitdiffstats
path: root/src/vlib/buffer.c
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2019-02-06 17:56:57 +0100
committerFlorin Coras <florin.coras@gmail.com>2019-02-06 17:58:32 +0000
commit672ab690182f3d4941d2640c68bb6ced38880bc3 (patch)
treedcd263384ea96a3b18159ea16dd9cb035fd83be2 /src/vlib/buffer.c
parentb74fe32d545668938a8db7f19d94c42747ef95f6 (diff)
buffers: improve buffer init performance
Change-Id: Ib59a3c32af754a898ade17c42e60a88f48b797ff Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'src/vlib/buffer.c')
-rw-r--r--src/vlib/buffer.c31
1 files 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;
}