Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/kern - In kern_mutex.c, if MUTEX_CAS() is not defined, d...



details:   https://anonhg.NetBSD.org/src/rev/f55d662387fa
branches:  trunk
changeset: 1023111:f55d662387fa
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Wed Aug 25 04:13:41 2021 +0000

description:
- In kern_mutex.c, if MUTEX_CAS() is not defined, define it in terms of
  atomic_cas_ulong().
- For arm, ia64, m68k, mips, or1k, riscv, vax: don't define our own
  MUTEX_CAS(), as they either use atomic_cas_ulong() or equivalent
  (atomic_cas_uint() on m68k).
- For alpha and sparc64, don't define MUTEX_CAS() in terms of their own
  _lock_cas(), which has its own memory barriers; the call sites in
  kern_mutex.c already have the appropriate memory barrier calls.  Thus,
  alpha and sparc64 can use default definition.
- For sh3, don't define MUTEX_CAS() in terms of its own _lock_cas();
  atomic_cas_ulong() is strong-aliased to _lock_cas(), therefore defining
  our own MUTEX_CAS() is redundant.

Per thread:
        https://mail-index.netbsd.org/tech-kern/2021/07/25/msg027562.html

diffstat:

 sys/arch/alpha/include/mutex.h   |  6 +-----
 sys/arch/arm/include/mutex.h     |  5 +----
 sys/arch/ia64/include/mutex.h    |  5 +----
 sys/arch/m68k/include/mutex.h    |  4 +---
 sys/arch/mips/include/mutex.h    |  5 +----
 sys/arch/or1k/include/mutex.h    |  5 +----
 sys/arch/riscv/include/mutex.h   |  5 +----
 sys/arch/sh3/include/mutex.h     |  6 +-----
 sys/arch/sparc64/include/mutex.h |  6 +-----
 sys/arch/vax/include/mutex.h     |  4 +---
 sys/kern/kern_mutex.c            |  9 +++++++--
 11 files changed, 17 insertions(+), 43 deletions(-)

diffs (221 lines):

diff -r 0e15762bc188 -r f55d662387fa sys/arch/alpha/include/mutex.h
--- a/sys/arch/alpha/include/mutex.h    Tue Aug 24 23:38:51 2021 +0000
+++ b/sys/arch/alpha/include/mutex.h    Wed Aug 25 04:13:41 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mutex.h,v 1.10 2021/07/14 02:18:10 thorpej Exp $       */
+/*     $NetBSD: mutex.h,v 1.11 2021/08/25 04:13:41 thorpej Exp $       */
 
 /*-
  * Copyright (c) 2002, 2006, 2007 The NetBSD Foundation, Inc.
@@ -61,10 +61,6 @@
 #define        __HAVE_MUTEX_STUBS              1
 /* XXX #define __HAVE_SPIN_MUTEX_STUBS         1 XXX */
 
-#define        MUTEX_CAS(p, o, n)              _lock_cas((p), (o), (n))
-
-int    _lock_cas(volatile uintptr_t *, uintptr_t, uintptr_t);
-
 #endif /* __MUTEX_PRIVATE */
 
 __CTASSERT(sizeof(struct kmutex) == sizeof(uintptr_t));
diff -r 0e15762bc188 -r f55d662387fa sys/arch/arm/include/mutex.h
--- a/sys/arch/arm/include/mutex.h      Tue Aug 24 23:38:51 2021 +0000
+++ b/sys/arch/arm/include/mutex.h      Wed Aug 25 04:13:41 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mutex.h,v 1.25 2020/12/01 14:53:47 skrll Exp $ */
+/*     $NetBSD: mutex.h,v 1.26 2021/08/25 04:13:41 thorpej Exp $       */
 
 /*-
  * Copyright (c) 2002, 2007 The NetBSD Foundation, Inc.
@@ -80,9 +80,6 @@
 #endif
 #define        __HAVE_SIMPLE_MUTEXES           1
 
-#define        MUTEX_CAS(p, o, n)              \
-    (atomic_cas_ulong((volatile unsigned long *)(p), (o), (n)) == (o))
-
 #endif /* __MUTEX_PRIVATE */
 
 #endif /* _ARM_MUTEX_H_ */
diff -r 0e15762bc188 -r f55d662387fa sys/arch/ia64/include/mutex.h
--- a/sys/arch/ia64/include/mutex.h     Tue Aug 24 23:38:51 2021 +0000
+++ b/sys/arch/ia64/include/mutex.h     Wed Aug 25 04:13:41 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mutex.h,v 1.5 2019/11/29 22:55:33 riastradh Exp $      */
+/*     $NetBSD: mutex.h,v 1.6 2021/08/25 04:13:41 thorpej Exp $        */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -56,9 +56,6 @@
 */
 #define        __HAVE_SIMPLE_MUTEXES           1
 
