summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPierre Pfister <ppfister@cisco.com>2018-08-20 13:48:15 +0200
committerDamjan Marion <dmarion@me.com>2018-08-20 19:30:22 +0000
commit052c2dc7e1fb5c9ec793371b48b988cfeed1c87f (patch)
treec2b89a864cab0208d58c6b18e30e4c06c78ec368
parent324454492cdc1022397486bb54db63d96e14532c (diff)
Enable storing state in flowhash hash tables
Flowhash user can now rely on the table to be initialized to zero and know when an entry is cleaned up by the garbage collector. This is usefull to store state in flowhash entries without the need for callbacks when an entry timeouts. Change-Id: Ieece6b7277241f84ea3f2473d0771c6ee8ce460c Signed-off-by: Pierre Pfister <ppfister@cisco.com>
-rw-r--r--src/vppinfra/flowhash_template.h13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/vppinfra/flowhash_template.h b/src/vppinfra/flowhash_template.h
index 359b9690a50..92272563878 100644
--- a/src/vppinfra/flowhash_template.h
+++ b/src/vppinfra/flowhash_template.h
@@ -374,6 +374,7 @@ FVT(flowhash) *FV(flowhash_alloc)(u32 fixed_entries, u32 collision_buckets)
/* Fill free elements list */
int i;
+ memset(h->entries, 0, sizeof(h->entries[0]) * entries);
for (i = 1; i <= collision_buckets; i++)
{
h->free_buckets_indices[-i] =
@@ -525,9 +526,13 @@ FV(__flowhash_get_chained) (FVT(flowhash) *h, FVT(flowhash_lkey) *k,
}
static_always_inline void
-FV(flowhash_gc)(FVT(flowhash) *h, u32 time_now)
+FV(flowhash_gc)(FVT(flowhash) *h, u32 time_now,
+ u32 *freed_index, u32 *freed_len)
{
u32 ei;
+ if (freed_index)
+ *freed_len = 0;
+
if (PREDICT_FALSE(h->collision_buckets_mask == (((u32)0) - 1)))
return;
@@ -565,6 +570,12 @@ FV(flowhash_gc)(FVT(flowhash) *h, u32 time_now)
if (!found)
{
+ /* Tell caller we freed this */
+ if (freed_index)
+ {
+ *freed_index = ei;
+ *freed_len = FLOWHASH_ENTRIES_PER_BUCKETS;
+ }
/* The bucket is not used. Let's free it. */
h->free_buckets_position--;
/* Reset forward link */