From 30765e77ac98913abefbdb9e8325a2b3f1e11082 Mon Sep 17 00:00:00 2001 From: Dave Barach Date: Fri, 23 Feb 2018 07:45:36 -0500 Subject: Add prefetch inlines, update bi-hash doc tags Change-Id: I2e9d01ccba5288e89b886464436097d3cb7d2d18 Signed-off-by: Dave Barach --- src/vppinfra/bihash_template.h | 53 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 47 insertions(+), 6 deletions(-) (limited to 'src/vppinfra/bihash_template.h') diff --git a/src/vppinfra/bihash_template.h b/src/vppinfra/bihash_template.h index 81d9ffad41e..2101d44defe 100644 --- a/src/vppinfra/bihash_template.h +++ b/src/vppinfra/bihash_template.h @@ -26,6 +26,7 @@ #include #include #include +#include #ifndef BIHASH_TYPE #error BIHASH_TYPE not defined @@ -91,7 +92,7 @@ typedef struct BVT (clib_bihash_value) ** freelists; /* - * Backing store allocation. Since bihash mananges its own + * Backing store allocation. Since bihash manages its own * freelists, we simple dole out memory at alloc_arena_next. */ uword alloc_arena; @@ -269,10 +270,9 @@ format_function_t BV (format_bihash); format_function_t BV (format_bihash_kvp); format_function_t BV (format_bihash_lru); -static inline int BV (clib_bihash_search_inline) - (BVT (clib_bihash) * h, BVT (clib_bihash_kv) * key_result) +static inline int BV (clib_bihash_search_inline_with_hash) + (BVT (clib_bihash) * h, u64 hash, BVT (clib_bihash_kv) * key_result) { - u64 hash; u32 bucket_index; BVT (clib_bihash_value) * v; BVT (clib_bihash_bucket) * b; @@ -281,8 +281,6 @@ static inline int BV (clib_bihash_search_inline) #endif int i, limit; - hash = BV (clib_bihash_hash) (key_result); - bucket_index = hash & (h->nbuckets - 1); b = &h->buckets[bucket_index]; @@ -343,6 +341,49 @@ static inline int BV (clib_bihash_search_inline) return -1; } +static inline int BV (clib_bihash_search_inline) + (BVT (clib_bihash) * h, BVT (clib_bihash_kv) * key_result) +{ + u64 hash; + + hash = BV (clib_bihash_hash) (key_result); + + return BV (clib_bihash_search_inline_with_hash) (h, hash, key_result); +} + +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); +} + +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; + + bucket_index = hash & (h->nbuckets - 1); + b = &h->buckets[bucket_index]; + + if (PREDICT_FALSE (b->offset == 0)) + return; + + hash >>= h->log2_nbuckets; + v = BV (clib_bihash_get_value) (h, b->offset); + + v += (b->linear_search == 0) ? hash & ((1 << b->log2_pages) - 1) : 0; + + CLIB_PREFETCH (v, CLIB_CACHE_LINE_BYTES, READ); +} + static inline int BV (clib_bihash_search_inline_2) (BVT (clib_bihash) * h, BVT (clib_bihash_kv) * search_key, BVT (clib_bihash_kv) * valuep) -- cgit 1.2.3-korg