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=-13.0 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham 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 4B729C433E1 for ; Thu, 27 Aug 2020 19:41:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2D63620714 for ; Thu, 27 Aug 2020 19:41:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727095AbgH0Tlk (ORCPT ); Thu, 27 Aug 2020 15:41:40 -0400 Received: from foss.arm.com ([217.140.110.172]:34000 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726120AbgH0Tlj (ORCPT ); Thu, 27 Aug 2020 15:41:39 -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 82D0931B; Thu, 27 Aug 2020 12:41:38 -0700 (PDT) Received: from [10.57.40.122] (unknown [10.57.40.122]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id CD8DC3F68F; Thu, 27 Aug 2020 12:41:37 -0700 (PDT) Subject: Re: [PATCH] iommu/iova: Replace cmpxchg with xchg in queue_iova To: Shaokun Zhang , iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org Cc: Yuqi Jin References: <1598517834-30275-1-git-send-email-zhangshaokun@hisilicon.com> From: Robin Murphy Message-ID: <3afcc7b2-0bfb-b79c-513f-1beb66c5f164@arm.com> Date: Thu, 27 Aug 2020 20:41:36 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:68.0) Gecko/20100101 Thunderbird/68.11.0 MIME-Version: 1.0 In-Reply-To: <1598517834-30275-1-git-send-email-zhangshaokun@hisilicon.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020-08-27 09:43, Shaokun Zhang wrote: > From: Yuqi Jin > > The performance of the atomic_xchg is better than atomic_cmpxchg because > no comparison is required. While the value of @fq_timer_on can only be 0 > or 1. Let's use atomic_xchg instead of atomic_cmpxchg here because we > only need to check that the value changes from 0 to 1 or from 1 to 1. Looks reasonable to me - the "compare" part is already covered by the separate atomic_read(), and as you say there's no harm if the "exchange" part races as long as it's still atomic. Reviewed-by: Robin Murphy > Cc: Joerg Roedel > Signed-off-by: Yuqi Jin > Signed-off-by: Shaokun Zhang > --- > drivers/iommu/iova.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/iommu/iova.c b/drivers/iommu/iova.c > index 45a251da5453..30d969a4c5fd 100644 > --- a/drivers/iommu/iova.c > +++ b/drivers/iommu/iova.c > @@ -579,7 +579,7 @@ void queue_iova(struct iova_domain *iovad, > > /* Avoid false sharing as much as possible. */ > if (!atomic_read(&iovad->fq_timer_on) && > - !atomic_cmpxchg(&iovad->fq_timer_on, 0, 1)) > + !atomic_xchg(&iovad->fq_timer_on, 1)) > mod_timer(&iovad->fq_timer, > jiffies + msecs_to_jiffies(IOVA_FQ_TIMEOUT)); > } >