From: Ankur Arora <ankur.a.arora@oracle.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>,
Ankur Arora <ankur.a.arora@oracle.com>,
LKML <linux-kernel@vger.kernel.org>,
linux-arch <linux-arch@vger.kernel.org>,
linux-arm-kernel <linux-arm-kernel@lists.infradead.org>,
bpf <bpf@vger.kernel.org>, Arnd Bergmann <arnd@arndb.de>,
Will Deacon <will@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
Andrew Morton <akpm@linux-foundation.org>,
Mark Rutland <mark.rutland@arm.com>,
harisokn@amazon.com, cl@gentwo.org,
Alexei Starovoitov <ast@kernel.org>,
Kumar Kartikeya Dwivedi <memxor@gmail.com>,
zhenglifeng1@huawei.com, xueshuai@linux.alibaba.com,
joao.m.martins@oracle.com,
Boris Ostrovsky <boris.ostrovsky@oracle.com>,
konrad.wilk@oracle.com
Subject: Re: [PATCH v4 5/5] rqspinlock: use smp_cond_load_acquire_timewait()
Date: Tue, 02 Sep 2025 14:30:58 -0700 [thread overview]
Message-ID: <87plc8r17x.fsf@oracle.com> (raw)
In-Reply-To: <CAADnVQJf317mXSDLs=K0pzTDGqMA8vqSDoNm5=LvEst6kdAi6w@mail.gmail.com>
Alexei Starovoitov <alexei.starovoitov@gmail.com> writes:
> On Mon, Sep 1, 2025 at 4:28 AM Catalin Marinas <catalin.marinas@arm.com> wrote:
>>
>> On Fri, Aug 29, 2025 at 01:07:35AM -0700, Ankur Arora wrote:
>> > diff --git a/arch/arm64/include/asm/rqspinlock.h b/arch/arm64/include/asm/rqspinlock.h
>> > index a385603436e9..ce8feadeb9a9 100644
>> > --- a/arch/arm64/include/asm/rqspinlock.h
>> > +++ b/arch/arm64/include/asm/rqspinlock.h
>> > @@ -3,6 +3,9 @@
>> > #define _ASM_RQSPINLOCK_H
>> >
>> > #include <asm/barrier.h>
>> > +
>> > +#define res_smp_cond_load_acquire_waiting() arch_timer_evtstrm_available()
>>
>> More on this below, I don't think we should define it.
>>
>> > diff --git a/kernel/bpf/rqspinlock.c b/kernel/bpf/rqspinlock.c
>> > index 5ab354d55d82..8de1395422e8 100644
>> > --- a/kernel/bpf/rqspinlock.c
>> > +++ b/kernel/bpf/rqspinlock.c
>> > @@ -82,6 +82,7 @@ struct rqspinlock_timeout {
>> > u64 duration;
>> > u64 cur;
>> > u16 spin;
>> > + u8 wait;
>> > };
>> >
>> > #define RES_TIMEOUT_VAL 2
>> > @@ -241,26 +242,20 @@ static noinline int check_timeout(rqspinlock_t *lock, u32 mask,
>> > }
>> >
>> > /*
>> > - * Do not amortize with spins when res_smp_cond_load_acquire is defined,
>> > - * as the macro does internal amortization for us.
>> > + * Only amortize with spins when we don't have a waiting implementation.
>> > */
>> > -#ifndef res_smp_cond_load_acquire
>> > #define RES_CHECK_TIMEOUT(ts, ret, mask) \
>> > ({ \
>> > - if (!(ts).spin++) \
>> > + if ((ts).wait || !(ts).spin++) \
>> > (ret) = check_timeout((lock), (mask), &(ts)); \
>> > (ret); \
>> > })
>> > -#else
>> > -#define RES_CHECK_TIMEOUT(ts, ret, mask) \
>> > - ({ (ret) = check_timeout((lock), (mask), &(ts)); })
>> > -#endif
>>
>> IIUC, RES_CHECK_TIMEOUT in the current res_smp_cond_load_acquire() usage
>> doesn't amortise the spins, as the comment suggests, but rather the
>> calls to check_timeout(). This is fine, it matches the behaviour of
>> smp_cond_load_relaxed_timewait() you introduced in the first patch. The
>> only difference is the number of spins - 200 (matching poll_idle) vs 64K
>> above. Does 200 work for the above?
>>
>> > /*
>> > * Initialize the 'spin' member.
>> > * Set spin member to 0 to trigger AA/ABBA checks immediately.
>> > */
>> > -#define RES_INIT_TIMEOUT(ts) ({ (ts).spin = 0; })
>> > +#define RES_INIT_TIMEOUT(ts) ({ (ts).spin = 0; (ts).wait = res_smp_cond_load_acquire_waiting(); })
>>
>> First of all, I don't really like the smp_cond_load_acquire_waiting(),
>> that's an implementation detail of smp_cond_load_*_timewait() that
>> shouldn't leak outside. But more importantly, RES_CHECK_TIMEOUT() is
>> also used outside the smp_cond_load_acquire_timewait() condition. The
>> (ts).wait check only makes sense when used together with the WFE
>> waiting.
>
> +1 to the above.
Ack.
> Penalizing all other architectures with pointless runtime check:
>
>> - if (!(ts).spin++) \
>> + if ((ts).wait || !(ts).spin++) \
>
> is not acceptable.
Is it still a penalty if the context is a busy wait loop.
Oddly enough the compiler does not eliminate this check on x86 (given
that it is statically defined to be 0 and ts does not escape the
function.)
--
ankur
next prev parent reply other threads:[~2025-09-02 21:31 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-29 8:07 [PATCH v4 0/5] barrier: Add smp_cond_load_*_timewait() Ankur Arora
2025-08-29 8:07 ` [PATCH v4 1/5] asm-generic: barrier: Add smp_cond_load_relaxed_timewait() Ankur Arora
2025-09-01 11:29 ` Catalin Marinas
2025-09-02 21:34 ` Ankur Arora
2025-08-29 8:07 ` [PATCH v4 2/5] arm64: " Ankur Arora
2025-09-01 11:47 ` Catalin Marinas
2025-09-02 22:40 ` Ankur Arora
2025-08-29 8:07 ` [PATCH v4 3/5] arm64: rqspinlock: Remove private copy of smp_cond_load_acquire_timewait Ankur Arora
2025-09-01 11:47 ` Catalin Marinas
2025-08-29 8:07 ` [PATCH v4 4/5] asm-generic: barrier: Add smp_cond_load_acquire_timewait() Ankur Arora
2025-09-01 11:47 ` Catalin Marinas
2025-08-29 8:07 ` [PATCH v4 5/5] rqspinlock: use smp_cond_load_acquire_timewait() Ankur Arora
2025-09-01 11:28 ` Catalin Marinas
2025-09-02 17:43 ` Alexei Starovoitov
2025-09-02 21:30 ` Ankur Arora [this message]
2025-09-02 21:31 ` Ankur Arora
2025-08-29 18:54 ` [PATCH v4 0/5] barrier: Add smp_cond_load_*_timewait() Okanovic, Haris
2025-08-29 22:38 ` Ankur Arora
2025-09-01 11:49 ` Catalin Marinas
2025-09-02 22:46 ` Ankur Arora
2025-09-03 9:27 ` Catalin Marinas
2025-09-03 18:34 ` Ankur Arora
2025-09-03 15:56 ` Okanovic, Haris
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=87plc8r17x.fsf@oracle.com \
--to=ankur.a.arora@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=alexei.starovoitov@gmail.com \
--cc=arnd@arndb.de \
--cc=ast@kernel.org \
--cc=boris.ostrovsky@oracle.com \
--cc=bpf@vger.kernel.org \
--cc=catalin.marinas@arm.com \
--cc=cl@gentwo.org \
--cc=harisokn@amazon.com \
--cc=joao.m.martins@oracle.com \
--cc=konrad.wilk@oracle.com \
--cc=linux-arch@vger.kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=memxor@gmail.com \
--cc=peterz@infradead.org \
--cc=will@kernel.org \
--cc=xueshuai@linux.alibaba.com \
--cc=zhenglifeng1@huawei.com \
/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®