vppinfra: add clib_bihash_get_bucket 17/26217/2
authorDamjan Marion <damarion@cisco.com>
Fri, 27 Mar 2020 15:57:28 +0000 (16:57 +0100)
committerDave Barach <openvpp@barachs.net>
Fri, 27 Mar 2020 17:03:30 +0000 (17:03 +0000)
Type: improvement
Change-Id: I073bb7bea2a55eabbb6c253b003966f0a821e4a3
Signed-off-by: Damjan Marion <damarion@cisco.com>
src/vppinfra/bihash_template.c
src/vppinfra/bihash_template.h

index 2b37842..471251d 100644 (file)
@@ -472,7 +472,6 @@ static inline int BV (clib_bihash_add_del_inline)
   (BVT (clib_bihash) * h, BVT (clib_bihash_kv) * add_v, int is_add,
    int (*is_stale_cb) (BVT (clib_bihash_kv) *, void *), void *arg)
 {
-  u32 bucket_index;
   BVT (clib_bihash_bucket) * b, tmp_b;
   BVT (clib_bihash_value) * v, *new_v, *save_new_v, *working_copy;
   int i, limit;
@@ -499,8 +498,7 @@ static inline int BV (clib_bihash_add_del_inline)
 
   hash = BV (clib_bihash_hash) (add_v);
 
-  bucket_index = hash & (h->nbuckets - 1);
-  b = &h->buckets[bucket_index];
+  b = BV (clib_bihash_get_bucket) (h, hash);
 
   hash >>= h->log2_nbuckets;
 
@@ -758,7 +756,6 @@ int BV (clib_bihash_search)
    BVT (clib_bihash_kv) * search_key, BVT (clib_bihash_kv) * valuep)
 {
   u64 hash;
-  u32 bucket_index;
   BVT (clib_bihash_value) * v;
   BVT (clib_bihash_bucket) * b;
   int i, limit;
@@ -770,8 +767,7 @@ int BV (clib_bihash_search)
 
   hash = BV (clib_bihash_hash) (search_key);
 
-  bucket_index = hash & (h->nbuckets - 1);
-  b = &h->buckets[bucket_index];
+  b = BV (clib_bihash_get_bucket) (h, hash);
 
   if (BV (clib_bihash_bucket_is_empty) (b))
     return -1;
index f11e6d5..6abe7a3 100644 (file)
@@ -400,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;
@@ -433,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;
@@ -450,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;