All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] sched/clock: Use try_cmpxchg64 in sched_clock_{local,remote}
@ 2022-05-18 18:49 Uros Bizjak
  2022-05-19  7:47 ` Peter Zijlstra
  2022-05-19 21:49 ` [tip: locking/core] " tip-bot2 for Uros Bizjak
  0 siblings, 2 replies; 3+ messages in thread
From: Uros Bizjak @ 2022-05-18 18:49 UTC (permalink / raw)
  To: linux-kernel
  Cc: Uros Bizjak, Ingo Molnar, Peter Zijlstra, Juri Lelli,
	Vincent Guittot, Dietmar Eggemann, Steven Rostedt, Ben Segall,
	Mel Gorman, Daniel Bristot de Oliveira

Use try_cmpxchg64 instead of cmpxchg64 (*ptr, old, new) != old in
sched_clock_{local,remote}. x86 cmpxchg returns success in ZF flag,
so this change saves a compare after cmpxchg (and related move
instruction in front of cmpxchg).

Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Juri Lelli <juri.lelli@redhat.com>
Cc: Vincent Guittot <vincent.guittot@linaro.org>
Cc: Dietmar Eggemann <dietmar.eggemann@arm.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Ben Segall <bsegall@google.com>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Daniel Bristot de Oliveira <bristot@redhat.com>
---
Patch requires commits 0aa7be05d83cc584da0782405e8007e351dfb6cc
and c2df0a6af177b6c06a859806a876f92b072dc624 from tip.git
---
 kernel/sched/clock.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/sched/clock.c b/kernel/sched/clock.c
index d9272d9061a3..e374c0c923da 100644
--- a/kernel/sched/clock.c
+++ b/kernel/sched/clock.c
@@ -287,7 +287,7 @@ notrace static u64 sched_clock_local(struct sched_clock_data *scd)
 	clock = wrap_max(clock, min_clock);
 	clock = wrap_min(clock, max_clock);
 
-	if (cmpxchg64(&scd->clock, old_clock, clock) != old_clock)
+	if (!try_cmpxchg64(&scd->clock, &old_clock, clock))
 		goto again;
 
 	return clock;
@@ -349,7 +349,7 @@ notrace static u64 sched_clock_remote(struct sched_clock_data *scd)
 		val = remote_clock;
 	}
 
-	if (cmpxchg64(ptr, old_val, val) != old_val)
+	if (!try_cmpxchg64(ptr, &old_val, val))
 		goto again;
 
 	return val;
-- 
2.35.1


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

* Re: [PATCH] sched/clock: Use try_cmpxchg64 in sched_clock_{local,remote}
  2022-05-18 18:49 [PATCH] sched/clock: Use try_cmpxchg64 in sched_clock_{local,remote} Uros Bizjak
@ 2022-05-19  7:47 ` Peter Zijlstra
  2022-05-19 21:49 ` [tip: locking/core] " tip-bot2 for Uros Bizjak
  1 sibling, 0 replies; 3+ messages in thread
From: Peter Zijlstra @ 2022-05-19  7:47 UTC (permalink / raw)
  To: Uros Bizjak
  Cc: linux-kernel, Ingo Molnar, Juri Lelli, Vincent Guittot,
	Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
	Daniel Bristot de Oliveira

On Wed, May 18, 2022 at 08:49:53PM +0200, Uros Bizjak wrote:
> Use try_cmpxchg64 instead of cmpxchg64 (*ptr, old, new) != old in
> sched_clock_{local,remote}. x86 cmpxchg returns success in ZF flag,
> so this change saves a compare after cmpxchg (and related move
> instruction in front of cmpxchg).
> 
> Signed-off-by: Uros Bizjak <ubizjak@gmail.com>

Thanks!

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

* [tip: locking/core] sched/clock: Use try_cmpxchg64 in sched_clock_{local,remote}
  2022-05-18 18:49 [PATCH] sched/clock: Use try_cmpxchg64 in sched_clock_{local,remote} Uros Bizjak
  2022-05-19  7:47 ` Peter Zijlstra
@ 2022-05-19 21:49 ` tip-bot2 for Uros Bizjak
  1 sibling, 0 replies; 3+ messages in thread
From: tip-bot2 for Uros Bizjak @ 2022-05-19 21:49 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: Uros Bizjak, Peter Zijlstra (Intel), x86, linux-kernel

The following commit has been merged into the locking/core branch of tip:

Commit-ID:     8491d1bdf5de152f27fc941e2dcdc4e66c950542
Gitweb:        https://git.kernel.org/tip/8491d1bdf5de152f27fc941e2dcdc4e66c950542
Author:        Uros Bizjak <ubizjak@gmail.com>
AuthorDate:    Wed, 18 May 2022 20:49:53 +02:00
Committer:     Peter Zijlstra <peterz@infradead.org>
CommitterDate: Thu, 19 May 2022 23:46:09 +02:00

sched/clock: Use try_cmpxchg64 in sched_clock_{local,remote}

Use try_cmpxchg64 instead of cmpxchg64 (*ptr, old, new) != old in
sched_clock_{local,remote}. x86 cmpxchg returns success in ZF flag,
so this change saves a compare after cmpxchg (and related move
instruction in front of cmpxchg).

Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20220518184953.3446778-1-ubizjak@gmail.com
---
 kernel/sched/clock.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/sched/clock.c b/kernel/sched/clock.c
index d9272d9..e374c0c 100644
--- a/kernel/sched/clock.c
+++ b/kernel/sched/clock.c
@@ -287,7 +287,7 @@ again:
 	clock = wrap_max(clock, min_clock);
 	clock = wrap_min(clock, max_clock);
 
-	if (cmpxchg64(&scd->clock, old_clock, clock) != old_clock)
+	if (!try_cmpxchg64(&scd->clock, &old_clock, clock))
 		goto again;
 
 	return clock;
@@ -349,7 +349,7 @@ again:
 		val = remote_clock;
 	}
 
-	if (cmpxchg64(ptr, old_val, val) != old_val)
+	if (!try_cmpxchg64(ptr, &old_val, val))
 		goto again;
 
 	return val;

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

end of thread, other threads:[~2022-05-19 21:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-18 18:49 [PATCH] sched/clock: Use try_cmpxchg64 in sched_clock_{local,remote} Uros Bizjak
2022-05-19  7:47 ` Peter Zijlstra
2022-05-19 21:49 ` [tip: locking/core] " tip-bot2 for Uros Bizjak

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.