Received: by 2002:a05:6a10:6006:0:0:0:0 with SMTP id w6csp678038pxa; Thu, 27 Aug 2020 12:43:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyhXOJ1FXnvFZkeqWM56j2msnDH1oXxBKtIqg34rP2Q4vz5/OjG2AbEDyuq2g5i9/jCh7xt X-Received: by 2002:a05:6402:13c4:: with SMTP id a4mr21477072edx.108.1598557383118; Thu, 27 Aug 2020 12:43:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598557383; cv=none; d=google.com; s=arc-20160816; b=zSJQWLAjW0t0imMFz7P6S1bOhh0xLqUWrNOVl02L19ZxN1yf8XZgrWL9o0Gk9CSLpC nqccrLHDHavzfAUktdZZIsZW61FsELHqfuLICiOnhQbfThIHNdM2ZFYgSiZXR5BLT4aq BTXRllOcO7Q0NbEqdtRY+PUkbe4R28oq8sxpqmV1hUCL1ZAqJdbvRuLKHSfwbbSIRosS ozAZ/eDqCXgHd8YB+dk9wqh1dT3+nftRNY3Lf2nEpa6yRPWLWV5r5hfABf9Th0el/wJX XvfZ8p1HdC3QWwLoQR9QsR4vzu3tFAfzJ668beeED1/ug4J5RIqQOn8e6atqX94/Qp5P dbfA== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=SnbKIQDl7LhpajgwCkX4vq1s3KnBk0aH2Cr7I/PEP0U=; b=FJul1JwTQlatkJSiH3L+GSnaAUAR9KnhA1MzXFqxCvNxwy000N/OnGt0Jjpyifh9E4 HYoVYf824l7JYMi0GYGEfpvt65d5DFNTB3Rk4edqRIEg9AEw+87lnlG1WUO4YnF0tv/v e22jLdfkuyX8XaseH69U/m+sHS2uuGae2ohOjGr2Zjg8Dy9MyNPNSEFkwSO2V0biyPgr w3wMNSzjrZVdkZd+/A2k2Ib/TJOqVwbOCPugqBUgXvQwD0rJxA1xJox2kdflylVuxlTu IyQXlmiVjeNOkc7HKYQGWefarLdxqpVOfnagZlq+RGmM1js2YpmBfo76kjWMeHX44KVc eLYA== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 25si2278213ejl.76.2020.08.27.12.42.40; Thu, 27 Aug 2020 12:43:03 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727061AbgH0Tlj (ORCPT + 99 others); Thu, 27 Aug 2020 15:41:39 -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)); > } >