mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Robin Murphy <robin.murphy@arm.com>
To: joro@8bytes.org
Cc: iommu@lists.linux-foundation.org, thunder.leizhen@huawei.com,
	nwatters@codeaurora.org, tomasz.nowicki@caviumnetworks.com,
	linux-kernel@vger.kernel.org
Subject: [PATCH v4 1/6] iommu/iova: Optimise rbtree searching
Date: Tue, 19 Sep 2017 17:31:52 +0100	[thread overview]
Message-ID: <9d6aff3f458a54d210eabdaa38ee6baa0a901a3a.1505829018.git.robin.murphy@arm.com> (raw)
In-Reply-To: <cover.1505829018.git.robin.murphy@arm.com>

From: Zhen Lei <thunder.leizhen@huawei.com>

Checking the IOVA bounds separately before deciding which direction to
continue the search (if necessary) results in redundantly comparing both
pfns twice each. GCC can already determine that the final comparison op
is redundant and optimise it down to 3 in total, but we can go one
further with a little tweak of the ordering (which makes the intent of
the code that much cleaner as a bonus).

Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
Tested-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Tested-by: Zhen Lei <thunder.leizhen@huawei.com>
Tested-by: Nate Watterson <nwatters@codeaurora.org>
[rm: rewrote commit message to clarify]
Signed-off-by: Robin Murphy <robin.murphy@arm.com>
---

v4: No change

 drivers/iommu/iova.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/iommu/iova.c b/drivers/iommu/iova.c
index 33edfa794ae9..f129ff4f5c89 100644
--- a/drivers/iommu/iova.c
+++ b/drivers/iommu/iova.c
@@ -342,15 +342,12 @@ private_find_iova(struct iova_domain *iovad, unsigned long pfn)
 	while (node) {
 		struct iova *iova = rb_entry(node, struct iova, node);
 
-		/* If pfn falls within iova's range, return iova */
-		if ((pfn >= iova->pfn_lo) && (pfn <= iova->pfn_hi)) {
-			return iova;
-		}
-
 		if (pfn < iova->pfn_lo)
 			node = node->rb_left;
-		else if (pfn > iova->pfn_lo)
+		else if (pfn > iova->pfn_hi)
 			node = node->rb_right;
+		else
+			return iova;	/* pfn falls within iova's range */
 	}
 
 	return NULL;
-- 
2.13.4.dirty

  reply	other threads:[~2017-09-19 16:32 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-19 16:31 [PATCH v4 0/6] Optimise 64-bit IOVA allocations Robin Murphy
2017-09-19 16:31 ` Robin Murphy [this message]
2017-09-19 16:31 ` [PATCH v4 2/6] iommu/iova: Optimise the padding calculation Robin Murphy
2017-09-19 16:31 ` [PATCH v4 3/6] iommu/iova: Add rbtree anchor node Robin Murphy
2017-09-19 16:31 ` [PATCH v4 4/6] iommu/iova: Simplify cached node logic Robin Murphy
2017-09-19 16:31 ` [PATCH v4 5/6] iommu/iova: Extend rbtree node caching Robin Murphy
2017-09-20 12:59   ` Tomasz Nowicki
2017-09-20 17:27     ` Robin Murphy
2017-09-19 16:31 ` [PATCH v4 6/6] iommu/iova: Make dma_32bit_pfn implicit Robin Murphy
2017-09-20 11:02 ` [PATCH v4 7/6] iommu/iova: Make cached_node always valid Robin Murphy

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=9d6aff3f458a54d210eabdaa38ee6baa0a901a3a.1505829018.git.robin.murphy@arm.com \
    --to=robin.murphy@arm.com \
    --cc=iommu@lists.linux-foundation.org \
    --cc=joro@8bytes.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nwatters@codeaurora.org \
    --cc=thunder.leizhen@huawei.com \
    --cc=tomasz.nowicki@caviumnetworks.com \
    /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

all inboxes | Powered by JetHome®