DPDK patches and discussions
 help / color / mirror / Atom feed
From: Pablo de Lara <pablo.de.lara.guarch@intel.com>
To: dev@dpdk.org
Cc: bruce.richardson@intel.com,
	Pablo de Lara <pablo.de.lara.guarch@intel.com>
Subject: [dpdk-dev] [PATCH 3/3] hash: check if slot is empty with key index
Date: Fri, 26 Aug 2016 22:30:09 +0100	[thread overview]
Message-ID: <1472247009-166860-4-git-send-email-pablo.de.lara.guarch@intel.com> (raw)
In-Reply-To: <1472247009-166860-1-git-send-email-pablo.de.lara.guarch@intel.com>

Instead of checking if the current and alternative signatures are 0,
it is faster to check if the key index associated to an entry
is 0, meaning that the slot is empty.

Signed-off-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
---
 lib/librte_hash/rte_cuckoo_hash.c     | 16 ++++++++--------
 lib/librte_hash/rte_cuckoo_hash.h     |  2 ++
 lib/librte_hash/rte_cuckoo_hash_x86.h |  5 ++---
 3 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/lib/librte_hash/rte_cuckoo_hash.c b/lib/librte_hash/rte_cuckoo_hash.c
index be1490a..dd0290f 100644
--- a/lib/librte_hash/rte_cuckoo_hash.c
+++ b/lib/librte_hash/rte_cuckoo_hash.c
@@ -423,7 +423,7 @@ make_space_bucket(const struct rte_hash *h, struct rte_hash_bucket *bkt)
 		next_bucket_idx = bkt->signatures[i].alt & h->bucket_bitmask;
 		next_bkt[i] = &h->buckets[next_bucket_idx];
 		for (j = 0; j < RTE_HASH_BUCKET_ENTRIES; j++) {
-			if (next_bkt[i]->signatures[j].sig == NULL_SIGNATURE)
+			if (next_bkt[i]->key_idx[j] == EMPTY_SLOT)
 				break;
 		}
 
