X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=src%2Fvppinfra%2Fbihash_template.h;h=6abe7a36b27fe19b5add329eadf6768b9195fc2c;hb=7654a718669f0dc950344c049186b9452bf48ca9;hp=0865c2b3ab43825d4b512510e9e83529091cee14;hpb=67d09e05d0400c62ae3ee654efbbc8cee5806f4f;p=vpp.git diff --git a/src/vppinfra/bihash_template.h b/src/vppinfra/bihash_template.h index 0865c2b3ab4..6abe7a36b27 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); @@ -315,8 +328,16 @@ int BV (clib_bihash_search) (BVT (clib_bihash) * h, BVT (clib_bihash_kv) * search_v, BVT (clib_bihash_kv) * return_v); +#define BIHASH_WALK_STOP 0 +#define BIHASH_WALK_CONTINUE 1 + +typedef + int (*BV (clib_bihash_foreach_key_value_pair_cb)) (BVT (clib_bihash_kv) *, + void *); void BV (clib_bihash_foreach_key_value_pair) (BVT (clib_bihash) * h, - void *callback, void *arg); + BV + (clib_bihash_foreach_key_value_pair_cb) + cb, void *arg); void *clib_all_bihash_set_heap (void); void clib_bihash_copied (void *dst, void *src); @@ -379,30 +400,29 @@ static inline int BV (clib_bihash_search_inline) return BV (clib_bihash_search_inline_with_hash) (h, hash, key_result); } +static inline +BVT (clib_bihash_bucket) * +BV (clib_bihash_get_bucket) (BVT (clib_bihash) * h, u64 hash) +{ + return h->buckets + (hash & (h->nbuckets - 1)); +} + static inline void BV (clib_bihash_prefetch_bucket) (BVT (clib_bihash) * h, u64 hash) { - u32 bucket_index; - BVT (clib_bihash_bucket) * b; - - bucket_index = hash & (h->nbuckets - 1); - b = &h->buckets[bucket_index]; - - CLIB_PREFETCH (b, CLIB_CACHE_LINE_BYTES, READ); + clib_prefetch_load (BV (clib_bihash_get_bucket) (h, hash)); } static inline void BV (clib_bihash_prefetch_data) (BVT (clib_bihash) * h, u64 hash) { - u32 bucket_index; BVT (clib_bihash_value) * v; BVT (clib_bihash_bucket) * b; if (PREDICT_FALSE (alloc_arena (h) == 0)) return; - bucket_index = hash & (h->nbuckets - 1); - b = &h->buckets[bucket_index]; + b = BV (clib_bihash_get_bucket) (h, hash); if (PREDICT_FALSE (BV (clib_bihash_bucket_is_empty) (b))) return; @@ -412,14 +432,13 @@ static inline void BV (clib_bihash_prefetch_data) v += (b->linear_search == 0) ? hash & ((1 << b->log2_pages) - 1) : 0; - CLIB_PREFETCH (v, CLIB_CACHE_LINE_BYTES, READ); + clib_prefetch_load (v); } static inline int BV (clib_bihash_search_inline_2_with_hash) (BVT (clib_bihash) * h, u64 hash, BVT (clib_bihash_kv) * search_key, BVT (clib_bihash_kv) * valuep) { - u32 bucket_index; BVT (clib_bihash_value) * v; BVT (clib_bihash_bucket) * b; int i, limit; @@ -429,8 +448,7 @@ static inline int BV (clib_bihash_search_inline_2_with_hash) if (PREDICT_FALSE (alloc_arena (h) == 0)) return -1; - bucket_index = hash & (h->nbuckets - 1); - b = &h->buckets[bucket_index]; + b = BV (clib_bihash_get_bucket) (h, hash); if (PREDICT_FALSE (BV (clib_bihash_bucket_is_empty) (b))) return -1;