Re: [PATCH v2 1/4] seqlock: introduce scoped_seqlock_read() and scoped_seqlock_read_irqsave()

From: Oleg Nesterov

Date: Mon Oct 13 2025 - 07:50:21 EST


On 10/13, Peter Zijlstra wrote:
>
> On Fri, Oct 10, 2025 at 03:14:39PM +0200, Oleg Nesterov wrote:
> > static inline void __scoped_seqlock_cleanup(struct ss_tmp *sst)
> > {
> > if (sst->state & ss_lock)
> > spin_unlock(&sst->lock.lock);
> > if (sst->state & ss_lock_irqsave)
> > spin_unlock_irqrestore(&sst->lock.lock, sst->data);
> > }
> >
> > static inline void
> > __scoped_seqlock_next(struct ss_tmp *sst, enum ss_state target)
> > {
> > switch (sst->state) {
> > case ss_lock:
> > case ss_lock_irqsave:
> > sst->state |= ss_done;
>
> So GCC is clever enough to see through this scheme, but Clang gets
> confused and generates worse code. Specifically it emits the whole
> __scoped_seqlock_cleanup() sequence, testing both bits and both unlock
> options.

OK, thanks and sorry for the noise then.

> So while that additional pointer might seem wasteful, it actually makes
> the state tracking easier and allows the compiler to more easily throw
> away stuff.

Great ;)

Oleg.