From: David Laight <David.Laight@ACULAB.COM>
To: 'Peter Zijlstra' <peterz@infradead.org>, Will Deacon <will@kernel.org>
Cc: Muchun Song <songmuchun@bytedance.com>,
"mingo@redhat.com" <mingo@redhat.com>,
"mingo@kernel.org" <mingo@kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: RE: [PATCH] seqlock: Use while instead of if+goto in __read_seqcount_begin
Date: Wed, 15 Apr 2020 09:37:18 +0000 [thread overview]
Message-ID: <75b4b9ff3a31432c913b521a98259123@AcuMS.aculab.com> (raw)
In-Reply-To: <20200414110516.GO20713@hirez.programming.kicks-ass.net>
From: Peter Zijlstra
> Sent: 14 April 2020 12:05
> On Fri, Apr 10, 2020 at 12:56:58PM +0100, Will Deacon wrote:
> > On Thu, Apr 09, 2020 at 09:45:58PM +0800, Muchun Song wrote:
> > > The creators of the C language gave us the while keyword. Let's use
> > > that instead of synthesizing it from if+goto.
> > >
> > > Signed-off-by: Muchun Song <songmuchun@bytedance.com>
> > > ---
> > > include/linux/seqlock.h | 6 +-----
> > > 1 file changed, 1 insertion(+), 5 deletions(-)
> > >
> > > diff --git a/include/linux/seqlock.h b/include/linux/seqlock.h
> > > index 8b97204f35a77..7bdea019814ce 100644
> > > --- a/include/linux/seqlock.h
> > > +++ b/include/linux/seqlock.h
> > > @@ -125,12 +125,8 @@ static inline unsigned __read_seqcount_begin(const seqcount_t *s)
> > > {
> > > unsigned ret;
> > >
> > > -repeat:
> > > - ret = READ_ONCE(s->sequence);
> > > - if (unlikely(ret & 1)) {
> > > + while (unlikely((ret = READ_ONCE(s->sequence)) & 1))
> > > cpu_relax();
> > > - goto repeat;
> > > - }
> > > kcsan_atomic_next(KCSAN_SEQLOCK_REGION_MAX);
> > > return ret;
> >
> > Patch looks fine to me, but I'll leave it to Peter as I don't have a
> > preference either way.
>
> Linus sometimes prefers the goto variant as that better expresses the
> exception model. But like Will, I don't particularly care. That said,
> Will, would it make sense to use smp_cond_load_relaxed() here ?
gcc also has a nasty habit of converting:
while (foo)
bar;
into:
if (foo) {
do
bar;
while (foo);
}
with all the code bloat that entails - especially when 'foo'
is non-trivial.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
prev parent reply other threads:[~2020-04-15 9:37 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-09 13:45 Muchun Song
2020-04-10 11:56 ` Will Deacon
2020-04-14 8:58 ` [External] " Muchun Song
2020-04-14 11:05 ` Peter Zijlstra
2020-04-14 12:01 ` [External] " Muchun Song
2020-04-15 11:41 ` Peter Zijlstra
2020-04-14 13:48 ` Will Deacon
2020-04-15 11:44 ` Peter Zijlstra
2020-04-15 9:37 ` David Laight [this message]
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=75b4b9ff3a31432c913b521a98259123@AcuMS.aculab.com \
--to=david.laight@aculab.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=songmuchun@bytedance.com \
--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®