public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: David Carlier <devnexen@gmail.com>
To: Ingo Molnar <mingo@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Juri Lelli <juri.lelli@redhat.com>,
	Vincent Guittot <vincent.guittot@linaro.org>,
	Dietmar Eggemann <dietmar.eggemann@arm.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
	Valentin Schneider <vschneid@redhat.com>,
	K Prateek Nayak <kprateek.nayak@amd.com>
Cc: David Carlier <devnexen@gmail.com>, linux-kernel@vger.kernel.org
Subject: [PATCH] sched/rt: Use atomic_try_cmpxchg_acquire() in rto_start_trylock()
Date: Wed, 15 Apr 2026 13:40:44 +0100	[thread overview]
Message-ID: <20260415124045.372307-1-devnexen@gmail.com> (raw)

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


             reply	other threads:[~2026-04-15 12:40 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-15 12:40 David Carlier [this message]
2026-04-15 18:14 ` [PATCH] sched/rt: Use atomic_try_cmpxchg_acquire() in rto_start_trylock() Uros Bizjak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260415124045.372307-1-devnexen@gmail.com \
    --to=devnexen@gmail.com \
    --cc=bsegall@google.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=juri.lelli@redhat.com \
    --cc=kprateek.nayak@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=vincent.guittot@linaro.org \
    --cc=vschneid@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox