diff options
author | David Gwynne <dlg@cvs.openbsd.org> | 2015-07-08 13:37:32 +0000 |
---|---|---|
committer | David Gwynne <dlg@cvs.openbsd.org> | 2015-07-08 13:37:32 +0000 |
commit | 9b58256c90b2119530e0b7e88ab0981a575611c3 (patch) | |
tree | 4b3eb83663aa64e2d4b9b1772e6e790467300fdf /sys/arch/octeon | |
parent | 3458dd6c8d73f1df563bcf8fa9908fecee025db1 (diff) |
unify the mutex implementations on all the mips64 platforms.
this basically copies the sgi implementation to mips64 and removes
it from the rest. this way they get an optimised UP mutex implementation
and correct asserts on all platforms.
ok miod@ jmatthew@
Diffstat (limited to 'sys/arch/octeon')
-rw-r--r-- | sys/arch/octeon/conf/files.octeon | 3 | ||||
-rw-r--r-- | sys/arch/octeon/include/intr.h | 4 | ||||
-rw-r--r-- | sys/arch/octeon/include/mutex.h | 60 | ||||
-rw-r--r-- | sys/arch/octeon/octeon/mutex.c | 129 |
4 files changed, 6 insertions, 190 deletions
diff --git a/sys/arch/octeon/conf/files.octeon b/sys/arch/octeon/conf/files.octeon index 1fb41a37927..0bd2551e1a5 100644 --- a/sys/arch/octeon/conf/files.octeon +++ b/sys/arch/octeon/conf/files.octeon @@ -1,4 +1,4 @@ -# $OpenBSD: files.octeon,v 1.20 2015/02/11 00:15:41 uebayasi Exp $ +# $OpenBSD: files.octeon,v 1.21 2015/07/08 13:37:31 dlg Exp $ # Standard stanzas config(8) can't run without maxpartitions 16 @@ -19,7 +19,6 @@ file arch/octeon/octeon/disksubr.c disk file arch/octeon/octeon/lock_machdep.c multiprocessor file arch/octeon/octeon/machdep.c file arch/mips64/mips64/mips64r2.S -file arch/octeon/octeon/mutex.c include "dev/ata/files.ata" include "dev/atapiscsi/files.atapiscsi" diff --git a/sys/arch/octeon/include/intr.h b/sys/arch/octeon/include/intr.h index b90dbfad563..26db9ca4650 100644 --- a/sys/arch/octeon/include/intr.h +++ b/sys/arch/octeon/include/intr.h @@ -1,4 +1,4 @@ -/* $OpenBSD: intr.h,v 1.3 2013/05/17 19:38:52 kettenis Exp $ */ +/* $OpenBSD: intr.h,v 1.4 2015/07/08 13:37:31 dlg Exp $ */ /* * Copyright (c) 2001-2004 Opsycon AB (www.opsycon.se / www.opsycon.com) @@ -59,6 +59,8 @@ #define IPL_IPI 8 /* interprocessor interrupt */ #define NIPLS 9 /* Number of levels */ +#define IPL_MPFLOOR IPL_TTY + /* Interrupt priority 'flags'. */ #define IPL_MPSAFE 0 /* no "mpsafe" interrupts */ diff --git a/sys/arch/octeon/include/mutex.h b/sys/arch/octeon/include/mutex.h index 53c8262934a..138aea9e5e2 100644 --- a/sys/arch/octeon/include/mutex.h +++ b/sys/arch/octeon/include/mutex.h @@ -1,59 +1,3 @@ -/* $OpenBSD: mutex.h,v 1.2 2014/07/14 10:23:58 jasper Exp $ */ +/* $OpenBSD: mutex.h,v 1.3 2015/07/08 13:37:31 dlg Exp $ */ -/* - * Copyright (c) 2004 Artur Grabowski <art@openbsd.org> - * 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. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED ``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_MUTEX_H_ -#define _MACHINE_MUTEX_H_ - -struct mutex { - int mtx_lock; - int mtx_wantipl; - int mtx_oldipl; - void *mtx_owner; -}; - -void mtx_init(struct mutex *, int); - -#define MUTEX_INITIALIZER(ipl) { 0, (ipl), IPL_NONE } - -#ifdef DIAGNOSTIC -#define MUTEX_ASSERT_LOCKED(mtx) do { \ - if ((mtx)->mtx_lock == 0) \ - panic("mutex %p not held in %s", (mtx), __func__); \ -} while (0) - -#define MUTEX_ASSERT_UNLOCKED(mtx) do { \ - if ((mtx)->mtx_lock != 0) \ - panic("mutex %p held in %s", (mtx), __func__); \ -} while (0) -#else -#define MUTEX_ASSERT_LOCKED(mtx) do { } while (0) -#define MUTEX_ASSERT_UNLOCKED(mtx) do { } while (0) -#endif - -#define MUTEX_OLDIPL(mtx) (mtx)->mtx_oldipl - -#endif +#include <mips64/mutex.h> diff --git a/sys/arch/octeon/octeon/mutex.c b/sys/arch/octeon/octeon/mutex.c deleted file mode 100644 index 8876a5edd66..00000000000 --- a/sys/arch/octeon/octeon/mutex.c +++ /dev/null @@ -1,129 +0,0 @@ -/* $OpenBSD: mutex.c,v 1.6 2013/12/26 21:02:37 miod Exp $ */ - -/* - * Copyright (c) 2004 Artur Grabowski <art@openbsd.org> - * 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. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED ``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. - */ - -#include <sys/param.h> -#include <sys/mutex.h> -#include <sys/systm.h> - -#include <machine/intr.h> - -static inline int -try_lock(struct mutex *mtx) -{ -#ifdef MULTIPROCESSOR - int tmp, ret = 0; - - asm volatile ( - ".set noreorder\n" - "1:\n" - "ll %0, %2\n" /* tmp = mtx->mtx_lock */ - "bnez %0, 2f\n" - " li %1, 0\n" /* ret = 0 */ - "li %1, 1\n" /* ret = 1 */ - "sc %1, %2\n" /* mtx->mtx_lock = 1 */ - "beqz %1, 1b\n" /* update failed */ - " nop\n" - "2:\n" - ".set reorder\n" - : "+r"(tmp), "+r"(ret) - : "m"(mtx->mtx_lock)); - - return ret; -#else /* MULTIPROCESSOR */ - mtx->mtx_lock = 1; - return 1; -#endif /* MULTIPROCESSOR */ -} - -void -mtx_init(struct mutex *mtx, int wantipl) -{ - mtx->mtx_lock = 0; - mtx->mtx_wantipl = wantipl; - mtx->mtx_oldipl = IPL_NONE; -} - -void -mtx_enter(struct mutex *mtx) -{ - int s; - int i = 10000000; - for (;;) { - if (mtx->mtx_wantipl != IPL_NONE) - s = splraise(mtx->mtx_wantipl); - if (try_lock(mtx)) { - if (mtx->mtx_wantipl != IPL_NONE) - mtx->mtx_oldipl = s; - mtx->mtx_owner = curcpu(); -#ifdef DIAGNOSTIC - curcpu()->ci_mutex_level++; -#endif - return; - } - if (mtx->mtx_wantipl != IPL_NONE) - splx(s); - if(i-- <= 0) - panic("mtx_enter timed out\n"); - } -} - -int -mtx_enter_try(struct mutex *mtx) -{ - int s; - - if (mtx->mtx_wantipl != IPL_NONE) - s = splraise(mtx->mtx_wantipl); - if (try_lock(mtx)) { - if (mtx->mtx_wantipl != IPL_NONE) - mtx->mtx_oldipl = s; - mtx->mtx_owner = curcpu(); -#ifdef DIAGNOSTIC - curcpu()->ci_mutex_level++; -#endif - return 1; - } - if (mtx->mtx_wantipl != IPL_NONE) - splx(s); - return 0; -} - -void -mtx_leave(struct mutex *mtx) -{ - int s; - - MUTEX_ASSERT_LOCKED(mtx); -#ifdef DIAGNOSTIC - curcpu()->ci_mutex_level--; -#endif - s = mtx->mtx_oldipl; - mtx->mtx_owner = NULL; - mtx->mtx_lock = 0; - if (mtx->mtx_wantipl != IPL_NONE) - splx(s); -} |