summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDave Barach <dave@barachs.net>2019-09-03 10:57:19 -0400
committerDamjan Marion <dmarion@me.com>2019-09-03 19:43:34 +0000
commit5bdc1f5245054f8b183b75f6b4442d45018afbe3 (patch)
tree3419327c967dc07ff50d6a5db79ef97307a78ab0 /src
parent08940a2cb8177ce6c89ba0e9146515978dc66560 (diff)
vppinfra: add bihash_init2
Add controls to list / not list a specific bihash in clib_all_bihashes, to immediately initialize a bihash. clib_bihash_init2 is now the primary API. It takes a typical args_t structure. clib_bihash_init becomes a compatibility widget. It fabricates an args_t and calls init2... Type: refactor Ticket: VPP-1758 Signed-off-by: Dave Barach <dave@barachs.net> Change-Id: Ib3e1304884997cf7025af20bdc67a7dda290f15b (cherry picked from commit bdf9b97774f02458ede6b7c7ae2d5728bddba000)
Diffstat (limited to 'src')
-rw-r--r--src/vppinfra/bihash_template.c60
-rw-r--r--src/vppinfra/bihash_template.h13
2 files changed, 53 insertions, 20 deletions
diff --git a/src/vppinfra/bihash_template.c b/src/vppinfra/bihash_template.c
index 4ef32efbe89..97c4cd08eb1 100644
--- a/src/vppinfra/bihash_template.c
+++ b/src/vppinfra/bihash_template.c
@@ -46,18 +46,21 @@ void BV (clib_bihash_instantiate) (BVT (clib_bihash) * h)
h->instantiated = 1;
}
-void BV (clib_bihash_init)
- (BVT (clib_bihash) * h, char *name, u32 nbuckets, uword memory_size)
+void BV (clib_bihash_init2) (BVT (clib_bihash_init2_args) * a)
{
int i;
void *oldheap;
- nbuckets = 1 << (max_log2 (nbuckets));
+ BVT (clib_bihash) * h = a->h;
- h->name = (u8 *) name;
- h->nbuckets = nbuckets;
- h->log2_nbuckets = max_log2 (nbuckets);
- h->memory_size = memory_size;
+ a->nbuckets = 1 << (max_log2 (a->nbuckets));
+
+ h->name = (u8 *) a->name;
+ h->nbuckets = a->nbuckets;
+ h->log2_nbuckets = max_log2 (a->nbuckets);
+ h->memory_size = a->memory_size;
h->instantiated = 0;
+ h->fmt_fn = a->fmt_fn;
+
alloc_arena (h) = 0;
/*
@@ -66,19 +69,22 @@ void BV (clib_bihash_init)
* If someone starts complaining that's not enough, we can shift
* the offset by CLIB_LOG2_CACHE_LINE_BYTES...
*/
- ASSERT (memory_size < (1ULL << BIHASH_BUCKET_OFFSET_BITS));
- h->fmt_fn = NULL;
+ ASSERT (h->memory_size < (1ULL << BIHASH_BUCKET_OFFSET_BITS));
/* Add this hash table to the list */
- for (i = 0; i < vec_len (clib_all_bihashes); i++)
- if (clib_all_bihashes[i] == h)
- return;
-
- /* Unfortunately, the heap push/pop is required.... */
- oldheap = clib_all_bihash_set_heap ();
- vec_add1 (clib_all_bihashes, (void *) h);
- clib_mem_set_heap (oldheap);
+ if (a->dont_add_to_all_bihash_list == 0)
+ {
+ for (i = 0; i < vec_len (clib_all_bihashes); i++)
+ if (clib_all_bihashes[i] == h)
+ goto do_lock;
+ oldheap = clib_all_bihash_set_heap ();
+ vec_add1 (clib_all_bihashes, (void *) h);
+ clib_mem_set_heap (oldheap);
+ }
+do_lock:
+ if (h->alloc_lock)
+ clib_mem_free ((void *) h->alloc_lock);
/*
* Set up the lock now, so we can use it to make the first add
@@ -88,9 +94,23 @@ void BV (clib_bihash_init)
CLIB_CACHE_LINE_BYTES);
h->alloc_lock[0] = 0;
-#if BIHASH_INSTANTIATE_IMMEDIATELY
- BV (clib_bihash_instantiate) (h);
-#endif
+ if (a->instantiate_immediately)
+ BV (clib_bihash_instantiate) (h);
+}
+
+void BV (clib_bihash_init)
+ (BVT (clib_bihash) * h, char *name, u32 nbuckets, uword memory_size)
+{
+ BVT (clib_bihash_init2_args) _a, *a = &_a;
+
+ memset (a, 0, sizeof (*a));
+
+ a->h = h;
+ a->name = name;
+ a->nbuckets = nbuckets;
+ a->memory_size = memory_size;
+
+ BV (clib_bihash_init2) (a);
}
#if BIHASH_32_64_SVM
diff --git a/src/vppinfra/bihash_template.h b/src/vppinfra/bihash_template.h
index 0865c2b3ab4..ebd70c03371 100644
--- a/src/vppinfra/bihash_template.h
+++ b/src/vppinfra/bihash_template.h
@@ -159,6 +159,17 @@ BVS (clib_bihash)
} BVT (clib_bihash);
+typedef struct
+{
+ BVT (clib_bihash) * h;
+ char *name;
+ u32 nbuckets;
+ uword memory_size;
+ format_function_t *fmt_fn;
+ u8 instantiate_immediately;
+ u8 dont_add_to_all_bihash_list;
+} BVT (clib_bihash_init2_args);
+
extern void **clib_all_bihashes;
#if BIHASH_32_64_SVM
@@ -291,6 +302,8 @@ static inline uword BV (clib_bihash_get_offset) (BVT (clib_bihash) * h,
void BV (clib_bihash_init)
(BVT (clib_bihash) * h, char *name, u32 nbuckets, uword memory_size);
+void BV (clib_bihash_init2) (BVT (clib_bihash_init2_args) * a);
+
#if BIHASH_32_64_SVM
void BV (clib_bihash_master_init_svm)
(BVT (clib_bihash) * h, char *name, u32 nbuckets, u64 memory_size);