From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by dpdk.org (Postfix) with ESMTP id AE001C400 for ; Fri, 10 Jul 2015 19:24:34 +0200 (CEST) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga102.jf.intel.com with ESMTP; 10 Jul 2015 10:24:36 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.15,448,1432623600"; d="scan'208";a="726563786" Received: from pdelarag-mobl.ger.corp.intel.com ([10.237.208.60]) by orsmga001.jf.intel.com with SMTP; 10 Jul 2015 10:24:33 -0700 Received: by (sSMTP sendmail emulation); Fri, 10 Jul 2015 18:24:31 +0100 From: Pablo de Lara To: dev@dpdk.org Date: Fri, 10 Jul 2015 18:24:19 +0100 Message-Id: <1436549064-5200-3-git-send-email-pablo.de.lara.guarch@intel.com> X-Mailer: git-send-email 2.4.5 In-Reply-To: <1436549064-5200-1-git-send-email-pablo.de.lara.guarch@intel.com> References: <1435530330-10132-1-git-send-email-pablo.de.lara.guarch@intel.com> <1436549064-5200-1-git-send-email-pablo.de.lara.guarch@intel.com> Subject: [dpdk-dev] [PATCH v4 2/7] hash: add new function rte_hash_reset X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 10 Jul 2015 17:24:35 -0000 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 | 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.2