From: David Laight <david.laight.linux@gmail.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Waiman Long <longman@redhat.com>, Ingo Molnar <mingo@redhat.com>,
Will Deacon <will@kernel.org>, Boqun Feng <boqun@kernel.org>,
linux-kernel@vger.kernel.org,
Linus Torvalds <torvalds@linux-foundation.org>,
Yafang Shao <laoar.shao@gmail.com>,
Steven Rostedt <rostedt@goodmis.org>
Subject: Re: [PATCH v4 next 3/9] locking/osq_lock: Set prev_cpu=0 instead of locked=1
Date: Tue, 15 Sep 2026 11:14:08 +0100 [thread overview]
Message-ID: <20260915111408.2c8a3ecd@pumpkin> (raw)
In-Reply-To: <20260915084047.GZ4121339@noisy.programming.kicks-ass.net>
On Tue, 15 Sep 2026 10:40:47 +0200
Peter Zijlstra <peterz@infradead.org> wrote:
> On Mon, Sep 14, 2026 at 02:08:32PM +0100, David Laight wrote:
> > On Mon, 14 Sep 2026 14:03:52 +0200
> > Peter Zijlstra <peterz@infradead.org> wrote:
> >
> > > On Mon, Sep 07, 2026 at 09:41:27AM +0100, David Laight wrote:
> > >
> > > > - for (;;) {
> > > > - /*
> > > > - * cpu_relax() below implies a compiler barrier which would
> > > > - * prevent this comparison being optimized away.
> > > > - */
> > > > + for (;; prev = READ_ONCE(node->prev)) {
> > > > + if (!prev)
> > > > + /* Lock acquired */
> > > > + return true;
> > >
> > > This lacks {}, but also, is not ACQUIRE like the return you remove
> > > below. Did you want smp_acquire__after_ctrl_dep() in there?
> >
> > I need to get my head around the acquire/release logic.
> > I think the READ_ONCE() in the for(;;) needs to be an acquire
> > (matching the smp_cond_load - which seems to have been wrong for ages).
> > I may have decided that because the smp_cond_load was relaxed this
> > read could be as well.
> > (They both need to be the same.)
>
> You cannot change ordering and not mention in the changelog. If you're
> unsure, retain existing ordering and make note in changelog.
The existing ordering seems to have been broken.
I'll rework it for the next version.
(It rather depends on what happens to the patch to change the smp_cond_load.)
>
> > >
> > > > +
> > > > + prev_ptr = decode_cpu(prev);
> > > > +
> > > > if (data_race(prev_ptr->next) == node &&
> >
> > I'm also going to remove that 'optimisation' check.
> > It is there to avoid the atomic below - but it only fails under
> > race conditions.
> >
> > David
> >
> > > > cmpxchg(&prev_ptr->next, node, NULL) == node)
> > > > break;
>
> Someone will put it back eventually. It is typically good form to have
> this pre check. It improved the contended behaviour of these loops. The
> regular load can be a forward, while CAS requires an exclusive load --
> or something along those lines.
I know. I think it really depends on the likelyhood of the compare failing.
It there is a reasonable chance of it failing you definitely need the compare.
David
next prev parent reply other threads:[~2026-09-15 10:14 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-07 8:41 [PATCH v4 next 0/9] locking/osq_lock: Optimisations to osq_lock code David Laight
2026-09-07 8:41 ` [PATCH v4 next 1/9] locking/osq_lock: Add some comments about how it works David Laight
2026-09-09 14:57 ` Waiman Long
2026-09-07 8:41 ` [PATCH v4 next 2/9] locking/osq_lock: Save the cpu number for 'prev' not the node address David Laight
2026-09-09 17:36 ` Waiman Long
2026-09-15 8:33 ` Peter Zijlstra
2026-09-15 10:26 ` Peter Zijlstra
2026-09-15 11:11 ` David Laight
2026-09-07 8:41 ` [PATCH v4 next 3/9] locking/osq_lock: Set prev_cpu=0 instead of locked=1 David Laight
2026-09-09 18:01 ` Waiman Long
2026-09-09 18:52 ` David Laight
2026-09-14 12:01 ` Peter Zijlstra
2026-09-14 13:10 ` David Laight
2026-09-14 12:03 ` Peter Zijlstra
2026-09-14 13:08 ` David Laight
2026-09-15 8:40 ` Peter Zijlstra
2026-09-15 10:14 ` David Laight [this message]
2026-09-15 8:50 ` Peter Zijlstra
2026-09-15 10:20 ` David Laight
2026-09-15 10:40 ` Peter Zijlstra
2026-09-15 13:13 ` Peter Zijlstra
2026-09-15 13:15 ` Peter Zijlstra
2026-09-15 13:55 ` David Laight
2026-09-15 14:01 ` Peter Zijlstra
2026-09-07 8:41 ` [PATCH v4 next 4/9] locking/osq_lock: Delete 'fast path' code from osq_unlock() David Laight
2026-09-15 14:15 ` Peter Zijlstra
2026-09-07 8:41 ` [PATCH v4 next 5/9] locking/osq_lock: Avoid writing to node->next in the osq_lock() fast path David Laight
2026-09-07 8:41 ` [PATCH v4 next 6/9] locking/osq: Use cpu number for 'next' pointer David Laight
2026-09-07 8:41 ` [PATCH v4 next 7/9] locking/osq: Use 'unsigned int' for next/prev/tail David Laight
2026-09-07 8:41 ` [PATCH v4 next 8/9] locking/osq: inline encode_cpu() and rename decode_cpu() David Laight
2026-09-07 8:41 ` [PATCH v4 next 9/9] locking/osq_lock: Swap next<->prev and tail<->head David Laight
2026-09-07 16:08 ` [PATCH v4 next 0/9] locking/osq_lock: Optimisations to osq_lock code Linus Torvalds
2026-09-07 17:27 ` David Laight
2026-09-09 14:15 ` Haakon Bugge
2026-09-09 19:09 ` David Laight
2026-09-09 20:14 ` Waiman Long
2026-09-09 20:33 ` Waiman Long
2026-09-10 9:45 ` Haakon Bugge
2026-09-10 11:00 ` David Laight
2026-09-10 11:31 ` Haakon Bugge
2026-09-10 12:05 ` David Laight
2026-09-10 15:30 ` Haakon Bugge
2026-09-10 16:22 ` Waiman Long
2026-09-11 17:15 ` David Laight
2026-09-14 11:46 ` Haakon Bugge
2026-09-14 13:24 ` David Laight
2026-09-11 10:08 ` David Laight
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=20260915111408.2c8a3ecd@pumpkin \
--to=david.laight.linux@gmail.com \
--cc=boqun@kernel.org \
--cc=laoar.shao@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=longman@redhat.com \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=torvalds@linux-foundation.org \
--cc=will@kernel.org \
/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
all inboxes | Powered by JetHome®