tcp: avoid fr segments less than mss if possible
[vpp.git] / src / vppinfra / test_bihash_template.c
index c1a4469..17cc056 100644 (file)
@@ -73,9 +73,9 @@ test_bihash_vec64 (test_main_t * tm)
   h = &tm->hash;
 
 #if BIHASH_32_64_SVM
-  BV (clib_bihash_master_init_svm) (h, "test", user_buckets,
-                                   0x30000000 /* base_addr */ ,
-                                   user_memory_size);
+  BV (clib_bihash_initiator_init_svm) (h, "test", user_buckets,
+                                      0x30000000 /* base_addr */ ,
+                                      user_memory_size);
 #else
   BV (clib_bihash_init) (h, "test", user_buckets, user_memory_size);
 #endif
@@ -123,9 +123,9 @@ test_bihash_stale_overwrite (test_main_t * tm)
   h = &tm->hash;
 
 #if BIHASH_32_64_SVM
-  BV (clib_bihash_master_init_svm) (h, "test", tm->nbuckets,
-                                   0x30000000 /* base_addr */ ,
-                                   tm->hash_memory_size);
+  BV (clib_bihash_initiator_init_svm) (h, "test", tm->nbuckets,
+                                      0x30000000 /* base_addr */ ,
+                                      tm->hash_memory_size);
 #else
   BV (clib_bihash_init) (h, "test", tm->nbuckets, tm->hash_memory_size);
 #endif
@@ -208,9 +208,9 @@ test_bihash_threads (test_main_t * tm)
   h = &tm->hash;
 
 #if BIHASH_32_64_SVM
-  BV (clib_bihash_master_init_svm) (h, "test", tm->nbuckets,
-                                   0x30000000 /* base_addr */ ,
-                                   tm->hash_memory_size);
+  BV (clib_bihash_initiator_init_svm) (h, "test", tm->nbuckets,
+                                      0x30000000 /* base_addr */ ,
+                                      tm->hash_memory_size);
 #else
   BV (clib_bihash_init) (h, "test", tm->nbuckets, tm->hash_memory_size);
 #endif
@@ -247,6 +247,59 @@ test_bihash_threads (test_main_t * tm)
   return 0;
 }
 
+static clib_error_t *
+test_bihash_vanilla_overwrite (test_main_t *tm)
+{
+  int i;
+  BVT (clib_bihash) * h;
+  BVT (clib_bihash_kv) kv;
+
+  h = &tm->hash;
+
+#if BIHASH_32_64_SVM
+  BV (clib_bihash_initiator_init_svm)
+  (h, "test", tm->nbuckets, 0x30000000 /* base_addr */, tm->hash_memory_size);
+#else
+  BV (clib_bihash_init) (h, "test", tm->nbuckets, tm->hash_memory_size);
+#endif
+
+  for (i = 0; i < 100; i++)
+    {
+      kv.key = 12345;
+      kv.value = i;
+
+      BV (clib_bihash_add_del) (h, &kv, 1 /* is_add */);
+    }
+
+  fformat (stdout, "End of run, should one item...\n");
+  fformat (stdout, "%U", BV (format_bihash), h, 0 /* very verbose */);
+  BV (clib_bihash_free) (h);
+  return 0;
+}
+
+static clib_error_t *
+test_bihash_value_assert (test_main_t *tm)
+{
+  BVT (clib_bihash) * h;
+  BVT (clib_bihash_kv) kv;
+
+  h = &tm->hash;
+
+#if BIHASH_32_64_SVM
+  BV (clib_bihash_initiator_init_svm)
+  (h, "test", tm->nbuckets, 0x30000000 /* base_addr */, tm->hash_memory_size);
+#else
+  BV (clib_bihash_init) (h, "test", tm->nbuckets, tm->hash_memory_size);
+#endif
+
+  kv.key = 12345;
+  kv.value = 0xFEEDFACE8BADF00DULL;
+
+  fformat (stderr, "The following add should ASSERT...\n");
+  BV (clib_bihash_add_del) (h, &kv, 1 /* is_add */);
+
+  return 0;
+}
 
 static clib_error_t *
 test_bihash (test_main_t * tm)
