From: Zhen Lei Date: Thu, 21 Sep 2017 15:52:42 +0000 (+0100) Subject: iommu/iova: Optimise rbtree searching X-Git-Tag: v4.19~2208^2^5~1^6~12 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2070f940a6d5148cf2df0d0087ff0a64d9f15237;p=platform%2Fkernel%2Flinux-rpi.git iommu/iova: Optimise rbtree searching 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 Tested-by: Ard Biesheuvel Tested-by: Zhen Lei Tested-by: Nate Watterson [rm: rewrote commit message to clarify] Signed-off-by: Robin Murphy Signed-off-by: Joerg Roedel --- diff --git a/drivers/iommu/iova.c b/drivers/iommu/iova.c index 33edfa7..f129ff4 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;