From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE, SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9A07CC433E0 for ; Tue, 19 Jan 2021 15:55:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 64D50208E4 for ; Tue, 19 Jan 2021 15:55:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391479AbhASPze (ORCPT ); Tue, 19 Jan 2021 10:55:34 -0500 Received: from foss.arm.com ([217.140.110.172]:37278 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728824AbhASPxb (ORCPT ); Tue, 19 Jan 2021 10:53:31 -0500 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 79CDDD6E; Tue, 19 Jan 2021 07:52:43 -0800 (PST) Received: from [10.57.39.58] (unknown [10.57.39.58]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 7CA143F66E; Tue, 19 Jan 2021 07:52:42 -0800 (PST) Subject: Re: [PATCH 1/2 v2] dma-iommu: use static-key to minimize the impact in the fast-path To: Christoph Hellwig , Lianbo Jiang Cc: linux-kernel@vger.kernel.org, thomas.lendacky@amd.com, will@kernel.org, iommu@lists.linux-foundation.org References: <20210119111616.12761-1-lijiang@redhat.com> <20210119111616.12761-2-lijiang@redhat.com> <20210119152641.GA3453587@infradead.org> From: Robin Murphy Message-ID: Date: Tue, 19 Jan 2021 15:52:41 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Thunderbird/78.6.1 MIME-Version: 1.0 In-Reply-To: <20210119152641.GA3453587@infradead.org> 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-01-19 15:26, Christoph Hellwig wrote: > On Tue, Jan 19, 2021 at 07:16:15PM +0800, Lianbo Jiang wrote: >> +static DEFINE_STATIC_KEY_FALSE(__deferred_attach); > > Why the strange underscores? Wouldn't iommu_deferred_attach_enabled > be a better name? > >> - if (unlikely(iommu_dma_deferred_attach(dev, domain))) >> + if (static_branch_unlikely(&__deferred_attach) && >> + iommu_dma_deferred_attach(dev, domain)) > > Also insted of duplicating this logic in three places, maybe rename > iommu_dma_deferred_attach to __iommu_dma_deferred_attach and create > a small inline wrapper for it? Once patch #2 is in place, I really don't see any point. The "helper" would add a minimum of 5 lines to save at most 3, and would have to be annotated as always_inline - which a whole other camp of people would probably object to - in order for the static branch to be properly useful. It's not as if this is a complex or hard-to-read expression, so IMO having 3 lines repeated 3 times is objectively better than having 2 lines necessarily repeated 3 times plus having to scroll up and find several more lines to follow what it's doing. Robin.