blob: 98dcf14673f8db97d0978cde5021329a9b6c8d78 [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
2 Copyright (c) 2014 Cisco and/or its affiliates.
3
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15*/
16
Chris Luke16bcf7d2016-09-01 14:31:46 -040017/** @cond DOCUMENTATION_IS_IN_BIHASH_DOC_H */
Dave Barachdd3a57f2016-07-27 16:58:51 -040018
Dave Barachc3799992016-08-15 11:12:27 -040019/*
Ed Warnickecb9cada2015-12-08 15:45:58 -070020 * Note: to instantiate the template multiple times in a single file,
21 * #undef __included_bihash_template_h__...
22 */
23#ifndef __included_bihash_template_h__
24#define __included_bihash_template_h__
25
26#include <vppinfra/heap.h>
27#include <vppinfra/format.h>
28#include <vppinfra/pool.h>
Dave Barach30765e72018-02-23 07:45:36 -050029#include <vppinfra/cache.h>
Damjan Marion2a03efe2018-07-20 21:48:59 +020030#include <vppinfra/lock.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070031
32#ifndef BIHASH_TYPE
33#error BIHASH_TYPE not defined
34#endif
35
Dave Barach9466c452018-08-24 17:21:14 -040036#ifdef BIHASH_32_64_SVM
37#undef HAVE_MEMFD_CREATE
38#include <vppinfra/linux/syscall.h>
39#include <fcntl.h>
40#define F_LINUX_SPECIFIC_BASE 1024
41#define F_ADD_SEALS (F_LINUX_SPECIFIC_BASE + 9)
42#define F_SEAL_SHRINK (2)
43/* Max page size 2**16 due to refcount width */
44#define BIHASH_FREELIST_LENGTH 17
45#endif
46
Ed Warnickecb9cada2015-12-08 15:45:58 -070047#define _bv(a,b) a##b
48#define __bv(a,b) _bv(a,b)
49#define BV(a) __bv(a,BIHASH_TYPE)
50
51#define _bvt(a,b) a##b##_t
52#define __bvt(a,b) _bvt(a,b)
53#define BVT(a) __bvt(a,BIHASH_TYPE)
54
Dave Barach9466c452018-08-24 17:21:14 -040055#if _LP64 == 0
56#define OVERFLOW_ASSERT(x) ASSERT(((x) & 0xFFFFFFFF00000000ULL) == 0)
57#define u64_to_pointer(x) (void *)(u32)((x))
58#define pointer_to_u64(x) (u64)(u32)((x))
59#else
60#define OVERFLOW_ASSERT(x)
61#define u64_to_pointer(x) (void *)((x))
62#define pointer_to_u64(x) (u64)((x))
63#endif
64
Dave Barachc3799992016-08-15 11:12:27 -040065typedef struct BV (clib_bihash_value)
66{
67 union
68 {
69 BVT (clib_bihash_kv) kvp[BIHASH_KVP_PER_PAGE];
Dave Barach9466c452018-08-24 17:21:14 -040070 u64 next_free_as_u64;
Ed Warnickecb9cada2015-12-08 15:45:58 -070071 };
Dave Barachc3799992016-08-15 11:12:27 -040072} BVT (clib_bihash_value);
Ed Warnickecb9cada2015-12-08 15:45:58 -070073
Dave Barach508498f2018-07-19 12:11:16 -040074#define BIHASH_BUCKET_OFFSET_BITS 36
Dave Barach908a5ea2017-07-14 12:42:21 -040075
Dave Barachc3799992016-08-15 11:12:27 -040076typedef struct
77{
78 union
79 {
80 struct
81 {
Dave Barach508498f2018-07-19 12:11:16 -040082 u64 offset:BIHASH_BUCKET_OFFSET_BITS;
83 u64 lock:1;
Damjan Marion882fcfe2018-07-17 23:01:49 +020084 u64 linear_search:1;
85 u64 log2_pages:8;
Dave Barach9466c452018-08-24 17:21:14 -040086 u64 refcnt:16;
Ed Warnickecb9cada2015-12-08 15:45:58 -070087 };
88 u64 as_u64;
89 };
Dave Barach908a5ea2017-07-14 12:42:21 -040090} BVT (clib_bihash_bucket);
Ed Warnickecb9cada2015-12-08 15:45:58 -070091
Damjan Marion882fcfe2018-07-17 23:01:49 +020092STATIC_ASSERT_SIZEOF (BVT (clib_bihash_bucket), sizeof (u64));
Damjan Marion882fcfe2018-07-17 23:01:49 +020093
Dave Barach9466c452018-08-24 17:21:14 -040094/* *INDENT-OFF* */
95typedef CLIB_PACKED (struct {
96 /*
97 * Backing store allocation. Since bihash manages its own
Andrew Yourtchenkoa7132542018-09-19 15:50:55 +020098 * freelists, we simple dole out memory starting from alloc_arena[alloc_arena_next].
Dave Barach9466c452018-08-24 17:21:14 -040099 */
Andrew Yourtchenkoa7132542018-09-19 15:50:55 +0200100 u64 alloc_arena_next; /* Next offset from alloc_arena to allocate, definitely NOT a constant */
Dave Barach9466c452018-08-24 17:21:14 -0400101 u64 alloc_arena_size; /* Size of the arena */
Dave Barach9466c452018-08-24 17:21:14 -0400102 /* Two SVM pointers stored as 8-byte integers */
103 u64 alloc_lock_as_u64;
104 u64 buckets_as_u64;
105 /* freelist list-head arrays/vectors */
106 u64 freelists_as_u64;
107 u32 nbuckets; /* Number of buckets */
108 /* Set when header valid */
109 volatile u32 ready;
Dave Barachffb14b92018-09-11 17:20:23 -0400110 u64 pad[2];
Dave Barach9466c452018-08-24 17:21:14 -0400111}) BVT (clib_bihash_shared_header);
112/* *INDENT-ON* */
113
114STATIC_ASSERT_SIZEOF (BVT (clib_bihash_shared_header), 8 * sizeof (u64));
115
Dave Barachc3799992016-08-15 11:12:27 -0400116typedef struct
117{
Dave Barach908a5ea2017-07-14 12:42:21 -0400118 BVT (clib_bihash_bucket) * buckets;
Dave Barach508498f2018-07-19 12:11:16 -0400119 volatile u32 *alloc_lock;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700120
Dave Barachc3799992016-08-15 11:12:27 -0400121 BVT (clib_bihash_value) ** working_copies;
Dave Barachba7ddfe2017-05-17 20:20:50 -0400122 int *working_copy_lengths;
Dave Barach908a5ea2017-07-14 12:42:21 -0400123 BVT (clib_bihash_bucket) saved_bucket;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700124
125 u32 nbuckets;
126 u32 log2_nbuckets;
Dave Barachc3799992016-08-15 11:12:27 -0400127 u8 *name;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700128
Dave Barach9466c452018-08-24 17:21:14 -0400129 u64 *freelists;
Dave Barach97f5af02018-02-22 09:48:45 -0500130
Dave Barach9466c452018-08-24 17:21:14 -0400131#if BIHASH_32_64_SVM
132 BVT (clib_bihash_shared_header) * sh;
133 int memfd;
134#else
135 BVT (clib_bihash_shared_header) sh;
136#endif
Ed Warnickecb9cada2015-12-08 15:45:58 -0700137
Dave Barachffb14b92018-09-11 17:20:23 -0400138 u64 alloc_arena; /* Base of the allocation arena */
139
Vijayabhaskar Katamreddyfb8e61c2017-12-14 13:20:50 -0800140 /**
141 * A custom format function to print the Key and Value of bihash_key instead of default hexdump
142 */
143 format_function_t *fmt_fn;
144
Dave Barachc3799992016-08-15 11:12:27 -0400145} BVT (clib_bihash);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700146
Dave Barach9466c452018-08-24 17:21:14 -0400147#if BIHASH_32_64_SVM
148#undef alloc_arena_next
149#undef alloc_arena_size
150#undef alloc_arena
151#undef CLIB_BIHASH_READY_MAGIC
152#define alloc_arena_next(h) (((h)->sh)->alloc_arena_next)
153#define alloc_arena_size(h) (((h)->sh)->alloc_arena_size)
Dave Barachffb14b92018-09-11 17:20:23 -0400154#define alloc_arena(h) ((h)->alloc_arena)
Dave Barach9466c452018-08-24 17:21:14 -0400155#define CLIB_BIHASH_READY_MAGIC 0xFEEDFACE
156#else
157#undef alloc_arena_next
158#undef alloc_arena_size
159#undef alloc_arena
160#undef CLIB_BIHASH_READY_MAGIC
161#define alloc_arena_next(h) ((h)->sh.alloc_arena_next)
162#define alloc_arena_size(h) ((h)->sh.alloc_arena_size)
Dave Barachffb14b92018-09-11 17:20:23 -0400163#define alloc_arena(h) ((h)->alloc_arena)
Dave Barach9466c452018-08-24 17:21:14 -0400164#define CLIB_BIHASH_READY_MAGIC 0
165#endif
166
Dave Barach508498f2018-07-19 12:11:16 -0400167static inline void BV (clib_bihash_alloc_lock) (BVT (clib_bihash) * h)
Dave Barach908a5ea2017-07-14 12:42:21 -0400168{
Dave Barach508498f2018-07-19 12:11:16 -0400169 while (__atomic_test_and_set (h->alloc_lock, __ATOMIC_ACQUIRE))
Damjan Marion2a03efe2018-07-20 21:48:59 +0200170 CLIB_PAUSE ();
Dave Barach908a5ea2017-07-14 12:42:21 -0400171}
172
Dave Barach508498f2018-07-19 12:11:16 -0400173static inline void BV (clib_bihash_alloc_unlock) (BVT (clib_bihash) * h)
Dave Barach908a5ea2017-07-14 12:42:21 -0400174{
Dave Barach508498f2018-07-19 12:11:16 -0400175 __atomic_clear (h->alloc_lock, __ATOMIC_RELEASE);
Dave Barach908a5ea2017-07-14 12:42:21 -0400176}
177
Dave Barach508498f2018-07-19 12:11:16 -0400178static inline void BV (clib_bihash_lock_bucket) (BVT (clib_bihash_bucket) * b)
Dave Barach908a5ea2017-07-14 12:42:21 -0400179{
Dave Barach508498f2018-07-19 12:11:16 -0400180 BVT (clib_bihash_bucket) unlocked_bucket, locked_bucket;
Dave Barach908a5ea2017-07-14 12:42:21 -0400181
Dave Barach508498f2018-07-19 12:11:16 -0400182 do
183 {
184 locked_bucket.as_u64 = unlocked_bucket.as_u64 = b->as_u64;
185 unlocked_bucket.lock = 0;
186 locked_bucket.lock = 1;
Damjan Marion2a03efe2018-07-20 21:48:59 +0200187 CLIB_PAUSE ();
Dave Barach508498f2018-07-19 12:11:16 -0400188 }
189 while (__atomic_compare_exchange_n (&b->as_u64, &unlocked_bucket.as_u64,
190 locked_bucket.as_u64, 1 /* weak */ ,
191 __ATOMIC_ACQUIRE,
192 __ATOMIC_ACQUIRE) == 0);
Dave Barach858c06f2017-07-21 10:44:27 -0400193}
194
195static inline void BV (clib_bihash_unlock_bucket)
196 (BVT (clib_bihash_bucket) * b)
197{
Dave Barach508498f2018-07-19 12:11:16 -0400198 CLIB_MEMORY_BARRIER ();
199 b->lock = 0;
Dave Barach908a5ea2017-07-14 12:42:21 -0400200}
201
202static inline void *BV (clib_bihash_get_value) (BVT (clib_bihash) * h,
Dave Barachc3799992016-08-15 11:12:27 -0400203 uword offset)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700204{
Dave Barach9466c452018-08-24 17:21:14 -0400205 u8 *hp = (u8 *) (uword) alloc_arena (h);
Dave Barachc3799992016-08-15 11:12:27 -0400206 u8 *vp = hp + offset;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700207
208 return (void *) vp;
209}
210
Damjan Marion882fcfe2018-07-17 23:01:49 +0200211static inline int BV (clib_bihash_bucket_is_empty)
212 (BVT (clib_bihash_bucket) * b)
213{
Dave Barach508498f2018-07-19 12:11:16 -0400214 /* Note: applied to locked buckets, test offset */
215 return b->offset == 0;
Damjan Marion882fcfe2018-07-17 23:01:49 +0200216}
217
Dave Barach908a5ea2017-07-14 12:42:21 -0400218static inline uword BV (clib_bihash_get_offset) (BVT (clib_bihash) * h,
Dave Barachc3799992016-08-15 11:12:27 -0400219 void *v)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700220{
Dave Barachc3799992016-08-15 11:12:27 -0400221 u8 *hp, *vp;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700222
Dave Barach9466c452018-08-24 17:21:14 -0400223 hp = (u8 *) (uword) alloc_arena (h);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700224 vp = (u8 *) v;
225
Ed Warnickecb9cada2015-12-08 15:45:58 -0700226 return vp - hp;
227}
228
Dave Barachc3799992016-08-15 11:12:27 -0400229void BV (clib_bihash_init)
230 (BVT (clib_bihash) * h, char *name, u32 nbuckets, uword memory_size);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700231
Dave Barach9466c452018-08-24 17:21:14 -0400232#if BIHASH_32_64_SVM
233void BV (clib_bihash_master_init_svm)
Dave Barachffb14b92018-09-11 17:20:23 -0400234 (BVT (clib_bihash) * h, char *name, u32 nbuckets, u64 memory_size);
Dave Barach9466c452018-08-24 17:21:14 -0400235void BV (clib_bihash_slave_init_svm)
236 (BVT (clib_bihash) * h, char *name, int fd);
237#endif
238
Vijayabhaskar Katamreddyfb8e61c2017-12-14 13:20:50 -0800239void BV (clib_bihash_set_kvp_format_fn) (BVT (clib_bihash) * h,
240 format_function_t * fmt_fn);
241
Dave Barachc3799992016-08-15 11:12:27 -0400242void BV (clib_bihash_free) (BVT (clib_bihash) * h);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700243
Dave Barachc3799992016-08-15 11:12:27 -0400244int BV (clib_bihash_add_del) (BVT (clib_bihash) * h,
245 BVT (clib_bihash_kv) * add_v, int is_add);
Matus Fabian828d27e2018-08-21 03:15:50 -0700246int BV (clib_bihash_add_or_overwrite_stale) (BVT (clib_bihash) * h,
247 BVT (clib_bihash_kv) * add_v,
248 int (*is_stale_cb) (BVT
249 (clib_bihash_kv)
250 *, void *),
251 void *arg);
Dave Barach908a5ea2017-07-14 12:42:21 -0400252int BV (clib_bihash_search) (BVT (clib_bihash) * h,
Dave Barachc3799992016-08-15 11:12:27 -0400253 BVT (clib_bihash_kv) * search_v,
254 BVT (clib_bihash_kv) * return_v);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700255
Dave Barachc3799992016-08-15 11:12:27 -0400256void BV (clib_bihash_foreach_key_value_pair) (BVT (clib_bihash) * h,
257 void *callback, void *arg);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700258
Dave Barachc3799992016-08-15 11:12:27 -0400259format_function_t BV (format_bihash);
260format_function_t BV (format_bihash_kvp);
Dave Barach908a5ea2017-07-14 12:42:21 -0400261format_function_t BV (format_bihash_lru);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700262
Dave Barach30765e72018-02-23 07:45:36 -0500263static inline int BV (clib_bihash_search_inline_with_hash)
264 (BVT (clib_bihash) * h, u64 hash, BVT (clib_bihash_kv) * key_result)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700265{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700266 u32 bucket_index;
Dave Barachc3799992016-08-15 11:12:27 -0400267 BVT (clib_bihash_value) * v;
Dave Barach908a5ea2017-07-14 12:42:21 -0400268 BVT (clib_bihash_bucket) * b;
Dave Barach5e6b9582016-12-12 15:37:29 -0500269 int i, limit;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700270
Dave Barachc3799992016-08-15 11:12:27 -0400271 bucket_index = hash & (h->nbuckets - 1);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700272 b = &h->buckets[bucket_index];
273
Damjan Marion882fcfe2018-07-17 23:01:49 +0200274 if (PREDICT_FALSE (BV (clib_bihash_bucket_is_empty) (b)))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700275 return -1;
276
Dave Barach508498f2018-07-19 12:11:16 -0400277 if (PREDICT_FALSE (b->lock))
Dave Barach908a5ea2017-07-14 12:42:21 -0400278 {
Dave Barach508498f2018-07-19 12:11:16 -0400279 volatile BVT (clib_bihash_bucket) * bv = b;
280 while (bv->lock)
Damjan Marion2a03efe2018-07-20 21:48:59 +0200281 CLIB_PAUSE ();
Dave Barach908a5ea2017-07-14 12:42:21 -0400282 }
283
Ed Warnickecb9cada2015-12-08 15:45:58 -0700284 hash >>= h->log2_nbuckets;
285
Dave Barachc3799992016-08-15 11:12:27 -0400286 v = BV (clib_bihash_get_value) (h, b->offset);
Dave Barachc3799992016-08-15 11:12:27 -0400287
Dave Barach5e6b9582016-12-12 15:37:29 -0500288 /* If the bucket has unresolvable collisions, use linear search */
289 limit = BIHASH_KVP_PER_PAGE;
290 v += (b->linear_search == 0) ? hash & ((1 << b->log2_pages) - 1) : 0;
291 if (PREDICT_FALSE (b->linear_search))
292 limit <<= b->log2_pages;
293
294 for (i = 0; i < limit; i++)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700295 {
Dave Barach908a5ea2017-07-14 12:42:21 -0400296 if (BV (clib_bihash_key_compare) (v->kvp[i].key, key_result->key))
Dave Barachc3799992016-08-15 11:12:27 -0400297 {
Dave Barach908a5ea2017-07-14 12:42:21 -0400298 *key_result = v->kvp[i];
Dave Barachc3799992016-08-15 11:12:27 -0400299 return 0;
300 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700301 }
302 return -1;
303}
304
Dave Barach30765e72018-02-23 07:45:36 -0500305static inline int BV (clib_bihash_search_inline)
306 (BVT (clib_bihash) * h, BVT (clib_bihash_kv) * key_result)
307{
308 u64 hash;
309
310 hash = BV (clib_bihash_hash) (key_result);
311
312 return BV (clib_bihash_search_inline_with_hash) (h, hash, key_result);
313}
314
315static inline void BV (clib_bihash_prefetch_bucket)
316 (BVT (clib_bihash) * h, u64 hash)
317{
318 u32 bucket_index;
319 BVT (clib_bihash_bucket) * b;
320
321 bucket_index = hash & (h->nbuckets - 1);
322 b = &h->buckets[bucket_index];
323
324 CLIB_PREFETCH (b, CLIB_CACHE_LINE_BYTES, READ);
325}
326
327static inline void BV (clib_bihash_prefetch_data)
328 (BVT (clib_bihash) * h, u64 hash)
329{
330 u32 bucket_index;
331 BVT (clib_bihash_value) * v;
332 BVT (clib_bihash_bucket) * b;
333
334 bucket_index = hash & (h->nbuckets - 1);
335 b = &h->buckets[bucket_index];
336
Damjan Marion882fcfe2018-07-17 23:01:49 +0200337 if (PREDICT_FALSE (BV (clib_bihash_bucket_is_empty) (b)))
Dave Barach30765e72018-02-23 07:45:36 -0500338 return;
339
340 hash >>= h->log2_nbuckets;
341 v = BV (clib_bihash_get_value) (h, b->offset);
342
343 v += (b->linear_search == 0) ? hash & ((1 << b->log2_pages) - 1) : 0;
344
345 CLIB_PREFETCH (v, CLIB_CACHE_LINE_BYTES, READ);
346}
347
Andrew Yourtchenkoabcddcb2018-05-27 20:56:26 +0200348static inline int BV (clib_bihash_search_inline_2_with_hash)
Dave Barach908a5ea2017-07-14 12:42:21 -0400349 (BVT (clib_bihash) * h,
Andrew Yourtchenkoabcddcb2018-05-27 20:56:26 +0200350 u64 hash, BVT (clib_bihash_kv) * search_key, BVT (clib_bihash_kv) * valuep)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700351{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700352 u32 bucket_index;
Dave Barachc3799992016-08-15 11:12:27 -0400353 BVT (clib_bihash_value) * v;
Dave Barach908a5ea2017-07-14 12:42:21 -0400354 BVT (clib_bihash_bucket) * b;
Dave Barach5e6b9582016-12-12 15:37:29 -0500355 int i, limit;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700356
Dave Barachc3799992016-08-15 11:12:27 -0400357 ASSERT (valuep);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700358
Dave Barachc3799992016-08-15 11:12:27 -0400359 bucket_index = hash & (h->nbuckets - 1);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700360 b = &h->buckets[bucket_index];
361
Damjan Marion882fcfe2018-07-17 23:01:49 +0200362 if (PREDICT_FALSE (BV (clib_bihash_bucket_is_empty) (b)))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700363 return -1;
364
Dave Barach508498f2018-07-19 12:11:16 -0400365 if (PREDICT_FALSE (b->lock))
Dave Barach908a5ea2017-07-14 12:42:21 -0400366 {
Dave Barach508498f2018-07-19 12:11:16 -0400367 volatile BVT (clib_bihash_bucket) * bv = b;
368 while (bv->lock)
Damjan Marion2a03efe2018-07-20 21:48:59 +0200369 CLIB_PAUSE ();
Dave Barach908a5ea2017-07-14 12:42:21 -0400370 }
371
Ed Warnickecb9cada2015-12-08 15:45:58 -0700372 hash >>= h->log2_nbuckets;
Dave Barachc3799992016-08-15 11:12:27 -0400373 v = BV (clib_bihash_get_value) (h, b->offset);
Dave Barachc3799992016-08-15 11:12:27 -0400374
Dave Barach5e6b9582016-12-12 15:37:29 -0500375 /* If the bucket has unresolvable collisions, use linear search */
376 limit = BIHASH_KVP_PER_PAGE;
377 v += (b->linear_search == 0) ? hash & ((1 << b->log2_pages) - 1) : 0;
378 if (PREDICT_FALSE (b->linear_search))
379 limit <<= b->log2_pages;
380
381 for (i = 0; i < limit; i++)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700382 {
Dave Barachc3799992016-08-15 11:12:27 -0400383 if (BV (clib_bihash_key_compare) (v->kvp[i].key, search_key->key))
384 {
385 *valuep = v->kvp[i];
386 return 0;
387 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700388 }
389 return -1;
390}
391
Andrew Yourtchenkoabcddcb2018-05-27 20:56:26 +0200392static inline int BV (clib_bihash_search_inline_2)
393 (BVT (clib_bihash) * h,
394 BVT (clib_bihash_kv) * search_key, BVT (clib_bihash_kv) * valuep)
395{
396 u64 hash;
397
398 hash = BV (clib_bihash_hash) (search_key);
399
400 return BV (clib_bihash_search_inline_2_with_hash) (h, hash, search_key,
401 valuep);
402}
403
404
Ed Warnickecb9cada2015-12-08 15:45:58 -0700405#endif /* __included_bihash_template_h__ */
Dave Barachdd3a57f2016-07-27 16:58:51 -0400406
Chris Luke16bcf7d2016-09-01 14:31:46 -0400407/** @endcond */
Dave Barachc3799992016-08-15 11:12:27 -0400408
409/*
410 * fd.io coding-style-patch-verification: ON
411 *
412 * Local Variables:
413 * eval: (c-set-style "gnu")
414 * End:
415 */