-#define        MUTEX_CAS(ptr, old, new)                \
-    (atomic_cas_ulong((volatile unsigned long *)(ptr), (old), (new)) == (old))
-
 #endif /* __MUTEX_PRIVATE */
 
 #endif /* _IA64_MUTEX_H_ */
diff -r 0e15762bc188 -r f55d662387fa sys/arch/m68k/include/mutex.h
--- a/sys/arch/m68k/include/mutex.h     Tue Aug 24 23:38:51 2021 +0000
+++ b/sys/arch/m68k/include/mutex.h     Wed Aug 25 04:13:41 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mutex.h,v 1.10 2020/03/08 06:12:01 rin Exp $   */
+/*     $NetBSD: mutex.h,v 1.11 2021/08/25 04:13:41 thorpej Exp $       */
 
 /*-
  * Copyright (c) 2002, 2007 The NetBSD Foundation, Inc.
@@ -64,8 +64,6 @@
 #define        __HAVE_MUTEX_STUBS              1
 #endif
 
-#define        MUTEX_CAS(p, o, n)              (atomic_cas_uint((p), (o), (n)) == (o))
-
 #endif /* __MUTEX_PRIVATE */
 
 #endif /* _M68K_MUTEX_H_ */
diff -r 0e15762bc188 -r f55d662387fa sys/arch/mips/include/mutex.h
--- a/sys/arch/mips/include/mutex.h     Tue Aug 24 23:38:51 2021 +0000
+++ b/sys/arch/mips/include/mutex.h     Wed Aug 25 04:13:41 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mutex.h,v 1.8 2019/11/29 22:55:33 riastradh Exp $      */
+/*     $NetBSD: mutex.h,v 1.9 2021/08/25 04:13:41 thorpej Exp $        */
 
 /*-
  * Copyright (c) 2002, 2007 The NetBSD Foundation, Inc.
@@ -55,9 +55,6 @@
 #define        __HAVE_MUTEX_STUBS              1
 #define        __HAVE_SPIN_MUTEX_STUBS         1
 
-#define        MUTEX_CAS(p, o, n)              \
-    (atomic_cas_ulong((volatile u_long *)(p), (o), (n)) == (o))
-
 #endif /* __MUTEX_PRIVATE */
 
 #endif /* _MIPS_MUTEX_H_ */
diff -r 0e15762bc188 -r f55d662387fa sys/arch/or1k/include/mutex.h
--- a/sys/arch/or1k/include/mutex.h     Tue Aug 24 23:38:51 2021 +0000
+++ b/sys/arch/or1k/include/mutex.h     Wed Aug 25 04:13:41 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mutex.h,v 1.2 2019/11/29 22:55:33 riastradh Exp $      */
+/*     $NetBSD: mutex.h,v 1.3 2021/08/25 04:13:41 thorpej Exp $        */
 
 /*-
  * Copyright (c) 2002, 2007 The NetBSD Foundation, Inc.
@@ -70,9 +70,6 @@
 #endif
 #define        __HAVE_SIMPLE_MUTEXES           1
 
-#define        MUTEX_CAS(p, o, n)              \
-    (atomic_cas_ulong((volatile unsigned long *)(p), (o), (n)) == (o))
-
 #endif /* __MUTEX_PRIVATE */
 
 #endif /* _OR1K_MUTEX_H_ */
diff -r 0e15762bc188 -r f55d662387fa sys/arch/riscv/include/mutex.h
--- a/sys/arch/riscv/include/mutex.h    Tue Aug 24 23:38:51 2021 +0000
+++ b/sys/arch/riscv/include/mutex.h    Wed Aug 25 04:13:41 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mutex.h,v 1.3 2019/11/29 22:55:34 riastradh Exp $      */
+/*     $NetBSD: mutex.h,v 1.4 2021/08/25 04:13:41 thorpej Exp $        */
 
 /*-
  * Copyright (c) 2002, 2007 The NetBSD Foundation, Inc.
@@ -113,9 +113,6 @@
 #endif
 #define        __HAVE_SIMPLE_MUTEXES           1
 
-#define        MUTEX_CAS(p, o, n)              \
-    (atomic_cas_ulong((volatile unsigned long *)(p), (o), (n)) == (o))
-
 #endif /* __MUTEX_PRIVATE */
 
 #endif /* _RISCV_MUTEX_H_ */
