From patchwork Thu Aug 1 12:20:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Leizhen \(ThunderTown\)" X-Patchwork-Id: 170375 Delivered-To: patch@linaro.org Received: by 2002:a92:512:0:0:0:0:0 with SMTP id q18csp5363870ile; Thu, 1 Aug 2019 05:21:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqwf7St8nL1HP9N2Wo8q44KviJBzeYphTzX65Gnh7Wv7eo8ogYTMlXaYD2vu0hQJFSxLZJnc X-Received: by 2002:a63:f304:: with SMTP id l4mr117944825pgh.66.1564662105489; Thu, 01 Aug 2019 05:21:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564662105; cv=none; d=google.com; s=arc-20160816; b=p1GrnBiSQ0o+LBPV3cuXUEn7V0Mgc4ZgSg0Nr5YZKbh46F2zRxdX4lXgjO4Xg0jhAT PAPl7O+cfc7gDZs9P8cK0gKo5TV1pncrnj3okWb/e1jL3p1ITCdbNM445rO3EqQePGEH g45UoP0xwZ9N5PZcA4znvDuRhaPGzx1aI14eMLAXHdidsjy80w0ndJesrKK7h6JrpP/Z XdQjDyAi1EjG49sT4cn3LColOkG8yUDWU6LdnhqZbgDetK99z2iLrZnxnRd32qgNMSbT ik0Lda/0rk0jQZA4babkJ1J119bpijbz9niLprHSYeAAx6LWk4+LBgDLUTv8XlQd/KVx SGTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=i+UXe/IxJeW/xUjMi0uDlDmq+LbC5nDVBBcwZIXSOHw=; b=CWB5Hr5LYXfQcxNK/nk7WShA1qakc3xygcXrn+XGJXA8ZvDGdi3o6iCIm+UCHn4uys 1DkdU0fv3xvhuUdN7s3TX5bG3BF2XpKuhVbaXScg+IrF/WLiTfRmHViXwZ1P6a2yjizY 3mnhi4DEsCIpvhWQWUXzmHhaZRQa0LrO7cH8Gjw752bHvclMTW4hQ9+md9cM2zpQKlcH NCnsa7lyWI6sB8dtAg/HdcFfDN19qk8iIMyvLECnhW5He2ZrC72GAHdKE15kx4XV/4xO gOtodE3uT2ViabXxQIDj6hQueWOit4J/3Q04Jkllawa3caHRpS8pA3L9xVFx2BkJWbKJ 7SJw== 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 f12si37152326pfq.187.2019.08.01.05.21.45; Thu, 01 Aug 2019 05:21:45 -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 S1731058AbfHAMVn (ORCPT + 29 others); Thu, 1 Aug 2019 08:21:43 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:51546 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728791AbfHAMVn (ORCPT ); Thu, 1 Aug 2019 08:21:43 -0400 Received: from DGGEMS409-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 5C0348E4323954FF7DE6; Thu, 1 Aug 2019 20:21:41 +0800 (CST) Received: from HGHY4L002753561.china.huawei.com (10.133.215.186) by DGGEMS409-HUB.china.huawei.com (10.3.19.209) with Microsoft SMTP Server id 14.3.439.0; Thu, 1 Aug 2019 20:21:31 +0800 From: Zhen Lei To: Jean-Philippe Brucker , John Garry , Robin Murphy , Will Deacon , Joerg Roedel , linux-arm-kernel , iommu , linux-kernel CC: Zhen Lei Subject: [PATCH] iommu/arm-smmu-v3: add nr_ats_masters to avoid unnecessary operations Date: Thu, 1 Aug 2019 20:20:40 +0800 Message-ID: <20190801122040.26024-1-thunder.leizhen@huawei.com> X-Mailer: git-send-email 2.21.0.windows.1 MIME-Version: 1.0 X-Originating-IP: [10.133.215.186] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When (smmu_domain->smmu->features & ARM_SMMU_FEAT_ATS) is true, even if a smmu domain does not contain any ats master, the operations of arm_smmu_atc_inv_to_cmd() and lock protection in arm_smmu_atc_inv_domain() are always executed. This will impact performance, especially in multi-core and stress scenarios. For my FIO test scenario, about 8% performance reduced. In fact, we can use a atomic member to record how many ats masters the smmu contains. And check that without traverse the list and check all masters one by one in the lock protection. Fixes: 9ce27afc0830 ("iommu/arm-smmu-v3: Add support for PCI ATS") Signed-off-by: Zhen Lei --- drivers/iommu/arm-smmu-v3.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) -- 1.8.3 diff --git a/drivers/iommu/arm-smmu-v3.c b/drivers/iommu/arm-smmu-v3.c index a9a9fabd396804a..1b370d9aca95f94 100644 --- a/drivers/iommu/arm-smmu-v3.c +++ b/drivers/iommu/arm-smmu-v3.c @@ -631,6 +631,7 @@ struct arm_smmu_domain { struct io_pgtable_ops *pgtbl_ops; bool non_strict; + atomic_t nr_ats_masters; enum arm_smmu_domain_stage stage; union { @@ -1531,7 +1532,7 @@ static int arm_smmu_atc_inv_domain(struct arm_smmu_domain *smmu_domain, struct arm_smmu_cmdq_ent cmd; struct arm_smmu_master *master; - if (!(smmu_domain->smmu->features & ARM_SMMU_FEAT_ATS)) + if (!atomic_read(&smmu_domain->nr_ats_masters)) return 0; arm_smmu_atc_inv_to_cmd(ssid, iova, size, &cmd); @@ -1869,6 +1870,7 @@ static int arm_smmu_enable_ats(struct arm_smmu_master *master) size_t stu; struct pci_dev *pdev; struct arm_smmu_device *smmu = master->smmu; + struct arm_smmu_domain *smmu_domain = master->domain; struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(master->dev); if (!(smmu->features & ARM_SMMU_FEAT_ATS) || !dev_is_pci(master->dev) || @@ -1887,12 +1889,15 @@ static int arm_smmu_enable_ats(struct arm_smmu_master *master) return ret; master->ats_enabled = true; + atomic_inc(&smmu_domain->nr_ats_masters); + return 0; } static void arm_smmu_disable_ats(struct arm_smmu_master *master) { struct arm_smmu_cmdq_ent cmd; + struct arm_smmu_domain *smmu_domain = master->domain; if (!master->ats_enabled || !dev_is_pci(master->dev)) return; @@ -1901,6 +1906,7 @@ static void arm_smmu_disable_ats(struct arm_smmu_master *master) arm_smmu_atc_inv_master(master, &cmd); pci_disable_ats(to_pci_dev(master->dev)); master->ats_enabled = false; + atomic_dec(&smmu_domain->nr_ats_masters); } static void arm_smmu_detach_dev(struct arm_smmu_master *master) @@ -1915,10 +1921,10 @@ static void arm_smmu_detach_dev(struct arm_smmu_master *master) list_del(&master->domain_head); spin_unlock_irqrestore(&smmu_domain->devices_lock, flags); - master->domain = NULL; arm_smmu_install_ste_for_dev(master); arm_smmu_disable_ats(master); + master->domain = NULL; } static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev)