diff options
author | Visa Hankala <visa@cvs.openbsd.org> | 2015-09-09 15:48:54 +0000 |
---|---|---|
committer | Visa Hankala <visa@cvs.openbsd.org> | 2015-09-09 15:48:54 +0000 |
commit | 740cf0ffb44de2a0e0ad5d0a77412f247adbafa7 (patch) | |
tree | 7c2f20d3c4b81c0b89e0aa1e65cd13a3bdb70662 /sys | |
parent | 11099a36b194d986967030fd051ec577cd8bfd34 (diff) |
The mplock implementations on MP-enabled mips64 platforms, octeon and
sgi, are identical. Put one implementation in mips64 and drop the
platform-specific copies, to remove duplicated code.
ok miod@
Diffstat (limited to 'sys')
-rw-r--r-- | sys/arch/mips64/conf/files.mips64 | 3 | ||||
-rw-r--r-- | sys/arch/mips64/include/mplock.h | 52 | ||||
-rw-r--r-- | sys/arch/mips64/mips64/lock_machdep.c (renamed from sys/arch/octeon/octeon/lock_machdep.c) | 2 | ||||
-rw-r--r-- | sys/arch/octeon/conf/files.octeon | 3 | ||||
-rw-r--r-- | sys/arch/octeon/include/mplock.h | 53 | ||||
-rw-r--r-- | sys/arch/sgi/conf/files.sgi | 3 | ||||
-rw-r--r-- | sys/arch/sgi/include/mplock.h | 53 | ||||
-rw-r--r-- | sys/arch/sgi/sgi/lock_machdep.c | 172 |
8 files changed, 61 insertions, 280 deletions
diff --git a/sys/arch/mips64/conf/files.mips64 b/sys/arch/mips64/conf/files.mips64 index d5b3f02ecad..a33de306281 100644 --- a/sys/arch/mips64/conf/files.mips64 +++ b/sys/arch/mips64/conf/files.mips64 @@ -1,9 +1,10 @@ -# $OpenBSD: files.mips64,v 1.25 2015/08/15 22:31:38 miod Exp $ +# $OpenBSD: files.mips64,v 1.26 2015/09/09 15:48:52 visa Exp $ file arch/mips64/mips64/arcbios.c arcbios file arch/mips64/mips64/clock.c clock file arch/mips64/mips64/cpu.c file arch/mips64/mips64/interrupt.c +file arch/mips64/mips64/lock_machdep.c multiprocessor file arch/mips64/mips64/mem.c file arch/mips64/mips64/mips64_machdep.c file arch/mips64/mips64/pmap.c diff --git a/sys/arch/mips64/include/mplock.h b/sys/arch/mips64/include/mplock.h new file mode 100644 index 00000000000..addb3d6466e --- /dev/null +++ b/sys/arch/mips64/include/mplock.h @@ -0,0 +1,52 @@ +/* $OpenBSD: mplock.h,v 1.1 2015/09/09 15:48:52 visa Exp $ */ + +/* + * Copyright (c) 2004 Niklas Hallqvist. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _MACHINE_MPLOCK_H_ +#define _MACHINE_MPLOCK_H_ + +/* + * Really simple spinlock implementation with recursive capabilities. + * Correctness is paramount, no fancyness allowed. + */ + +struct __mp_lock { + volatile struct cpu_info *mpl_cpu; + volatile long mpl_count; +}; + +#ifndef _LOCORE + +void __mp_lock_init(struct __mp_lock *); +void __mp_lock(struct __mp_lock *); +void __mp_unlock(struct __mp_lock *); +int __mp_release_all(struct __mp_lock *); +int __mp_release_all_but_one(struct __mp_lock *); +void __mp_acquire_count(struct __mp_lock *, int); +int __mp_lock_held(struct __mp_lock *); + +#endif + +#endif /* !_MACHINE_MPLOCK_H */ diff --git a/sys/arch/octeon/octeon/lock_machdep.c b/sys/arch/mips64/mips64/lock_machdep.c index d059839246d..e393c4664c9 100644 --- a/sys/arch/octeon/octeon/lock_machdep.c +++ b/sys/arch/mips64/mips64/lock_machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lock_machdep.c,v 1.7 2015/07/21 16:17:15 visa Exp $ */ +/* $OpenBSD: lock_machdep.c,v 1.1 2015/09/09 15:48:52 visa Exp $ */ /* * Copyright (c) 2007 Artur Grabowski <art@openbsd.org> diff --git a/sys/arch/octeon/conf/files.octeon b/sys/arch/octeon/conf/files.octeon index 9632468bb72..3e10ccae675 100644 --- a/sys/arch/octeon/conf/files.octeon +++ b/sys/arch/octeon/conf/files.octeon @@ -1,4 +1,4 @@ -# $OpenBSD: files.octeon,v 1.25 2015/08/18 12:49:41 visa Exp $ +# $OpenBSD: files.octeon,v 1.26 2015/09/09 15:48:52 visa Exp $ # Standard stanzas config(8) can't run without maxpartitions 16 @@ -17,7 +17,6 @@ file arch/octeon/octeon/autoconf.c file arch/octeon/octeon/bus_dma.c file arch/octeon/octeon/conf.c file arch/octeon/octeon/disksubr.c disk -file arch/octeon/octeon/lock_machdep.c multiprocessor file arch/octeon/octeon/machdep.c include "dev/ata/files.ata" diff --git a/sys/arch/octeon/include/mplock.h b/sys/arch/octeon/include/mplock.h index eb2a5a90f88..3176079a03d 100644 --- a/sys/arch/octeon/include/mplock.h +++ b/sys/arch/octeon/include/mplock.h @@ -1,52 +1,3 @@ -/* $OpenBSD: mplock.h,v 1.1 2010/09/20 06:32:30 syuu Exp $ */ +/* $OpenBSD: mplock.h,v 1.2 2015/09/09 15:48:52 visa Exp $ */ -/* - * Copyright (c) 2004 Niklas Hallqvist. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef _MACHINE_MPLOCK_H_ -#define _MACHINE_MPLOCK_H_ - -/* - * Really simple spinlock implementation with recursive capabilities. - * Correctness is paramount, no fancyness allowed. - */ - -struct __mp_lock { - volatile struct cpu_info *mpl_cpu; - volatile long mpl_count; -}; - -#ifndef _LOCORE - -void __mp_lock_init(struct __mp_lock *); -void __mp_lock(struct __mp_lock *); -void __mp_unlock(struct __mp_lock *); -int __mp_release_all(struct __mp_lock *); -int __mp_release_all_but_one(struct __mp_lock *); -void __mp_acquire_count(struct __mp_lock *, int); -int __mp_lock_held(struct __mp_lock *); - -#endif - -#endif /* !_MACHINE_MPLOCK_H */ +#include <mips64/mplock.h> diff --git a/sys/arch/sgi/conf/files.sgi b/sys/arch/sgi/conf/files.sgi index b8c0b5b439b..9ebf9894748 100644 --- a/sys/arch/sgi/conf/files.sgi +++ b/sys/arch/sgi/conf/files.sgi @@ -1,4 +1,4 @@ -# $OpenBSD: files.sgi,v 1.53 2015/07/08 13:37:31 dlg Exp $ +# $OpenBSD: files.sgi,v 1.54 2015/09/09 15:48:53 visa Exp $ # # maxpartitions must be first item in files.${ARCH} # @@ -13,7 +13,6 @@ file arch/sgi/sgi/autoconf.c file arch/sgi/sgi/bus_dma.c file arch/sgi/sgi/conf.c file arch/sgi/sgi/disksubr.c disk -file arch/sgi/sgi/lock_machdep.c multiprocessor file arch/sgi/sgi/ip22_machdep.c tgt_indigo | tgt_indigo2 | tgt_indy file arch/sgi/sgi/ip27_machdep.c tgt_origin diff --git a/sys/arch/sgi/include/mplock.h b/sys/arch/sgi/include/mplock.h index 50dc8f797fd..c225ed39020 100644 --- a/sys/arch/sgi/include/mplock.h +++ b/sys/arch/sgi/include/mplock.h @@ -1,52 +1,3 @@ -/* $OpenBSD: mplock.h,v 1.1 2009/11/21 23:28:14 syuu Exp $ */ +/* $OpenBSD: mplock.h,v 1.2 2015/09/09 15:48:53 visa Exp $ */ -/* - * Copyright (c) 2004 Niklas Hallqvist. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef _MACHINE_MPLOCK_H_ -#define _MACHINE_MPLOCK_H_ - -/* - * Really simple spinlock implementation with recursive capabilities. - * Correctness is paramount, no fancyness allowed. - */ - -struct __mp_lock { - volatile struct cpu_info *mpl_cpu; - volatile long mpl_count; -}; - -#ifndef _LOCORE - -void __mp_lock_init(struct __mp_lock *); -void __mp_lock(struct __mp_lock *); -void __mp_unlock(struct __mp_lock *); -int __mp_release_all(struct __mp_lock *); -int __mp_release_all_but_one(struct __mp_lock *); -void __mp_acquire_count(struct __mp_lock *, int); -int __mp_lock_held(struct __mp_lock *); - -#endif - -#endif /* !_MACHINE_MPLOCK_H */ +#include <mips64/mplock.h> diff --git a/sys/arch/sgi/sgi/lock_machdep.c b/sys/arch/sgi/sgi/lock_machdep.c deleted file mode 100644 index 44d89d7e375..00000000000 --- a/sys/arch/sgi/sgi/lock_machdep.c +++ /dev/null @@ -1,172 +0,0 @@ -/* $OpenBSD: lock_machdep.c,v 1.7 2015/02/11 07:05:39 dlg Exp $ */ - -/* - * Copyright (c) 2007 Artur Grabowski <art@openbsd.org> - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - - -#include <sys/param.h> -#include <sys/systm.h> -#include <sys/atomic.h> - -#include <machine/cpu.h> -#include <machine/lock.h> - -#include <ddb/db_output.h> - -void -__mp_lock_init(struct __mp_lock *lock) -{ - lock->mpl_cpu = NULL; - lock->mpl_count = 0; -} - -#if defined(MP_LOCKDEBUG) -#ifndef DDB -#error "MP_LOCKDEBUG requires DDB" -#endif - -/* CPU-dependent timing, needs this to be settable from ddb. */ -extern int __mp_lock_spinout; -#endif - -#define SPINLOCK_SPIN_HOOK /**/ - -static __inline void -__mp_lock_spin(struct __mp_lock *mpl) -{ -#ifndef MP_LOCKDEBUG - while (mpl->mpl_count != 0) - SPINLOCK_SPIN_HOOK; -#else - int ticks = __mp_lock_spinout; - - while (mpl->mpl_count != 0 && --ticks > 0) - SPINLOCK_SPIN_HOOK; - - if (ticks == 0) { - db_printf("__mp_lock(0x%x): lock spun out", mpl); - Debugger(); - } -#endif -} - -void -__mp_lock(struct __mp_lock *mpl) -{ - register_t sr; - struct cpu_info *ci = curcpu(); - - /* - * Please notice that mpl_count gets incremented twice for the - * first lock. This is on purpose. The way we release the lock - * in mp_unlock is to decrement the mpl_count and then check if - * the lock should be released. Since mpl_count is what we're - * spinning on, decrementing it in mpl_unlock to 0 means that - * we can't clear mpl_cpu, because we're no longer holding the - * lock. In theory mpl_cpu doesn't need to be cleared, but it's - * safer to clear it and besides, setting mpl_count to 2 on the - * first lock makes most of this code much simpler. - */ - while (1) { - sr = disableintr(); - if (__cpu_cas(&mpl->mpl_count, 0, 1) == 0) { - mips_sync(); - mpl->mpl_cpu = ci; - } - - if (mpl->mpl_cpu == ci) { - mpl->mpl_count++; - setsr(sr); - break; - } - setsr(sr); - - __mp_lock_spin(mpl); - } -} - -void -__mp_unlock(struct __mp_lock *mpl) -{ - register_t sr; - -#ifdef MP_LOCKDEBUG - if (mpl->mpl_cpu != curcpu()) { - db_printf("__mp_unlock(%p): not held lock\n", mpl); - Debugger(); - } -#endif - - sr = disableintr(); - if (--mpl->mpl_count == 1) { - mpl->mpl_cpu = NULL; - mips_sync(); - mpl->mpl_count = 0; - } - - setsr(sr); -} - -int -__mp_release_all(struct __mp_lock *mpl) -{ - int rv = mpl->mpl_count - 1; - register_t sr; - -#ifdef MP_LOCKDEBUG - if (mpl->mpl_cpu != curcpu()) { - db_printf("__mp_release_all(%p): not held lock\n", mpl); - Debugger(); - } -#endif - - sr = disableintr(); - mpl->mpl_cpu = NULL; - mips_sync(); - mpl->mpl_count = 0; - setsr(sr); - - return (rv); -} - -int -__mp_release_all_but_one(struct __mp_lock *mpl) -{ - int rv = mpl->mpl_count - 2; -#ifdef MP_LOCKDEBUG - if (mpl->mpl_cpu != curcpu()) { - db_printf("__mp_release_all_but_one(%p): not held lock\n", mpl); - Debugger(); - } -#endif - - mpl->mpl_count = 2; - - return (rv); -} - -void -__mp_acquire_count(struct __mp_lock *mpl, int count) -{ - while (count--) - __mp_lock(mpl); -} - -int -__mp_lock_held(struct __mp_lock *mpl) -{ - return mpl->mpl_cpu == curcpu(); -} |