vppinfra: will_expand for pool_put and bitmap 32/34332/6
authorStanislav Zaikin <zstaseg@gmail.com>
Thu, 4 Nov 2021 08:32:32 +0000 (09:32 +0100)
committerFlorin Coras <florin.coras@gmail.com>
Thu, 25 Nov 2021 22:45:58 +0000 (22:45 +0000)
Macro for pool_put and put a barrier inside load_balance_destroy when bitmap is actually growing.

Type: improvement

Signed-off-by: Stanislav Zaikin <zstaseg@gmail.com>
Change-Id: Ief2912e8efd744289ebed68373fa6fd0ee83118e

src/vppinfra/bitmap.h
src/vppinfra/pool.h

index af651ef..3c95bfb 100644 (file)
@@ -206,6 +206,14 @@ clib_bitmap_set (uword * ai, uword i, uword value)
   return ai;
 }
 
+always_inline u8
+clib_bitmap_will_expand (uword *ai, uword i)
+{
+  uword i0 = i / BITS (ai[0]);
+  return _vec_resize_will_expand (ai, 1, i0 * sizeof (ai[0]), 0,
+                                 sizeof (uword));
+}
+
 /** Gets the ith bit value from a bitmap
     @param ai - pointer to the bitmap
     @param i - the bit position to interrogate
index 68a859e..3b5a900 100644 (file)
@@ -287,6 +287,25 @@ do {                                                                    \
     }                                                                   \
 } while (0)
 
+/** See if pool_put will expand free_bitmap or free_indices or not */
+#define pool_put_will_expand(P, E, YESNO)                                     \
+  do                                                                          \
+    {                                                                         \
+      pool_header_t *_pool_var (p) = pool_header (P);                         \
+                                                                              \
+      uword _pool_var (i) = (E) - (P);                                        \
+      /* free_bitmap or free_indices may expand. */                           \
+      YESNO =                                                                 \
+       clib_bitmap_will_expand (_pool_var (p)->free_bitmap, _pool_var (i));  \
+                                                                              \
+      YESNO += _vec_resize_will_expand (                                      \
+       _pool_var (p)->free_indices, 1,                                       \
+       (vec_len (_pool_var (p)->free_indices) + 1) *                         \
+         sizeof (_pool_var (p)->free_indices[0]),                            \
+       0, 0);                                                                \
+    }                                                                         \
+  while (0)
+
 /** Tell the caller if pool get will expand the pool */
 #define pool_get_will_expand(P,YESNO) pool_get_aligned_will_expand(P,YESNO,0)