diff options
author | Miod Vallat <miod@cvs.openbsd.org> | 2011-04-21 04:34:13 +0000 |
---|---|---|
committer | Miod Vallat <miod@cvs.openbsd.org> | 2011-04-21 04:34:13 +0000 |
commit | e98d69b14dd08856abde29fb967f9eb1c845bb3a (patch) | |
tree | 944b112e2faa13021c7af6cb8e644090316911cf /sys | |
parent | f2eeae2112eae0b48bcd954af6ff7d73a0e39ab1 (diff) |
Revert the ``remove the `skip splraise/splx for IPL_NONE mutexes' optimization''
change. It seems to have unexpected side effects, especially on MP systems,
and drahn@ disagrees with the way this change has been done and think there
is a better way to solve the original problem of msleep() fiddling with
mutex internals.
Diffstat (limited to 'sys')
-rw-r--r-- | sys/arch/alpha/alpha/mutex.c | 11 | ||||
-rw-r--r-- | sys/arch/hppa64/hppa64/mutex.c | 11 | ||||
-rw-r--r-- | sys/arch/loongson/loongson/mutex.c | 11 | ||||
-rw-r--r-- | sys/arch/m68k/m68k/mutex.c | 11 | ||||
-rw-r--r-- | sys/arch/m88k/m88k/mutex.S | 20 | ||||
-rw-r--r-- | sys/arch/octeon/octeon/mutex.c | 23 | ||||
-rw-r--r-- | sys/arch/sgi/sgi/mutex.c | 23 | ||||
-rw-r--r-- | sys/arch/sh/sh/mutex.c | 11 | ||||
-rw-r--r-- | sys/arch/sparc/sparc/mutex.c | 25 | ||||
-rw-r--r-- | sys/arch/vax/vax/mutex.c | 11 |
10 files changed, 105 insertions, 52 deletions
diff --git a/sys/arch/alpha/alpha/mutex.c b/sys/arch/alpha/alpha/mutex.c index 747753b9157..1ced8104d95 100644 --- a/sys/arch/alpha/alpha/mutex.c +++ b/sys/arch/alpha/alpha/mutex.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mutex.c,v 1.6 2011/04/03 18:46:38 miod Exp $ */ +/* $OpenBSD: mutex.c,v 1.7 2011/04/21 04:34:12 miod Exp $ */ /* * Copyright (c) 2004 Artur Grabowski <art@openbsd.org> @@ -50,7 +50,8 @@ mtx_init(struct mutex *mtx, int wantipl) void mtx_enter(struct mutex *mtx) { - mtx->mtx_oldipl = _splraise(mtx->mtx_wantipl); + if (mtx->mtx_wantipl != IPL_NONE) + mtx->mtx_oldipl = _splraise(mtx->mtx_wantipl); MUTEX_ASSERT_UNLOCKED(mtx); mtx->mtx_lock = 1; #ifdef DIAGNOSTIC @@ -61,7 +62,8 @@ mtx_enter(struct mutex *mtx) int mtx_enter_try(struct mutex *mtx) { - mtx->mtx_oldipl = _splraise(mtx->mtx_wantipl); + if (mtx->mtx_wantipl != IPL_NONE) + mtx->mtx_oldipl = _splraise(mtx->mtx_wantipl); MUTEX_ASSERT_UNLOCKED(mtx); mtx->mtx_lock = 1; #ifdef DIAGNOSTIC @@ -79,5 +81,6 @@ mtx_leave(struct mutex *mtx) #ifdef DIAGNOSTIC curcpu()->ci_mutex_level--; #endif - splx(mtx->mtx_oldipl); + if (mtx->mtx_wantipl != IPL_NONE) + splx(mtx->mtx_oldipl); } diff --git a/sys/arch/hppa64/hppa64/mutex.c b/sys/arch/hppa64/hppa64/mutex.c index 7a1efbe5060..c51aa9a31c7 100644 --- a/sys/arch/hppa64/hppa64/mutex.c +++ b/sys/arch/hppa64/hppa64/mutex.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mutex.c,v 1.6 2011/04/03 18:46:40 miod Exp $ */ +/* $OpenBSD: mutex.c,v 1.7 2011/04/21 04:34:12 miod Exp $ */ /* * Copyright (c) 2004 Artur Grabowski <art@openbsd.org> @@ -48,7 +48,8 @@ mtx_init(struct mutex *mtx, int wantipl) void mtx_enter(struct mutex *mtx) { - mtx->mtx_oldipl = splraise(mtx->mtx_wantipl); + if (mtx->mtx_wantipl != IPL_NONE) + mtx->mtx_oldipl = splraise(mtx->mtx_wantipl); MUTEX_ASSERT_UNLOCKED(mtx); mtx->mtx_lock = 1; #ifdef DIAGNOSTIC @@ -59,7 +60,8 @@ mtx_enter(struct mutex *mtx) int mtx_enter_try(struct mutex *mtx) { - mtx->mtx_oldipl = splraise(mtx->mtx_wantipl); + if (mtx->mtx_wantipl != IPL_NONE) + mtx->mtx_oldipl = splraise(mtx->mtx_wantipl); MUTEX_ASSERT_UNLOCKED(mtx); mtx->mtx_lock = 1; #ifdef DIAGNOSTIC @@ -77,5 +79,6 @@ mtx_leave(struct mutex *mtx) curcpu()->ci_mutex_level--; #endif mtx->mtx_lock = 0; - splx(mtx->mtx_oldipl); + if (mtx->mtx_wantipl != IPL_NONE) + splx(mtx->mtx_oldipl); } diff --git a/sys/arch/loongson/loongson/mutex.c b/sys/arch/loongson/loongson/mutex.c index 648bee18fbb..f12ea0a374d 100644 --- a/sys/arch/loongson/loongson/mutex.c +++ b/sys/arch/loongson/loongson/mutex.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mutex.c,v 1.3 2011/04/03 18:46:40 miod Exp $ */ +/* $OpenBSD: mutex.c,v 1.4 2011/04/21 04:34:12 miod Exp $ */ /* * Copyright (c) 2004 Artur Grabowski <art@openbsd.org> @@ -50,7 +50,8 @@ mtx_init(struct mutex *mtx, int wantipl) void mtx_enter(struct mutex *mtx) { - mtx->mtx_oldipl = splraise(mtx->mtx_wantipl); + if (mtx->mtx_wantipl != IPL_NONE) + mtx->mtx_oldipl = splraise(mtx->mtx_wantipl); MUTEX_ASSERT_UNLOCKED(mtx); mtx->mtx_lock = 1; @@ -62,7 +63,8 @@ mtx_enter(struct mutex *mtx) int mtx_enter_try(struct mutex *mtx) { - mtx->mtx_oldipl = splraise(mtx->mtx_wantipl); + if (mtx->mtx_wantipl != IPL_NONE) + mtx->mtx_oldipl = splraise(mtx->mtx_wantipl); MUTEX_ASSERT_UNLOCKED(mtx); mtx->mtx_lock = 1; @@ -81,5 +83,6 @@ mtx_leave(struct mutex *mtx) curcpu()->ci_mutex_level--; #endif mtx->mtx_lock = 0; - splx(mtx->mtx_oldipl); + if (mtx->mtx_wantipl != IPL_NONE) + splx(mtx->mtx_oldipl); } diff --git a/sys/arch/m68k/m68k/mutex.c b/sys/arch/m68k/m68k/mutex.c index a4915fc1caf..6116a320e03 100644 --- a/sys/arch/m68k/m68k/mutex.c +++ b/sys/arch/m68k/m68k/mutex.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mutex.c,v 1.7 2011/04/03 18:46:40 miod Exp $ */ +/* $OpenBSD: mutex.c,v 1.8 2011/04/21 04:34:12 miod Exp $ */ /* * Copyright (c) 2004 Artur Grabowski <art@openbsd.org> @@ -51,7 +51,8 @@ mtx_init(struct mutex *mtx, int wantipl) void mtx_enter(struct mutex *mtx) { - mtx->mtx_oldipl = _splraise(MD_IPLTOPSL(mtx->mtx_wantipl)); + if (mtx->mtx_wantipl != IPL_NONE) + mtx->mtx_oldipl = _splraise(MD_IPLTOPSL(mtx->mtx_wantipl)); MUTEX_ASSERT_UNLOCKED(mtx); mtx->mtx_lock = 1; @@ -63,7 +64,8 @@ mtx_enter(struct mutex *mtx) int mtx_enter_try(struct mutex *mtx) { - mtx->mtx_oldipl = _splraise(MD_IPLTOPSL(mtx->mtx_wantipl)); + if (mtx->mtx_wantipl != IPL_NONE) + mtx->mtx_oldipl = _splraise(MD_IPLTOPSL(mtx->mtx_wantipl)); MUTEX_ASSERT_UNLOCKED(mtx); mtx->mtx_lock = 1; #ifdef DIAGNOSTIC @@ -81,5 +83,6 @@ mtx_leave(struct mutex *mtx) curcpu()->ci_mutex_level--; #endif mtx->mtx_lock = 0; - splx(mtx->mtx_oldipl); + if (mtx->mtx_wantipl != IPL_NONE) + splx(mtx->mtx_oldipl); } diff --git a/sys/arch/m88k/m88k/mutex.S b/sys/arch/m88k/m88k/mutex.S index 787efabe879..d6adb3708d8 100644 --- a/sys/arch/m88k/m88k/mutex.S +++ b/sys/arch/m88k/m88k/mutex.S @@ -1,4 +1,4 @@ -/* $OpenBSD: mutex.S,v 1.10 2011/04/03 18:46:40 miod Exp $ */ +/* $OpenBSD: mutex.S,v 1.11 2011/04/21 04:34:12 miod Exp $ */ /* * Copyright (c) 2005, Miodrag Vallat. @@ -54,7 +54,9 @@ ENTRY(mtx_enter) st r2, r31, 0 /* save mtx */ enter_again: ld r2, r2, MTX_WANTIPL + bcnd eq0, r2, 1f bsr _C_LABEL(raiseipl) /* raiseipl(mtx->mtx_wantipl) */ +1: ld r4, r31, 0 or r3, r0, 1 xmem r3, r4, r0 /* attempt to claim the lock, old */ @@ -74,6 +76,8 @@ enter_again: addu r31, r31, 8 enter_failed: /* the lock is not ours... */ + ld r3, r4, MTX_WANTIPL + bcnd eq0, r3, 2f bcnd ne0, r2, 1f /* splx(oldipl) */ bsr.n _C_LABEL(spl0) addu r1, r1, 2f - . - 4 @@ -107,7 +111,9 @@ enter_panic: st r2, r31, 0 /* save mtx */ ld r2, r2, MTX_WANTIPL + bcnd eq0, r2, 1f bsr _C_LABEL(raiseipl) /* raiseipl(mtx->mtx_wantipl) */ +1: ld r4, r31, 0 ldcr r3, CPU st r3, r4, MTX_LOCK /* locked! */ @@ -141,7 +147,9 @@ ENTRY(mtx_enter_try) st r2, r31, 0 /* save mtx */ enter_try_again: ld r2, r2, MTX_WANTIPL + bcnd eq0, r2, 1f bsr _C_LABEL(raiseipl) /* raiseipl(mtx->mtx_wantipl) */ +1: ld r4, r31, 0 or r3, r0, 1 xmem r3, r4, r0 /* attempt to claim the lock, old */ @@ -162,6 +170,8 @@ enter_try_again: addu r31, r31, 8 enter_try_failed: /* the lock is not ours... */ + ld r3, r4, MTX_WANTIPL + bcnd eq0, r3, 2f bcnd ne0, r2, 1f /* splx(oldipl) */ bsr.n _C_LABEL(spl0) addu r1, r1, 2f - . - 4 @@ -194,7 +204,9 @@ enter_try_panic: st r2, r31, 0 /* save mtx */ ld r2, r2, MTX_WANTIPL + bcnd eq0, r2, 1f bsr _C_LABEL(raiseipl) /* raiseipl(mtx->mtx_wantipl) */ +1: ld r4, r31, 0 ldcr r3, CPU st r3, r4, MTX_LOCK /* locked! */ @@ -222,6 +234,7 @@ enter_try_panic: */ ENTRY(mtx_leave) ld r3, r2, MTX_OLDIPL + ld r4, r2, MTX_WANTIPL #ifdef DIAGNOSTIC ld r5, r2, MTX_CPU ld r6, r5, CI_MUTEX_LEVEL @@ -229,10 +242,13 @@ ENTRY(mtx_leave) st r6, r5, CI_MUTEX_LEVEL #endif st r0, r2, MTX_CPU /* mtx->mtx_cpu = NULL */ - st r0, r2, MTX_LOCK /* mtx->mtx_lock = 0 */ + bcnd.n eq0, r4, 2f + st r0, r2, MTX_LOCK /* mtx->mtx_lock = 0 */ bcnd ne0, r3, 1f /* splx(mtx->mtx_oldipl) */ br _C_LABEL(spl0) 1: br.n _C_LABEL(setipl) or r2, r3, r0 +2: + jmp r1 diff --git a/sys/arch/octeon/octeon/mutex.c b/sys/arch/octeon/octeon/mutex.c index 52c35e003b4..2026a6088e3 100644 --- a/sys/arch/octeon/octeon/mutex.c +++ b/sys/arch/octeon/octeon/mutex.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mutex.c,v 1.4 2011/04/03 22:26:24 miod Exp $ */ +/* $OpenBSD: mutex.c,v 1.5 2011/04/21 04:34:12 miod Exp $ */ /* * Copyright (c) 2004 Artur Grabowski <art@openbsd.org> @@ -70,16 +70,19 @@ mtx_enter(struct mutex *mtx) int s; int i = 10000000; for (;;) { - s = splraise(mtx->mtx_wantipl); + if (mtx->mtx_wantipl != IPL_NONE) + s = splraise(mtx->mtx_wantipl); if (try_lock(mtx)) { - mtx->mtx_oldipl = s; + if (mtx->mtx_wantipl != IPL_NONE) + mtx->mtx_oldipl = s; mtx->mtx_owner = curcpu(); #ifdef DIAGNOSTIC curcpu()->ci_mutex_level++; #endif return; } - splx(s); + if (mtx->mtx_wantipl != IPL_NONE) + splx(s); if(i-- <= 0) panic("mtx_enter timed out\n"); } @@ -90,16 +93,19 @@ mtx_enter_try(struct mutex *mtx) { int s; - s = splraise(mtx->mtx_wantipl); + if (mtx->mtx_wantipl != IPL_NONE) + s = splraise(mtx->mtx_wantipl); if (try_lock(mtx)) { - mtx->mtx_oldipl = s; + if (mtx->mtx_wantipl != IPL_NONE) + mtx->mtx_oldipl = s; mtx->mtx_owner = curcpu(); #ifdef DIAGNOSTIC curcpu()->ci_mutex_level++; #endif return 1; } - splx(s); + if (mtx->mtx_wantipl != IPL_NONE) + splx(s); return 0; } @@ -115,5 +121,6 @@ mtx_leave(struct mutex *mtx) s = mtx->mtx_oldipl; mtx->mtx_owner = NULL; mtx->mtx_lock = 0; - splx(s); + if (mtx->mtx_wantipl != IPL_NONE) + splx(s); } diff --git a/sys/arch/sgi/sgi/mutex.c b/sys/arch/sgi/sgi/mutex.c index 57ca2e62ff3..2c85fa89e19 100644 --- a/sys/arch/sgi/sgi/mutex.c +++ b/sys/arch/sgi/sgi/mutex.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mutex.c,v 1.11 2011/04/03 22:26:24 miod Exp $ */ +/* $OpenBSD: mutex.c,v 1.12 2011/04/21 04:34:12 miod Exp $ */ /* * Copyright (c) 2004 Artur Grabowski <art@openbsd.org> @@ -70,16 +70,19 @@ mtx_enter(struct mutex *mtx) int s; for (;;) { - s = splraise(mtx->mtx_wantipl); + if (mtx->mtx_wantipl != IPL_NONE) + s = splraise(mtx->mtx_wantipl); if (try_lock(mtx)) { - mtx->mtx_oldipl = s; + if (mtx->mtx_wantipl != IPL_NONE) + mtx->mtx_oldipl = s; mtx->mtx_owner = curcpu(); #ifdef DIAGNOSTIC curcpu()->ci_mutex_level++; #endif return; } - splx(s); + if (mtx->mtx_wantipl != IPL_NONE) + splx(s); } } @@ -88,16 +91,19 @@ mtx_enter_try(struct mutex *mtx) { int s; - s = splraise(mtx->mtx_wantipl); + if (mtx->mtx_wantipl != IPL_NONE) + s = splraise(mtx->mtx_wantipl); if (try_lock(mtx)) { - mtx->mtx_oldipl = s; + if (mtx->mtx_wantipl != IPL_NONE) + mtx->mtx_oldipl = s; mtx->mtx_owner = curcpu(); #ifdef DIAGNOSTIC curcpu()->ci_mutex_level++; #endif return 1; } - splx(s); + if (mtx->mtx_wantipl != IPL_NONE) + splx(s); return 0; } @@ -113,5 +119,6 @@ mtx_leave(struct mutex *mtx) s = mtx->mtx_oldipl; mtx->mtx_owner = NULL; mtx->mtx_lock = 0; - splx(s); + if (mtx->mtx_wantipl != IPL_NONE) + splx(s); } diff --git a/sys/arch/sh/sh/mutex.c b/sys/arch/sh/sh/mutex.c index 432bcd0a4cf..24b1814250c 100644 --- a/sys/arch/sh/sh/mutex.c +++ b/sys/arch/sh/sh/mutex.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mutex.c,v 1.6 2011/04/03 18:46:40 miod Exp $ */ +/* $OpenBSD: mutex.c,v 1.7 2011/04/21 04:34:12 miod Exp $ */ /* * Copyright (c) 2004 Artur Grabowski <art@openbsd.org> @@ -50,7 +50,8 @@ mtx_init(struct mutex *mtx, int wantipl) void mtx_enter(struct mutex *mtx) { - mtx->mtx_oldipl = _cpu_intr_raise(mtx->mtx_wantipl); + if (mtx->mtx_wantipl != IPL_NONE << 4) + mtx->mtx_oldipl = _cpu_intr_raise(mtx->mtx_wantipl); MUTEX_ASSERT_UNLOCKED(mtx); mtx->mtx_lock = 1; @@ -62,7 +63,8 @@ mtx_enter(struct mutex *mtx) int mtx_enter_try(struct mutex *mtx) { - mtx->mtx_oldipl = _cpu_intr_raise(mtx->mtx_wantipl); + if (mtx->mtx_wantipl != IPL_NONE) + mtx->mtx_oldipl = _cpu_intr_raise(mtx->mtx_wantipl); MUTEX_ASSERT_UNLOCKED(mtx); mtx->mtx_lock = 1; #ifdef DIAGNOSTIC @@ -80,5 +82,6 @@ mtx_leave(struct mutex *mtx) curcpu()->ci_mutex_level--; #endif mtx->mtx_lock = 0; - _cpu_intr_resume(mtx->mtx_oldipl); + if (mtx->mtx_wantipl != IPL_NONE << 4) + _cpu_intr_resume(mtx->mtx_oldipl); } diff --git a/sys/arch/sparc/sparc/mutex.c b/sys/arch/sparc/sparc/mutex.c index 03b532d018a..5045faa193d 100644 --- a/sys/arch/sparc/sparc/mutex.c +++ b/sys/arch/sparc/sparc/mutex.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mutex.c,v 1.6 2011/04/03 18:46:40 miod Exp $ */ +/* $OpenBSD: mutex.c,v 1.7 2011/04/21 04:34:12 miod Exp $ */ /* * Copyright (c) 2004 Artur Grabowski <art@openbsd.org> @@ -52,10 +52,12 @@ mtx_enter(struct mutex *mtx) { int psr; - psr = getpsr(); - mtx->mtx_oldipl = psr & PSR_PIL; - if (mtx->mtx_oldipl < mtx->mtx_wantipl) - setpsr((psr & ~PSR_PIL) | mtx->mtx_wantipl); + if (mtx->mtx_wantipl != IPL_NONE << 8) { + psr = getpsr(); + mtx->mtx_oldipl = psr & PSR_PIL; + if (mtx->mtx_oldipl < mtx->mtx_wantipl) + setpsr((psr & ~PSR_PIL) | mtx->mtx_wantipl); + } MUTEX_ASSERT_UNLOCKED(mtx); mtx->mtx_lock = 1; @@ -69,10 +71,12 @@ mtx_enter_try(struct mutex *mtx) { int psr; - psr = getpsr(); - mtx->mtx_oldipl = psr & PSR_PIL; - if (mtx->mtx_oldipl < mtx->mtx_wantipl) - setpsr((psr & ~PSR_PIL) | mtx->mtx_wantipl); + if (mtx->mtx_wantipl != IPL_NONE << 8) { + psr = getpsr(); + mtx->mtx_oldipl = psr & PSR_PIL; + if (mtx->mtx_oldipl < mtx->mtx_wantipl) + setpsr((psr & ~PSR_PIL) | mtx->mtx_wantipl); + } MUTEX_ASSERT_UNLOCKED(mtx); mtx->mtx_lock = 1; @@ -91,5 +95,6 @@ mtx_leave(struct mutex *mtx) curcpu()->ci_mutex_level--; #endif mtx->mtx_lock = 0; - splx(mtx->mtx_oldipl); + if (mtx->mtx_wantipl != IPL_NONE << 8) + splx(mtx->mtx_oldipl); } diff --git a/sys/arch/vax/vax/mutex.c b/sys/arch/vax/vax/mutex.c index 4757ce45347..60ffe07b827 100644 --- a/sys/arch/vax/vax/mutex.c +++ b/sys/arch/vax/vax/mutex.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mutex.c,v 1.6 2011/04/03 18:46:41 miod Exp $ */ +/* $OpenBSD: mutex.c,v 1.7 2011/04/21 04:34:12 miod Exp $ */ /* * Copyright (c) 2004 Artur Grabowski <art@openbsd.org> @@ -50,7 +50,8 @@ mtx_init(struct mutex *mtx, int wantipl) void mtx_enter(struct mutex *mtx) { - mtx->mtx_oldipl = _splraise(mtx->mtx_wantipl); + if (mtx->mtx_wantipl != IPL_NONE) + mtx->mtx_oldipl = _splraise(mtx->mtx_wantipl); MUTEX_ASSERT_UNLOCKED(mtx); mtx->mtx_lock = 1; @@ -62,7 +63,8 @@ mtx_enter(struct mutex *mtx) int mtx_enter_try(struct mutex *mtx) { - mtx->mtx_oldipl = _splraise(mtx->mtx_wantipl); + if (mtx->mtx_wantipl != IPL_NONE) + mtx->mtx_oldipl = _splraise(mtx->mtx_wantipl); MUTEX_ASSERT_UNLOCKED(mtx); mtx->mtx_lock = 1; #ifdef DIAGNOSTIC @@ -80,5 +82,6 @@ mtx_leave(struct mutex *mtx) curcpu()->ci_mutex_level--; #endif mtx->mtx_lock = 0; - splx(mtx->mtx_oldipl); + if (mtx->mtx_wantipl != IPL_NONE) + splx(mtx->mtx_oldipl); } |