X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvppinfra%2Fbihash_template.c;h=2b378427ce8c79e325d64ae700a0fff4e8e153f6;hb=a690fdbfe179e0ea65818c03b52535bf9210efd0;hp=4ef32efbe890cd4fea912494eeb9ce2b8e2cb92f;hpb=67d09e05d0400c62ae3ee654efbbc8cee5806f4f;p=vpp.git diff --git a/src/vppinfra/bihash_template.c b/src/vppinfra/bihash_template.c index 4ef32efbe89..2b378427ce8 100644 --- a/src/vppinfra/bihash_template.c +++ b/src/vppinfra/bihash_template.c @@ -32,7 +32,7 @@ static inline void *BV (alloc_aligned) (BVT (clib_bihash) * h, uword nbytes) return (void *) (uword) (rv + alloc_arena (h)); } -void BV (clib_bihash_instantiate) (BVT (clib_bihash) * h) +static void BV (clib_bihash_instantiate) (BVT (clib_bihash) * h) { uword bucket_size; @@ -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 @@ -159,12 +179,12 @@ void BV (clib_bihash_master_init_svm) sizeof (vec_header_t) + BIHASH_FREELIST_LENGTH * sizeof (u64)); freelist_vh->len = BIHASH_FREELIST_LENGTH; - freelist_vh->dlmalloc_header_offset = 0xDEADBEEF; h->sh->freelists_as_u64 = (u64) BV (clib_bihash_get_offset) (h, freelist_vh->vector_data); h->freelists = (void *) (freelist_vh->vector_data); h->fmt_fn = NULL; + h->instantiated = 1; } void BV (clib_bihash_slave_init_svm) @@ -249,7 +269,7 @@ never_initialized: } } clib_warning ("Couldn't find hash table %llx on clib_all_bihashes...", - (u64) h); + (u64) (uword) h); } static @@ -886,12 +906,12 @@ u8 *BV (format_bihash) (u8 * s, va_list * args) } void BV (clib_bihash_foreach_key_value_pair) - (BVT (clib_bihash) * h, void *callback, void *arg) + (BVT (clib_bihash) * h, + BV (clib_bihash_foreach_key_value_pair_cb) cb, void *arg) { int i, j, k; BVT (clib_bihash_bucket) * b; BVT (clib_bihash_value) * v; - void (*fp) (BVT (clib_bihash_kv) *, void *) = callback; if (PREDICT_FALSE (alloc_arena (h) == 0)) return; @@ -910,7 +930,8 @@ void BV (clib_bihash_foreach_key_value_pair) if (BV (clib_bihash_is_free) (&v->kvp[k])) continue; - (*fp) (&v->kvp[k], arg); + if (BIHASH_WALK_STOP == cb (&v->kvp[k], arg)) + return; /* * In case the callback deletes the last entry in the bucket... */