Linux-RISC-V Archive on lore.kernel.org
 help / Atom feed
* [PATCH] riscv, atomic: Add #define's for the atomic_{cmp, }xchg_*() variants
@ 2018-12-01  0:01 Andrea Parri
  2018-12-01 10:23 ` [PATCH] riscv, atomic: Add #define's for the atomic_{cmp,}xchg_*() variants Peter Zijlstra
  0 siblings, 1 reply; 2+ messages in thread
From: Andrea Parri @ 2018-12-01  0:01 UTC (permalink / raw)
  To: linux-kernel, linux-riscv
  Cc: Andrea Parri, Albert Ou, Peter Zijlstra, Boqun Feng,
	Palmer Dabbelt, Will Deacon

If an architecture does not define the atomic_{cmp,}xchg_*() variants,
the generic implementation defaults them to the fully-ordered version.

riscv's had its own variants since "the beginning", but it never told
(#define-d these for) the generic implementation: it is time to do so.

Signed-off-by: Andrea Parri <andrea.parri@amarulasolutions.com>
Cc: Palmer Dabbelt <palmer@sifive.com>
Cc: Albert Ou <aou@eecs.berkeley.edu>
Cc: Will Deacon <will.deacon@arm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Boqun Feng <boqun.feng@gmail.com>
---
TBH, the delay was not intentional: I've just become aware of it while
working on moving riscv over to queued rwlocks.  There's currently one
callsite for the non-fully-ordered variants mentioned above for riscv:
for atomic_cmpxchg_acquire() in kernel/sched/rt.c:rto_start_trylock(),

[before]

     51a:	100726af          	lr.w	a3,(a4)
     51e:	00069763          	bnez	a3,52c <.L1\x027>
     522:	1af7262f          	sc.w.rl	a2,a5,(a4)
     526:	fa75                	bnez	a2,51a <.L\x021>
     528:	0330000f          	fence	rw,rw

[after]

     51a:	100726af          	lr.w	a3,(a4)
     51e:	00069763          	bnez	a3,52c <.L1\x027>
     522:	18f7262f          	sc.w	a2,a5,(a4)
     526:	fa75                	bnez	a2,51a <.L\x021>
     528:	0230000f          	fence	r,rw

---
 arch/riscv/include/asm/atomic.h | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/arch/riscv/include/asm/atomic.h b/arch/riscv/include/asm/atomic.h
index c452359c9cb8a..93826771b616a 100644
--- a/arch/riscv/include/asm/atomic.h
+++ b/arch/riscv/include/asm/atomic.h
@@ -303,6 +303,15 @@ c_t atomic##prefix##_cmpxchg(atomic##prefix##_t *v, c_t o, c_t n)	\
 
 ATOMIC_OPS()
 
+#define atomic_xchg_relaxed atomic_xchg_relaxed
+#define atomic_xchg_acquire atomic_xchg_acquire
+#define atomic_xchg_release atomic_xchg_release
+#define atomic_xchg atomic_xchg
+#define atomic_cmpxchg_relaxed atomic_cmpxchg_relaxed
+#define atomic_cmpxchg_acquire atomic_cmpxchg_acquire
+#define atomic_cmpxchg_release atomic_cmpxchg_release
+#define atomic_cmpxchg atomic_cmpxchg
+
 #undef ATOMIC_OPS
 #undef ATOMIC_OP
 
-- 
2.17.1


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] riscv, atomic: Add #define's for the atomic_{cmp,}xchg_*() variants
  2018-12-01  0:01 [PATCH] riscv, atomic: Add #define's for the atomic_{cmp, }xchg_*() variants Andrea Parri
@ 2018-12-01 10:23 ` Peter Zijlstra
  0 siblings, 0 replies; 2+ messages in thread
From: Peter Zijlstra @ 2018-12-01 10:23 UTC (permalink / raw)
  To: Andrea Parri
  Cc: Albert Ou, Boqun Feng, Palmer Dabbelt, Will Deacon, linux-kernel,
	linux-riscv

On Sat, Dec 01, 2018 at 01:01:56AM +0100, Andrea Parri wrote:
> If an architecture does not define the atomic_{cmp,}xchg_*() variants,
> the generic implementation defaults them to the fully-ordered version.
> 
> riscv's had its own variants since "the beginning", but it never told
> (#define-d these for) the generic implementation: it is time to do so.
> 
> Signed-off-by: Andrea Parri <andrea.parri@amarulasolutions.com>
> Cc: Palmer Dabbelt <palmer@sifive.com>
> Cc: Albert Ou <aou@eecs.berkeley.edu>
> Cc: Will Deacon <will.deacon@arm.com>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Boqun Feng <boqun.feng@gmail.com>

Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>

> ---
>  arch/riscv/include/asm/atomic.h | 9 +++++++++
>  1 file changed, 9 insertions(+)
> 
> diff --git a/arch/riscv/include/asm/atomic.h b/arch/riscv/include/asm/atomic.h
> index c452359c9cb8a..93826771b616a 100644
> --- a/arch/riscv/include/asm/atomic.h
> +++ b/arch/riscv/include/asm/atomic.h
> @@ -303,6 +303,15 @@ c_t atomic##prefix##_cmpxchg(atomic##prefix##_t *v, c_t o, c_t n)	\
>  
>  ATOMIC_OPS()
>  
> +#define atomic_xchg_relaxed atomic_xchg_relaxed
> +#define atomic_xchg_acquire atomic_xchg_acquire
> +#define atomic_xchg_release atomic_xchg_release
> +#define atomic_xchg atomic_xchg
> +#define atomic_cmpxchg_relaxed atomic_cmpxchg_relaxed
> +#define atomic_cmpxchg_acquire atomic_cmpxchg_acquire
> +#define atomic_cmpxchg_release atomic_cmpxchg_release
> +#define atomic_cmpxchg atomic_cmpxchg
> +
>  #undef ATOMIC_OPS
>  #undef ATOMIC_OP
>  
> -- 
> 2.17.1
> 

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-01  0:01 [PATCH] riscv, atomic: Add #define's for the atomic_{cmp, }xchg_*() variants Andrea Parri
2018-12-01 10:23 ` [PATCH] riscv, atomic: Add #define's for the atomic_{cmp,}xchg_*() variants Peter Zijlstra

Linux-RISC-V Archive on lore.kernel.org

Archives are clonable: git clone --mirror https://lore.kernel.org/linux-riscv/0 linux-riscv/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-riscv linux-riscv/ https://lore.kernel.org/linux-riscv \
		linux-riscv@lists.infradead.org infradead-linux-riscv@archiver.kernel.org
	public-inbox-index linux-riscv


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.infradead.lists.linux-riscv


AGPL code for this site: git clone https://public-inbox.org/ public-inbox