Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1735097

[PATCH v4 1/6] iommu/iova: Optimise rbtree searching

From Robin Murphy <robin.murphy@arm.com>
Newsgroups linux.kernel
Subject [PATCH v4 1/6] iommu/iova: Optimise rbtree searching
Date 2017-09-19 18:40 +0200
Message-ID <urtJ0-7LM-35@gated-at.bofh.it> (permalink)
References <urtIZ-7LM-13@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


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

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH v4 0/6] Optimise 64-bit IOVA allocations Robin Murphy <robin.murphy@arm.com> - 2017-09-19 18:40 +0200
  [PATCH v4 5/6] iommu/iova: Extend rbtree node caching Robin Murphy <robin.murphy@arm.com> - 2017-09-19 18:40 +0200
    Re: [PATCH v4 5/6] iommu/iova: Extend rbtree node caching Robin Murphy <robin.murphy@arm.com> - 2017-09-20 19:30 +0200
  [PATCH v4 6/6] iommu/iova: Make dma_32bit_pfn implicit Robin Murphy <robin.murphy@arm.com> - 2017-09-19 18:40 +0200
  [PATCH v4 1/6] iommu/iova: Optimise rbtree searching Robin Murphy <robin.murphy@arm.com> - 2017-09-19 18:40 +0200
  [PATCH v4 2/6] iommu/iova: Optimise the padding calculation Robin Murphy <robin.murphy@arm.com> - 2017-09-19 18:40 +0200
  [PATCH v4 7/6] iommu/iova: Make cached_node always valid Robin Murphy <robin.murphy@arm.com> - 2017-09-20 13:10 +0200

csiph-web