summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorpooka <pooka@NetBSD.org>2010-05-18 15:12:19 +0000
committerpooka <pooka@NetBSD.org>2010-05-18 15:12:19 +0000
commitfdeac1d7dfc2d2c558e3fce650206e57e98f2b4e (patch)
tree33bedaeda114b787b1ba42c5db1c2d9265ddb705 /sys
parent58b647273995ff86c8b0ae3d5888b145b013fb29 (diff)
Move routines related to kernel locking and scheduling from
locks.c to klock.c. No functional change.
Diffstat (limited to 'sys')
-rw-r--r--sys/rump/librump/rumpkern/Makefile.rumpkern8
-rw-r--r--sys/rump/librump/rumpkern/klock.c145
-rw-r--r--sys/rump/librump/rumpkern/locks.c110
3 files changed, 151 insertions, 112 deletions
diff --git a/sys/rump/librump/rumpkern/Makefile.rumpkern b/sys/rump/librump/rumpkern/Makefile.rumpkern
index 882c02cbd2b..740307b9c2f 100644
--- a/sys/rump/librump/rumpkern/Makefile.rumpkern
+++ b/sys/rump/librump/rumpkern/Makefile.rumpkern
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile.rumpkern,v 1.84 2010/05/11 22:21:05 pooka Exp $
+# $NetBSD: Makefile.rumpkern,v 1.85 2010/05/18 15:12:19 pooka Exp $
#
.include "${RUMPTOP}/Makefile.rump"
@@ -15,9 +15,9 @@ LIB= rump
#
# Source modules, first the ones specifically implemented for librump.
#
-SRCS= rump.c rumpcopy.c emul.c intr.c kobj_rename.c locks.c \
- ltsleep.c memalloc.c scheduler.c signals.c sleepq.c \
- sysproxy_socket.c threads.c vm.c
+SRCS= rump.c rumpcopy.c emul.c intr.c klock.c kobj_rename.c \
+ locks.c ltsleep.c memalloc.c scheduler.c signals.c \
+ sleepq.c sysproxy_socket.c threads.c vm.c
vers.c: ${RUMPTOP}/../conf/newvers.sh ${RUMPTOP}/../conf/osrelease.sh
${_MKMSG_CREATE} vers.c
diff --git a/sys/rump/librump/rumpkern/klock.c b/sys/rump/librump/rumpkern/klock.c
new file mode 100644
index 00000000000..e038e76e5d7
--- /dev/null
+++ b/sys/rump/librump/rumpkern/klock.c
@@ -0,0 +1,145 @@
+/* $NetBSD: klock.c,v 1.1 2010/05/18 15:12:19 pooka Exp $ */
+
+/*
+ * Copyright (c) 2007-2010 Antti Kantee. All Rights Reserved.
+ *
+ * Development of this software was supported by the
+ * Finnish Cultural Foundation.
+ *
+ * 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. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 OR CONTRIBUTORS 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/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: klock.c,v 1.1 2010/05/18 15:12:19 pooka Exp $");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+
+#include <rump/rumpuser.h>
+
+#include "rump_private.h"
+
+/*
+ * giant lock
+ */
+
+static volatile int lockcnt;
+
+bool
+kernel_biglocked()
+{
+
+ return rumpuser_mutex_held(rump_giantlock) && lockcnt > 0;
+}
+
+void
+kernel_unlock_allbutone(int *countp)
+{
+ int minusone = lockcnt-1;
+
+ KASSERT(kernel_biglocked());
+ if (minusone) {
+ _kernel_unlock(minusone, countp);
+ }
+ KASSERT(lockcnt == 1);
+ *countp = minusone;
+
+ /*
+ * We drop lockcnt to 0 since rumpuser doesn't know that the
+ * kernel biglock is being used as the interlock for cv in
+ * tsleep.
+ */
+ lockcnt = 0;
+}
+
+void
+kernel_ununlock_allbutone(int nlocks)
+{
+
+ KASSERT(rumpuser_mutex_held(rump_giantlock) && lockcnt == 0);
+ lockcnt = 1;
+ _kernel_lock(nlocks);
+}
+
+void
+_kernel_lock(int nlocks)
+{
+
+ while (nlocks--) {
+ if (!rumpuser_mutex_tryenter(rump_giantlock)) {
+ struct lwp *l = curlwp;
+
+ rump_unschedule_cpu1(l, NULL);
+ rumpuser_mutex_enter_nowrap(rump_giantlock);
+ rump_schedule_cpu(l);
+ }
+ lockcnt++;
+ }
+}
+
+void
+_kernel_unlock(int nlocks, int *countp)
+{
+
+ if (!rumpuser_mutex_held(rump_giantlock)) {
+ KASSERT(nlocks == 0);
+ if (countp)
+ *countp = 0;
+ return;
+ }
+
+ if (countp)
+ *countp = lockcnt;
+ if (nlocks == 0)
+ nlocks = lockcnt;
+ if (nlocks == -1) {
+ KASSERT(lockcnt == 1);
+ nlocks = 1;
+ }
+ KASSERT(nlocks <= lockcnt);
+ while (nlocks--) {
+ lockcnt--;
+ rumpuser_mutex_exit(rump_giantlock);
+ }
+}
+
+void
+rump_user_unschedule(int nlocks, int *countp, void *interlock)
+{
+
+ _kernel_unlock(nlocks, countp);
+ /*
+ * XXX: technically we should unschedule_cpu1() here, but that
+ * requires rump_intr_enter/exit to be implemented.
+ */
+ rump_unschedule_cpu_interlock(curlwp, interlock);
+}
+
+void
+rump_user_schedule(int nlocks, void *interlock)
+{
+
+ rump_schedule_cpu_interlock(curlwp, interlock);
+
+ if (nlocks)
+ _kernel_lock(nlocks);
+}
diff --git a/sys/rump/librump/rumpkern/locks.c b/sys/rump/librump/rumpkern/locks.c
index 87d857d1c40..ba2a370c578 100644
--- a/sys/rump/librump/rumpkern/locks.c
+++ b/sys/rump/librump/rumpkern/locks.c
@@ -1,4 +1,4 @@
-/* $NetBSD: locks.c,v 1.40 2010/05/18 14:58:42 pooka Exp $ */
+/* $NetBSD: locks.c,v 1.41 2010/05/18 15:12:19 pooka Exp $ */
/*
* Copyright (c) 2007, 2008 Antti Kantee. All Rights Reserved.
@@ -29,7 +29,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: locks.c,v 1.40 2010/05/18 14:58:42 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: locks.c,v 1.41 2010/05/18 15:12:19 pooka Exp $");
#include <sys/param.h>
#include <sys/kmem.h>
@@ -281,109 +281,3 @@ cv_is_valid(kcondvar_t *cv)
return RUMPCV(cv) != NULL;
}
-
-/*
- * giant lock
- */
-
-static volatile int lockcnt;
-
-bool
-kernel_biglocked()
-{
-
- return rumpuser_mutex_held(rump_giantlock) && lockcnt > 0;
-}
-
-void
-kernel_unlock_allbutone(int *countp)
-{
- int minusone = lockcnt-1;
-
- KASSERT(kernel_biglocked());
- if (minusone) {
- _kernel_unlock(minusone, countp);
- }
- KASSERT(lockcnt == 1);
- *countp = minusone;
-
- /*
- * We drop lockcnt to 0 since rumpuser doesn't know that the
- * kernel biglock is being used as the interlock for cv in
- * tsleep.
- */
- lockcnt = 0;
-}
-
-void
-kernel_ununlock_allbutone(int nlocks)
-{
-
- KASSERT(rumpuser_mutex_held(rump_giantlock) && lockcnt == 0);
- lockcnt = 1;
- _kernel_lock(nlocks);
-}
-
-void
-_kernel_lock(int nlocks)
-{
-
- while (nlocks--) {
- if (!rumpuser_mutex_tryenter(rump_giantlock)) {
- struct lwp *l = curlwp;
-
- rump_unschedule_cpu1(l, NULL);
- rumpuser_mutex_enter_nowrap(rump_giantlock);
- rump_schedule_cpu(l);
- }
- lockcnt++;
- }
-}
-
-void
-_kernel_unlock(int nlocks, int *countp)
-{
-
- if (!rumpuser_mutex_held(rump_giantlock)) {
- KASSERT(nlocks == 0);
- if (countp)
- *countp = 0;
- return;
- }
-
- if (countp)
- *countp = lockcnt;
- if (nlocks == 0)
- nlocks = lockcnt;
- if (nlocks == -1) {
- KASSERT(lockcnt == 1);
- nlocks = 1;
- }
- KASSERT(nlocks <= lockcnt);
- while (nlocks--) {
- lockcnt--;
- rumpuser_mutex_exit(rump_giantlock);
- }
-}
-
-void
-rump_user_unschedule(int nlocks, int *countp, void *interlock)
-{
-
- _kernel_unlock(nlocks, countp);
- /*
- * XXX: technically we should unschedule_cpu1() here, but that
- * requires rump_intr_enter/exit to be implemented.
- */
- rump_unschedule_cpu_interlock(curlwp, interlock);
-}
-
-void
-rump_user_schedule(int nlocks, void *interlock)
-{
-
- rump_schedule_cpu_interlock(curlwp, interlock);
-
- if (nlocks)
- _kernel_lock(nlocks);
-}