diff options
author | David Gwynne <dlg@cvs.openbsd.org> | 2015-02-11 00:14:12 +0000 |
---|---|---|
committer | David Gwynne <dlg@cvs.openbsd.org> | 2015-02-11 00:14:12 +0000 |
commit | c4427bcd781765e2f91f6109bbd3267e7d9c4232 (patch) | |
tree | 3d165a2943dc27e75242e5c202c9cb43389d9218 /sys | |
parent | 327e76719bad93f8260eacba21e3bf58cfe1f944 (diff) |
make the rwlock implementation MI.
each arch used to have to provide an rw_cas operation, but now we
have the rwlock code build its own version. on smp machines it uses
atomic_cas_ulong. on uniproc machines it avoids interlocked
instructions by using straight loads and stores. this is safe because
rwlocks are only used from process context and processes are currently
not preemptible in our kernel. so alpha/ppc/etc might get a benefit.
ok miod@ kettenis@ deraadt@
Diffstat (limited to 'sys')
-rw-r--r-- | sys/arch/alpha/include/lock.h | 3 | ||||
-rw-r--r-- | sys/arch/amd64/include/lock.h | 6 | ||||
-rw-r--r-- | sys/arch/hppa/include/lock.h | 6 | ||||
-rw-r--r-- | sys/arch/i386/include/lock.h | 3 | ||||
-rw-r--r-- | sys/arch/m88k/include/lock.h | 6 | ||||
-rw-r--r-- | sys/arch/mips64/include/lock.h | 3 | ||||
-rw-r--r-- | sys/arch/powerpc/include/lock.h | 3 | ||||
-rw-r--r-- | sys/arch/sparc64/include/lock.h | 6 | ||||
-rw-r--r-- | sys/kern/kern_rwlock.c | 30 | ||||
-rw-r--r-- | sys/sys/rwlock.h | 6 |
10 files changed, 24 insertions, 48 deletions
diff --git a/sys/arch/alpha/include/lock.h b/sys/arch/alpha/include/lock.h index 2d24ca142f8..e40761990d2 100644 --- a/sys/arch/alpha/include/lock.h +++ b/sys/arch/alpha/include/lock.h @@ -1,4 +1,4 @@ -/* $OpenBSD: lock.h,v 1.7 2014/03/29 18:09:28 guenther Exp $ */ +/* $OpenBSD: lock.h,v 1.8 2015/02/11 00:14:11 dlg Exp $ */ /* $NetBSD: lock.h,v 1.16 2001/12/17 23:34:57 thorpej Exp $ */ /*- @@ -61,7 +61,6 @@ do { \ } while (0) #endif /* MULTIPROCESSOR */ -#define rw_cas __cpu_cas static inline int __cpu_cas(volatile unsigned long *addr, unsigned long old, unsigned long new) { diff --git a/sys/arch/amd64/include/lock.h b/sys/arch/amd64/include/lock.h index 6fe29ddc75f..40bee59167b 100644 --- a/sys/arch/amd64/include/lock.h +++ b/sys/arch/amd64/include/lock.h @@ -1,4 +1,4 @@ -/* $OpenBSD: lock.h,v 1.9 2014/03/29 18:09:28 guenther Exp $ */ +/* $OpenBSD: lock.h,v 1.10 2015/02/11 00:14:11 dlg Exp $ */ /* $NetBSD: lock.h,v 1.1.2.2 2000/05/03 14:40:55 sommerfeld Exp $ */ /*- @@ -48,8 +48,4 @@ #define __lockbarrier() __asm volatile("": : :"memory") #define SPINLOCK_SPIN_HOOK __asm volatile("pause": : :"memory"); -#include <machine/atomic.h> - -#define rw_cas(p, o, n) (atomic_cas_ulong(p, o, n) != o) - #endif /* _MACHINE_LOCK_H_ */ diff --git a/sys/arch/hppa/include/lock.h b/sys/arch/hppa/include/lock.h index f0766ae614a..cb7e1edae89 100644 --- a/sys/arch/hppa/include/lock.h +++ b/sys/arch/hppa/include/lock.h @@ -1,12 +1,8 @@ -/* $OpenBSD: lock.h,v 1.8 2014/09/22 12:12:23 dlg Exp $ */ +/* $OpenBSD: lock.h,v 1.9 2015/02/11 00:14:11 dlg Exp $ */ /* public domain */ #ifndef _MACHINE_LOCK_H_ #define _MACHINE_LOCK_H_ -#include <machine/atomic.h> - -#define rw_cas(p, o, n) (atomic_cas_ulong(p, o, n) != o) - #endif /* _MACHINE_LOCK_H_ */ diff --git a/sys/arch/i386/include/lock.h b/sys/arch/i386/include/lock.h index d1d39f704e5..63e616b0e26 100644 --- a/sys/arch/i386/include/lock.h +++ b/sys/arch/i386/include/lock.h @@ -1,4 +1,4 @@ -/* $OpenBSD: lock.h,v 1.9 2014/03/29 18:09:29 guenther Exp $ */ +/* $OpenBSD: lock.h,v 1.10 2015/02/11 00:14:11 dlg Exp $ */ /* $NetBSD: lock.h,v 1.1.2.2 2000/05/03 14:40:55 sommerfeld Exp $ */ /*- @@ -53,7 +53,6 @@ #ifdef _KERNEL extern int rw_cas_486(volatile unsigned long *, unsigned long, unsigned long); -#define rw_cas rw_cas_486 #endif #endif /* _MACHINE_LOCK_H_ */ diff --git a/sys/arch/m88k/include/lock.h b/sys/arch/m88k/include/lock.h index 2ad1c95d8bc..5b3e70745ef 100644 --- a/sys/arch/m88k/include/lock.h +++ b/sys/arch/m88k/include/lock.h @@ -1,6 +1,6 @@ #ifndef _M88K_LOCK_H_ #define _M88K_LOCK_H_ -/* $OpenBSD: lock.h,v 1.10 2014/07/15 16:28:11 miod Exp $ */ +/* $OpenBSD: lock.h,v 1.11 2015/02/11 00:14:11 dlg Exp $ */ /* * Copyright (c) 2005, Miodrag Vallat. @@ -74,8 +74,4 @@ __cpu_simple_unlock(__cpu_simple_lock_t *l) *l = __SIMPLELOCK_UNLOCKED; } -#if defined(_KERNEL) && defined(MULTIPROCESSOR) -#define rw_cas(p, o, n) (atomic_cas_ulong(p, o, n) != o) -#endif - #endif /* _M88K_LOCK_H_ */ diff --git a/sys/arch/mips64/include/lock.h b/sys/arch/mips64/include/lock.h index c19cd7362c5..ee927014ad7 100644 --- a/sys/arch/mips64/include/lock.h +++ b/sys/arch/mips64/include/lock.h @@ -1,4 +1,4 @@ -/* $OpenBSD: lock.h,v 1.6 2014/09/30 06:51:58 jmatthew Exp $ */ +/* $OpenBSD: lock.h,v 1.7 2015/02/11 00:14:11 dlg Exp $ */ /* public domain */ @@ -7,7 +7,6 @@ #include <sys/atomic.h> -#define rw_cas __cpu_cas static __inline int __cpu_cas(volatile unsigned long *addr, unsigned long old, unsigned long new) { diff --git a/sys/arch/powerpc/include/lock.h b/sys/arch/powerpc/include/lock.h index 18f9bf6d88b..757cdedd343 100644 --- a/sys/arch/powerpc/include/lock.h +++ b/sys/arch/powerpc/include/lock.h @@ -1,4 +1,4 @@ -/* $OpenBSD: lock.h,v 1.4 2013/05/21 20:05:30 tedu Exp $ */ +/* $OpenBSD: lock.h,v 1.5 2015/02/11 00:14:11 dlg Exp $ */ /* $NetBSD: lock.h,v 1.8 2005/12/28 19:09:29 perry Exp $ */ /*- @@ -37,7 +37,6 @@ #ifndef _POWERPC_LOCK_H_ #define _POWERPC_LOCK_H_ -#define rw_cas __cpu_cas static __inline int __cpu_cas(volatile unsigned long *addr, unsigned long old, unsigned long new) { diff --git a/sys/arch/sparc64/include/lock.h b/sys/arch/sparc64/include/lock.h index ac39aefdfa5..a34bb3d7be3 100644 --- a/sys/arch/sparc64/include/lock.h +++ b/sys/arch/sparc64/include/lock.h @@ -1,12 +1,8 @@ -/* $OpenBSD: lock.h,v 1.9 2014/01/30 00:51:13 dlg Exp $ */ +/* $OpenBSD: lock.h,v 1.10 2015/02/11 00:14:11 dlg Exp $ */ /* public domain */ #ifndef _MACHINE_LOCK_H_ #define _MACHINE_LOCK_H_ -#include <sys/atomic.h> - -#define rw_cas(p, o, n) (atomic_cas_ulong(p, o, n) != o) - #endif /* _MACHINE_LOCK_H_ */ diff --git a/sys/kern/kern_rwlock.c b/sys/kern/kern_rwlock.c index f50cf65a033..3ad22be632a 100644 --- a/sys/kern/kern_rwlock.c +++ b/sys/kern/kern_rwlock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_rwlock.c,v 1.24 2015/02/10 10:04:27 dlg Exp $ */ +/* $OpenBSD: kern_rwlock.c,v 1.25 2015/02/11 00:14:11 dlg Exp $ */ /* * Copyright (c) 2002, 2003 Artur Grabowski <art@openbsd.org> @@ -24,11 +24,23 @@ #include <sys/limits.h> #include <sys/atomic.h> -#include <machine/lock.h> - /* XXX - temporary measure until proc0 is properly aligned */ #define RW_PROC(p) (((long)p) & ~RWLOCK_MASK) +#ifdef MULTIPROCESSOR +#define rw_cas(p, o, n) (atomic_cas_ulong(p, o, n) != o) +#else +static inline int +rw_cas(volatile unsigned long *p, unsigned long o, unsigned long n) +{ + if (*p != o) + return (1); + *p = n; + + return (0); +} +#endif + /* * Magic wand for lock operations. Every operation checks if certain * flags are set and if they aren't, it increments the lock with some @@ -124,18 +136,6 @@ rw_exit_write(struct rwlock *rwl) rw_exit(rwl); } -#ifndef rw_cas -int -rw_cas(volatile unsigned long *p, unsigned long o, unsigned long n) -{ - if (*p != o) - return (1); - *p = n; - - return (0); -} -#endif - #ifdef DIAGNOSTIC /* * Put the diagnostic functions here to keep the main code free diff --git a/sys/sys/rwlock.h b/sys/sys/rwlock.h index 594463ea0f3..10db90ae94f 100644 --- a/sys/sys/rwlock.h +++ b/sys/sys/rwlock.h @@ -1,4 +1,4 @@ -/* $OpenBSD: rwlock.h,v 1.17 2015/02/10 10:04:27 dlg Exp $ */ +/* $OpenBSD: rwlock.h,v 1.18 2015/02/11 00:14:11 dlg Exp $ */ /* * Copyright (c) 2002 Artur Grabowski <art@openbsd.org> * @@ -110,10 +110,6 @@ int rw_status(struct rwlock *); */ #define RW_WRITE_OTHER 0x0100UL -#ifndef rw_cas -int rw_cas(volatile unsigned long *, unsigned long, unsigned long); -#endif - /* recursive rwlocks; */ struct rrwlock { struct rwlock rrwl_lock; |