linux-arch.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Okanovic, Haris" <harisokn@amazon.com>
To: "linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-arch@vger.kernel.org" <linux-arch@vger.kernel.org>,
	"ankur.a.arora@oracle.com" <ankur.a.arora@oracle.com>,
	"bpf@vger.kernel.org" <bpf@vger.kernel.org>
Cc: "Okanovic, Haris" <harisokn@amazon.com>,
	"cl@gentwo.org" <cl@gentwo.org>,
	"joao.m.martins@oracle.com" <joao.m.martins@oracle.com>,
	"akpm@linux-foundation.org" <akpm@linux-foundation.org>,
	"peterz@infradead.org" <peterz@infradead.org>,
	"mark.rutland@arm.com" <mark.rutland@arm.com>,
	"memxor@gmail.com" <memxor@gmail.com>,
	"catalin.marinas@arm.com" <catalin.marinas@arm.com>,
	"arnd@arndb.de" <arnd@arndb.de>,
	"will@kernel.org" <will@kernel.org>,
	"zhenglifeng1@huawei.com" <zhenglifeng1@huawei.com>,
	"ast@kernel.org" <ast@kernel.org>,
	"xueshuai@linux.alibaba.com" <xueshuai@linux.alibaba.com>,
	"konrad.wilk@oracle.com" <konrad.wilk@oracle.com>,
	"boris.ostrovsky@oracle.com" <boris.ostrovsky@oracle.com>
Subject: Re: [PATCH v2 0/7] barrier: introduce smp_cond_load_*_timewait()
Date: Fri, 16 May 2025 22:50:58 +0000	[thread overview]
Message-ID: <f2f5d09e79539754ced085ed89865787fa668695.camel@amazon.com> (raw)
In-Reply-To: <20250502085223.1316925-1-ankur.a.arora@oracle.com>

On Fri, 2025-05-02 at 01:52 -0700, Ankur Arora wrote:
> CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you can confirm the sender and know the content is safe.
> 
> 
> 
> Hi,
> 
> This series adds waited variants of the smp_cond_load() primitives:
> smp_cond_load_relaxed_timewait(), and smp_cond_load_acquire_timewait().
> 
> There are two known users for these interfaces:
> 
>  - poll_idle() [1]
>  - resilient queued spinlocks [2]
> 
> For both of these cases we want to wait on a condition but also want
> to terminate the wait based on a timeout.
> 
> Before describing how v2 implements these interfaces, let me recap the
> problems in v1 (Catalin outlined most of these in [3]):
> 
> smp_cond_load_relaxed_spinwait(ptr, cond_expr, time_expr_ns, time_limit_ns)
> took four arguments, with ptr and cond_expr doing the usual smp_cond_load()
> things and time_expr_ns and time_limit_ns being used to decide the
> terminating condition.
> 
> There were some problems in the timekeeping:
> 
> 1. How often do we do the (relatively expensive) time-check?
> 
>    The choice made was once very 200 spin-wait iterations, with each
>    iteration trying to idle the pipeline by executing cpu_relax().
> 
>    The choice of 200 was, of course, arbitrary and somewhat meaningless
>    across architectures. On recent x86, cpu_relax()/PAUSE takes ~20-30
>    cycles, but on (non-SMT) arm64 cpu_relax()/YIELD is effectively
>    just a NOP.
> 
>    Even if each architecture had its own limit, this will also vary
>    across microarchitectures.
> 
> 2. On arm64, which can do better than just cpu_relax(), for instance,
>    by waiting for a store on an address (WFE), the implementation
>    exclusively used WFE, with the spin-wait only used as a fallback
>    for when the event-stream was disabled.
> 
>    One problem with this was that the worst case timeout overshoot
>    with WFE is ARCH_TIMER_EVT_STREAM_PERIOD_US (100us) and so there's
>    a vast gulf between that and a potentially much smaller granularity
>    with the spin-wait versions. In addition the interface provided
>    no way for the caller to specify or limit the oveshoot.
> 
> Non-timekeeping issues:
> 
> 3. The interface was useful for poll_idle() like users but was not
>    usable if the caller needed to do any work. For instance,
>    rqspinlock uses it thus:
> 
>      smp_cond_load_acquire_timewait(v, c, 0, 1)
> 
>    Here the time-check always evaluates to false and all of the logic
>    (ex. deadlock checking) is folded into the conditional.
> 
> 
> With that foundation, the new interface is:
> 
>    smp_cond_load_relaxed_timewait(ptr, cond_expr, wait_policy,
>                                          time_expr, time_end)
> 
> The added parameter, wait_policy provides a mechanism for the caller
> to apportion time spent spinning or, where supported, in a wait.
> This is somewhat inspired from the queue_poll() mechanism used
> with smp_cond_load() in arm-smmu-v3 [4].
> 
> It addresses (1) by deciding the time-check granularity based on a
> time interval instead of spinning for a fixed number of iterations.
> 
> (2) is addressed by the wait_policy allowing for different slack
> values. The implemented versions of wait_policy allow for a coarse
> or a fine grained slack. A user defined wait_policy could choose
> its own wait parameter. This would also address (3).
> 
> 
> With that, patches 1-5, add the generic and arm64 logic:
> 
>   "asm-generic: barrier: add smp_cond_load_relaxed_timewait()",
>   "asm-generic: barrier: add wait_policy handlers"
> 
>   "arm64: barrier: enable waiting in smp_cond_load_relaxed_timewait()"
>   "arm64: barrier: add coarse wait for smp_cond_load_relaxed_timewait()"
>   "arm64: barrier: add fine wait for smp_cond_load_relaxed_timewait()".
> 
> And, patch 6, adds the acquire variant:
> 
>   "asm-generic: barrier: add smp_cond_load_acquire_timewait()"
> 
> And, finally patch 7 lays out how this could be used for rqspinlock:
> 
>   "bpf: rqspinlock: add rqspinlock policy handler for arm64".
> 
> Any comments appreciated!
> 
> Ankur
> 
> 
> [1] https://lore.kernel.org/lkml/20241107190818.522639-3-ankur.a.arora@oracle.com/
> [2] Uses the smp_cond_load_acquire_timewait() from v1
>     https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/arm64/include/asm/rqspinlock.h
> [3] https://lore.kernel.org/lkml/Z8dRalfxYcJIcLGj@arm.com/
> [4] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c#n223
> 
> 
> Cc: Arnd Bergmann <arnd@arndb.de>
> Cc: Will Deacon <will@kernel.org>
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Kumar Kartikeya Dwivedi <memxor@gmail.com>
> Cc: Alexei Starovoitov <ast@kernel.org>
> Cc: linux-arch@vger.kernel.org
> 
> 
> Ankur Arora (7):
>   asm-generic: barrier: add smp_cond_load_relaxed_timewait()
>   asm-generic: barrier: add wait_policy handlers
>   arm64: barrier: enable waiting in smp_cond_load_relaxed_timewait()
>   arm64: barrier: add coarse wait for smp_cond_load_relaxed_timewait()
>   arm64: barrier: add fine wait for smp_cond_load_relaxed_timewait()
>   asm-generic: barrier: add smp_cond_load_acquire_timewait()
>   bpf: rqspinlock: add rqspinlock policy handler for arm64
> 
>  arch/arm64/include/asm/barrier.h    |  82 +++++++++++++++
>  arch/arm64/include/asm/rqspinlock.h |  96 ++++--------------
>  include/asm-generic/barrier.h       | 150 ++++++++++++++++++++++++++++
>  3 files changed, 251 insertions(+), 77 deletions(-)
> 
> --
> 2.43.5
> 

