diff options
author | Dave Barach <dave@barachs.net> | 2017-12-05 12:21:59 -0500 |
---|---|---|
committer | Damjan Marion <dmarion.lists@gmail.com> | 2017-12-06 10:43:45 +0000 |
commit | 22229864cb6e30c9b75a9c36e4ffa8500c0cdc5f (patch) | |
tree | 6a0f00aebc127b73d104fb769857792e94e4734d /src/vppinfra | |
parent | 55c79e9c7e14b501baa72bc8b415e0a66752ed01 (diff) |
Remove unused, uninteresting code
Move elog_sample.c to src/examples/vlib
Change-Id: I7d32c83c424b9ca4a057372c7fc6a6e2b7dab034
Signed-off-by: Dave Barach <dave@barachs.net>
Diffstat (limited to 'src/vppinfra')
-rw-r--r-- | src/vppinfra/mod_test_hash.c | 27 | ||||
-rw-r--r-- | src/vppinfra/pfhash.c | 689 | ||||
-rw-r--r-- | src/vppinfra/test_pfhash.c | 322 | ||||
-rw-r--r-- | src/vppinfra/test_pool.c | 86 |
4 files changed, 0 insertions, 1124 deletions
diff --git a/src/vppinfra/mod_test_hash.c b/src/vppinfra/mod_test_hash.c deleted file mode 100644 index b3fa676d2e2..00000000000 --- a/src/vppinfra/mod_test_hash.c +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2015 Cisco and/or its affiliates. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include <vppinfra/linux_kernel_init.h> -#include <vppinfra/hash.h> - -CLIB_LINUX_KERNEL_MODULE ("test_hash", test_hash_main, - /* kernel-thread flags */ 0 & CLONE_KERNEL); - -/* - * fd.io coding-style-patch-verification: ON - * - * Local Variables: - * eval: (c-set-style "gnu") - * End: - */ diff --git a/src/vppinfra/pfhash.c b/src/vppinfra/pfhash.c deleted file mode 100644 index 3b9fa8f34aa..00000000000 --- a/src/vppinfra/pfhash.c +++ /dev/null @@ -1,689 +0,0 @@ -/* - Copyright (c) 2013 Cisco and/or its affiliates. - - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. -*/ - -#include <vppinfra/pfhash.h> -#include <vppinfra/format.h> - -/* This is incredibly handy when debugging */ -u32 vl (void *v) __attribute__ ((weak)); -u32 -vl (void *v) -{ - return vec_len (v); -} - -#if defined(CLIB_HAVE_VEC128) && ! defined (__ALTIVEC__) - -typedef struct -{ - u8 *key[16]; - u64 value; -} pfhash_show_t; - -static int -sh_compare (pfhash_show_t * sh0, pfhash_show_t * sh1) -{ - return ((i32) (sh0->value) - ((i32) sh1->value)); -} - -u8 * -format_pfhash (u8 * s, va_list * args) -{ - pfhash_t *p = va_arg (*args, pfhash_t *); - int verbose = va_arg (*args, int); - - if (p == 0 || p->overflow_hash == 0 || p->buckets == 0) - { - s = format (s, "*** uninitialized ***"); - return s; - } - - s = format (s, "Prefetch hash '%s'\n", p->name); - s = - format (s, " %d buckets, %u bucket overflows, %.1f%% bucket overflow \n", - vec_len (p->buckets), p->overflow_count, - 100.0 * ((f64) p->overflow_count) / ((f64) vec_len (p->buckets))); - if (p->nitems) - s = - format (s, - " %u items, %u items in overflow, %.1f%% items in overflow\n", - p->nitems, p->nitems_in_overflow, - 100.0 * ((f64) p->nitems_in_overflow) / ((f64) p->nitems)); - - if (verbose) - { - pfhash_show_t *shs = 0, *sh; - hash_pair_t *hp; - int i, j; - - for (i = 0; i < vec_len (p->buckets); i++) - { - pfhash_kv_t *kv; - pfhash_kv_16_t *kv16; - pfhash_kv_8_t *kv8; - pfhash_kv_8v8_t *kv8v8; - pfhash_kv_4_t *kv4; - - if (p->buckets[i] == 0 || p->buckets[i] == PFHASH_BUCKET_OVERFLOW) - continue; - - kv = pool_elt_at_index (p->kvp, p->buckets[i]); - - switch (p->key_size) - { - case 16: - kv16 = &kv->kv16; - for (j = 0; j < 3; j++) - { - if (kv16->values[j] != (u32) ~ 0) - { - vec_add2 (shs, sh, 1); - clib_memcpy (sh->key, &kv16->kb.k_u32x4[j], - p->key_size); - sh->value = kv16->values[j]; - } - } - break; - case 8: - if (p->value_size == 4) - { - kv8 = &kv->kv8; - for (j = 0; j < 5; j++) - { - if (kv8->values[j] != (u32) ~ 0) - { - vec_add2 (shs, sh, 1); - clib_memcpy (sh->key, &kv8->kb.k_u64[j], - p->key_size); - sh->value = kv8->values[j]; - } - } - } - else - { - kv8v8 = &kv->kv8v8; - for (j = 0; j < 4; j++) - { - if (kv8v8->values[j] != (u64) ~ 0) - { - vec_add2 (shs, sh, 1); - clib_memcpy (sh->key, &kv8v8->kb.k_u64[j], - p->key_size); - sh->value = kv8v8->values[j]; - } - } - - } - break; - case 4: - kv4 = &kv->kv4; - for (j = 0; j < 8; j++) - { - if (kv4->values[j] != (u32) ~ 0) - { - vec_add2 (shs, sh, 1); - clib_memcpy (sh->key, &kv4->kb.kb[j], p->key_size); - sh->value = kv4->values[j]; - } - } - break; - } - } - - /* *INDENT-OFF* */ - hash_foreach_pair (hp, p->overflow_hash, - ({ - vec_add2 (shs, sh, 1); - clib_memcpy (sh->key, (u8 *)hp->key, p->key_size); - sh->value = hp->value[0]; - })); - /* *INDENT-ON* */ - - vec_sort_with_function (shs, sh_compare); - - for (i = 0; i < vec_len (shs); i++) - { - sh = vec_elt_at_index (shs, i); - s = format (s, " %U value %u\n", format_hex_bytes, sh->key, - p->key_size, sh->value); - } - vec_free (shs); - } - return s; -} - - -void abort (void); - -void -pfhash_init (pfhash_t * p, char *name, u32 key_size, u32 value_size, - u32 nbuckets) -{ - pfhash_kv_t *kv; - memset (p, 0, sizeof (*p)); - u32 key_bytes; - - switch (key_size) - { - case 4: - key_bytes = 4; - break; - case 8: - key_bytes = 8; - break; - case 16: - key_bytes = 16; - break; - default: - ASSERT (0); - abort (); - } - - switch (value_size) - { - case 4: - case 8: - break; - default: - ASSERT (0); - abort (); - } - - - p->name = format (0, "%s", name); - vec_add1 (p->name, 0); - p->overflow_hash = hash_create_mem (0, key_bytes, sizeof (uword)); - - nbuckets = 1 << (max_log2 (nbuckets)); - - /* This sets the entire bucket array to zero */ - vec_validate (p->buckets, nbuckets - 1); - p->key_size = key_size; - p->value_size = value_size; - - /* - * Unset buckets implicitly point at the 0th pool elt. - * All search routines will return ~0 if they go there. - */ - pool_get_aligned (p->kvp, kv, 16); - memset (kv, 0xff, sizeof (*kv)); -} - -static pfhash_kv_16_t * -pfhash_get_kv_16 (pfhash_t * p, u32 bucket_contents, - u32x4 * key, u32 * match_index) -{ - u32x4 diff[3]; - u32 is_equal[3]; - pfhash_kv_16_t *kv = 0; - - *match_index = (u32) ~ 0; - - kv = &p->kvp[bucket_contents].kv16; - - diff[0] = u32x4_sub (kv->kb.k_u32x4[0], key[0]); - diff[1] = u32x4_sub (kv->kb.k_u32x4[1], key[0]); - diff[2] = u32x4_sub (kv->kb.k_u32x4[2], key[0]); - - is_equal[0] = u32x4_zero_byte_mask (diff[0]) == 0xffff; - is_equal[1] = u32x4_zero_byte_mask (diff[1]) == 0xffff; - is_equal[2] = u32x4_zero_byte_mask (diff[2]) == 0xffff; - - if (is_equal[0]) - *match_index = 0; - if (is_equal[1]) - *match_index = 1; - if (is_equal[2]) - *match_index = 2; - - return kv; -} - -static pfhash_kv_8_t * -pfhash_get_kv_8 (pfhash_t * p, u32 bucket_contents, - u64 * key, u32 * match_index) -{ - pfhash_kv_8_t *kv; - - *match_index = (u32) ~ 0; - - kv = &p->kvp[bucket_contents].kv8; - - if (kv->kb.k_u64[0] == key[0]) - *match_index = 0; - if (kv->kb.k_u64[1] == key[0]) - *match_index = 1; - if (kv->kb.k_u64[2] == key[0]) - *match_index = 2; - if (kv->kb.k_u64[3] == key[0]) - *match_index = 3; - if (kv->kb.k_u64[4] == key[0]) - *match_index = 4; - - return kv; -} - -static pfhash_kv_8v8_t * -pfhash_get_kv_8v8 (pfhash_t * p, - u32 bucket_contents, u64 * key, u32 * match_index) -{ - pfhash_kv_8v8_t *kv; - - *match_index = (u32) ~ 0; - - kv = &p->kvp[bucket_contents].kv8v8; - - if (kv->kb.k_u64[0] == key[0]) - *match_index = 0; - if (kv->kb.k_u64[1] == key[0]) - *match_index = 1; - if (kv->kb.k_u64[2] == key[0]) - *match_index = 2; - if (kv->kb.k_u64[3] == key[0]) - *match_index = 3; - - return kv; -} - -static pfhash_kv_4_t * -pfhash_get_kv_4 (pfhash_t * p, u32 bucket_contents, - u32 * key, u32 * match_index) -{ - u32x4 vector_key; - u32x4 is_equal[2]; - u32 zbm[2], winner_index; - pfhash_kv_4_t *kv; - - *match_index = (u32) ~ 0; - - kv = &p->kvp[bucket_contents].kv4; - - vector_key = u32x4_splat (key[0]); - - is_equal[0] = u32x4_is_equal (kv->kb.k_u32x4[0], vector_key); - is_equal[1] = u32x4_is_equal (kv->kb.k_u32x4[1], vector_key); - zbm[0] = ~u32x4_zero_byte_mask (is_equal[0]) & 0xFFFF; - zbm[1] = ~u32x4_zero_byte_mask (is_equal[1]) & 0xFFFF; - - if (PREDICT_FALSE ((zbm[0] == 0) && (zbm[1] == 0))) - return kv; - - winner_index = min_log2 (zbm[0]) >> 2; - winner_index = zbm[1] ? (4 + (min_log2 (zbm[1]) >> 2)) : winner_index; - - *match_index = winner_index; - return kv; -} - -static pfhash_kv_t * -pfhash_get_internal (pfhash_t * p, u32 bucket_contents, - void *key, u32 * match_index) -{ - pfhash_kv_t *kv = 0; - - switch (p->key_size) - { - case 16: - kv = - (pfhash_kv_t *) pfhash_get_kv_16 (p, bucket_contents, key, - match_index); - break; - case 8: - if (p->value_size == 4) - kv = (pfhash_kv_t *) pfhash_get_kv_8 (p, bucket_contents, - key, match_index); - else - kv = (pfhash_kv_t *) pfhash_get_kv_8v8 (p, bucket_contents, - key, match_index); - break; - case 4: - kv = - (pfhash_kv_t *) pfhash_get_kv_4 (p, bucket_contents, key, - match_index); - break; - default: - ASSERT (0); - } - return kv; -} - -u64 -pfhash_get (pfhash_t * p, u32 bucket, void *key) -{ - pfhash_kv_t *kv; - u32 match_index = ~0; - pfhash_kv_16_t *kv16; - pfhash_kv_8_t *kv8; - pfhash_kv_8v8_t *kv8v8; - pfhash_kv_4_t *kv4; - - u32 bucket_contents = pfhash_read_bucket_prefetch_kv (p, bucket); - - if (bucket_contents == PFHASH_BUCKET_OVERFLOW) - { - uword *hp; - - hp = hash_get_mem (p->overflow_hash, key); - if (hp) - return hp[0]; - return (u64) ~ 0; - } - - kv = pfhash_get_internal (p, bucket_contents, key, &match_index); - if (match_index == (u32) ~ 0) - return (u64) ~ 0; - - kv16 = (void *) kv; - kv8 = (void *) kv; - kv4 = (void *) kv; - kv8v8 = (void *) kv; - - switch (p->key_size) - { - case 16: - return (kv16->values[match_index] == (u32) ~ 0) - ? (u64) ~ 0 : (u64) kv16->values[match_index]; - case 8: - if (p->value_size == 4) - return (kv8->values[match_index] == (u32) ~ 0) - ? (u64) ~ 0 : (u64) kv8->values[match_index]; - else - return kv8v8->values[match_index]; - case 4: - return (kv4->values[match_index] == (u32) ~ 0) - ? (u64) ~ 0 : (u64) kv4->values[match_index]; - default: - ASSERT (0); - } - return (u64) ~ 0; -} - -void -pfhash_set (pfhash_t * p, u32 bucket, void *key, void *value) -{ - u32 bucket_contents = pfhash_read_bucket_prefetch_kv (p, bucket); - u32 match_index = (u32) ~ 0; - pfhash_kv_t *kv; - pfhash_kv_16_t *kv16; - pfhash_kv_8_t *kv8; - pfhash_kv_8v8_t *kv8v8; - pfhash_kv_4_t *kv4; - int i; - u8 *kcopy; - - if (bucket_contents == PFHASH_BUCKET_OVERFLOW) - { - hash_pair_t *hp; - hp = hash_get_pair_mem (p->overflow_hash, key); - if (hp) - { - clib_warning ("replace value 0x%08x with value 0x%08x", - hp->value[0], (u64) value); - hp->value[0] = (u64) value; - return; - } - kcopy = clib_mem_alloc (p->key_size); - clib_memcpy (kcopy, key, p->key_size); - hash_set_mem (p->overflow_hash, kcopy, value); - p->nitems++; - p->nitems_in_overflow++; - return; - } - - if (bucket_contents == 0) - { - pool_get_aligned (p->kvp, kv, 16); - memset (kv, 0xff, sizeof (*kv)); - p->buckets[bucket] = kv - p->kvp; - } - else - kv = pfhash_get_internal (p, bucket_contents, key, &match_index); - - kv16 = (void *) kv; - kv8 = (void *) kv; - kv8v8 = (void *) kv; - kv4 = (void *) kv; - - p->nitems++; - - if (match_index != (u32) ~ 0) - { - switch (p->key_size) - { - case 16: - kv16->values[match_index] = (u32) (u64) value; - return; - - case 8: - if (p->value_size == 4) - kv8->values[match_index] = (u32) (u64) value; - else - kv8v8->values[match_index] = (u64) value; - return; - - case 4: - kv4->values[match_index] = (u64) value; - return; - - default: - ASSERT (0); - } - } - - switch (p->key_size) - { - case 16: - for (i = 0; i < 3; i++) - { - if (kv16->values[i] == (u32) ~ 0) - { - clib_memcpy (&kv16->kb.k_u32x4[i], key, p->key_size); - kv16->values[i] = (u32) (u64) value; - return; - } - } - /* copy bucket contents to overflow hash tbl */ - for (i = 0; i < 3; i++) - { - kcopy = clib_mem_alloc (p->key_size); - clib_memcpy (kcopy, &kv16->kb.k_u32x4[i], p->key_size); - hash_set_mem (p->overflow_hash, kcopy, kv16->values[i]); - p->nitems_in_overflow++; - } - /* Add new key to overflow */ - kcopy = clib_mem_alloc (p->key_size); - clib_memcpy (kcopy, key, p->key_size); - hash_set_mem (p->overflow_hash, kcopy, value); - p->buckets[bucket] = PFHASH_BUCKET_OVERFLOW; - p->overflow_count++; - p->nitems_in_overflow++; - return; - - case 8: - if (p->value_size == 4) - { - for (i = 0; i < 5; i++) - { - if (kv8->values[i] == (u32) ~ 0) - { - clib_memcpy (&kv8->kb.k_u64[i], key, 8); - kv8->values[i] = (u32) (u64) value; - return; - } - } - /* copy bucket contents to overflow hash tbl */ - for (i = 0; i < 5; i++) - { - kcopy = clib_mem_alloc (p->key_size); - clib_memcpy (kcopy, &kv8->kb.k_u64[i], 8); - hash_set_mem (p->overflow_hash, kcopy, kv8->values[i]); - p->nitems_in_overflow++; - } - } - else - { - for (i = 0; i < 4; i++) - { - if (kv8v8->values[i] == (u64) ~ 0) - { - clib_memcpy (&kv8v8->kb.k_u64[i], key, 8); - kv8v8->values[i] = (u64) value; - return; - } - } - /* copy bucket contents to overflow hash tbl */ - for (i = 0; i < 4; i++) - { - kcopy = clib_mem_alloc (p->key_size); - clib_memcpy (kcopy, &kv8v8->kb.k_u64[i], 8); - hash_set_mem (p->overflow_hash, kcopy, kv8v8->values[i]); - p->nitems_in_overflow++; - } - - } - /* Add new key to overflow */ - kcopy = clib_mem_alloc (p->key_size); - clib_memcpy (kcopy, key, p->key_size); - hash_set_mem (p->overflow_hash, kcopy, value); - p->buckets[bucket] = PFHASH_BUCKET_OVERFLOW; - p->overflow_count++; - p->nitems_in_overflow++; - return; - - case 4: - for (i = 0; i < 8; i++) - { - if (kv4->values[i] == (u32) ~ 0) - { - clib_memcpy (&kv4->kb.kb[i], key, 4); - kv4->values[i] = (u32) (u64) value; - return; - } - } - /* copy bucket contents to overflow hash tbl */ - for (i = 0; i < 8; i++) - { - kcopy = clib_mem_alloc (p->key_size); - clib_memcpy (kcopy, &kv4->kb.kb[i], 4); - hash_set_mem (p->overflow_hash, kcopy, kv4->values[i]); - p->nitems_in_overflow++; - } - /* Add new key to overflow */ - kcopy = clib_mem_alloc (p->key_size); - clib_memcpy (kcopy, key, p->key_size); - hash_set_mem (p->overflow_hash, kcopy, value); - p->buckets[bucket] = PFHASH_BUCKET_OVERFLOW; - p->overflow_count++; - p->nitems_in_overflow++; - return; - - default: - ASSERT (0); - } -} - -void -pfhash_unset (pfhash_t * p, u32 bucket, void *key) -{ - u32 bucket_contents = pfhash_read_bucket_prefetch_kv (p, bucket); - u32 match_index = (u32) ~ 0; - pfhash_kv_t *kv; - pfhash_kv_16_t *kv16; - pfhash_kv_8_t *kv8; - pfhash_kv_8v8_t *kv8v8; - pfhash_kv_4_t *kv4; - void *oldkey; - - if (bucket_contents == PFHASH_BUCKET_OVERFLOW) - { - hash_pair_t *hp; - hp = hash_get_pair_mem (p->overflow_hash, key); - if (hp) - { - oldkey = (void *) hp->key; - hash_unset_mem (p->overflow_hash, key); - clib_mem_free (oldkey); - p->nitems--; - p->nitems_in_overflow--; - } - return; - } - - kv = pfhash_get_internal (p, bucket_contents, key, &match_index); - if (match_index == (u32) ~ 0) - return; - - p->nitems--; - - kv16 = (void *) kv; - kv8 = (void *) kv; - kv8v8 = (void *) kv; - kv4 = (void *) kv; - - switch (p->key_size) - { - case 16: - kv16->values[match_index] = (u32) ~ 0; - return; - - case 8: - if (p->value_size == 4) - kv8->values[match_index] = (u32) ~ 0; - else - kv8v8->values[match_index] = (u64) ~ 0; - return; - - case 4: - kv4->values[match_index] = (u32) ~ 0; - return; - - default: - ASSERT (0); - } -} - -void -pfhash_free (pfhash_t * p) -{ - hash_pair_t *hp; - int i; - u8 **keys = 0; - - vec_free (p->name); - - pool_free (p->kvp); - - /* *INDENT-OFF* */ - hash_foreach_pair (hp, p->overflow_hash, - ({ - vec_add1 (keys, (u8 *)hp->key); - })); - /* *INDENT-ON* */ - hash_free (p->overflow_hash); - for (i = 0; i < vec_len (keys); i++) - vec_free (keys[i]); - vec_free (keys); -} - -#endif - -/* - * fd.io coding-style-patch-verification: ON - * - * Local Variables: - * eval: (c-set-style "gnu") - * End: - */ diff --git a/src/vppinfra/test_pfhash.c b/src/vppinfra/test_pfhash.c deleted file mode 100644 index ddbdbb34be5..00000000000 --- a/src/vppinfra/test_pfhash.c +++ /dev/null @@ -1,322 +0,0 @@ -/* - Copyright (c) 2013 Cisco and/or its affiliates. - - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. -*/ - -#include <vppinfra/pfhash.h> -#include <vppinfra/format.h> -#include <vppinfra/random.h> - -#if defined(CLIB_HAVE_VEC128) && ! defined (__ALTIVEC__) - -int verbose = 0; - -always_inline u8 * -random_aligned_string (u32 * seed, uword len) -{ - u8 *alphabet = (u8 *) "abcdefghijklmnopqrstuvwxyz"; - u8 *s = 0; - word i; - - vec_resize_aligned (s, len, 16); - for (i = 0; i < len; i++) - s[i] = alphabet[random_u32 (seed) % 26]; - - return s; -} - -void exit (int); - -int -test_pfhash_main (unformat_input_t * input) -{ - u32 seed = 0xdeaddabe; - int i, iter; - u32 nkeys = 4; - u32 niter = 1; - u32 nbuckets = 1; - u32 bucket; - u32 sizes[3] = { 16, 8, 4 }, this_size, size; - u8 **keys = 0; - pfhash_t _rec, *p = &_rec; - - while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) - { - if (unformat (input, "seed %d", &seed)) - ; - else if (unformat (input, "niter %d", &niter)) - ; - else if (unformat (input, "nkeys %d", &nkeys)) - ; - else if (unformat (input, "nbuckets %d", &nbuckets)) - ; - else if (unformat (input, "verbose %d", &verbose)) - ; - else if (unformat (input, "verbose")) - verbose = 1; - else - clib_error ("unknown input `%U'", format_unformat_error, input); - } - - vec_validate (keys, nkeys - 1); - - for (i = 0; i < nkeys; i++) - { - int j, k; - - again: - keys[i] = random_aligned_string (&seed, 16); - for (j = 0; j < (i - 1); j++) - { - /* Make sure we don't have a dup key in the min key size */ - for (k = 0; k < 4; k++) - { - if (keys[i][k] != keys[j][k]) - goto check_next_key; - } - vec_free (keys[i]); - goto again; - check_next_key: - ; - } - } - - /* test 8 byte key, 8 byte value case separately */ - - for (size = 8; size < 9; size++) - { - this_size = 8; - - fformat (stdout, "%d-byte key 8 byte value test\n", this_size); - - pfhash_init (p, "test", 8 /* key size */ , 8 /* value size */ , - nbuckets + 1); - - for (iter = 0; iter < niter; iter++) - { - bucket = 0; - for (i = 0; i < nkeys; i++) - { - bucket = (i % nbuckets) + 1; - pfhash_set (p, bucket, keys[i], - (void *) (u64) 0x100000000ULL + i + 1); - } - - for (i = 0; i < nkeys; i++) - { - bucket = (i % nbuckets) + 1; - if (pfhash_get (p, bucket, keys[i]) - != (u64) 0x100000000ULL + i + 1) - { - clib_warning ("key %d bucket %d lookup FAIL\n", i, bucket); - (void) pfhash_get (p, bucket, keys[i]); - } - } - - /* test inline functions */ - for (i = 0; i < nkeys; i++) - { - u32 bucket_contents; - u64 value = 0xdeadbeef; - bucket = (i % nbuckets) + 1; - - pfhash_prefetch_bucket (p, bucket); - bucket_contents = pfhash_read_bucket_prefetch_kv (p, bucket); - - value = pfhash_search_kv_8v8 (p, bucket_contents, - (u64 *) keys[i]); - if (value != (u64) 0x100000000ULL + i + 1) - clib_warning ("key %d bucket %d lookup FAIL\n", i, bucket); - } - - if (verbose) - fformat (stdout, "%U\n", format_pfhash, p, verbose > 1); - - for (i = 0; i < nkeys; i++) - { - bucket = (i % nbuckets) + 1; - pfhash_unset (p, bucket, keys[i]); - } - - for (i = 0; i < nkeys; i++) - { - bucket = (i % nbuckets) + 1; - if (pfhash_get (p, bucket, keys[i]) != (u64) ~ 0) - { - clib_warning ("key %d bucket %d lookup FAIL\n", i, bucket); - (void) pfhash_get (p, bucket, keys[i]); - } - } - /* test inline functions */ - for (i = 0; i < nkeys; i++) - { - u32 bucket_contents; - u64 value = 0xdeadbeef; - bucket = (i % nbuckets) + 1; - - pfhash_prefetch_bucket (p, bucket); - bucket_contents = pfhash_read_bucket_prefetch_kv (p, bucket); - - value = pfhash_search_kv_8v8 (p, bucket_contents, - (u64 *) keys[i]); - - if (value != (u64) ~ 0) - clib_warning ("key %d bucket %d lookup FAIL\n", i, bucket); - } - } - pfhash_free (p); - } - - /* test other cases */ - - for (size = 0; size < ARRAY_LEN (sizes); size++) - { - this_size = sizes[size]; - - fformat (stdout, "%d-byte key test\n", this_size); - - pfhash_init (p, "test", this_size, 4 /* value size */ , nbuckets + 1); - - for (iter = 0; iter < niter; iter++) - { - bucket = 0; - for (i = 0; i < nkeys; i++) - { - bucket = (i % nbuckets) + 1; - pfhash_set (p, bucket, keys[i], (void *) (u64) i + 1); - } - - for (i = 0; i < nkeys; i++) - { - bucket = (i % nbuckets) + 1; - if (pfhash_get (p, bucket, keys[i]) != i + 1) - { - clib_warning ("key %d bucket %d lookup FAIL\n", i, bucket); - (void) pfhash_get (p, bucket, keys[i]); - } - } - - /* test inline functions */ - for (i = 0; i < nkeys; i++) - { - u32 bucket_contents; - u32 value = 0xdeadbeef; - bucket = (i % nbuckets) + 1; - - pfhash_prefetch_bucket (p, bucket); - bucket_contents = pfhash_read_bucket_prefetch_kv (p, bucket); - switch (p->key_size) - { - case 16: - value = - pfhash_search_kv_16 (p, bucket_contents, - (u32x4 *) keys[i]); - break; - case 8: - value = - pfhash_search_kv_8 (p, bucket_contents, (u64 *) keys[i]); - break; - case 4: - value = - pfhash_search_kv_4 (p, bucket_contents, (u32 *) keys[i]); - break; - } - - if (value != (i + 1)) - clib_warning ("key %d bucket %d lookup FAIL\n", i, bucket); - } - - if (verbose) - fformat (stdout, "%U\n", format_pfhash, p, verbose > 1); - - for (i = 0; i < nkeys; i++) - { - bucket = (i % nbuckets) + 1; - pfhash_unset (p, bucket, keys[i]); - } - - for (i = 0; i < nkeys; i++) - { - bucket = (i % nbuckets) + 1; - if (pfhash_get (p, bucket, keys[i]) != (u64) ~ 0) - { - clib_warning ("key %d bucket %d lookup FAIL\n", i, bucket); - (void) pfhash_get (p, bucket, keys[i]); - } - } - /* test inline functions */ - for (i = 0; i < nkeys; i++) - { - u32 bucket_contents; - u32 value = 0xdeadbeef; - bucket = (i % nbuckets) + 1; - - pfhash_prefetch_bucket (p, bucket); - bucket_contents = pfhash_read_bucket_prefetch_kv (p, bucket); - switch (p->key_size) - { - case 16: - value = - pfhash_search_kv_16 (p, bucket_contents, - (u32x4 *) keys[i]); - break; - case 8: - value = - pfhash_search_kv_8 (p, bucket_contents, (u64 *) keys[i]); - break; - case 4: - value = - pfhash_search_kv_4 (p, bucket_contents, (u32 *) keys[i]); - break; - } - if (value != (u32) ~ 0) - clib_warning ("key %d bucket %d lookup FAIL\n", i, bucket); - } - } - pfhash_free (p); - } - - exit (0); -} -#else -int -test_pfhash_main (unformat_input_t * input) -{ - clib_warning ("MMX unit not available"); - return 0; -} -#endif - -#ifdef CLIB_UNIX -int -main (int argc, char *argv[]) -{ - unformat_input_t i; - int ret; - - unformat_init_command_line (&i, argv); - ret = test_pfhash_main (&i); - unformat_free (&i); - - return ret; -} -#endif /* CLIB_UNIX */ - -/* - * fd.io coding-style-patch-verification: ON - * - * Local Variables: - * eval: (c-set-style "gnu") - * End: - */ diff --git a/src/vppinfra/test_pool.c b/src/vppinfra/test_pool.c deleted file mode 100644 index 67a5e50a38a..00000000000 --- a/src/vppinfra/test_pool.c +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (c) 2015 Cisco and/or its affiliates. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/* - Copyright (c) 2001, 2002, 2003 Eliot Dresselhaus - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -#include <vppinfra/mem.h> -#include <vppinfra/pool.h> - -#ifdef __KERNEL__ -#include <linux/unistd.h> -#else -#include <unistd.h> -#endif - -int -main (int argc, char *argv[]) -{ - int i, n, seed; - - int *p = 0, *e, j, *o = 0; - - n = atoi (argv[1]); - seed = getpid (); - srandom (1); - - for (i = 0; i < n; i++) - { - if (vec_len (o) < 10 || (random () & 1)) - { - pool_get (p, e); - j = e - p; - *e = j; - vec_add1 (o, j); - } - else - { - j = random () % vec_len (o); - e = p + j; - pool_put (p, e); - vec_delete (o, 1, j); - } - } - p = pool_free (p); - vec_free (o); - return 0; -} - -/* - * fd.io coding-style-patch-verification: ON - * - * Local Variables: - * eval: (c-set-style "gnu") - * End: - */ |