From patchwork Thu May 18 07:59:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhen Lei X-Patchwork-Id: 100051 Delivered-To: patch@linaro.org Received: by 10.140.96.100 with SMTP id j91csp602262qge; Thu, 18 May 2017 01:02:57 -0700 (PDT) X-Received: by 10.84.216.30 with SMTP id m30mr3294092pli.161.1495094577836; Thu, 18 May 2017 01:02:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1495094577; cv=none; d=google.com; s=arc-20160816; b=JzFtzmV/GdErOH59lfcz42hJ+3xkVA1UqoDuw0FsgdXy0t603CAudBmNRUricMgQHY fAvsABOMaAjawPejbnx9ycNgNp60PfoGHr78AqCzDgji7+GAnFxwX9ygw/pVITBBvJ9j Cg5hFuk8H+rMi0oc10VGVcltaM4KEbV9DnpEcR5blVwneckqvGF7LWuxcLJrULm5MGw3 scjR2zoWei/ZEycBpLISjAE3PVZmROJa3FCEbjN1nHOfx/x8Xv+tzkYMc0TKKBProIxw 7BkSl36cjCFsFIdsRklhEHGUy0Bn2/KE1Mtx/pK/QTNVdMke4w6N/UwNXSwbIz+/mFeJ TalQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=t4ooPprsG/K0uI5APOHZyxeqa/9g14tcx2+lDMALFqc=; b=xN5GWpFZC2CGUMvXqLGcIGxjokrdU3VHgFcY/4RCDrU53tViCnqj34QKt8jBRXWM2n 5Ve3PyVYbj0ygrTOcus7LsPWyciFjZjRcCRhOw1fT5P3nJXzfCs3yL2HlidiUmQCDdAn gzvO/fkjpvBiMYm1tissILB3Ot3BDMwPLclhP+EGZY3WF2GZv/bvkvuW/bgPwEe577Zj COci1JpAkvh/u7Bw4ihICFaShbqW/2U8fw3ZeL4AL+OUQBaRYPW07jDlb3Jsi7Cxo9CQ MMxDUxBkqV9E140rQQceyzjCH62YOEmqMmrtHG4npYR26EsfkuHpugKXAxXOqe2iRnNI Tq+A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y4si4547127plb.230.2017.05.18.01.02.57; Thu, 18 May 2017 01:02:57 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755134AbdERIC2 (ORCPT + 25 others); Thu, 18 May 2017 04:02:28 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:6778 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752083AbdERICH (ORCPT ); Thu, 18 May 2017 04:02:07 -0400 Received: from 172.30.72.56 (EHLO DGGEML401-HUB.china.huawei.com) ([172.30.72.56]) by dggrg01-dlp.huawei.com (MOS 4.4.6-GA FastPath queued) with ESMTP id AOU59814; Thu, 18 May 2017 16:01:59 +0800 (CST) Received: from localhost (10.177.23.164) by DGGEML401-HUB.china.huawei.com (10.3.17.32) with Microsoft SMTP Server id 14.3.301.0; Thu, 18 May 2017 16:01:53 +0800 From: Zhen Lei To: Joerg Roedel , iommu , Robin Murphy , David Woodhouse , Sudeep Dutt , Ashutosh Dixit , linux-kernel CC: Zefan Li , Xinwei Hu , "Tianhong Ding" , Hanjun Guo , Zhen Lei Subject: [PATCH v3 5/6] iommu/iova: move the caculation of pad mask out of loop Date: Thu, 18 May 2017 15:59:56 +0800 Message-ID: <1495094397-9132-6-git-send-email-thunder.leizhen@huawei.com> X-Mailer: git-send-email 1.9.5.msysgit.0 In-Reply-To: <1495094397-9132-1-git-send-email-thunder.leizhen@huawei.com> References: <1495094397-9132-1-git-send-email-thunder.leizhen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.177.23.164] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020206.591D54F8.00E0, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2014-11-16 11:51:01, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 08ca033ee96ecb3c8ed75ac13331400e Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org I'm not sure whether the compiler can optimize it, but move it out will be better. At least, it does not require lock protection. Signed-off-by: Zhen Lei --- drivers/iommu/iova.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) -- 2.5.0 diff --git a/drivers/iommu/iova.c b/drivers/iommu/iova.c index 711b10a..338930b 100644 --- a/drivers/iommu/iova.c +++ b/drivers/iommu/iova.c @@ -155,23 +155,16 @@ iova_insert_rbtree(struct rb_root *root, struct iova *iova, rb_insert_color(&iova->node, root); } -/* - * Computes the padding size required, to make the start address - * naturally aligned on the power-of-two order of its size - */ -static unsigned int -iova_get_pad_size(unsigned int size, unsigned int limit_pfn) -{ - return (limit_pfn + 1 - size) & (__roundup_pow_of_two(size) - 1); -} - static int __alloc_and_insert_iova_range(struct iova_domain *iovad, unsigned long size, unsigned long limit_pfn, struct iova *new, bool size_aligned) { struct rb_node *prev, *curr; unsigned long flags; - unsigned int pad_size = 0; + unsigned long pad_mask, pad_size = 0; + + if (size_aligned) + pad_mask = __roundup_pow_of_two(size) - 1; /* Walk the tree backwards */ spin_lock_irqsave(&iovad->iova_rbtree_lock, flags); @@ -185,8 +178,13 @@ static int __alloc_and_insert_iova_range(struct iova_domain *iovad, else if (limit_pfn < curr_iova->pfn_hi) goto adjust_limit_pfn; else { + /* + * Computes the padding size required, to make the start + * address naturally aligned on the power-of-two order + * of its size + */ if (size_aligned) - pad_size = iova_get_pad_size(size, limit_pfn); + pad_size = (limit_pfn + 1 - size) & pad_mask; if ((curr_iova->pfn_hi + size + pad_size) <= limit_pfn) break; /* found a free slot */ }