blob: c1a446919667df4a1a8b75d455f57f0e54036c9a [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
2 * Copyright (c) 2015 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15#include <vppinfra/time.h>
16#include <vppinfra/cache.h>
17#include <vppinfra/error.h>
Dave Barache7d212f2018-02-07 13:14:06 -050018#include <sys/resource.h>
19#include <stdio.h>
Dave Barach508498f2018-07-19 12:11:16 -040020#include <pthread.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070021
22#include <vppinfra/bihash_8_8.h>
23#include <vppinfra/bihash_template.h>
24
25#include <vppinfra/bihash_template.c>
26
Dave Barachc3799992016-08-15 11:12:27 -040027typedef struct
28{
Dave Barach508498f2018-07-19 12:11:16 -040029 volatile u32 thread_barrier;
30 volatile u32 threads_running;
31 volatile u64 sequence_number;
Filip Tehlar397fd7d2016-10-26 14:31:24 +020032 u64 seed;
Ed Warnickecb9cada2015-12-08 15:45:58 -070033 u32 nbuckets;
34 u32 nitems;
Dave Barache7d212f2018-02-07 13:14:06 -050035 u32 ncycles;
36 u32 report_every_n;
Ed Warnickecb9cada2015-12-08 15:45:58 -070037 u32 search_iter;
Matus Fabian828d27e2018-08-21 03:15:50 -070038 u32 noverwritten;
Ed Warnickecb9cada2015-12-08 15:45:58 -070039 int careful_delete_tests;
40 int verbose;
41 int non_random_keys;
Dave Barach508498f2018-07-19 12:11:16 -040042 u32 nthreads;
Dave Barachc3799992016-08-15 11:12:27 -040043 uword *key_hash;
44 u64 *keys;
Dave Barach97f5af02018-02-22 09:48:45 -050045 uword hash_memory_size;
Dave Barachc3799992016-08-15 11:12:27 -040046 BVT (clib_bihash) hash;
Ed Warnickecb9cada2015-12-08 15:45:58 -070047 clib_time_t clib_time;
Dave Barach508498f2018-07-19 12:11:16 -040048 void *global_heap;
Ed Warnickecb9cada2015-12-08 15:45:58 -070049
Dave Barachc3799992016-08-15 11:12:27 -040050 unformat_input_t *input;
51
Ed Warnickecb9cada2015-12-08 15:45:58 -070052} test_main_t;
53
54test_main_t test_main;
55
Dave Barachc3799992016-08-15 11:12:27 -040056uword
57vl (void *v)
Ed Warnickecb9cada2015-12-08 15:45:58 -070058{
Dave Barachc3799992016-08-15 11:12:27 -040059 return vec_len (v);
Ed Warnickecb9cada2015-12-08 15:45:58 -070060}
61
Dave Barachc3799992016-08-15 11:12:27 -040062static clib_error_t *
Dave Barachba7ddfe2017-05-17 20:20:50 -040063test_bihash_vec64 (test_main_t * tm)
64{
65 u32 user_buckets = 1228800;
66 u32 user_memory_size = 209715200;
67 BVT (clib_bihash_kv) kv;
68 int i, j;
69 f64 before;
70 f64 *cum_times = 0;
71 BVT (clib_bihash) * h;
72
73 h = &tm->hash;
74
Dave Barach9466c452018-08-24 17:21:14 -040075#if BIHASH_32_64_SVM
76 BV (clib_bihash_master_init_svm) (h, "test", user_buckets,
77 0x30000000 /* base_addr */ ,
78 user_memory_size);
79#else
Dave Barachba7ddfe2017-05-17 20:20:50 -040080 BV (clib_bihash_init) (h, "test", user_buckets, user_memory_size);
Dave Barach9466c452018-08-24 17:21:14 -040081#endif
Dave Barachba7ddfe2017-05-17 20:20:50 -040082
83 before = clib_time_now (&tm->clib_time);
84
85 for (j = 0; j < 10; j++)
86 {
87 for (i = 1; i <= j * 1000 + 1; i++)
88 {
89 kv.key = i;
90 kv.value = 1;
91
92 BV (clib_bihash_add_del) (h, &kv, 1 /* is_add */ );
93 }
94
95 vec_add1 (cum_times, clib_time_now (&tm->clib_time) - before);
96 }
97
98 for (j = 0; j < vec_len (cum_times); j++)
99 fformat (stdout, "Cum time for %d: %.4f (us)\n", (j + 1) * 1000,
100 cum_times[j] * 1e6);
101
102 return 0;
103}
104
Matus Fabian828d27e2018-08-21 03:15:50 -0700105static int
106stale_cb (BVT (clib_bihash_kv) * kv, void *ctx)
107{
108 test_main_t *tm = ctx;
109
110 tm->noverwritten++;
111
112 return 1;
113}
114
115static clib_error_t *
116test_bihash_stale_overwrite (test_main_t * tm)
117{
118 BVT (clib_bihash) * h;
119 BVT (clib_bihash_kv) kv;
120 int i;
121 tm->noverwritten = 0;
122
123 h = &tm->hash;
124
Dave Barach9466c452018-08-24 17:21:14 -0400125#if BIHASH_32_64_SVM
126 BV (clib_bihash_master_init_svm) (h, "test", tm->nbuckets,
127 0x30000000 /* base_addr */ ,
128 tm->hash_memory_size);
129#else
Matus Fabian828d27e2018-08-21 03:15:50 -0700130 BV (clib_bihash_init) (h, "test", tm->nbuckets, tm->hash_memory_size);
Dave Barach9466c452018-08-24 17:21:14 -0400131#endif
Matus Fabian828d27e2018-08-21 03:15:50 -0700132
133 fformat (stdout, "Add %d items to %d buckets\n", tm->nitems, tm->nbuckets);
134
135 for (i = 0; i < tm->nitems; i++)
136 {
137 kv.key = i;
138 kv.value = 1;
139
140 BV (clib_bihash_add_or_overwrite_stale) (h, &kv, stale_cb, tm);
141 }
142
143 fformat (stdout, "%d items overwritten\n", tm->noverwritten);
144 fformat (stdout, "%U", BV (format_bihash), h, 0);
145
146 return 0;
147}
148
Dave Barach508498f2018-07-19 12:11:16 -0400149void *
150test_bihash_thread_fn (void *arg)
151{
152 BVT (clib_bihash) * h;
153 BVT (clib_bihash_kv) kv;
154 test_main_t *tm = &test_main;
155
156 int i, j;
157
158 u32 my_thread_index = (u32) (u64) arg;
159 __os_thread_index = my_thread_index;
160 clib_mem_set_per_cpu_heap (tm->global_heap);
161
162 while (tm->thread_barrier)
163 ;
164
165 h = &tm->hash;
166
167 for (i = 0; i < tm->ncycles; i++)
168 {
169 for (j = 0; j < tm->nitems; j++)
170 {
171 kv.key = ((u64) my_thread_index << 32) | (u64) j;
172 kv.value = ((u64) my_thread_index << 32) | (u64) j;
173 (void) __atomic_add_fetch (&tm->sequence_number, 1,
174 __ATOMIC_ACQUIRE);
175 BV (clib_bihash_add_del) (h, &kv, 1 /* is_add */ );
176 }
177 for (j = 0; j < tm->nitems; j++)
178 {
179 kv.key = ((u64) my_thread_index << 32) | (u64) j;
180 kv.value = ((u64) my_thread_index << 32) | (u64) j;
181 (void) __atomic_add_fetch (&tm->sequence_number, 1,
182 __ATOMIC_ACQUIRE);
183 BV (clib_bihash_add_del) (h, &kv, 0 /* is_add */ );
184 }
185 }
186
187 (void) __atomic_sub_fetch (&tm->threads_running, 1, __ATOMIC_ACQUIRE);
188 while (1)
189 {
190 struct timespec ts, tsrem;
191 ts.tv_sec = 1;
192 ts.tv_nsec = 0;
193
194 while (nanosleep (&ts, &tsrem) < 0)
195 ts = tsrem;
196 }
197 return (0); /* not so much */
198}
199
200static clib_error_t *
201test_bihash_threads (test_main_t * tm)
202{
203 int i;
204 pthread_t handle;
205 BVT (clib_bihash) * h;
206 int rv;
207
208 h = &tm->hash;
209
Dave Barach9466c452018-08-24 17:21:14 -0400210#if BIHASH_32_64_SVM
211 BV (clib_bihash_master_init_svm) (h, "test", tm->nbuckets,
212 0x30000000 /* base_addr */ ,
213 tm->hash_memory_size);
214#else
Dave Barach508498f2018-07-19 12:11:16 -0400215 BV (clib_bihash_init) (h, "test", tm->nbuckets, tm->hash_memory_size);
Dave Barach9466c452018-08-24 17:21:14 -0400216#endif
Dave Barach508498f2018-07-19 12:11:16 -0400217
218 tm->thread_barrier = 1;
219
220 /* Start the worker threads */
221 for (i = 0; i < tm->nthreads; i++)
222 {
223 rv = pthread_create (&handle, NULL, test_bihash_thread_fn,
224 (void *) (u64) i);
225 if (rv)
226 {
227 clib_unix_warning ("pthread_create returned %d", rv);
228 }
229 }
230 tm->threads_running = i;
231 tm->sequence_number = 0;
232 CLIB_MEMORY_BARRIER ();
233
234 /* start the workers */
235 tm->thread_barrier = 0;
236
237 while (tm->threads_running)
238 {
239 struct timespec ts, tsrem;
240 ts.tv_sec = 0;
241 ts.tv_nsec = 20 * 1000 * 1000; /* sleep for 20ms at a time */
242
243 while (nanosleep (&ts, &tsrem) < 0)
244 ts = tsrem;
245 }
246
247 return 0;
248}
249
250
Dave Barachba7ddfe2017-05-17 20:20:50 -0400251static clib_error_t *
Dave Barachc3799992016-08-15 11:12:27 -0400252test_bihash (test_main_t * tm)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700253{
254 int i, j;
Dave Barachc3799992016-08-15 11:12:27 -0400255 uword *p;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700256 uword total_searches;
257 f64 before, delta;
Dave Barachc3799992016-08-15 11:12:27 -0400258 BVT (clib_bihash) * h;
259 BVT (clib_bihash_kv) kv;
Dave Barache7d212f2018-02-07 13:14:06 -0500260 u32 acycle;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700261
262 h = &tm->hash;
263
Dave Barach9466c452018-08-24 17:21:14 -0400264#if BIHASH_32_64_SVM
265 BV (clib_bihash_master_init_svm) (h, "test", tm->nbuckets,
266 0x30000000 /* base_addr */ ,
267 tm->hash_memory_size);
268#else
Dave Barach97f5af02018-02-22 09:48:45 -0500269 BV (clib_bihash_init) (h, "test", tm->nbuckets, tm->hash_memory_size);
Dave Barach9466c452018-08-24 17:21:14 -0400270#endif
Ed Warnickecb9cada2015-12-08 15:45:58 -0700271
Dave Barache7d212f2018-02-07 13:14:06 -0500272 for (acycle = 0; acycle < tm->ncycles; acycle++)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700273 {
Dave Barache7d212f2018-02-07 13:14:06 -0500274 if ((acycle % tm->report_every_n) == 0)
Dave Barachc3799992016-08-15 11:12:27 -0400275 {
Dave Barache7d212f2018-02-07 13:14:06 -0500276 fformat (stdout, "Cycle %lld out of %lld...\n",
277 acycle, tm->ncycles);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700278
Dave Barache7d212f2018-02-07 13:14:06 -0500279 fformat (stdout, "Pick %lld unique %s keys...\n",
280 tm->nitems, tm->non_random_keys ? "non-random" : "random");
Dave Barachc3799992016-08-15 11:12:27 -0400281 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700282
Dave Barache7d212f2018-02-07 13:14:06 -0500283 for (i = 0; i < tm->nitems; i++)
Dave Barachc3799992016-08-15 11:12:27 -0400284 {
Dave Barache7d212f2018-02-07 13:14:06 -0500285 u64 rndkey;
286
287 if (tm->non_random_keys == 0)
288 {
289
290 again:
291 rndkey = random_u64 (&tm->seed);
292
293 p = hash_get (tm->key_hash, rndkey);
294 if (p)
295 goto again;
296 }
297 else
298 rndkey = (u64) (i + 1) << 16;
299 rndkey += acycle;
300
301 hash_set (tm->key_hash, rndkey, i + 1);
302 vec_add1 (tm->keys, rndkey);
Dave Barachc3799992016-08-15 11:12:27 -0400303 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700304
Ed Warnickecb9cada2015-12-08 15:45:58 -0700305
Dave Barache7d212f2018-02-07 13:14:06 -0500306 if ((acycle % tm->report_every_n) == 0)
307 fformat (stdout, "Add items...\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -0700308
Ed Warnickecb9cada2015-12-08 15:45:58 -0700309 for (i = 0; i < tm->nitems; i++)
Dave Barachc3799992016-08-15 11:12:27 -0400310 {
Dave Barachc3799992016-08-15 11:12:27 -0400311 kv.key = tm->keys[i];
Dave Barache7d212f2018-02-07 13:14:06 -0500312 kv.value = i + 1;
313
314 BV (clib_bihash_add_del) (h, &kv, 1 /* is_add */ );
315
316 if (tm->verbose > 1)
317 {
318 fformat (stdout, "--------------------\n");
319 fformat (stdout, "After adding key %llu value %lld...\n",
320 tm->keys[i], (u64) (i + 1));
321 fformat (stdout, "%U", BV (format_bihash), h,
322 2 /* very verbose */ );
323 }
Dave Barachc3799992016-08-15 11:12:27 -0400324 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700325
Dave Barache7d212f2018-02-07 13:14:06 -0500326 if ((acycle % tm->report_every_n) == 0)
327 {
328 fformat (stdout, "%U", BV (format_bihash), h,
329 0 /* very verbose */ );
Ed Warnickecb9cada2015-12-08 15:45:58 -0700330
Dave Barache7d212f2018-02-07 13:14:06 -0500331 fformat (stdout, "Search for items %d times...\n", tm->search_iter);
332 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700333
Dave Barache7d212f2018-02-07 13:14:06 -0500334 before = clib_time_now (&tm->clib_time);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700335
Dave Barache7d212f2018-02-07 13:14:06 -0500336 for (j = 0; j < tm->search_iter; j++)
337 {
338 for (i = 0; i < tm->nitems; i++)
339 {
340 kv.key = tm->keys[i];
341 if (BV (clib_bihash_search) (h, &kv, &kv) < 0)
342 if (BV (clib_bihash_search) (h, &kv, &kv) < 0)
343 clib_warning
344 ("[%d] search for key %lld failed unexpectedly\n", i,
345 tm->keys[i]);
346 if (kv.value != (u64) (i + 1))
347 clib_warning
348 ("[%d] search for key %lld returned %lld, not %lld\n", i,
349 tm->keys, kv.value, (u64) (i + 1));
350 }
351 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700352
Dave Barache7d212f2018-02-07 13:14:06 -0500353 if ((acycle % tm->report_every_n) == 0)
354 {
355 delta = clib_time_now (&tm->clib_time) - before;
356 total_searches = (uword) tm->search_iter * (uword) tm->nitems;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700357
Dave Barache7d212f2018-02-07 13:14:06 -0500358 if (delta > 0)
359 fformat (stdout, "%.f searches per second\n",
360 ((f64) total_searches) / delta);
361
362 fformat (stdout, "%lld searches in %.6f seconds\n", total_searches,
363 delta);
364
365 fformat (stdout, "Standard E-hash search for items %d times...\n",
366 tm->search_iter);
367 }
368
369 before = clib_time_now (&tm->clib_time);
370
371 for (j = 0; j < tm->search_iter; j++)
372 {
373 for (i = 0; i < tm->nitems; i++)
374 {
375 p = hash_get (tm->key_hash, tm->keys[i]);
376 if (p == 0 || p[0] != (uword) (i + 1))
377 clib_warning ("ugh, couldn't find %lld\n", tm->keys[i]);
378 }
379 }
380
381 delta = clib_time_now (&tm->clib_time) - before;
382 total_searches = (uword) tm->search_iter * (uword) tm->nitems;
383
384 if ((acycle % tm->report_every_n) == 0)
385 {
386 fformat (stdout, "%lld searches in %.6f seconds\n",
387 total_searches, delta);
388
389 if (delta > 0)
390 fformat (stdout, "%.f searches per second\n",
391 ((f64) total_searches) / delta);
392 fformat (stdout, "Delete items...\n");
393 }
394
Ed Warnickecb9cada2015-12-08 15:45:58 -0700395 for (i = 0; i < tm->nitems; i++)
Dave Barachc3799992016-08-15 11:12:27 -0400396 {
Dave Barache7d212f2018-02-07 13:14:06 -0500397 int j;
398 int rv;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700399
Dave Barache7d212f2018-02-07 13:14:06 -0500400 kv.key = tm->keys[i];
401 kv.value = (u64) (i + 1);
402 rv = BV (clib_bihash_add_del) (h, &kv, 0 /* is_add */ );
Ed Warnickecb9cada2015-12-08 15:45:58 -0700403
Dave Barache7d212f2018-02-07 13:14:06 -0500404 if (rv < 0)
405 clib_warning ("delete key %lld not ok but should be",
406 tm->keys[i]);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700407
Dave Barache7d212f2018-02-07 13:14:06 -0500408 if (tm->careful_delete_tests)
Dave Barachc3799992016-08-15 11:12:27 -0400409 {
Dave Barache7d212f2018-02-07 13:14:06 -0500410 for (j = 0; j < tm->nitems; j++)
Dave Barachc3799992016-08-15 11:12:27 -0400411 {
Dave Barache7d212f2018-02-07 13:14:06 -0500412 kv.key = tm->keys[j];
413 rv = BV (clib_bihash_search) (h, &kv, &kv);
414 if (j <= i && rv >= 0)
415 {
416 clib_warning
417 ("i %d j %d search ok but should not be, value %lld",
418 i, j, kv.value);
419 }
420 if (j > i && rv < 0)
421 {
422 clib_warning ("i %d j %d search not ok but should be",
423 i, j);
424 }
Dave Barachc3799992016-08-15 11:12:27 -0400425 }
426 }
427 }
Dave Barache7d212f2018-02-07 13:14:06 -0500428 if ((acycle % tm->report_every_n) == 0)
429 {
430 struct rusage r_usage;
431 getrusage (RUSAGE_SELF, &r_usage);
432 fformat (stdout, "Kernel RSS: %ld bytes\n", r_usage.ru_maxrss);
433 fformat (stdout, "%U\n", BV (format_bihash), h, 0 /* verbose */ );
434 }
435
436 /* Clean up side-bet hash table and random key vector */
Dave Barach97f5af02018-02-22 09:48:45 -0500437 hash_free (tm->key_hash);
Dave Barache7d212f2018-02-07 13:14:06 -0500438 vec_reset_length (tm->keys);
Dave Barach97f5af02018-02-22 09:48:45 -0500439 /* Recreate hash table if we're going to need it again */
440 if (acycle != (tm->ncycles - 1))
441 tm->key_hash = hash_create (tm->nitems, sizeof (uword));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700442 }
443
Dave Barache7d212f2018-02-07 13:14:06 -0500444 fformat (stdout, "End of run, should be empty...\n");
Ed Warnickecb9cada2015-12-08 15:45:58 -0700445
Dave Barachc3799992016-08-15 11:12:27 -0400446 fformat (stdout, "%U", BV (format_bihash), h, 0 /* very verbose */ );
Dave Barach9466c452018-08-24 17:21:14 -0400447
448 BV (clib_bihash_free) (h);
449
Ed Warnickecb9cada2015-12-08 15:45:58 -0700450 return 0;
451}
452
Dave Barachc3799992016-08-15 11:12:27 -0400453clib_error_t *
Ed Warnickecb9cada2015-12-08 15:45:58 -0700454test_bihash_main (test_main_t * tm)
455{
Dave Barachc3799992016-08-15 11:12:27 -0400456 unformat_input_t *i = tm->input;
457 clib_error_t *error;
Dave Barach908a5ea2017-07-14 12:42:21 -0400458 int which = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700459
Dave Barache7d212f2018-02-07 13:14:06 -0500460 tm->report_every_n = 1;
Dave Barach9466c452018-08-24 17:21:14 -0400461 tm->hash_memory_size = 1ULL << 30;
Dave Barache7d212f2018-02-07 13:14:06 -0500462
Ed Warnickecb9cada2015-12-08 15:45:58 -0700463 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
464 {
465 if (unformat (i, "seed %u", &tm->seed))
Dave Barachc3799992016-08-15 11:12:27 -0400466 ;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700467
468 else if (unformat (i, "nbuckets %d", &tm->nbuckets))
Dave Barachc3799992016-08-15 11:12:27 -0400469 ;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700470 else if (unformat (i, "non-random-keys"))
Dave Barachc3799992016-08-15 11:12:27 -0400471 tm->non_random_keys = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700472 else if (unformat (i, "nitems %d", &tm->nitems))
Dave Barachc3799992016-08-15 11:12:27 -0400473 ;
Dave Barache7d212f2018-02-07 13:14:06 -0500474 else if (unformat (i, "ncycles %d", &tm->ncycles))
475 ;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700476 else if (unformat (i, "careful %d", &tm->careful_delete_tests))
Dave Barachc3799992016-08-15 11:12:27 -0400477 ;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700478 else if (unformat (i, "verbose %d", &tm->verbose))
Dave Barachc3799992016-08-15 11:12:27 -0400479 ;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700480 else if (unformat (i, "search %d", &tm->search_iter))
Dave Barachc3799992016-08-15 11:12:27 -0400481 ;
Dave Barache7d212f2018-02-07 13:14:06 -0500482 else if (unformat (i, "report-every %d", &tm->report_every_n))
483 ;
Dave Barach97f5af02018-02-22 09:48:45 -0500484 else if (unformat (i, "memory-size %U",
485 unformat_memory_size, &tm->hash_memory_size))
486 ;
Dave Barachba7ddfe2017-05-17 20:20:50 -0400487 else if (unformat (i, "vec64"))
Dave Barach908a5ea2017-07-14 12:42:21 -0400488 which = 1;
Dave Barach508498f2018-07-19 12:11:16 -0400489 else if (unformat (i, "threads %u", &tm->nthreads))
Dave Barach908a5ea2017-07-14 12:42:21 -0400490 which = 2;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700491 else if (unformat (i, "verbose"))
Dave Barachc3799992016-08-15 11:12:27 -0400492 tm->verbose = 1;
Matus Fabian828d27e2018-08-21 03:15:50 -0700493 else if (unformat (i, "stale-overwrite"))
494 which = 3;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700495 else
Dave Barachc3799992016-08-15 11:12:27 -0400496 return clib_error_return (0, "unknown input '%U'",
497 format_unformat_error, i);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700498 }
Dave Barachc3799992016-08-15 11:12:27 -0400499
Dave Barach97f5af02018-02-22 09:48:45 -0500500 /* Preallocate hash table, key vector */
501 tm->key_hash = hash_create (tm->nitems, sizeof (uword));
502 vec_validate (tm->keys, tm->nitems - 1);
503 _vec_len (tm->keys) = 0;
504
505
Dave Barach908a5ea2017-07-14 12:42:21 -0400506 switch (which)
507 {
508 case 0:
509 error = test_bihash (tm);
510 break;
511
512 case 1:
513 error = test_bihash_vec64 (tm);
514 break;
515
516 case 2:
Dave Barach508498f2018-07-19 12:11:16 -0400517 error = test_bihash_threads (tm);
Dave Barach908a5ea2017-07-14 12:42:21 -0400518 break;
519
Matus Fabian828d27e2018-08-21 03:15:50 -0700520 case 3:
521 error = test_bihash_stale_overwrite (tm);
522 break;
523
Dave Barach908a5ea2017-07-14 12:42:21 -0400524 default:
525 return clib_error_return (0, "no such test?");
526 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700527
528 return error;
529}
530
531#ifdef CLIB_UNIX
Dave Barachc3799992016-08-15 11:12:27 -0400532int
533main (int argc, char *argv[])
Ed Warnickecb9cada2015-12-08 15:45:58 -0700534{
535 unformat_input_t i;
Dave Barachc3799992016-08-15 11:12:27 -0400536 clib_error_t *error;
537 test_main_t *tm = &test_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700538
Dave Barach97f5af02018-02-22 09:48:45 -0500539 clib_mem_init (0, 4095ULL << 20);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700540
Dave Barach508498f2018-07-19 12:11:16 -0400541 tm->global_heap = clib_mem_get_per_cpu_heap ();
542
Ed Warnickecb9cada2015-12-08 15:45:58 -0700543 tm->input = &i;
544 tm->seed = 0xdeaddabe;
545
546 tm->nbuckets = 2;
547 tm->nitems = 5;
Dave Barache7d212f2018-02-07 13:14:06 -0500548 tm->ncycles = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700549 tm->verbose = 1;
550 tm->search_iter = 1;
551 tm->careful_delete_tests = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700552 clib_time_init (&tm->clib_time);
553
554 unformat_init_command_line (&i, argv);
555 error = test_bihash_main (tm);
556 unformat_free (&i);
557
558 if (error)
559 {
560 clib_error_report (error);
561 return 1;
562 }
563 return 0;
564}
565#endif /* CLIB_UNIX */
Dave Barachc3799992016-08-15 11:12:27 -0400566
567/*
568 * fd.io coding-style-patch-verification: ON
569 *
570 * Local Variables:
571 * eval: (c-set-style "gnu")
572 * End:
573 */