From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by dpdk.org (Postfix) with ESMTP id D506DC762 for ; Fri, 26 Jun 2015 00:08:33 +0200 (CEST) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga101.jf.intel.com with ESMTP; 25 Jun 2015 15:08:31 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.13,680,1427785200"; d="scan'208";a="750578485" Received: from msvmon001.ims.intel.com ([10.125.148.15]) by fmsmga002.fm.intel.com with ESMTP; 25 Jun 2015 15:08:30 -0700 Received: from sivswdev02.ir.intel.com (sivswdev02.ir.intel.com [10.237.217.46]) by msvmon001.ims.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id t5PM8TWb028739; Fri, 26 Jun 2015 01:08:29 +0300 Received: from sivswdev02.ir.intel.com (localhost [127.0.0.1]) by sivswdev02.ir.intel.com with ESMTP id t5PM5KOw007096; Thu, 25 Jun 2015 23:05:20 +0100 Received: (from pdelarax@localhost) by sivswdev02.ir.intel.com with id t5PM5Kkd007092; Thu, 25 Jun 2015 23:05:20 +0100 From: Pablo de Lara To: dev@dpdk.org Date: Thu, 25 Jun 2015 23:05:15 +0100 Message-Id: <1435269919-7007-8-git-send-email-pablo.de.lara.guarch@intel.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1435269919-7007-1-git-send-email-pablo.de.lara.guarch@intel.com> References: <1433514804-7075-1-git-send-email-pablo.de.lara.guarch@intel.com> <1435269919-7007-1-git-send-email-pablo.de.lara.guarch@intel.com> Subject: [dpdk-dev] [PATCH v2 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: Thu, 25 Jun 2015 22:08: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 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