From mboxrd@z Thu Jan 1 00:00:00 1970 From: Pablo de Lara Subject: [PATCH v3 07/11] hash: add new function rte_hash_reset Date: Sun, 28 Jun 2015 23:25:26 +0100 Message-ID: <1435530330-10132-8-git-send-email-pablo.de.lara.guarch@intel.com> References: <1435269919-7007-1-git-send-email-pablo.de.lara.guarch@intel.com> <1435530330-10132-1-git-send-email-pablo.de.lara.guarch@intel.com> To: dev@dpdk.org Return-path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id 5EBE3C55C for ; Mon, 29 Jun 2015 00:25:33 +0200 (CEST) In-Reply-To: <1435530330-10132-1-git-send-email-pablo.de.lara.guarch@intel.com> List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Added reset function to be able to empty the table, without having to destroy and create it again. Signed-off-by: Pablo de Lara --- 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 86295b8..6e8b255 100644 --- a/app/test/test_hash_perf.c +++ b/app/test/test_hash_perf.c @@ -368,14 +368,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 @@ -417,8 +413,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 1e70069..44f87fb 100644 --- a/lib/librte_hash/rte_cuckoo_hash.c +++ b/lib/librte_hash/rte_cuckoo_hash.c @@ -358,6 +358,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)); +} + /* * 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