@@ -609,7 +609,7 @@ __rte_hash_add_key_with_hash(const struct rte_hash *h, const void *key,
 #endif
 		for (i = 0; i < RTE_HASH_BUCKET_ENTRIES; i++) {
 			/* Check if slot is available */
-			if (likely(prim_bkt->signatures[i].sig == NULL_SIGNATURE)) {
+			if (likely(prim_bkt->key_idx[i] == EMPTY_SLOT)) {
 				prim_bkt->signatures[i].current = sig;
 				prim_bkt->signatures[i].alt = alt_hash;
 				prim_bkt->key_idx[i] = new_idx;
@@ -707,7 +707,7 @@ __rte_hash_lookup_with_hash(const struct rte_hash *h, const void *key,
 	/* Check if key is in primary location */
 	for (i = 0; i < RTE_HASH_BUCKET_ENTRIES; i++) {
 		if (bkt->signatures[i].current == sig &&
-				bkt->signatures[i].sig != NULL_SIGNATURE) {
+				bkt->key_idx[i] != EMPTY_SLOT) {
 			k = (struct rte_hash_key *) ((char *)keys +
 					bkt->key_idx[i] * h->key_entry_size);
 			if (rte_hash_cmp_eq(key, k->key, h) == 0) {
@@ -823,7 +823,7 @@ __rte_hash_del_key_with_hash(const struct rte_hash *h, const void *key,
 	/* Check if key is in primary location */
 	for (i = 0; i < RTE_HASH_BUCKET_ENTRIES; i++) {
 		if (bkt->signatures[i].current == sig &&
-				bkt->signatures[i].sig != NULL_SIGNATURE) {
+				bkt->key_idx[i] != EMPTY_SLOT) {
 			k = (struct rte_hash_key *) ((char *)keys +
 					bkt->key_idx[i] * h->key_entry_size);
 			if (rte_hash_cmp_eq(key, k->key, h) == 0) {
@@ -834,7 +834,7 @@ __rte_hash_del_key_with_hash(const struct rte_hash *h, const void *key,
 				 * substracting the first dummy index
 				 */
 				ret = bkt->key_idx[i] - 1;
-				bkt->key_idx[i] = 0;
+				bkt->key_idx[i] = EMPTY_SLOT;
 				return ret;
 			}
 		}
@@ -848,7 +848,7 @@ __rte_hash_del_key_with_hash(const struct rte_hash *h, const void *key,
 	/* Check if key is in secondary location */
 	for (i = 0; i < RTE_HASH_BUCKET_ENTRIES; i++) {
 		if (bkt->signatures[i].current == alt_hash &&
-				bkt->signatures[i].sig != NULL_SIGNATURE) {
+				bkt->key_idx[i] != EMPTY_SLOT) {
 			k = (struct rte_hash_key *) ((char *)keys +
 					bkt->key_idx[i] * h->key_entry_size);
 			if (rte_hash_cmp_eq(key, k->key, h) == 0) {
@@ -859,7 +859,7 @@ __rte_hash_del_key_with_hash(const struct rte_hash *h, const void *key,
 				 * substracting the first dummy index
 				 */
 				ret = bkt->key_idx[i] - 1;
-				bkt->key_idx[i] = 0;
+				bkt->key_idx[i] = EMPTY_SLOT;
 				return ret;
 			}
 		}
@@ -1229,7 +1229,7 @@ rte_hash_iterate(const struct rte_hash *h, const void **key, void **data, uint32
 	idx = *next % RTE_HASH_BUCKET_ENTRIES;
 
 	/* If current position is empty, go to the next one */
-	while (h->buckets[bucket_idx].signatures[idx].sig == NULL_SIGNATURE) {
+	while (h->buckets[bucket_idx].key_idx[idx] == EMPTY_SLOT) {
 		(*next)++;
 		/* End of table */
 		if (*next == total_entries)
diff --git a/lib/librte_hash/rte_cuckoo_hash.h b/lib/librte_hash/rte_cuckoo_hash.h
index 6c76700..e290dab 100644
--- a/lib/librte_hash/rte_cuckoo_hash.h
+++ b/lib/librte_hash/rte_cuckoo_hash.h
@@ -134,6 +134,8 @@ enum add_key_case {
 
 #define NULL_SIGNATURE			0
 
+#define EMPTY_SLOT			0
+
 #define KEY_ALIGNMENT			16
 
 #define LCORE_CACHE_SIZE		64
diff --git a/lib/librte_hash/rte_cuckoo_hash_x86.h b/lib/librte_hash/rte_cuckoo_hash_x86.h
index fa5630b..e16d69c 100644
--- a/lib/librte_hash/rte_cuckoo_hash_x86.h
+++ b/lib/librte_hash/rte_cuckoo_hash_x86.h
@@ -53,8 +53,7 @@ rte_hash_cuckoo_insert_mw_tm(struct rte_hash_bucket *prim_bkt,
 			*/
 			for (i = 0; i < RTE_HASH_BUCKET_ENTRIES; i++) {
 				/* Check if slot is available */
-				if (likely(prim_bkt->signatures[i].sig ==
-						NULL_SIGNATURE)) {
+				if (likely(prim_bkt->key_idx == EMPTY_SLOT)) {
 					prim_bkt->signatures[i].current = sig;
 					prim_bkt->signatures[i].alt = alt_hash;
 					prim_bkt->key_idx[i] = new_idx;
@@ -171,7 +170,7 @@ rte_hash_cuckoo_make_space_mw_tm(const struct rte_hash *h,
 					queue + RTE_HASH_BFS_QUEUE_MAX_LEN - 4)) {
 		curr_bkt = tail->bkt;
 		for (i = 0; i < RTE_HASH_BUCKET_ENTRIES; i++) {
-			if (curr_bkt->signatures[i].sig == NULL_SIGNATURE) {
+			if (curr_bkt->key_idx[i] == EMPTY_SLOT) {
 				if (likely(rte_hash_cuckoo_move_insert_mw_tm(h,
 						tail, i, sig,
 						alt_hash, new_idx) == 0))
-- 
2.7.4

  parent reply	other threads:[~2016-08-26 21:29 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-26 21:30 [dpdk-dev] [PATCH 0/3] Hash library fixes Pablo de Lara
2016-08-26 21:30 ` [dpdk-dev] [PATCH 1/3] hash: fix ring size Pablo de Lara
2016-08-26 21:30 ` [dpdk-dev] [PATCH 2/3] hash: fix false zero signature key hit lookup Pablo de Lara
2016-08-26 21:30 ` Pablo de Lara [this message]
2016-08-29  6:58 ` [dpdk-dev] [PATCH 0/3] Hash library fixes Christian Ehrhardt
2016-09-27 22:34 ` Edupuganti, Saikrishna
2016-09-29 19:52   ` Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1472247009-166860-4-git-send-email-pablo.de.lara.guarch@intel.com \
    --to=pablo.de.lara.guarch@intel.com \
    --cc=bruce.richardson@intel.com \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).