@@ -262,9 +315,9 @@ test_bihash (test_main_t * tm)
   h = &tm->hash;
 
 #if BIHASH_32_64_SVM
-  BV (clib_bihash_master_init_svm) (h, "test", tm->nbuckets,
-                                   0x30000000 /* base_addr */ ,
-                                   tm->hash_memory_size);
+  BV (clib_bihash_initiator_init_svm) (h, "test", tm->nbuckets,
+                                      0x30000000 /* base_addr */ ,
+                                      tm->hash_memory_size);
 #else
   BV (clib_bihash_init) (h, "test", tm->nbuckets, tm->hash_memory_size);
 #endif
@@ -337,6 +390,16 @@ test_bihash (test_main_t * tm)
        {
          for (i = 0; i < tm->nitems; i++)
            {
+             /* Prefetch buckets 8 iterations ahead */
+             if (1 && (i < ((i64) tm->nitems - 8)))
+               {
+                 BVT (clib_bihash_kv) pref_kv;
+                 u64 pref_hash;
+                 pref_kv.key = tm->keys[i + 8];
+                 pref_hash = BV (clib_bihash_hash) (&pref_kv);
+                 BV (clib_bihash_prefetch_bucket) (h, pref_hash);
+               }
+
              kv.key = tm->keys[i];
              if (BV (clib_bihash_search) (h, &kv, &kv) < 0)
                if (BV (clib_bihash_search) (h, &kv, &kv) < 0)
@@ -356,8 +419,10 @@ test_bihash (test_main_t * tm)
          total_searches = (uword) tm->search_iter * (uword) tm->nitems;
 
          if (delta > 0)
-           fformat (stdout, "%.f searches per second\n",
-                    ((f64) total_searches) / delta);
+           fformat (stdout,
+                    "%.f searches per second, %.2f nsec per search\n",
+                    ((f64) total_searches) / delta,
+                    1e9 * (delta / ((f64) total_searches)));
 
          fformat (stdout, "%lld searches in %.6f seconds\n", total_searches,
                   delta);
@@ -409,6 +474,16 @@ test_bihash (test_main_t * tm)
            {
              for (j = 0; j < tm->nitems; j++)
                {
+                 /* Prefetch buckets 8 iterations ahead */
+                 if (1 && (j < ((i64) tm->nitems - 8)))
+                   {
+                     BVT (clib_bihash_kv) pref_kv;
+                     u64 pref_hash;
+                     pref_kv.key = tm->keys[j + 8];
+                     pref_hash = BV (clib_bihash_hash) (&pref_kv);
+                     BV (clib_bihash_prefetch_bucket) (h, pref_hash);
+                   }
+
                  kv.key = tm->keys[j];
                  rv = BV (clib_bihash_search) (h, &kv, &kv);
                  if (j <= i && rv >= 0)
@@ -492,6 +567,10 @@ test_bihash_main (test_main_t * tm)
        tm->verbose = 1;
       else if (unformat (i, "stale-overwrite"))
        which = 3;
+      else if (unformat (i, "overwrite"))
+       which = 4;
+      else if (unformat (i, "value-assert"))
+       which = 5;
       else
        return clib_error_return (0, "unknown input '%U'",
                                  format_unformat_error, i);
@@ -500,8 +579,7 @@ test_bihash_main (test_main_t * tm)
   /* Preallocate hash table, key vector */
   tm->key_hash = hash_create (tm->nitems, sizeof (uword));
   vec_validate (tm->keys, tm->nitems - 1);
-  _vec_len (tm->keys) = 0;
-
+  vec_set_len (tm->keys, 0);
 
   switch (which)
     {
@@ -521,6 +599,14 @@ test_bihash_main (test_main_t * tm)
       error = test_bihash_stale_overwrite (tm);
       break;
 
+    case 4:
+      error = test_bihash_vanilla_overwrite (tm);
+      break;
+
+    case 5:
+      error = test_bihash_value_assert (tm);
+      break;
+
     default:
       return clib_error_return (0, "no such test?");
     }