[dpdk-dev] [PATCH v2 07/11] hash: add new function rte_hash_reset
Pablo de Lara
pablo.de.lara.guarch at intel.com
Fri Jun 26 00:05: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 | 3 +--
app/test/test_hash_perf.c | 11 +++--------
lib/librte_hash/rte_cuckoo_hash.c | 21 +++++++++++++++++++++
lib/librte_hash/rte_hash.h | 11 +++++++++--
lib/librte_hash/rte_hash_version.map | 1 +
5 files changed, 35 insertions(+), 12 deletions(-)
diff --git a/app/test/test_hash.c b/app/test/test_hash.c
index 52de1bd..b1ca939 100644
--- a/app/test/test_hash.c
+++ b/app/test/test_hash.c
@@ -1156,8 +1156,7 @@ static int test_average_table_utilization(void)
no_space = 0;
/* Reset the table */
- rte_hash_free(handle);
- rte_hash_create(&ut_params);
+ rte_hash_reset(handle);
}
const unsigned average_keys_added = added_keys_until_no_space / ITERATIONS;
diff --git a/app/test/test_hash_perf.c b/app/test/test_hash_perf.c
index 469000e..db0c5e8 100644
--- a/app/test/test_hash_perf.c
+++ b/app/test/test_hash_perf.c
@@ -352,14 +352,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
@@ -396,8 +392,7 @@ run_all_tbl_perf_tests(void)
if (timed_deletes(1, i) < 0)
return -1;
- if (reset_table(i) < 0)
- return -1;
+ reset_table(i);
printf("\n ----- WITH JUST KEYS -----\n\n");
diff --git a/lib/librte_hash/rte_cuckoo_hash.c b/lib/librte_hash/rte_cuckoo_hash.c
index f1b6df0..8e5b9a6 100644
--- a/lib/librte_hash/rte_cuckoo_hash.c
+++ b/lib/librte_hash/rte_cuckoo_hash.c
@@ -356,6 +356,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);
+
+ /* 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));
+}
+
/*
* Try to insert a new entry. If bucket has space, hash value and key index
* to the key table are copied.
diff --git a/lib/librte_hash/rte_hash.h b/lib/librte_hash/rte_hash.h
index 7f7e75f..fa327c2 100644
--- a/lib/librte_hash/rte_hash.h
+++ b/lib/librte_hash/rte_hash.h
@@ -132,8 +132,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 fd92def..f011054 100644
--- a/lib/librte_hash/rte_hash_version.map
+++ b/lib/librte_hash/rte_hash_version.map
@@ -22,6 +22,7 @@ DPDK_2.1 {
global:
rte_hash_lookup_bulk_with_hash;
+ rte_hash_reset;
local: *;
} DPDK_2.0;
--
2.4.2
More information about the dev
mailing list