[dpdk-dev] [PATCH v6 2/7] hash: add new function rte_hash_reset

Pablo de Lara pablo.de.lara.guarch at intel.com
Sat Jul 11 01:30:15 CEST 2015


Added reset function to be able to empty the table,
without having to destroy and create it again.

Signed-off-by: Pablo de Lara <pablo.de.lara.guarch at intel.com>
---
 app/test/test_hash.c                 |  4 +---
 app/test/test_hash_perf.c            | 12 +++---------
 lib/librte_hash/rte_cuckoo_hash.c    | 21 +++++++++++++++++++++
 lib/librte_hash/rte_hash.h           | 11 +++++++++--
 lib/librte_hash/rte_hash_version.map |  8 ++++++++
 5 files changed, 42 insertions(+), 14 deletions(-)

diff --git a/app/test/test_hash.c b/app/test/test_hash.c
index e70d859..448586c 100644
--- a/app/test/test_hash.c
+++ b/app/test/test_hash.c
@@ -1132,9 +1132,7 @@ static int test_average_table_utilization(void)
 		average_keys_added += added_keys;
 
 		/* Reset the table */
-		rte_hash_free(handle);
-		handle = rte_hash_create(&ut_params);
-		RETURN_IF_ERROR(handle == NULL, "hash creation failed");
+		rte_hash_reset(handle);
 
 		/* Print a dot to show progress on operations */
 		printf(".");
diff --git a/app/test/test_hash_perf.c b/app/test/test_hash_perf.c
index a54f3c1..b01b040 100644
--- a/app/test/test_hash_perf.c
+++ b/app/test/test_hash_perf.c
@@ -382,14 +382,10 @@ free_table(unsigned table_index)
 	rte_hash_free(h[table_index]);
 }
 
-static int
+static void
 reset_table(unsigned table_index)
 {
-	free_table(table_index);
-	if (create_table(table_index) != 0)
-		return -1;
-
-	return 0;
+	rte_hash_reset(h[table_index]);
 }
 
 static int
@@ -421,13 +417,11 @@ run_all_tbl_perf_tests(unsigned with_pushes)
 			if (timed_deletes(with_hash, i) < 0)
 				return -1;
 
-			if (reset_table(i) < 0)
-				return -1;
+			reset_table(i);
 
 			/* Print a dot to show progress on operations */
 			printf(".");
 			fflush(stdout);
-
 		}
 
 		free_table(i);
diff --git a/lib/librte_hash/rte_cuckoo_hash.c b/lib/librte_hash/rte_cuckoo_hash.c
index 50e3acd..15c5da5 100644
--- a/lib/librte_hash/rte_cuckoo_hash.c
+++ b/lib/librte_hash/rte_cuckoo_hash.c
@@ -371,6 +371,27 @@ rte_hash_secondary_hash(const hash_sig_t primary_hash)
 	return (primary_hash ^ ((tag + 1) * alt_bits_xor));
 }
 
+void
+rte_hash_reset(struct rte_hash *h)
+{
+	void *ptr;
+	unsigned i;
+
+	if (h == NULL)
+		return;
+
+	memset(h->buckets, 0, h->num_buckets * sizeof(struct rte_hash_bucket));
+	memset(h->key_store, 0, h->key_entry_size * (h->entries + 1));
+
+	/* clear the free ring */
+	while (rte_ring_dequeue(h->free_slots, &ptr) == 0)
+		rte_pause();
+
+	/* Repopulate the free slots ring. Entry zero is reserved for key misses */
+	for (i = 1; i < h->entries + 1; i++)
+		rte_ring_sp_enqueue(h->free_slots, (void *)((uintptr_t) i));
+}
+
 /* Search for an entry that can be pushed to its alternative location */
 static inline int
 make_space_bucket(const struct rte_hash *h, struct rte_hash_bucket *bkt)
diff --git a/lib/librte_hash/rte_hash.h b/lib/librte_hash/rte_hash.h
index 936d170..8bbc9f0 100644
--- a/lib/librte_hash/rte_hash.h
+++ b/lib/librte_hash/rte_hash.h
@@ -128,8 +128,15 @@ void
 rte_hash_free(struct rte_hash *h);
 
 /**
- * Add a key to an existing hash table.
- * This operation is not multi-thread safe
+ * Reset all hash structure, by zeroing all entries
+ * @param h
+ *   Hash table to reset
+ */
+void
+rte_hash_reset(struct rte_hash *h);
+
+/**
+ * Add a key to an existing hash table. This operation is not multi-thread safe
  * and should only be called from one thread.
  *
  * @param h
diff --git a/lib/librte_hash/rte_hash_version.map b/lib/librte_hash/rte_hash_version.map
index 94a0fec..d5f5af5 100644
--- a/lib/librte_hash/rte_hash_version.map
+++ b/lib/librte_hash/rte_hash_version.map
@@ -18,3 +18,11 @@ DPDK_2.0 {
 
 	local: *;
 };
+
+DPDK_2.1 {
+	global:
+
+	rte_hash_reset;
+
+	local: *;
+} DPDK_2.0;
-- 
2.4.3



More information about the dev mailing list