buffers: improve buffer init performance 50/17350/2
authorDamjan Marion <damarion@cisco.com>
Wed, 6 Feb 2019 16:56:57 +0000 (17:56 +0100)
committerFlorin Coras <florin.coras@gmail.com>
Wed, 6 Feb 2019 17:58:32 +0000 (17:58 +0000)
Change-Id: Ib59a3c32af754a898ade17c42e60a88f48b797ff
Signed-off-by: Damjan Marion <damarion@cisco.com>
src/vlib/buffer.c

index 77602a6..345cd5c 100644 (file)
@@ -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;
 }