From: tedu Date: Tue, 16 Aug 2016 18:17:36 +0000 (+0000) Subject: replace hand rolled tsleep physlock with rwlock. ok mlarkin X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=89435ff54b91959471afcf069c9ddcacce7e195b;p=openbsd replace hand rolled tsleep physlock with rwlock. ok mlarkin --- 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 #include #include +#include #include #include @@ -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 #include #include +#include #include #include @@ -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 #include #include +#include #include #include @@ -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); }