diff options
author | Mark Kettenis <kettenis@cvs.openbsd.org> | 2007-08-25 18:36:48 +0000 |
---|---|---|
committer | Mark Kettenis <kettenis@cvs.openbsd.org> | 2007-08-25 18:36:48 +0000 |
commit | 15f834f1cf4d40e15512b242a685b765f5c0c202 (patch) | |
tree | fc61caa28ce536da14cf4350e96016e5eed8796d /sys/arch | |
parent | 95bdcb16c30875be0b3c9b6c943e581c4630a585 (diff) |
Real mutexes for sparc64. Some comments from henric@ and claudio@.
Tested by fkr@, claudio@, nick@.
Diffstat (limited to 'sys/arch')
-rw-r--r-- | sys/arch/sparc64/conf/files.sparc64 | 4 | ||||
-rw-r--r-- | sys/arch/sparc64/include/mutex.h | 15 | ||||
-rw-r--r-- | sys/arch/sparc64/sparc64/mutex.S | 75 | ||||
-rw-r--r-- | sys/arch/sparc64/sparc64/mutex.c | 70 |
4 files changed, 82 insertions, 82 deletions
diff --git a/sys/arch/sparc64/conf/files.sparc64 b/sys/arch/sparc64/conf/files.sparc64 index ce8966276ec..b4a2764d28b 100644 --- a/sys/arch/sparc64/conf/files.sparc64 +++ b/sys/arch/sparc64/conf/files.sparc64 @@ -1,4 +1,4 @@ -# $OpenBSD: files.sparc64,v 1.87 2007/08/21 21:45:29 kettenis Exp $ +# $OpenBSD: files.sparc64,v 1.88 2007/08/25 18:36:47 kettenis Exp $ # $NetBSD: files.sparc64,v 1.50 2001/08/10 20:53:50 eeh Exp $ # maxpartitions must be first item in files.${ARCH} @@ -245,7 +245,7 @@ file arch/sparc64/sparc64/kgdb_machdep.c kgdb file arch/sparc64/sparc64/locore2.c file arch/sparc64/sparc64/machdep.c file arch/sparc64/sparc64/mem.c -file arch/sparc64/sparc64/mutex.c +file arch/sparc64/sparc64/mutex.S file arch/sparc64/sparc64/openprom.c file arch/sparc64/sparc64/openfirm.c file arch/sparc64/sparc64/ofw_machdep.c diff --git a/sys/arch/sparc64/include/mutex.h b/sys/arch/sparc64/include/mutex.h index 158c43c56bd..8b8654ee554 100644 --- a/sys/arch/sparc64/include/mutex.h +++ b/sys/arch/sparc64/include/mutex.h @@ -1,4 +1,4 @@ -/* $OpenBSD: mutex.h,v 1.1 2007/02/03 20:08:50 miod Exp $ */ +/* $OpenBSD: mutex.h,v 1.2 2007/08/25 18:36:47 kettenis Exp $ */ /* * Copyright (c) 2004 Artur Grabowski <art@openbsd.org> @@ -28,27 +28,22 @@ #ifndef _MACHINE_MUTEX_H_ #define _MACHINE_MUTEX_H_ -/* - * Simple non-mp implementation. - */ struct mutex { - int mtx_lock; + __volatile void *mtx_owner; /* mutex.S relies upon this being first */ int mtx_wantipl; int mtx_oldipl; }; -void mtx_init(struct mutex *, int); - -#define MUTEX_INITIALIZER(ipl) { 0, ipl, 0 } +#define MUTEX_INITIALIZER(ipl) { NULL, ipl, 0 } #ifdef DIAGNOSTIC #define MUTEX_ASSERT_LOCKED(mtx) do { \ - if ((mtx)->mtx_lock == 0) \ + 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_lock != 0) \ + if ((mtx)->mtx_owner == curcpu()) \ panic("mutex %p held in %s", (mtx), __func__); \ } while (0) #else diff --git a/sys/arch/sparc64/sparc64/mutex.S b/sys/arch/sparc64/sparc64/mutex.S new file mode 100644 index 00000000000..70f7e146041 --- /dev/null +++ b/sys/arch/sparc64/sparc64/mutex.S @@ -0,0 +1,75 @@ +/* $OpenBSD: mutex.S,v 1.1 2007/08/25 18:36:47 kettenis Exp $ */ + +/* + * Copyright (c) 2007 Mark Kettenis + * + * 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. + */ + +/* + * Mutex implementation based on Example 9 from Appendix J of + * SPARC-V9/R1.4.5, The SPARC Architecture Manual. + */ + +#include "assym.h" +#include <machine/asm.h> +#include <machine/param.h> + +ENTRY(mtx_init) + stx %g0, [%o0 + MTX_OWNER] + stw %o1, [%o0 + MTX_WANTIPL] + retl + stw %g0, [%o0 + MTX_OLDIPL] + +ENTRY(mtx_enter) +#ifdef MULTIPROCESSOR + sethi %hi(CPUINFO_VA+CI_SELF), %g1 + ldx [%g1 + %lo(CPUINFO_VA+CI_SELF)], %g1 +#else + set CPUINFO_VA, %g1 +#endif + rdpr %pil, %g4 +1: + ld [%o0 + MTX_WANTIPL], %g5 + cmp %g4, %g5 + bge 2f + nop + wrpr %g5, %pil +2: + mov %g1, %g5 +/* + * The assembler doesn't like the next line, even if MTX_OWNER is 0. + */ +! casx [%o0 + MTX_OWNER], %g0, %g5 + casx [%o0], %g0, %g5 + tst %g5 + be 4f + nop + wrpr %g4, %pil +3: + ldx [%o0 + MTX_OWNER], %g5 + tst %g5 + bne 3b + nop + ba,a 1b +4: + stw %g4, [%o0 + MTX_OLDIPL] + retl + membar #LoadLoad | #LoadStore + +ENTRY(mtx_leave) + ld [%o0 + MTX_OLDIPL], %g1 + membar #StoreStore | #LoadStore + stx %g0, [%o0 + MTX_OWNER] + retl + wrpr %g1, %pil diff --git a/sys/arch/sparc64/sparc64/mutex.c b/sys/arch/sparc64/sparc64/mutex.c deleted file mode 100644 index 79ce415f06b..00000000000 --- a/sys/arch/sparc64/sparc64/mutex.c +++ /dev/null @@ -1,70 +0,0 @@ -/* $OpenBSD: mutex.c,v 1.1 2007/02/03 20:08:50 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/psl.h> -#include <machine/intr.h> - -#ifdef MULTIPROCESSOR -#error This code needs more work -#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_oldipl = 0; - mtx->mtx_wantipl = wantipl; - mtx->mtx_lock = 0; -} - -void -mtx_enter(struct mutex *mtx) -{ - if (mtx->mtx_wantipl != IPL_NONE) { - mtx->mtx_oldipl = sparc_rdpr(pil); - if (mtx->mtx_oldipl < mtx->mtx_wantipl) - sparc_wrpr(pil, mtx->mtx_wantipl, 0); - } - - MUTEX_ASSERT_UNLOCKED(mtx); - mtx->mtx_lock = 1; -} - -void -mtx_leave(struct mutex *mtx) -{ - MUTEX_ASSERT_LOCKED(mtx); - mtx->mtx_lock = 0; - if (mtx->mtx_wantipl != IPL_NONE) - splx(mtx->mtx_oldipl); -} |