classify: improve find entry performance 63/33763/1
authorDamjan Marion <damarion@cisco.com>
Mon, 20 Sep 2021 15:12:03 +0000 (17:12 +0200)
committerDamjan Marion <damarion@cisco.com>
Mon, 20 Sep 2021 15:44:10 +0000 (17:44 +0200)
Type: improvement
Change-Id: I5245fc3f35b7a70833916db2ebf33f7c87398915
Signed-off-by: Damjan Marion <damarion@cisco.com>
src/vnet/classify/vnet_classify.h

index 196a241..11b0530 100644 (file)
@@ -408,9 +408,7 @@ vnet_classify_find_entry_inline (vnet_classify_table_t *t, const u8 *h,
     u64 as_u64[2];
   } result __attribute__ ((aligned (sizeof (u32x4))));
   vnet_classify_bucket_t *b;
-  u32 value_index;
-  u32 bucket_index;
-  u32 limit;
+  u32 bucket_index, limit, pages;
   int i;
 
   bucket_index = hash & (t->nbuckets - 1);
@@ -420,18 +418,19 @@ vnet_classify_find_entry_inline (vnet_classify_table_t *t, const u8 *h,
   if (b->offset == 0)
     return 0;
 
-  hash >>= t->log2_nbuckets;
-
+  pages = 1 << b->log2_pages;
   v = vnet_classify_get_entry (t, b->offset);
-  value_index = hash & ((1 << b->log2_pages) - 1);
   limit = t->entries_per_page;
   if (PREDICT_FALSE (b->linear_search))
     {
-      value_index = 0;
-      limit *= (1 << b->log2_pages);
+      limit *= pages;
+      v = vnet_classify_entry_at_index (t, v, 0);
+    }
+  else
+    {
+      hash >>= t->log2_nbuckets;
+      v = vnet_classify_entry_at_index (t, v, hash & (pages - 1));
     }
-
-  v = vnet_classify_entry_at_index (t, v, value_index);
 
 #ifdef CLIB_HAVE_VEC128
   const u32x4u *data = (const u32x4u *) h;