[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251009221242.GX3419281@noisy.programming.kicks-ass.net>
Date: Fri, 10 Oct 2025 00:12:42 +0200
From: Peter Zijlstra <peterz@...radead.org>
To: Linus Torvalds <torvalds@...ux-foundation.org>
Cc: Oleg Nesterov <oleg@...hat.com>,
Alexander Viro <viro@...iv.linux.org.uk>,
Boqun Feng <boqun.feng@...il.com>,
David Howells <dhowells@...hat.com>, Ingo Molnar <mingo@...hat.com>,
Li RongQing <lirongqing@...du.com>,
Waiman Long <longman@...hat.com>, Will Deacon <will@...nel.org>,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2 1/4] seqlock: introduce scoped_seqlock_read() and
scoped_seqlock_read_irqsave()
On Thu, Oct 09, 2025 at 01:24:51PM -0700, Linus Torvalds wrote:
> On Thu, 9 Oct 2025 at 13:12, Peter Zijlstra <peterz@...radead.org> wrote:
> >
> > Slightly nicer version that's actually compiled :-)
>
> I assume that "target of ss_lockless" is an intentional extension to
> just make the loop never take a lock at all?
Yep. Almost came for free, so might as well do it.
> I do like it, but I think you'll find that having a separate 'seq' and
> 'flags' like this:
>
> > +struct ss_tmp {
> > + enum ss_state state;
> > + int seq;
> > + unsigned long flags;
> > + spinlock_t *lock;
> > +};
>
> makes it unnecessarily waste a register.
>
> You never need both seq and flags at the same time, since if you take
> the spinlock the sequence number is pointless.
>
> So please make that a union, and I think it will help avoid wasting a
> register in the loop.
Sure; otoh compiler should be able to tell the same using liveness
analysis I suppose, but perhaps they're not *that* clever.
> Other than that I like it. Except that "BUG()" really bugs me. It will
> generate horrendous code for no reason and we *really* shouldn't add
> BUG statements anyway.
>
> Either that inline function is fine, or it isn't. Don't make it
> generate stupid code for "I'm not fine" that will also be a huge pain
> to debug because if that code is buggy it will presumably trigger in
> context where the machine will be dead, dead, dead.
So I thought they were fine; we handle all the enum cases with 'return'
so its impossible to not exit the switch() but the silly compiler was
complaining about possible fall-through, so clearly it was getting
confused.
The ss_done case should never trip either -- perhaps I should make that
one of those __scoped_seqlock_fail like things as well.
Anyway, I'll play around with it some (and look at actual code-gen)
tomorrow.
Powered by blists - more mailing lists