public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] dmaengine:idxd: Use local64_try_cmpxchg in perfmon_pmu_event_update
@ 2023-07-03 14:52 Uros Bizjak
  2023-07-05 14:53 ` Dave Jiang
  2023-08-01 18:45 ` Vinod Koul
  0 siblings, 2 replies; 4+ messages in thread
From: Uros Bizjak @ 2023-07-03 14:52 UTC (permalink / raw)
  To: dmaengine, linux-kernel; +Cc: Uros Bizjak, Fenghua Yu, Dave Jiang, Vinod Koul

Use local64_try_cmpxchg instead of local64_cmpxchg (*ptr, old, new) == old
in perfmon_pmu_event_update.  x86 CMPXCHG instruction returns success in
ZF flag, so this change saves a compare after cmpxchg (and related move
instruction in front of cmpxchg).

Also, try_cmpxchg implicitly assigns old *ptr value to "old" when cmpxchg
fails. There is no need to re-read the value in the loop.

No functional change intended.

Cc: Fenghua Yu <fenghua.yu@intel.com>
Cc: Dave Jiang <dave.jiang@intel.com>
Cc: Vinod Koul <vkoul@kernel.org>
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
---
 drivers/dma/idxd/perfmon.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/dma/idxd/perfmon.c b/drivers/dma/idxd/perfmon.c
index d73004f47cf4..fdda6d604262 100644
--- a/drivers/dma/idxd/perfmon.c
+++ b/drivers/dma/idxd/perfmon.c
@@ -245,12 +245,11 @@ static void perfmon_pmu_event_update(struct perf_event *event)
 	int shift = 64 - idxd->idxd_pmu->counter_width;
 	struct hw_perf_event *hwc = &event->hw;
 
+	prev_raw_count = local64_read(&hwc->prev_count);
 	do {
-		prev_raw_count = local64_read(&hwc->prev_count);
 		new_raw_count = perfmon_pmu_read_counter(event);
-	} while (local64_cmpxchg(&hwc->prev_count, prev_raw_count,
-			new_raw_count) != prev_raw_count);
-
+	} while (!local64_try_cmpxchg(&hwc->prev_count,
+				      &prev_raw_count, new_raw_count));
 	n = (new_raw_count << shift);
 	p = (prev_raw_count << shift);
 
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] dmaengine:idxd: Use local64_try_cmpxchg in perfmon_pmu_event_update
  2023-07-03 14:52 [PATCH] dmaengine:idxd: Use local64_try_cmpxchg in perfmon_pmu_event_update Uros Bizjak
@ 2023-07-05 14:53 ` Dave Jiang
  2023-07-10 21:28   ` Tom Zanussi
  2023-08-01 18:45 ` Vinod Koul
  1 sibling, 1 reply; 4+ messages in thread
From: Dave Jiang @ 2023-07-05 14:53 UTC (permalink / raw)
  To: Uros Bizjak, dmaengine, linux-kernel; +Cc: Fenghua Yu, Vinod Koul, Zanussi, Tom



On 7/3/23 07:52, Uros Bizjak wrote:
> Use local64_try_cmpxchg instead of local64_cmpxchg (*ptr, old, new) == old
> in perfmon_pmu_event_update.  x86 CMPXCHG instruction returns success in
> ZF flag, so this change saves a compare after cmpxchg (and related move
> instruction in front of cmpxchg).
> 
> Also, try_cmpxchg implicitly assigns old *ptr value to "old" when cmpxchg
> fails. There is no need to re-read the value in the loop.
> 
> No functional change intended.
> 
> Cc: Fenghua Yu <fenghua.yu@intel.com>
> Cc: Dave Jiang <dave.jiang@intel.com>
> Cc: Vinod Koul <vkoul@kernel.org>
> Signed-off-by: Uros Bizjak <ubizjak@gmail.com>


Cc: Tom Zanussi

Tom do you mind review this patch? Thanks!

> ---
>   drivers/dma/idxd/perfmon.c | 7 +++----
>   1 file changed, 3 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/dma/idxd/perfmon.c b/drivers/dma/idxd/perfmon.c
> index d73004f47cf4..fdda6d604262 100644
> --- a/drivers/dma/idxd/perfmon.c
> +++ b/drivers/dma/idxd/perfmon.c
> @@ -245,12 +245,11 @@ static void perfmon_pmu_event_update(struct perf_event *event)
>   	int shift = 64 - idxd->idxd_pmu->counter_width;
>   	struct hw_perf_event *hwc = &event->hw;
>   
> +	prev_raw_count = local64_read(&hwc->prev_count);
>   	do {
> -		prev_raw_count = local64_read(&hwc->prev_count);
>   		new_raw_count = perfmon_pmu_read_counter(event);
> -	} while (local64_cmpxchg(&hwc->prev_count, prev_raw_count,
> -			new_raw_count) != prev_raw_count);
> -
> +	} while (!local64_try_cmpxchg(&hwc->prev_count,
> +				      &prev_raw_count, new_raw_count));
>   	n = (new_raw_count << shift);
>   	p = (prev_raw_count << shift);
>   

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] dmaengine:idxd: Use local64_try_cmpxchg in perfmon_pmu_event_update
  2023-07-05 14:53 ` Dave Jiang
