DPDK patches and discussions
 help / color / mirror / Atom feed
From: Anatoly Burakov <anatoly.burakov@intel.com>
To: dev@dpdk.org
Subject: [dpdk-dev] [PATCH 2/9] fbarray: reduce duplication in find_contig code
Date: Mon, 11 Jun 2018 21:55:35 +0100	[thread overview]
Message-ID: <4c43dd7982c8211249d45bf0e1ffbdd1ca788b1c.1528749451.git.anatoly.burakov@intel.com> (raw)
In-Reply-To: <cover.1528749451.git.anatoly.burakov@intel.com>
In-Reply-To: <cover.1528749451.git.anatoly.burakov@intel.com>

Mostly a code move, to have all code related to find_contig in
one place. This slightly changes the API in that previously,
calling find_contig_free() on a full fbarray would've been
an error, but equivalent call to find_contig_used() on an empty
array does not return an error, leading to an inconsistency in
the API.

The decision was made to not treat this condition as an error,
because it is equivalent to calling find_contig() on an index
that just happens to be used/free, which is not an error and
will return 0.

Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
---
 lib/librte_eal/common/eal_common_fbarray.c | 52 ++++++++++++----------
 1 file changed, 28 insertions(+), 24 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_fbarray.c b/lib/librte_eal/common/eal_common_fbarray.c
index 9ae942bfe..e37fe1e4d 100644
--- a/lib/librte_eal/common/eal_common_fbarray.c
+++ b/lib/librte_eal/common/eal_common_fbarray.c
@@ -773,8 +773,8 @@ rte_fbarray_find_next_n_used(struct rte_fbarray *arr, unsigned int start,
 	return ret;
 }
 
-int __rte_experimental
-rte_fbarray_find_contig_free(struct rte_fbarray *arr, unsigned int start)
+static int
+fbarray_find_contig(struct rte_fbarray *arr, unsigned int start, bool used)
 {
 	int ret = -1;
 
@@ -786,14 +786,25 @@ rte_fbarray_find_contig_free(struct rte_fbarray *arr, unsigned int start)
 	/* prevent array from changing under us */
 	rte_rwlock_read_lock(&arr->rwlock);
 
-	if (arr->len == arr->count) {
-		rte_errno = ENOSPC;
-		goto out;
-	}
-
-	if (arr->count == 0) {
-		ret = arr->len - start;
-		goto out;
+	/* cheap checks to prevent doing useless work */
+	if (used) {
+		if (arr->count == 0) {
+			ret = 0;
+			goto out;
+		}
+		if (arr->len == arr->count) {
+			ret = arr->len - start;
+			goto out;
+		}
+	} else {
+		if (arr->len == arr->count) {
+			ret = 0;
+			goto out;
+		}
+		if (arr->count == 0) {
+			ret = arr->len - start;
+			goto out;
+		}
 	}
 
 	ret = find_contig(arr, start, false);
@@ -803,22 +814,15 @@ rte_fbarray_find_contig_free(struct rte_fbarray *arr, unsigned int start)
 }
 
 int __rte_experimental
-rte_fbarray_find_contig_used(struct rte_fbarray *arr, unsigned int start)
+rte_fbarray_find_contig_free(struct rte_fbarray *arr, unsigned int start)
 {
-	int ret = -1;
-
-	if (arr == NULL || start >= arr->len) {
-		rte_errno = EINVAL;
-		return -1;
-	}
-
-	/* prevent array from changing under us */
-	rte_rwlock_read_lock(&arr->rwlock);
-
-	ret = find_contig(arr, start, true);
+	return fbarray_find_contig(arr, start, false);
+}
 
-	rte_rwlock_read_unlock(&arr->rwlock);
-	return ret;
+int __rte_experimental
+rte_fbarray_find_contig_used(struct rte_fbarray *arr, unsigned int start)
+{
+	return fbarray_find_contig(arr, start, true);
 }
 
 int __rte_experimental
-- 
2.17.1

  parent reply	other threads:[~2018-06-11 20:55 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-11 20:55 [dpdk-dev] [PATCH 0/9] mem: reduce memory fragmentation Anatoly Burakov
2018-06-11 20:55 ` [dpdk-dev] [PATCH 1/9] fbarray: fix errno values returned from functions Anatoly Burakov
2018-06-11 20:55 ` Anatoly Burakov [this message]
2018-06-11 20:55 ` [dpdk-dev] [PATCH 3/9] fbarray: reduce duplication in find_next_n code Anatoly Burakov
2018-06-11 20:55 ` [dpdk-dev] [PATCH 4/9] fbarray: reduce duplication in find_next code Anatoly Burakov
2018-06-11 20:55 ` [dpdk-dev] [PATCH 5/9] fbarray: add reverse find_free/used Anatoly Burakov
2018-06-11 20:55 ` [dpdk-dev] [PATCH 6/9] fbarray: add reverse find n used/free Anatoly Burakov
2018-06-11 20:55 ` [dpdk-dev] [PATCH 7/9] fbarray: add reverse find contig used/free Anatoly Burakov
2018-06-11 20:55 ` [dpdk-dev] [PATCH 8/9] test: add fbarray autotests Anatoly Burakov
2018-06-11 20:55 ` [dpdk-dev] [PATCH 9/9] memalloc: allocate memory in reverse Anatoly Burakov
2018-07-24 10:10   ` Burakov, Anatoly
2018-07-24 10:24     ` Thomas Monjalon
2018-07-13  9:06 ` [dpdk-dev] [PATCH 0/9] mem: reduce memory fragmentation 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=4c43dd7982c8211249d45bf0e1ffbdd1ca788b1c.1528749451.git.anatoly.burakov@intel.com \
    --to=anatoly.burakov@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).