vppinfra: add cmake option to grow vectors by 1 08/24908/3
authorDave Barach <dave@barachs.net>
Mon, 10 Feb 2020 15:16:40 +0000 (10:16 -0500)
committerNeale Ranns <nranns@cisco.com>
Thu, 13 Feb 2020 07:46:36 +0000 (07:46 +0000)
For debugging. Do not set this option in production.

Type: feature

Signed-off-by: Dave Barach <dave@barachs.net>
Change-Id: I5e59671c4932e064bc087b85bf9c62c6f3bf48cf

src/vppinfra/CMakeLists.txt
src/vppinfra/config.h.in
src/vppinfra/vec.c

index 3998ae6..7723e6b 100644 (file)
@@ -18,6 +18,13 @@ enable_language(ASM)
 ##############################################################################
 set(LOG2_CACHE_LINE_BYTES ${VPP_LOG2_CACHE_LINE_SIZE})
 
+option(VPP_VECTOR_GROW_BY_ONE "Vectors grow by one, instead of 3/2" OFF)
+if(VPP_VECTOR_GROW_BY_ONE)
+  set(VECTOR_GROW_BY_ONE 1)
+else(VPP_VECTOR_GROW_BY_ONE)
+  set(VECTOR_GROW_BY_ONE 0)
+endif(VPP_VECTOR_GROW_BY_ONE)
+
 configure_file(
   ${CMAKE_SOURCE_DIR}/vppinfra/config.h.in
   ${CMAKE_BINARY_DIR}/vppinfra/config.h
index 1a8e031..7aad027 100644 (file)
@@ -21,4 +21,6 @@
 #endif
 
 #define CLIB_TARGET_TRIPLET "@CMAKE_C_COMPILER_TARGET@"
+#define CLIB_VECTOR_GROW_BY_ONE @VECTOR_GROW_BY_ONE@
+
 #endif
index 2ee7895..05a557e 100644 (file)
@@ -95,9 +95,13 @@ vec_resize_allocate_memory (void *v,
       return v;
     }
 
+#if CLIB_VECTOR_GROW_BY_ONE > 0
+  new_alloc_bytes = data_bytes;
+#else
   new_alloc_bytes = (old_alloc_bytes * 3) / 2;
   if (new_alloc_bytes < data_bytes)
     new_alloc_bytes = data_bytes;
+#endif
 
   new =
     clib_mem_alloc_aligned_at_offset (new_alloc_bytes, data_align,