@ 2023-07-10 21:28   ` Tom Zanussi
  0 siblings, 0 replies; 4+ messages in thread
From: Tom Zanussi @ 2023-07-10 21:28 UTC (permalink / raw)
  To: Dave Jiang, Uros Bizjak, dmaengine, linux-kernel
  Cc: Fenghua Yu, Vinod Koul, Zanussi, Tom

On Wed, 2023-07-05 at 07:53 -0700, Dave Jiang wrote:
> 
> 
> On 7/3/23 07:52, Uros Bizjak wrote:
> > Use local64_try_cmpxchg instead of local64_cmpxchg (*ptr, old, new) == old
> > in perfmon_pmu_event_update.  x86 CMPXCHG instruction returns success in
> > ZF flag, so this change saves a compare after cmpxchg (and related move
> > instruction in front of cmpxchg).
> > 
> > Also, try_cmpxchg implicitly assigns old *ptr value to "old" when cmpxchg
> > fails. There is no need to re-read the value in the loop.
> > 
> > No functional change intended.
> > 
> > Cc: Fenghua Yu <fenghua.yu@intel.com>
> > Cc: Dave Jiang <dave.jiang@intel.com>
> > Cc: Vinod Koul <vkoul@kernel.org>
> > Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
> 
> 
> Cc: Tom Zanussi
> 
> Tom do you mind review this patch? Thanks!

Looks fine to me.

Thanks,

Reviewed-by: Tom Zanussi <tom.zanussi@linux.intel.com>

> 
> > ---
> >   drivers/dma/idxd/perfmon.c | 7 +++----
> >   1 file changed, 3 insertions(+), 4 deletions(-)
> > 
> > diff --git a/drivers/dma/idxd/perfmon.c b/drivers/dma/idxd/perfmon.c
> > index d73004f47cf4..fdda6d604262 100644
> > --- a/drivers/dma/idxd/perfmon.c
> > +++ b/drivers/dma/idxd/perfmon.c
> > @@ -245,12 +245,11 @@ static void perfmon_pmu_event_update(struct perf_event *event)
> >         int shift = 64 - idxd->idxd_pmu->counter_width;
> >         struct hw_perf_event *hwc = &event->hw;
> >   
> > +       prev_raw_count = local64_read(&hwc->prev_count);
> >         do {
> > -               prev_raw_count = local64_read(&hwc->prev_count);
> >                 new_raw_count = perfmon_pmu_read_counter(event);
> > -       } while (local64_cmpxchg(&hwc->prev_count, prev_raw_count,
> > -                       new_raw_count) != prev_raw_count);
> > -
> > +       } while (!local64_try_cmpxchg(&hwc->prev_count,
> > +                                     &prev_raw_count, new_raw_count));
> >         n = (new_raw_count << shift);
> >         p = (prev_raw_count << shift);
> >   


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] dmaengine:idxd: Use local64_try_cmpxchg in perfmon_pmu_event_update
  2023-07-03 14:52 [PATCH] dmaengine:idxd: Use local64_try_cmpxchg in perfmon_pmu_event_update Uros Bizjak
  2023-07-05 14:53 ` Dave Jiang
@ 2023-08-01 18:45 ` Vinod Koul
  1 sibling, 0 replies; 4+ messages in thread
From: Vinod Koul @ 2023-08-01 18:45 UTC (permalink / raw)
  To: dmaengine, linux-kernel, Uros Bizjak; +Cc: Fenghua Yu, Dave Jiang


On Mon, 03 Jul 2023 16:52:37 +0200, Uros Bizjak wrote:
> Use local64_try_cmpxchg instead of local64_cmpxchg (*ptr, old, new) == old
> in perfmon_pmu_event_update.  x86 CMPXCHG instruction returns success in
> ZF flag, so this change saves a compare after cmpxchg (and related move
> instruction in front of cmpxchg).
> 
> Also, try_cmpxchg implicitly assigns old *ptr value to "old" when cmpxchg
> fails. There is no need to re-read the value in the loop.
> 
> [...]

Applied, thanks!

[1/1] dmaengine:idxd: Use local64_try_cmpxchg in perfmon_pmu_event_update
      commit: cae701b9ccf128edea26982f73178087fc3ad180

Best regards,
-- 
~Vinod



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-08-01 18:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-03 14:52 [PATCH] dmaengine:idxd: Use local64_try_cmpxchg in perfmon_pmu_event_update Uros Bizjak
2023-07-05 14:53 ` Dave Jiang
2023-07-10 21:28   ` Tom Zanussi
2023-08-01 18:45 ` Vinod Koul

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox