public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] sched/rt: Use atomic_try_cmpxchg_acquire() in rto_start_trylock()
@ 2026-04-15 12:40 David Carlier
  2026-04-15 18:14 ` Uros Bizjak
  0 siblings, 1 reply; 2+ messages in thread
From: David Carlier @ 2026-04-15 12:40 UTC (permalink / raw)
  To: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
	Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
	Valentin Schneider, K Prateek Nayak
  Cc: David Carlier, linux-kernel

Replace this pattern in rto_start_trylock():

    !atomic_cmpxchg_acquire(*ptr, 0, new)

... with the simpler and faster:

    atomic_try_cmpxchg_acquire(*ptr, &zero, new)

The x86 CMPXCHG instruction returns success in the ZF flag, so
atomic_try_cmpxchg_acquire() saves a compare after the CMPXCHG.

No functional change intended.

Signed-off-by: David Carlier <devnexen@gmail.com>
---
 kernel/sched/rt.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c
index 4ee8faf01441..13ac94899c18 100644
--- a/kernel/sched/rt.c
+++ b/kernel/sched/rt.c
@@ -2172,7 +2172,8 @@ static int rto_next_cpu(struct root_domain *rd)
 
 static inline bool rto_start_trylock(atomic_t *v)
 {
-	return !atomic_cmpxchg_acquire(v, 0, 1);
+	int zero = 0;
+	return atomic_try_cmpxchg_acquire(v, &zero, 1);
 }
 
 static inline void rto_start_unlock(atomic_t *v)
-- 
2.53.0


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

end of thread, other threads:[~2026-04-15 18:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-15 12:40 [PATCH] sched/rt: Use atomic_try_cmpxchg_acquire() in rto_start_trylock() David Carlier
2026-04-15 18:14 ` Uros Bizjak

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