diff -r 0e15762bc188 -r f55d662387fa sys/arch/sh3/include/mutex.h
--- a/sys/arch/sh3/include/mutex.h      Tue Aug 24 23:38:51 2021 +0000
+++ b/sys/arch/sh3/include/mutex.h      Wed Aug 25 04:13:41 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mutex.h,v 1.10 2019/11/29 22:55:34 riastradh Exp $     */
+/*     $NetBSD: mutex.h,v 1.11 2021/08/25 04:13:42 thorpej Exp $       */
 
 /*-
  * Copyright (c) 2002, 2007 The NetBSD Foundation, Inc.
@@ -62,10 +62,6 @@
 #define        __HAVE_SIMPLE_MUTEXES           1
 #define        __HAVE_MUTEX_STUBS              1
 
-uintptr_t      _lock_cas(volatile uintptr_t *, uintptr_t, uintptr_t);
-
-#define        MUTEX_CAS(p, o, n)              (_lock_cas((p), (o), (n)) == (o))
-
 #endif /* __MUTEX_PRIVATE */
 
 #endif /* _SH3_MUTEX_H_ */
diff -r 0e15762bc188 -r f55d662387fa sys/arch/sparc64/include/mutex.h
--- a/sys/arch/sparc64/include/mutex.h  Tue Aug 24 23:38:51 2021 +0000
+++ b/sys/arch/sparc64/include/mutex.h  Wed Aug 25 04:13:41 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mutex.h,v 1.6 2019/11/29 22:55:34 riastradh Exp $      */
+/*     $NetBSD: mutex.h,v 1.7 2021/08/25 04:13:41 thorpej Exp $        */
 
 /*-
  * Copyright (c) 2002, 2007 The NetBSD Foundation, Inc.
@@ -55,10 +55,6 @@
 #define __HAVE_MUTEX_STUBS             1
 #define        __HAVE_SIMPLE_MUTEXES           1
 
-#define        MUTEX_CAS(p, o, n)              _lock_cas((p), (o), (n))
-
-int    _lock_cas(volatile uintptr_t *, uintptr_t, uintptr_t);
-
 #endif /* __MUTEX_PRIVATE */
 
 #endif /* _SPARC64_MUTEX_H_ */
diff -r 0e15762bc188 -r f55d662387fa sys/arch/vax/include/mutex.h
--- a/sys/arch/vax/include/mutex.h      Tue Aug 24 23:38:51 2021 +0000
+++ b/sys/arch/vax/include/mutex.h      Wed Aug 25 04:13:41 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mutex.h,v 1.15 2019/11/29 22:55:34 riastradh Exp $     */
+/*     $NetBSD: mutex.h,v 1.16 2021/08/25 04:13:42 thorpej Exp $       */
 
 /*-
  * Copyright (c) 2002, 2007 The NetBSD Foundation, Inc.
@@ -71,8 +71,6 @@
 #define        __HAVE_SPIN_MUTEX_STUBS         1
 #define        __HAVE_SIMPLE_MUTEXES           1
 
-#define        MUTEX_CAS(p, o, n)      (atomic_cas_ulong((p), (o), (n)) == (o))
-
 #endif /* __MUTEX_PRIVATE */
 
 #endif /* _VAX_MUTEX_H_ */
diff -r 0e15762bc188 -r f55d662387fa sys/kern/kern_mutex.c
--- a/sys/kern/kern_mutex.c     Tue Aug 24 23:38:51 2021 +0000
+++ b/sys/kern/kern_mutex.c     Wed Aug 25 04:13:41 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_mutex.c,v 1.97 2021/04/03 14:56:14 thorpej Exp $  */
+/*     $NetBSD: kern_mutex.c,v 1.98 2021/08/25 04:13:42 thorpej Exp $  */
 
 /*-
  * Copyright (c) 2002, 2006, 2007, 2008, 2019 The NetBSD Foundation, Inc.
@@ -40,7 +40,7 @@
 #define        __MUTEX_PRIVATE
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_mutex.c,v 1.97 2021/04/03 14:56:14 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_mutex.c,v 1.98 2021/08/25 04:13:42 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/atomic.h>
@@ -214,6 +214,11 @@
 #define        MUTEX_ADAPTIVE_P(owner)         \
     (((owner) & MUTEX_BIT_SPIN) == 0)
 
+#ifndef MUTEX_CAS
+#define        MUTEX_CAS(p, o, n)              \
+       (atomic_cas_ulong((volatile unsigned long *)(p), (o), (n)) == (o))
+#endif /* MUTEX_CAS */
+
 #define        MUTEX_DEBUG_P(mtx)      (((mtx)->mtx_owner & MUTEX_BIT_NODEBUG) == 0)
 #if defined(LOCKDEBUG)
 #define        MUTEX_OWNED(owner)              (((owner) & ~MUTEX_BIT_NODEBUG) != 0)



Home | Main Index | Thread Index | Old Index