public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Palmer Dabbelt <palmer@dabbelt.com>
To: christoph.muellner@vrull.eu
Cc: libc-alpha@sourceware.org, adhemerval.zanella@linaro.org,
	Darius Rad <darius@bluespec.com>,
	Andrew Waterman <andrew@sifive.com>,
	philipp.tomsich@vrull.eu, Evan Green <evan@rivosinc.com>,
	kito.cheng@sifive.com, jeffreyalaw@gmail.com,
	Vineet Gupta <vineetg@rivosinc.com>,
	christoph.muellner@vrull.eu
Subject: Re: [PATCH] RISC-V: Execute a PAUSE hint in spin loops
Date: Thu, 18 Apr 2024 18:03:02 -0700 (PDT)	[thread overview]
Message-ID: <mhng-b343db6a-f257-41fe-a3af-78bf548244ce@palmer-ri-x1c9a> (raw)
In-Reply-To: <20240418215858.4151969-1-christoph.muellner@vrull.eu>

On Thu, 18 Apr 2024 14:58:58 PDT (-0700), christoph.muellner@vrull.eu wrote:
> The atomic_spin_nop() macro can be used to run arch-specific
> code in the body of a spin loop to potentially improve efficiency.
> RISC-V's Zihintpause extension includes a PAUSE instruction for
> this use-case, which is encoded as a HINT, which means that it
> behaves like a NOP on systems that don't implement Zihintpause.
>
> Binutils supports Zihintpause since 2.36, so this patch uses
> the ".insn" directive to keep the code compatible with older
> toolchains.
>
> Signed-off-by: Christoph Müllner <christoph.muellner@vrull.eu>
> ---
>  sysdeps/unix/sysv/linux/riscv/atomic-machine.h | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/sysdeps/unix/sysv/linux/riscv/atomic-machine.h b/sysdeps/unix/sysv/linux/riscv/atomic-machine.h
> index c1c9d949a0..90283d9746 100644
> --- a/sysdeps/unix/sysv/linux/riscv/atomic-machine.h
> +++ b/sysdeps/unix/sysv/linux/riscv/atomic-machine.h
> @@ -178,4 +178,7 @@
>  # error "ISAs that do not subsume the A extension are not supported"
>  #endif /* !__riscv_atomic */
>
> +/* Execute a PAUSE hint when spinning.  */
> +#define atomic_spin_nop() __asm(".insn i 0x0f, 0, x0, x0, 0x010")
> +
>  #endif /* bits/atomic.h */

I think this one should be pretty non-controversial: the whole point of 
PAUSE is for this sort of spin loop, so I don't think we need any 
benchmarks to justify using it.  So

Reviewed-by: Palmer Dabbelt <palmer@rivosinc.com>
Acked-by: Palmer Dabbelt <palmer@rivosinc.com>

IIRC there's some tunables for spin counts already, so hopefully that's 
enough to cover us for now.  I guess we'll found out when people have 
hardware...

Thanks!

      reply	other threads:[~2024-04-19  1:03 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-18 21:58 Christoph Müllner
2024-04-19  1:03 ` Palmer Dabbelt [this message]

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=mhng-b343db6a-f257-41fe-a3af-78bf548244ce@palmer-ri-x1c9a \
    --to=palmer@dabbelt.com \
    --cc=adhemerval.zanella@linaro.org \
    --cc=andrew@sifive.com \
    --cc=christoph.muellner@vrull.eu \
    --cc=darius@bluespec.com \
    --cc=evan@rivosinc.com \
    --cc=jeffreyalaw@gmail.com \
    --cc=kito.cheng@sifive.com \
    --cc=libc-alpha@sourceware.org \
    --cc=philipp.tomsich@vrull.eu \
    --cc=vineetg@rivosinc.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 read-only IMAP folder(s) and NNTP newsgroup(s).