[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20251002125823.GC32506@redhat.com>
Date: Thu, 2 Oct 2025 14:58:24 +0200
From: Oleg Nesterov <oleg@...hat.com>
To: Peter Zijlstra <peterz@...radead.org>
Cc: Boqun Feng <boqun.feng@...il.com>, David Howells <dhowells@...hat.com>,
Ingo Molnar <mingo@...hat.com>, Li RongQing <lirongqing@...du.com>,
Linus Torvalds <torvalds@...ux-foundation.org>,
Waiman Long <longman@...hat.com>, Will Deacon <will@...nel.org>,
linux-kernel@...r.kernel.org
Subject: Re: [RFC 2/1] seqlock: make the read_seqbegin_or_lock() API more
simple and less error-prone ?
On 10/01, Oleg Nesterov wrote:
>
> +static inline int xxx(seqlock_t *lock, int lockless, int *seq, unsigned long *flags)
> +{
> + if (lockless) {
> + *seq = read_seqbegin(lock);
> + return 1;
> + } else if (*seq & 1) {
> + if (flags)
> + read_sequnlock_excl_irqrestore(lock, *flags);
> + else
> + read_sequnlock_excl(lock);
> + return 0;
> + } else if (read_seqretry(lock, *seq)) {
> + if (flags)
> + read_seqlock_excl_irqsave(lock, *flags);
> + else
> + read_seqlock_excl(lock);
> + *seq = 1;
> + return 1;
> + } else {
> + return 0;
> + }
> +}
> +
> +#define __XXX(lock, lockless, seq, flags) \
> + for (int lockless = 1, seq; xxx(lock, lockless, &seq, flags); lockless = 0)
> +
> +#define XXX(lock, flags) \
> + __XXX(lock, __UNIQUE_ID(lockless), __UNIQUE_ID(seq), flags)
Or, better
static inline int xxx(seqlock_t *lock, int *seq, unsigned long *flags)
{
int retry = 0;
if (*seq & 1) {
if (flags)
read_sequnlock_excl_irqrestore(lock, *flags);
else
read_sequnlock_excl(lock);
} else if (read_seqretry(lock, *seq)) {
retry = *seq = 1;
if (flags)
read_seqlock_excl_irqsave(lock, *flags);
else
read_seqlock_excl(lock);
}
return retry;
}
#define __XXX(lock, lockless, seq, flags) \
for (int lockless = 1, seq = read_seqbegin(lock); \
lockless || xxx(lock, &seq, flags); \
lockless = 0)
#define XXX(lock, flags) \
__XXX(lock, __UNIQUE_ID(lockless), __UNIQUE_ID(seq), flags)
With this version the change in thread_group_cputime() even shrinks .text a little bit.
I'd like to send the patch, but I still can't find a good name... Peter, will you agree
with SEQBEGIN_OR_LOCK(lock, flags) ?
Oleg.
Powered by blists - more mailing lists