summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Unangst <tedu@cvs.openbsd.org>2016-08-16 18:17:37 +0000
committerTed Unangst <tedu@cvs.openbsd.org>2016-08-16 18:17:37 +0000
commitf9cb710378989bd945b847693a39475a74af878e (patch)
treeee6fba3e51dbbb2da9a85ac4b74086ff6571dd17
parent32d28755379616ac2b09b7fb18dbc816fb8a2838 (diff)
replace hand rolled tsleep physlock with rwlock. ok mlarkin
-rw-r--r--sys/arch/arm/arm/mem.c21
-rw-r--r--sys/arch/sparc/sparc/mem.c20
-rw-r--r--sys/arch/sparc64/sparc64/mem.c20
3 files changed, 22 insertions, 39 deletions
diff --git a/sys/arch/arm/arm/mem.c b/sys/arch/arm/arm/mem.c
index 9d09331fbbd..9c636f8cfc6 100644
--- a/sys/arch/arm/arm/mem.c
+++ b/sys/arch/arm/arm/mem.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mem.c,v 1.16 2016/08/15 22:01:59 tedu Exp $ */
+/* $OpenBSD: mem.c,v 1.17 2016/08/16 18:17:36 tedu Exp $ */
/* $NetBSD: mem.c,v 1.11 2003/10/16 12:02:58 jdolecek Exp $ */
/*
@@ -81,6 +81,7 @@
#include <sys/malloc.h>
#include <sys/proc.h>
#include <sys/fcntl.h>
+#include <sys/rwlock.h>
#include <machine/cpu.h>
#include <arm/conf.h>
@@ -89,7 +90,6 @@
extern char *memhook; /* poor name! */
caddr_t zeropage;
-int physlock;
/* open counter for aperture */
#ifdef APERTURE
@@ -142,6 +142,7 @@ mmclose(dev_t dev, int flag, int mode, struct proc *p)
int
mmrw(dev_t dev, struct uio *uio, int flags)
{
+ static struct rwlock physlock = RWLOCK_INITIALIZER("mmrw");
vaddr_t o, v;
size_t c;
struct iovec *iov;
@@ -150,14 +151,10 @@ mmrw(dev_t dev, struct uio *uio, int flags)
if (minor(dev) == DEV_MEM) {
/* lock against other uses of shared vmmap */
- while (physlock > 0) {
- physlock++;
- error = tsleep((caddr_t)&physlock, PZERO | PCATCH,
- "mmrw", 0);
- if (error)
- return (error);
- }
- physlock = 1;
+ error = rw_enter(&physlock, RW_WRITE | RW_INTR);
+ if (error)
+ return (error);
+
}
while (uio->uio_resid > 0 && error == 0) {
iov = uio->uio_iov;
@@ -216,9 +213,7 @@ mmrw(dev_t dev, struct uio *uio, int flags)
}
}
if (minor(dev) == DEV_MEM) {
- if (physlock > 1)
- wakeup((caddr_t)&physlock);
- physlock = 0;
+ rw_exit(&physlock);
}
return (error);
}
diff --git a/sys/arch/sparc/sparc/mem.c b/sys/arch/sparc/sparc/mem.c
index 8cbbacd421b..24c67af9624 100644
--- a/sys/arch/sparc/sparc/mem.c
+++ b/sys/arch/sparc/sparc/mem.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mem.c,v 1.27 2016/08/15 22:01:59 tedu Exp $ */
+/* $OpenBSD: mem.c,v 1.28 2016/08/16 18:17:36 tedu Exp $ */
/* $NetBSD: mem.c,v 1.13 1996/03/30 21:12:16 christos Exp $ */
/*
@@ -47,6 +47,7 @@
#include <sys/uio.h>
#include <sys/malloc.h>
#include <sys/proc.h>
+#include <sys/rwlock.h>
#include <sys/conf.h>
#include <sparc/sparc/vaddrs.h>
@@ -86,24 +87,19 @@ mmclose(dev_t dev, int flag, int mode, struct proc *p)
int
mmrw(dev_t dev, struct uio *uio, int flags)
{
+ static struct rwlock physlock = RWLOCK_INITIALIZER("mmrw");
off_t o;
paddr_t pa;
vaddr_t va;
size_t c;
struct iovec *iov;
int error = 0;
- static int physlock;
if (minor(dev) == 0) {
/* lock against other uses of shared mem_page */
- while (physlock > 0) {
- physlock++;
- error = tsleep((caddr_t)&physlock, PZERO | PCATCH,
- "mmrw", 0);
- if (error)
- return (error);
- }
- physlock = 1;
+ error = rw_enter(&physlock, RW_WRITE | RW_INTR);
+ if (error)
+ return (error);
if (mem_page == 0)
mem_page = uvm_km_valloc_wait(kernel_map, NBPG);
if (mem_page == 0)
@@ -193,9 +189,7 @@ mmrw(dev_t dev, struct uio *uio, int flags)
}
if (minor(dev) == 0) {
unlock:
- if (physlock > 1)
- wakeup((caddr_t)&physlock);
- physlock = 0;
+ rw_exit(&physlock);
}
return (error);
}
diff --git a/sys/arch/sparc64/sparc64/mem.c b/sys/arch/sparc64/sparc64/mem.c
index 32615817070..7e21614180f 100644
--- a/sys/arch/sparc64/sparc64/mem.c
+++ b/sys/arch/sparc64/sparc64/mem.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mem.c,v 1.16 2016/08/15 22:01:59 tedu Exp $ */
+/* $OpenBSD: mem.c,v 1.17 2016/08/16 18:17:36 tedu Exp $ */
/* $NetBSD: mem.c,v 1.18 2001/04/24 04:31:12 thorpej Exp $ */
/*
@@ -47,6 +47,7 @@
#include <sys/uio.h>
#include <sys/malloc.h>
#include <sys/proc.h>
+#include <sys/rwlock.h>
#include <sys/conf.h>
#include <machine/conf.h>
@@ -75,24 +76,19 @@ mmclose(dev_t dev, int flag, int mode, struct proc *p)
int
mmrw(dev_t dev, struct uio *uio, int flags)
{
+ static struct rwlock physlock = RWLOCK_INITIALIZER("mmrw");
vaddr_t o, v;
size_t c;
struct iovec *iov;
int error = 0;
- static int physlock;
vm_prot_t prot;
extern caddr_t vmmap;
if (minor(dev) == 0) {
/* lock against other uses of shared vmmap */
- while (physlock > 0) {
- physlock++;
- error = tsleep((caddr_t)&physlock, PZERO | PCATCH,
- "mmrw", 0);
- if (error)
- return (error);
- }
- physlock = 1;
+ error = rw_enter(&physlock, RW_WRITE | RW_INTR);
+ if (error)
+ return (error);
}
while (uio->uio_resid > 0 && error == 0) {
int n;
@@ -169,9 +165,7 @@ mmrw(dev_t dev, struct uio *uio, int flags)
}
if (minor(dev) == 0) {
unlock:
- if (physlock > 1)
- wakeup((caddr_t)&physlock);
- physlock = 0;
+ rw_exit(&physlock);
}
return (error);
}