From mboxrd@z Thu Jan 1 00:00:00 1970 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) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga101.fm.intel.com with ESMTP; 28 Jun 2015 15:25:32 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.13,695,1427785200"; d="scan'208";a="719249698" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by orsmga001.jf.intel.com with ESMTP; 28 Jun 2015 15:25:31 -0700 Received: from sivswdev02.ir.intel.com (sivswdev02.ir.intel.com [10.237.217.46]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id t5SMPUlO030626; Sun, 28 Jun 2015 23:25:30 +0100 Received: from sivswdev02.ir.intel.com (localhost [127.0.0.1]) by sivswdev02.ir.intel.com with ESMTP id t5SMPUqk010216; Sun, 28 Jun 2015 23:25:30 +0100 Received: (from pdelarax@localhost) by sivswdev02.ir.intel.com with id t5SMPUOJ010212; Sun, 28 Jun 2015 23:25:30 +0100 From: Pablo de Lara To: dev@dpdk.org Date: Sun, 28 Jun 2015 23:25:26 +0100 Message-Id: <1435530330-10132-8-git-send-email-pablo.de.lara.guarch@intel.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1435530330-10132-1-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> Subject: [dpdk-dev] [PATCH v3 07/11] 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: Sun, 28 Jun 2015 22:25:34 -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 | 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