From: Andrew Jones <ajones@ventanamicro.com>
To: Alexandre Ghiti <alex@ghiti.fr>
Cc: linux-riscv@lists.infradead.org, kvm-riscv@lists.infradead.org,
devicetree@vger.kernel.org, paul.walmsley@sifive.com,
palmer@dabbelt.com, aou@eecs.berkeley.edu,
conor.dooley@microchip.com, anup@brainfault.org,
atishp@atishpatra.org, robh@kernel.org,
krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org,
christoph.muellner@vrull.eu, heiko@sntech.de,
charlie@rivosinc.com, David.Laight@aculab.com,
parri.andrea@gmail.com, luxu.kernel@bytedance.com
Subject: Re: [PATCH v3 3/6] riscv: Add Zawrs support for spinlocks
Date: Mon, 29 Jul 2024 16:01:02 +0200 [thread overview]
Message-ID: <20240729-b6707d037c0546c2c2f8da25@orel> (raw)
In-Reply-To: <4de22b20-8a6a-47d0-a4e9-74343c45411c@ghiti.fr>
On Mon, Jul 29, 2024 at 03:43:30PM GMT, Alexandre Ghiti wrote:
...
> > +static __always_inline void __cmpwait(volatile void *ptr,
> > + unsigned long val,
> > + int size)
> > +{
> > + unsigned long tmp;
> > +
> > + asm goto(ALTERNATIVE("j %l[no_zawrs]", "nop",
> > + 0, RISCV_ISA_EXT_ZAWRS, 1)
> > + : : : : no_zawrs);
> > +
> > + switch (size) {
> > + case 4:
> > + asm volatile(
> > + " lr.w %0, %1\n"
> > + " xor %0, %0, %2\n"
> > + " bnez %0, 1f\n"
> > + ZAWRS_WRS_NTO "\n"
> > + "1:"
> > + : "=&r" (tmp), "+A" (*(u32 *)ptr)
> > + : "r" (val));
> > + break;
> > +#if __riscv_xlen == 64
> > + case 8:
> > + asm volatile(
> > + " lr.d %0, %1\n"
> > + " xor %0, %0, %2\n"
> > + " bnez %0, 1f\n"
> > + ZAWRS_WRS_NTO "\n"
> > + "1:"
> > + : "=&r" (tmp), "+A" (*(u64 *)ptr)
> > + : "r" (val));
> > + break;
> > +#endif
> > + default:
> > + BUILD_BUG();
> > + }
> > +
> > + return;
> > +
> > +no_zawrs:
> > + asm volatile(RISCV_PAUSE : : : "memory");
>
>
> Shouldn't we fallback to the previous implementation (cpu_relax()) here? Not
> sure this is really important, but I want to make sure it was not an
> oversight.
>
Hi Alex,
It was intentional. We can't easily call cpu_relax() from here because
asm/vdso/processor.h includes asm/barrier.h which includes asm/cmpxchg.h.
We've mostly reproduced cpu_relax() here since we're only skipping the
div, and, as __cmpwait will be used in loops which load memory for the
comparison, I didn't think we needed the extra div stalls.
Thanks,
drew
next prev parent reply other threads:[~2024-07-29 14:01 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-26 10:08 [PATCH v3 0/6] riscv: Apply Zawrs when available Andrew Jones
2024-04-26 10:08 ` [PATCH v3 1/6] riscv: Provide a definition for 'pause' Andrew Jones
2024-04-26 10:08 ` [PATCH v3 2/6] dt-bindings: riscv: Add Zawrs ISA extension description Andrew Jones
2024-04-26 16:41 ` Conor Dooley
2024-04-26 10:08 ` [PATCH v3 3/6] riscv: Add Zawrs support for spinlocks Andrew Jones
2024-07-29 13:43 ` Alexandre Ghiti
2024-07-29 14:01 ` Andrew Jones [this message]
2024-07-29 14:30 ` Alexandre Ghiti
2024-04-26 10:08 ` [PATCH v3 4/6] riscv: hwprobe: export Zawrs ISA extension Andrew Jones
2024-06-18 13:48 ` Clément Léger
2024-06-18 16:01 ` Andrew Jones
2024-06-18 16:59 ` Conor Dooley
2024-06-18 17:05 ` Andrew Jones
2024-06-18 17:34 ` Conor Dooley
2024-07-15 15:45 ` Palmer Dabbelt
2024-04-26 10:08 ` [PATCH v3 5/6] KVM: riscv: Support guest wrs.nto Andrew Jones
2024-06-26 15:36 ` Anup Patel
2024-04-26 10:08 ` [PATCH v3 6/6] KVM: riscv: selftests: Add Zawrs extension to get-reg-list test Andrew Jones
2024-06-26 15:37 ` Anup Patel
2024-06-03 12:36 ` [PATCH v3 0/6] riscv: Apply Zawrs when available Andrew Jones
2024-06-26 14:34 ` Palmer Dabbelt
2024-06-26 15:19 ` Andrew Jones
2024-06-26 15:38 ` Anup Patel
2024-07-14 20:30 ` patchwork-bot+linux-riscv
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=20240729-b6707d037c0546c2c2f8da25@orel \
--to=ajones@ventanamicro.com \
--cc=David.Laight@aculab.com \
--cc=alex@ghiti.fr \
--cc=anup@brainfault.org \
--cc=aou@eecs.berkeley.edu \
--cc=atishp@atishpatra.org \
--cc=charlie@rivosinc.com \
--cc=christoph.muellner@vrull.eu \
--cc=conor+dt@kernel.org \
--cc=conor.dooley@microchip.com \
--cc=devicetree@vger.kernel.org \
--cc=heiko@sntech.de \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=kvm-riscv@lists.infradead.org \
--cc=linux-riscv@lists.infradead.org \
--cc=luxu.kernel@bytedance.com \
--cc=palmer@dabbelt.com \
--cc=parri.andrea@gmail.com \
--cc=paul.walmsley@sifive.com \
--cc=robh@kernel.org \
/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).