From patchwork Thu Aug 9 11:48:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Leizhen \(ThunderTown\)" X-Patchwork-Id: 143824 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp1994143ljj; Thu, 9 Aug 2018 04:50:44 -0700 (PDT) X-Google-Smtp-Source: AA+uWPwhsTtEN8m4WbAgG0aWLU3uNpe5nZaoneibscPcFFxRUq1VDgGZfpGKAwiMDyixjNa+XYT+ X-Received: by 2002:a62:ccd0:: with SMTP id j77-v6mr2064165pfk.22.1533815444088; Thu, 09 Aug 2018 04:50:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533815444; cv=none; d=google.com; s=arc-20160816; b=m/rxpqgiugJP4fvMalrYkUMUMHzBCrsa0w/HYPaqRNRm9OZBemaljK6SnUc1surSLr 6SeZpSh/++rViumtY1TuqHioIppGzv5zJaVdxfwYZ7rx+mmERekwRyqWJVTchMpKAVWk lgN5FbLRVJwpI+4JDWi9Dwx1wQOKlvxmSNMlcmaA/muy1mle/3/iiNJl48mreeujRbD3 u1g1aGCVcbBSQ0gF4YEegFAZ2i65F+pVvrMUXSqkP+rUWLSgzyCezDuQJawoQ8ZwvI7K R8HFQC2GMdizXXs8DDJyBese1OIvXGOH7NJJ0AZxERaTS9Os0eEV7QjEnSUA6iXs3dDl iIpA== 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=J4rDfBWEG+Df37JIhovPchgG1lvgX5xsdOwHYZL/UqU=; b=ajqmO+XaEpKeeWQvLfrIcElXcrql57smSNhxJSP/3PyMW4ipISHRYlOncM+w3B0ct5 rjkAWWKE1HeNKmGZgRuAIKs/EgUPICCZzmkckThIVL0IITnacitttBMySmXu/r2px6v9 yuX06T8YL5fcr6Xll1c3Mp2QqudoOKLDfS7099RaO+KACkZ6eYJaKUgSWG5+BX+ub8xc BO/mvP8ooSwOdPYkRDSwkxXm+COXcHC9F/Y9o/s3IYVS4ufl0Kf1un51ImvkYZ+ztQ84 QOJHFxJoVHjmDMCv1UmIDTFgEFLJ54CM6jyHWJaier6HzMantU8p/YCn+QU+kiFcqhWa QZKQ== 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 b16-v6si5496679pgw.478.2018.08.09.04.50.43; Thu, 09 Aug 2018 04:50:44 -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 S1731135AbeHIOPM (ORCPT + 31 others); Thu, 9 Aug 2018 10:15:12 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:10649 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1730090AbeHIOPM (ORCPT ); Thu, 9 Aug 2018 10:15:12 -0400 Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id EA74812D1310B; Thu, 9 Aug 2018 19:50:36 +0800 (CST) Received: from localhost (10.177.23.164) by DGGEMS405-HUB.china.huawei.com (10.3.19.205) with Microsoft SMTP Server id 14.3.399.0; Thu, 9 Aug 2018 19:50:28 +0800 From: Zhen Lei To: Robin Murphy , Will Deacon , Joerg Roedel , linux-arm-kernel , iommu , linux-kernel CC: Zhen Lei , LinuxArm , Hanjun Guo , Libin Subject: [PATCH v2 2/2] iommu/arm-smmu-v3: avoid redundant CMD_SYNCs if possible Date: Thu, 9 Aug 2018 19:48:53 +0800 Message-ID: <1533815333-17320-3-git-send-email-thunder.leizhen@huawei.com> X-Mailer: git-send-email 1.9.5.msysgit.0 In-Reply-To: <1533815333-17320-1-git-send-email-thunder.leizhen@huawei.com> References: <1533815333-17320-1-git-send-email-thunder.leizhen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.177.23.164] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org More than two CMD_SYNCs maybe adjacent in the command queue, and the first one has done what others want to do. Drop the redundant CMD_SYNCs can improve IO performance especially under the pressure scene. I did the statistics in my test environment, the number of CMD_SYNCs can be reduced about 1/3. See below: CMD_SYNCs reduced: 19542181 CMD_SYNCs total: 58098548 (include reduced) CMDs total: 116197099 (TLBI:SYNC about 1:1) Signed-off-by: Zhen Lei --- drivers/iommu/arm-smmu-v3.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) -- 1.8.3 diff --git a/drivers/iommu/arm-smmu-v3.c b/drivers/iommu/arm-smmu-v3.c index d17a9a7..b96d2d2 100644 --- a/drivers/iommu/arm-smmu-v3.c +++ b/drivers/iommu/arm-smmu-v3.c @@ -567,6 +567,7 @@ struct arm_smmu_device { int gerr_irq; int combined_irq; u32 sync_nr; + u8 prev_cmd_opcode; unsigned long ias; /* IPA */ unsigned long oas; /* PA */ @@ -775,6 +776,11 @@ static int queue_remove_raw(struct arm_smmu_queue *q, u64 *ent) return 0; } +static inline u8 arm_smmu_cmd_opcode_get(u64 *cmd) +{ + return cmd[0] & CMDQ_0_OP; +} + /* High-level queue accessors */ static int arm_smmu_cmdq_build_cmd(u64 *cmd, struct arm_smmu_cmdq_ent *ent) { @@ -900,6 +906,8 @@ static void arm_smmu_cmdq_insert_cmd(struct arm_smmu_device *smmu, u64 *cmd) struct arm_smmu_queue *q = &smmu->cmdq.q; bool wfe = !!(smmu->features & ARM_SMMU_FEAT_SEV); + smmu->prev_cmd_opcode = arm_smmu_cmd_opcode_get(cmd); + while (queue_insert_raw(q, cmd) == -ENOSPC) { if (queue_poll_cons(q, false, wfe)) dev_err_ratelimited(smmu->dev, "CMDQ timeout\n"); @@ -952,9 +960,17 @@ static int __arm_smmu_cmdq_issue_sync_msi(struct arm_smmu_device *smmu) }; spin_lock_irqsave(&smmu->cmdq.lock, flags); - ent.sync.msidata = ++smmu->sync_nr; - arm_smmu_cmdq_build_cmd(cmd, &ent); - arm_smmu_cmdq_insert_cmd(smmu, cmd); + if (smmu->prev_cmd_opcode == CMDQ_OP_CMD_SYNC) { + /* + * Previous command is CMD_SYNC also, there is no need to add + * one more. Just poll it. + */ + ent.sync.msidata = smmu->sync_nr; + } else { + ent.sync.msidata = ++smmu->sync_nr; + arm_smmu_cmdq_build_cmd(cmd, &ent); + arm_smmu_cmdq_insert_cmd(smmu, cmd); + } spin_unlock_irqrestore(&smmu->cmdq.lock, flags); return __arm_smmu_sync_poll_msi(smmu, ent.sync.msidata);