[dpdk-dev,6/6] static variable whouldn't be used to compute recursion level

Message ID 1503087559-103390-1-git-send-email-mike.stolarchuk@bigswitch.com (mailing list archive)
State Rejected, archived
Delegated to: Thomas Monjalon
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation fail apply issues

Commit Message

mstolarchuk Aug. 18, 2017, 8:19 p.m. UTC
  the 'static nr_pushes' variable creates a single instance of the value
across multiple invocations of the same procedure.   In the case of
a numa machine, this variable is then associated with one specifci numa
node, degrading performance.

but the more troublesome issue iw when two unrelated threads
are inserting into the hash, each of these threads treat
this static as their own property.

Signed-off-by: mstolarchuk <mike.stolarchuk@bigswitch.com>
---
 lib/librte_hash/rte_cuckoo_hash.c | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)
  

Patch

diff --git a/lib/librte_hash/rte_cuckoo_hash.c b/lib/librte_hash/rte_cuckoo_hash.c
index 946252f..4567eb7 100644
--- a/lib/librte_hash/rte_cuckoo_hash.c
+++ b/lib/librte_hash/rte_cuckoo_hash.c
@@ -417,9 +417,10 @@  struct rte_hash *
 
 /* 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)
+__make_space_bucket(const struct rte_hash *h,
+	struct rte_hash_bucket *bkt,
+	unsigned int *nr_pushes)
 {
-	static unsigned int nr_pushes;
 	unsigned i, j;
 	int ret;
 	uint32_t next_bucket_idx;
@@ -456,15 +457,15 @@  struct rte_hash *
 			break;
 
 	/* All entries have been pushed, so entry cannot be added */
-	if (i == RTE_HASH_BUCKET_ENTRIES || nr_pushes > RTE_HASH_MAX_PUSHES)
+	if (i == RTE_HASH_BUCKET_ENTRIES || nr_pushes[0] > RTE_HASH_MAX_PUSHES)
 		return -ENOSPC;
 
 	/* Set flag to indicate that this entry is going to be pushed */
 	bkt->flag[i] = 1;
 
-	nr_pushes++;
+	nr_pushes[0]++;
 	/* Need room in alternative bucket to insert the pushed entry */
-	ret = make_space_bucket(h, next_bkt[i]);
+	ret = __make_space_bucket(h, next_bkt[i], nr_pushes);
 	/*
 	 * After recursive function.
 	 * Clear flags and insert the pushed entry
@@ -472,7 +473,7 @@  struct rte_hash *
 	 * or return error
 	 */
 	bkt->flag[i] = 0;
-	nr_pushes = 0;
+	nr_pushes[0] = 0;
 	if (ret >= 0) {
 		next_bkt[i]->sig_alt[ret] = bkt->sig_current[i];
 		next_bkt[i]->sig_current[ret] = bkt->sig_alt[i];
@@ -483,6 +484,14 @@  struct rte_hash *
 
 }
 
+static inline int
+make_space_bucket(const struct rte_hash *h, struct rte_hash_bucket *bkt)
+{
+	unsigned int nr_pushes = 0;
+
+	return __make_space_bucket(h, bkt, &nr_pushes);
+}
+
 /*
  * Function called to enqueue back an index in the cache/ring,
  * as slot has not being used and it can be used in the