Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp471597pxt; Thu, 5 Aug 2021 04:26:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyAKx4ulMxwLkGyH/miioNz2nm6lJrGd98DIRYP0UPOxuTAcX7JiF0fivOQTSoJkYk02JeT X-Received: by 2002:a6b:f416:: with SMTP id i22mr904010iog.162.1628162759809; Thu, 05 Aug 2021 04:25:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628162759; cv=none; d=google.com; s=arc-20160816; b=aUI/CwPKybamPybQ43WhGkF2qy6OIX9anmQ3xTksJ0IibmX6rjzlmcwZXs6pVLeRTX k9foAYbO8n+F7J5IsrnLFsll1Jxk3ijCz8rgemDvgzyFG25PHZrhSSvS0FnpWOcyjRAa ssOb63KJbnPKA8vf8w/2wLgX5JUT3PK6tx+Cj/9w04FjfBRH5FWx80bP+TyMUTu+43or VtaVHazdzXNcHwZwLNS7bGxxJkxibhKZB8Ldnm2sN+ifx8Kwn9eU3e8Vz33qet2jWMSf uaKEdh3DjikqC9SXcIAOliKB3LjCve+411b0AvdoqK2adua1Nm0Af7y6I9DzSqwAs21m 2P/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=to0KGnjDvHO6Km+W3C5rcTJ8yS/4hQ1een6xvQwno2o=; b=d0V5ZDsm4MPVYwZxW9r4zC65E8EqPfAwogVLg1yWLeqth5iVO2WlLkdjm6f54tihSF Ynl5t27ZL0R/9+MZixYtTwCVT7Hn4LUSkqOuiqdDAO+cgTxI/3LTmwQwjuqaqmf9faWj Ot7x9P6lx4Sc6Cz72yWb35P+Cch/IZKREwKZQMQeHASreJuMWoHo6zs9fq6SBIlo31RK eP8g/pMGbdKbLKwa//1wgnNOu1Nv2Nj01YVOd+pc2CsLBjxJR25cNM0j2NARAdWjEQfP w89hi9mIvFQi0BS05jyyCZHyjIMfmMXfqImzjkcFzvGhioIw9WfcAyFBKodv+bEc8S9P +I8g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t2si1383967ilq.106.2021.08.05.04.25.47; Thu, 05 Aug 2021 04:25:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240893AbhHELYy (ORCPT + 99 others); Thu, 5 Aug 2021 07:24:54 -0400 Received: from foss.arm.com ([217.140.110.172]:43080 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240623AbhHELYy (ORCPT ); Thu, 5 Aug 2021 07:24:54 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id C67151FB; Thu, 5 Aug 2021 04:24:39 -0700 (PDT) Received: from [10.57.36.146] (unknown [10.57.36.146]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A99A63F719; Thu, 5 Aug 2021 04:24:38 -0700 (PDT) Subject: Re: [PATCH] iommu/arm-smmu-v3: Remove some unneeded init in arm_smmu_cmdq_issue_cmdlist() To: John Garry , will@kernel.org Cc: joro@8bytes.org, linux-arm-kernel@lists.infradead.org, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, linuxarm@huawei.com References: <1624293394-202509-1-git-send-email-john.garry@huawei.com> From: Robin Murphy Message-ID: Date: Thu, 5 Aug 2021 12:24:33 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: <1624293394-202509-1-git-send-email-john.garry@huawei.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021-06-21 17:36, John Garry wrote: > Members of struct "llq" will be zero-inited, apart from member max_n_shift. > But we write llq.val straight after the init, so it was pointless to zero > init those other members. As such, separately init member max_n_shift > only. > > In addition, struct "head" is initialised to "llq" only so that member > max_n_shift is set. But that member is never referenced for "head", so > remove any init there. > > Removing these initializations is seen as a small performance optimisation, > as this code is (very) hot path. I looked at this and immediately thought "surely the compiler can see that all the prod/cons/val fields are written anyway and elide the initialisation?", so I dumped the before and after disassembly, and... oh. You should probably clarify that it's zero-initialising all the cacheline padding which is both pointless and painful. With that, Reviewed-by: Robin Murphy However, having looked this closely I'm now tangentially wondering why max_n_shift isn't inside the padded union? It's read at the same time as both prod and cons by queue_has_space(), and never updated, so there doesn't appear to be any benefit to it being in a separate cacheline all by itself, and llq is already twice as big as it needs to be. Sorting that would also be a good opportunity to store the value of interest in its appropriate form so we're not needlessly recalculating 1 << shift every flippin' time... Robin. > Signed-off-by: John Garry > > diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c > index 54b2f27b81d4..8a8ad49bb7fd 100644 > --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c > +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c > @@ -727,11 +727,11 @@ static int arm_smmu_cmdq_issue_cmdlist(struct arm_smmu_device *smmu, > unsigned long flags; > bool owner; > struct arm_smmu_cmdq *cmdq = &smmu->cmdq; > - struct arm_smmu_ll_queue llq = { > - .max_n_shift = cmdq->q.llq.max_n_shift, > - }, head = llq; > + struct arm_smmu_ll_queue llq, head; > int ret = 0; > > + llq.max_n_shift = cmdq->q.llq.max_n_shift; > + > /* 1. Allocate some space in the queue */ > local_irq_save(flags); > llq.val = READ_ONCE(cmdq->q.llq.val); >