summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiod Vallat <miod@cvs.openbsd.org>2007-05-01 18:59:41 +0000
committerMiod Vallat <miod@cvs.openbsd.org>2007-05-01 18:59:41 +0000
commit5917a4a2ea51769e5620e10629e771c0d41e6984 (patch)
treeaa5e93cac233d5de616a744b2c5254e74b742fc5
parent70faf790f9b1740f13c9a8c5ada5076cf343467f (diff)
Simple monoprocessor mutex implementation, faster than the MI code, four left
to go.
-rw-r--r--sys/arch/landisk/include/mutex.h1
-rw-r--r--sys/arch/sgi/conf/files.sgi3
-rw-r--r--sys/arch/sgi/include/_types.h4
-rw-r--r--sys/arch/sgi/include/mutex.h59
-rw-r--r--sys/arch/sgi/sgi/mutex.c68
-rw-r--r--sys/arch/sh/conf/files.sh3
-rw-r--r--sys/arch/sh/include/_types.h3
-rw-r--r--sys/arch/sh/include/mutex.h59
-rw-r--r--sys/arch/sh/sh/mutex.c67
9 files changed, 263 insertions, 4 deletions
diff --git a/sys/arch/landisk/include/mutex.h b/sys/arch/landisk/include/mutex.h
new file mode 100644
index 00000000000..16343bb140a
--- /dev/null
+++ b/sys/arch/landisk/include/mutex.h
@@ -0,0 +1 @@
+#include <sh/mutex.h>
diff --git a/sys/arch/sgi/conf/files.sgi b/sys/arch/sgi/conf/files.sgi
index ee476b97502..9c9e343ff0c 100644
--- a/sys/arch/sgi/conf/files.sgi
+++ b/sys/arch/sgi/conf/files.sgi
@@ -1,4 +1,4 @@
-# $OpenBSD: files.sgi,v 1.10 2005/05/01 21:36:57 brad Exp $
+# $OpenBSD: files.sgi,v 1.11 2007/05/01 18:59:40 miod Exp $
#
# maxpartitions must be first item in files.${ARCH}
#
@@ -11,6 +11,7 @@ maxusers 2 8 64
file arch/sgi/sgi/autoconf.c
file arch/sgi/sgi/conf.c
file arch/sgi/sgi/machdep.c
+file arch/sgi/sgi/mutex.c
file arch/sgi/sgi/sginode.c tgt_origin200 | tgt_origin2000
file arch/sgi/dev/wscons_machdep.c wsdisplay
diff --git a/sys/arch/sgi/include/_types.h b/sys/arch/sgi/include/_types.h
index 0e704df4446..cb7a8cf8164 100644
--- a/sys/arch/sgi/include/_types.h
+++ b/sys/arch/sgi/include/_types.h
@@ -1,4 +1,6 @@
-/* $OpenBSD: _types.h,v 1.1 2006/01/06 18:50:09 millert Exp $ */
+/* $OpenBSD: _types.h,v 1.2 2007/05/01 18:59:40 miod Exp $ */
/* public domain */
#include <mips64/_types.h>
+
+#define __HAVE_MUTEX
diff --git a/sys/arch/sgi/include/mutex.h b/sys/arch/sgi/include/mutex.h
new file mode 100644
index 00000000000..2c5d340d309
--- /dev/null
+++ b/sys/arch/sgi/include/mutex.h
@@ -0,0 +1,59 @@
+/* $OpenBSD: mutex.h,v 1.1 2007/05/01 18:59:40 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.
+ */
+
+#ifndef _MACHINE_MUTEX_H_
+#define _MACHINE_MUTEX_H_
+
+/*
+ * Simple non-mp implementation.
+ */
+struct mutex {
+ int mtx_lock;
+ int mtx_wantipl;
+ int mtx_oldcpl;
+};
+
+void mtx_init(struct mutex *, int);
+
+#define MUTEX_INITIALIZER(ipl) { 0, (ipl), 0 }
+
+#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
+
+#endif
diff --git a/sys/arch/sgi/sgi/mutex.c b/sys/arch/sgi/sgi/mutex.c
new file mode 100644
index 00000000000..bfaf0550d6a
--- /dev/null
+++ b/sys/arch/sgi/sgi/mutex.c
@@ -0,0 +1,68 @@
+/* $OpenBSD: mutex.c,v 1.1 2007/05/01 18:59:40 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>
+
+#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_lock = 0;
+ /* We can't access imask[] here, since MUTEX_INITIALIZER can't. */
+ mtx->mtx_wantipl = wantipl;
+ mtx->mtx_oldcpl = 0;
+}
+
+void
+mtx_enter(struct mutex *mtx)
+{
+ if (mtx->mtx_wantipl != IPL_NONE)
+ mtx->mtx_oldcpl = splraise(imask[mtx->mtx_wantipl]);
+
+ 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 != 0)
+ splx(mtx->mtx_oldcpl);
+}
diff --git a/sys/arch/sh/conf/files.sh b/sys/arch/sh/conf/files.sh
index 3c45db7852b..112ffebf172 100644
--- a/sys/arch/sh/conf/files.sh
+++ b/sys/arch/sh/conf/files.sh
@@ -1,4 +1,4 @@
-# $OpenBSD: files.sh,v 1.1 2006/10/06 21:02:55 miod Exp $
+# $OpenBSD: files.sh,v 1.2 2007/05/01 18:59:40 miod Exp $
# $NetBSD: files.sh3,v 1.32 2005/12/11 12:18:58 christos Exp $
file arch/sh/sh/cache.c
@@ -17,6 +17,7 @@ file arch/sh/sh/mem.c
file arch/sh/sh/mmu.c
file arch/sh/sh/mmu_sh3.c sh3
file arch/sh/sh/mmu_sh4.c sh4
+file arch/sh/sh/mutex.c
file arch/sh/sh/pmap.c
file arch/sh/sh/process_machdep.c
file arch/sh/sh/sh_machdep.c
diff --git a/sys/arch/sh/include/_types.h b/sys/arch/sh/include/_types.h
index 8b528bbf524..f01260841f8 100644
--- a/sys/arch/sh/include/_types.h
+++ b/sys/arch/sh/include/_types.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: _types.h,v 1.1 2006/10/06 21:02:55 miod Exp $ */
+/* $OpenBSD: _types.h,v 1.2 2007/05/01 18:59:40 miod Exp $ */
/*-
* Copyright (c) 1990, 1993
@@ -117,5 +117,6 @@ typedef void * __wctype_t;
/* Feature test macros */
#define __HAVE_GENERIC_SOFT_INTERRUPTS
+#define __HAVE_MUTEX
#endif /* _SH__TYPES_H_ */
diff --git a/sys/arch/sh/include/mutex.h b/sys/arch/sh/include/mutex.h
new file mode 100644
index 00000000000..819ab6209a0
--- /dev/null
+++ b/sys/arch/sh/include/mutex.h
@@ -0,0 +1,59 @@
+/* $OpenBSD: mutex.h,v 1.1 2007/05/01 18:59:40 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.
+ */
+
+#ifndef _SH_MUTEX_H_
+#define _SH_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) << 4, 0 }
+
+#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
+
+#endif /* _SH_MUTEX_H_ */
diff --git a/sys/arch/sh/sh/mutex.c b/sys/arch/sh/sh/mutex.c
new file mode 100644
index 00000000000..d0b12c48a51
--- /dev/null
+++ b/sys/arch/sh/sh/mutex.c
@@ -0,0 +1,67 @@
+/* $OpenBSD: mutex.c,v 1.1 2007/05/01 18:59:40 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>
+
+#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 << 4;
+ mtx->mtx_lock = 0;
+}
+
+void
+mtx_enter(struct mutex *mtx)
+{
+ if (mtx->mtx_wantipl != IPL_NONE << 4)
+ mtx->mtx_oldipl = _cpu_intr_raise(mtx->mtx_wantipl);
+
+ 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 << 4)
+ _cpu_intr_resume(mtx->mtx_oldipl);
+}