diff options
author | 2015-07-08 13:37:31 +0000 | |
---|---|---|
committer | 2015-07-08 13:37:31 +0000 | |
commit | 706f15edab2700abea23666179b98e3d4aca7803 (patch) | |
tree | 55ac339b1666d2ebeffb0a248e3708fb46542a63 | |
parent | Linking the local socket to pf states went wrong when IPsec was (diff) | |
download | wireguard-openbsd-706f15edab2700abea23666179b98e3d4aca7803.tar.xz wireguard-openbsd-706f15edab2700abea23666179b98e3d4aca7803.zip |
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@
-rw-r--r-- | sys/arch/loongson/conf/files.loongson | 3 | ||||
-rw-r--r-- | sys/arch/loongson/include/intr.h | 4 | ||||
-rw-r--r-- | sys/arch/loongson/include/mutex.h | 62 | ||||
-rw-r--r-- | sys/arch/mips64/conf/files.mips64 | 3 | ||||
-rw-r--r-- | sys/arch/mips64/include/mutex.h (renamed from sys/arch/loongson/loongson/mutex.c) | 83 | ||||
-rw-r--r-- | sys/arch/mips64/mips64/mutex.c (renamed from sys/arch/sgi/sgi/mutex.c) | 2 | ||||
-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 | ||||
-rw-r--r-- | sys/arch/sgi/conf/files.sgi | 3 | ||||
-rw-r--r-- | sys/arch/sgi/include/intr.h | 4 | ||||
-rw-r--r-- | sys/arch/sgi/include/mutex.h | 74 |
13 files changed, 55 insertions, 379 deletions
diff --git a/sys/arch/loongson/conf/files.loongson b/sys/arch/loongson/conf/files.loongson index aca9bbb9611..70ce4a6ea79 100644 --- a/sys/arch/loongson/conf/files.loongson +++ b/sys/arch/loongson/conf/files.loongson @@ -1,4 +1,4 @@ -# $OpenBSD: files.loongson,v 1.18 2014/07/11 21:54:37 tedu Exp $ +# $OpenBSD: files.loongson,v 1.19 2015/07/08 13:37:31 dlg Exp $ # Standard stanzas config(8) can't run without maxpartitions 16 @@ -23,7 +23,6 @@ file arch/loongson/loongson/isa_machdep.c isa file arch/loongson/loongson/loongson2_machdep.c file arch/loongson/loongson/machdep.c file arch/loongson/loongson/hibernate_machdep.c hibernate -file arch/loongson/loongson/mutex.c file arch/loongson/loongson/pciide_machdep.c pciide file arch/loongson/loongson/pmon.c file arch/loongson/loongson/pmon32.S diff --git a/sys/arch/loongson/include/intr.h b/sys/arch/loongson/include/intr.h index 1169eba3a80..b624c15d6b6 100644 --- a/sys/arch/loongson/include/intr.h +++ b/sys/arch/loongson/include/intr.h @@ -1,4 +1,4 @@ -/* $OpenBSD: intr.h,v 1.5 2013/05/17 19:38:52 kettenis Exp $ */ +/* $OpenBSD: intr.h,v 1.6 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_HIGH 7 /* everything */ #define NIPLS 8 /* Number of levels */ +#define IPL_MPFLOOR IPL_TTY + /* Interrupt priority 'flags'. */ #define IPL_MPSAFE 0 /* no "mpsafe" interrupts */ diff --git a/sys/arch/loongson/include/mutex.h b/sys/arch/loongson/include/mutex.h index 4523b3199ee..74eb0aa1117 100644 --- a/sys/arch/loongson/include/mutex.h +++ b/sys/arch/loongson/include/mutex.h @@ -1,61 +1,3 @@ -/* $OpenBSD: mutex.h,v 1.1.1.1 2009/11/19 19:04:26 miod Exp $ */ +/* $OpenBSD: mutex.h,v 1.2 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_ - -/* - * Simple non-mp implementation. - */ -struct mutex { - int mtx_lock; - int mtx_wantipl; - int mtx_oldipl; -}; - -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/mips64/conf/files.mips64 b/sys/arch/mips64/conf/files.mips64 index 6a62a71753c..42d6ae206f7 100644 --- a/sys/arch/mips64/conf/files.mips64 +++ b/sys/arch/mips64/conf/files.mips64 @@ -1,4 +1,4 @@ -# $OpenBSD: files.mips64,v 1.22 2014/03/22 00:01:04 miod Exp $ +# $OpenBSD: files.mips64,v 1.23 2015/07/08 13:37:31 dlg Exp $ file arch/mips64/mips64/arcbios.c arcbios file arch/mips64/mips64/clock.c clock @@ -13,6 +13,7 @@ file arch/mips64/mips64/softintr.c file arch/mips64/mips64/sys_machdep.c file arch/mips64/mips64/trap.c file arch/mips64/mips64/vm_machdep.c +file arch/mips64/mips64/mutex.c file arch/mips64/mips64/cache_loongson2.c cpu_loongson2 file arch/mips64/mips64/cache_octeon.c cpu_octeon diff --git a/sys/arch/loongson/loongson/mutex.c b/sys/arch/mips64/include/mutex.h index f12ea0a374d..6ba15aca16e 100644 --- a/sys/arch/loongson/loongson/mutex.c +++ b/sys/arch/mips64/include/mutex.h @@ -1,4 +1,4 @@ -/* $OpenBSD: mutex.c,v 1.4 2011/04/21 04:34:12 miod Exp $ */ +/* $OpenBSD: mutex.h,v 1.1 2015/07/08 13:37:31 dlg Exp $ */ /* * Copyright (c) 2004 Artur Grabowski <art@openbsd.org> @@ -25,64 +25,49 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include <sys/param.h> -#include <sys/mutex.h> -#include <sys/systm.h> +#ifndef _MACHINE_MUTEX_H_ +#define _MACHINE_MUTEX_H_ -#include <machine/intr.h> +struct mutex { + void *mtx_owner; + int mtx_wantipl; + int mtx_oldipl; +}; +/* + * To prevent lock ordering problems with the kernel lock, we need to + * make sure we block all interrupts that can grab the kernel lock. + * The simplest way to achieve this is to make sure mutexes always + * raise the interrupt priority level to the highest level that has + * interrupts that grab the kernel lock. + */ #ifdef MULTIPROCESSOR -#error This code needs more work +#define __MUTEX_IPL(ipl) \ + (((ipl) > IPL_NONE && (ipl) < IPL_MPFLOOR) ? IPL_MPFLOOR : (ipl)) +#else +#define __MUTEX_IPL(ipl) (ipl) #endif -/* - * Single processor systems don't need any mutexes, but they need the spl - * raising semantics of the mutexes. - */ -void -mtx_init(struct mutex *mtx, int wantipl) -{ - mtx->mtx_lock = 0; - mtx->mtx_wantipl = wantipl; - mtx->mtx_oldipl = IPL_NONE; -} +#define MUTEX_INITIALIZER(ipl) { NULL, __MUTEX_IPL((ipl)), IPL_NONE } -void -mtx_enter(struct mutex *mtx) -{ - if (mtx->mtx_wantipl != IPL_NONE) - mtx->mtx_oldipl = splraise(mtx->mtx_wantipl); +void __mtx_init(struct mutex *, int); +#define mtx_init(mtx, ipl) __mtx_init((mtx), __MUTEX_IPL((ipl))) - MUTEX_ASSERT_UNLOCKED(mtx); - mtx->mtx_lock = 1; #ifdef DIAGNOSTIC - curcpu()->ci_mutex_level++; -#endif -} - -int -mtx_enter_try(struct mutex *mtx) -{ - if (mtx->mtx_wantipl != IPL_NONE) - mtx->mtx_oldipl = splraise(mtx->mtx_wantipl); +#define MUTEX_ASSERT_LOCKED(mtx) do { \ + if ((mtx)->mtx_owner != curcpu()) \ + panic("mutex %p not held in %s", (mtx), __func__); \ +} while (0) - MUTEX_ASSERT_UNLOCKED(mtx); - mtx->mtx_lock = 1; -#ifdef DIAGNOSTIC - curcpu()->ci_mutex_level++; +#define MUTEX_ASSERT_UNLOCKED(mtx) do { \ + if ((mtx)->mtx_owner == curcpu()) \ + 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 - return 1; -} +#define MUTEX_OLDIPL(mtx) (mtx)->mtx_oldipl -void -mtx_leave(struct mutex *mtx) -{ - MUTEX_ASSERT_LOCKED(mtx); -#ifdef DIAGNOSTIC - curcpu()->ci_mutex_level--; #endif - mtx->mtx_lock = 0; - if (mtx->mtx_wantipl != IPL_NONE) - splx(mtx->mtx_oldipl); -} diff --git a/sys/arch/sgi/sgi/mutex.c b/sys/arch/mips64/mips64/mutex.c index c5764e82600..90ed8452124 100644 --- a/sys/arch/sgi/sgi/mutex.c +++ b/sys/arch/mips64/mips64/mutex.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mutex.c,v 1.15 2015/04/21 01:31:51 dlg Exp $ */ +/* $OpenBSD: mutex.c,v 1.1 2015/07/08 13:37:31 dlg Exp $ */ /* * Copyright (c) 2004 Artur Grabowski <art@openbsd.org> 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); -} diff --git a/sys/arch/sgi/conf/files.sgi b/sys/arch/sgi/conf/files.sgi index 68dd99ff8ba..b8c0b5b439b 100644 --- a/sys/arch/sgi/conf/files.sgi +++ b/sys/arch/sgi/conf/files.sgi @@ -1,4 +1,4 @@ -# $OpenBSD: files.sgi,v 1.52 2013/11/04 14:07:16 deraadt Exp $ +# $OpenBSD: files.sgi,v 1.53 2015/07/08 13:37:31 dlg Exp $ # # maxpartitions must be first item in files.${ARCH} # @@ -23,7 +23,6 @@ file arch/sgi/sgi/ip32_machdep.c tgt_o2 file arch/sgi/sgi/l1.c tgt_origin file arch/sgi/sgi/machdep.c file arch/sgi/sgi/mainbus.c -file arch/sgi/sgi/mutex.c file arch/sgi/sgi/sginode.c tgt_origin file arch/sgi/sgi/wscons_machdep.c wsdisplay diff --git a/sys/arch/sgi/include/intr.h b/sys/arch/sgi/include/intr.h index 9fb7c95651e..92125694f94 100644 --- a/sys/arch/sgi/include/intr.h +++ b/sys/arch/sgi/include/intr.h @@ -1,4 +1,4 @@ -/* $OpenBSD: intr.h,v 1.43 2013/05/17 19:38:52 kettenis Exp $ */ +/* $OpenBSD: intr.h,v 1.44 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/sgi/include/mutex.h b/sys/arch/sgi/include/mutex.h index 8d44c879270..b13515a4101 100644 --- a/sys/arch/sgi/include/mutex.h +++ b/sys/arch/sgi/include/mutex.h @@ -1,73 +1,3 @@ -/* $OpenBSD: mutex.h,v 1.8 2015/04/21 01:31:51 dlg Exp $ */ +/* $OpenBSD: mutex.h,v 1.9 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 { - void *mtx_owner; - int mtx_wantipl; - int mtx_oldipl; -}; - -/* - * To prevent lock ordering problems with the kernel lock, we need to - * make sure we block all interrupts that can grab the kernel lock. - * The simplest way to achieve this is to make sure mutexes always - * raise the interrupt priority level to the highest level that has - * interrupts that grab the kernel lock. - */ -#ifdef MULTIPROCESSOR -#define __MUTEX_IPL(ipl) \ - (((ipl) > IPL_NONE && (ipl) < IPL_TTY) ? IPL_TTY : (ipl)) -#else -#define __MUTEX_IPL(ipl) (ipl) -#endif - -#define MUTEX_INITIALIZER(ipl) { NULL, __MUTEX_IPL((ipl)), IPL_NONE } - -void __mtx_init(struct mutex *, int); -#define mtx_init(mtx, ipl) __mtx_init((mtx), __MUTEX_IPL((ipl))) - -#ifdef DIAGNOSTIC -#define MUTEX_ASSERT_LOCKED(mtx) do { \ - if ((mtx)->mtx_owner != curcpu()) \ - panic("mutex %p not held in %s", (mtx), __func__); \ -} while (0) - -#define MUTEX_ASSERT_UNLOCKED(mtx) do { \ - if ((mtx)->mtx_owner == curcpu()) \ - 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> |