Tested on AWS Graviton (ARM64 Neoverse V1) with your V10 haltpoll
changes, atop master 83a896549f.

Reviewed-by: Haris Okanovic <harisokn@amazon.com>
Tested-by: Haris Okanovic <harisokn@amazon.com>

Regards,
Haris Okanovic
AWS Graviton Software


  parent reply	other threads:[~2025-05-16 22:50 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-02  8:52 [PATCH v2 0/7] barrier: introduce smp_cond_load_*_timewait() Ankur Arora
2025-05-02  8:52 ` [PATCH v2 1/7] asm-generic: barrier: add smp_cond_load_relaxed_timewait() Ankur Arora
2025-05-21 18:37   ` Catalin Marinas
2025-05-24  3:22     ` Ankur Arora
2025-05-02  8:52 ` [PATCH v2 2/7] asm-generic: barrier: add wait_policy handlers Ankur Arora
2025-05-02  8:52 ` [PATCH v2 3/7] arm64: barrier: enable waiting in smp_cond_load_relaxed_timewait() Ankur Arora
2025-05-02  8:52 ` [PATCH v2 4/7] arm64: barrier: add coarse wait for smp_cond_load_relaxed_timewait() Ankur Arora
2025-05-02  8:52 ` [PATCH v2 5/7] arm64: barrier: add fine " Ankur Arora
2025-05-02  8:52 ` [PATCH v2 6/7] asm-generic: barrier: add smp_cond_load_acquire_timewait() Ankur Arora
2025-05-02  8:52 ` [PATCH v2 7/7] bpf: rqspinlock: add rqspinlock policy handler for arm64 Ankur Arora
2025-05-02 16:42 ` [PATCH v2 0/7] barrier: introduce smp_cond_load_*_timewait() Christoph Lameter (Ampere)
2025-05-02 20:05   ` Ankur Arora
2025-05-05 16:13     ` Christoph Lameter (Ampere)
2025-05-05 17:08       ` Ankur Arora
2025-05-16 22:50 ` Okanovic, Haris [this message]
2025-05-17  1:16   ` Ankur Arora

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=f2f5d09e79539754ced085ed89865787fa668695.camel@amazon.com \
    --to=harisokn@amazon.com \
    --cc=akpm@linux-foundation.org \
    --cc=ankur.a.arora@oracle.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=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;
as well as URLs for NNTP newsgroup(s).