* [PATCH] iommu/iova: Replace cmpxchg with xchg in queue_iova
@ 2020-08-27 8:43 Shaokun Zhang
2020-08-27 19:41 ` Robin Murphy
2020-09-04 9:37 ` Joerg Roedel
0 siblings, 2 replies; 5+ messages in thread
From: Shaokun Zhang @ 2020-08-27 8:43 UTC (permalink / raw)
To: iommu, linux-kernel; +Cc: Shaokun Zhang, Yuqi Jin
From: Yuqi Jin <jinyuqi@huawei.com>
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.
Cc: Joerg Roedel <joro@8bytes.org>
Signed-off-by: Yuqi Jin <jinyuqi@huawei.com>
Signed-off-by: Shaokun Zhang <zhangshaokun@hisilicon.com>
---
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));
}
--
2.7.4
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] iommu/iova: Replace cmpxchg with xchg in queue_iova
2020-08-27 8:43 [PATCH] iommu/iova: Replace cmpxchg with xchg in queue_iova Shaokun Zhang
@ 2020-08-27 19:41 ` Robin Murphy
2020-09-04 9:37 ` Joerg Roedel
1 sibling, 0 replies; 5+ messages in thread
From: Robin Murphy @ 2020-08-27 19:41 UTC (permalink / raw)
To: Shaokun Zhang, iommu, linux-kernel; +Cc: Yuqi Jin
On 2020-08-27 09:43, Shaokun Zhang wrote:
> From: Yuqi Jin <jinyuqi@huawei.com>
>
> 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 <robin.murphy@arm.com>
> Cc: Joerg Roedel <joro@8bytes.org>
> Signed-off-by: Yuqi Jin <jinyuqi@huawei.com>
> Signed-off-by: Shaokun Zhang <zhangshaokun@hisilicon.com>
> ---
> 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));
> }
>
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] iommu/iova: Replace cmpxchg with xchg in queue_iova
2020-08-27 8:43 [PATCH] iommu/iova: Replace cmpxchg with xchg in queue_iova Shaokun Zhang
2020-08-27 19:41 ` Robin Murphy
@ 2020-09-04 9:37 ` Joerg Roedel
2020-09-04 9:58 ` Robin Murphy
1 sibling, 1 reply; 5+ messages in thread
From: Joerg Roedel @ 2020-09-04 9:37 UTC (permalink / raw)
To: Shaokun Zhang; +Cc: Yuqi Jin, iommu, Robin Murphy, linux-kernel
Adding Robin.
On Thu, Aug 27, 2020 at 04:43:54PM +0800, Shaokun Zhang wrote:
> From: Yuqi Jin <jinyuqi@huawei.com>
>
> 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.
>
> Cc: Joerg Roedel <joro@8bytes.org>
> Signed-off-by: Yuqi Jin <jinyuqi@huawei.com>
> Signed-off-by: Shaokun Zhang <zhangshaokun@hisilicon.com>
> ---
> 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));
> }
> --
> 2.7.4
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] iommu/iova: Replace cmpxchg with xchg in queue_iova
2020-09-04 9:37 ` Joerg Roedel
@ 2020-09-04 9:58 ` Robin Murphy
2020-09-04 10:10 ` Joerg Roedel
0 siblings, 1 reply; 5+ messages in thread
From: Robin Murphy @ 2020-09-04 9:58 UTC (permalink / raw)
To: Joerg Roedel, Shaokun Zhang; +Cc: Yuqi Jin, iommu, linux-kernel
Hi Joerg,
On 2020-09-04 10:37, Joerg Roedel wrote:
> Adding Robin.
Did you miss that I've reviewed this already? :)
https://lore.kernel.org/linux-iommu/3afcc7b2-0bfb-b79c-513f-1beb66c5f164@arm.com/
Robin.
> On Thu, Aug 27, 2020 at 04:43:54PM +0800, Shaokun Zhang wrote:
>> From: Yuqi Jin <jinyuqi@huawei.com>
>>
>> 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.
>>
>> Cc: Joerg Roedel <joro@8bytes.org>
>> Signed-off-by: Yuqi Jin <jinyuqi@huawei.com>
>> Signed-off-by: Shaokun Zhang <zhangshaokun@hisilicon.com>
>> ---
>> 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));
>> }
>> --
>> 2.7.4
> _______________________________________________
> iommu mailing list
> iommu@lists.linux-foundation.org
> https://lists.linuxfoundation.org/mailman/listinfo/iommu
>
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] iommu/iova: Replace cmpxchg with xchg in queue_iova
2020-09-04 9:58 ` Robin Murphy
@ 2020-09-04 10:10 ` Joerg Roedel
0 siblings, 0 replies; 5+ messages in thread
From: Joerg Roedel @ 2020-09-04 10:10 UTC (permalink / raw)
To: Robin Murphy; +Cc: Shaokun Zhang, Yuqi Jin, iommu, linux-kernel
Hi Robin,
On Fri, Sep 04, 2020 at 10:58:14AM +0100, Robin Murphy wrote:
> On 2020-09-04 10:37, Joerg Roedel wrote:
> > Adding Robin.
>
> Did you miss that I've reviewed this already? :)
>
> https://lore.kernel.org/linux-iommu/3afcc7b2-0bfb-b79c-513f-1beb66c5f164@arm.com/
Hmm, that mail wasn't in my inbox, but b4 found it. I'll need to look
why it didn't make it...
Joerg
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-09-04 10:10 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-27 8:43 [PATCH] iommu/iova: Replace cmpxchg with xchg in queue_iova Shaokun Zhang
2020-08-27 19:41 ` Robin Murphy
2020-09-04 9:37 ` Joerg Roedel
2020-09-04 9:58 ` Robin Murphy
2020-09-04 10:10 ` Joerg Roedel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).