Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Distinguish spin mutex and adaptive mutex on rump kernels fo...



details:   https://anonhg.NetBSD.org/src/rev/877f04050f59
branches:  trunk
changeset: 828691:877f04050f59
user:      ozaki-r <ozaki-r%NetBSD.org@localhost>
date:      Wed Dec 27 09:01:53 2017 +0000

description:
Distinguish spin mutex and adaptive mutex on rump kernels for LOCKDEBUG

Formerly rump kernels treated the two types of mutexes as both adaptive for
LOCKDEBUG for some reasons.

Now we can detect violations of mutex restrictions on rump kernels such as
taking an adaptive mutex with holding a spin mutex as well as normal kernels.

diffstat:

 lib/librumpuser/rumpfiber.c          |  11 +++++++++--
 lib/librumpuser/rumpuser_pth.c       |  11 +++++++++--
 lib/librumpuser/rumpuser_pth_dummy.c |  11 +++++++++--
 sys/rump/include/rump/rumpuser.h     |   3 ++-
 sys/rump/librump/rumpkern/locks.c    |  21 +++++++++++++++------
 5 files changed, 44 insertions(+), 13 deletions(-)

diffs (177 lines):

diff -r 447b8d326956 -r 877f04050f59 lib/librumpuser/rumpfiber.c
--- a/lib/librumpuser/rumpfiber.c       Wed Dec 27 08:45:45 2017 +0000
+++ b/lib/librumpuser/rumpfiber.c       Wed Dec 27 09:01:53 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rumpfiber.c,v 1.12 2015/02/15 00:54:32 justin Exp $    */
+/*     $NetBSD: rumpfiber.c,v 1.13 2017/12/27 09:01:53 ozaki-r Exp $   */
 
 /*
  * Copyright (c) 2007-2013 Antti Kantee.  All Rights Reserved.
@@ -68,7 +68,7 @@
 #include "rumpuser_port.h"
 
 #if !defined(lint)
-__RCSID("$NetBSD: rumpfiber.c,v 1.12 2015/02/15 00:54:32 justin Exp $");
+__RCSID("$NetBSD: rumpfiber.c,v 1.13 2017/12/27 09:01:53 ozaki-r Exp $");
 #endif /* !lint */
 
 #include <sys/mman.h>
@@ -693,6 +693,13 @@
        *mtxp = mtx;
 }
 
+int
+rumpuser_mutex_spin_p(struct rumpuser_mtx *mtx)
+{
+
+       return (mtx->flags & RUMPUSER_MTX_SPIN) != 0;
+}
+
 void
 rumpuser_mutex_enter(struct rumpuser_mtx *mtx)
 {
diff -r 447b8d326956 -r 877f04050f59 lib/librumpuser/rumpuser_pth.c
--- a/lib/librumpuser/rumpuser_pth.c    Wed Dec 27 08:45:45 2017 +0000
+++ b/lib/librumpuser/rumpuser_pth.c    Wed Dec 27 09:01:53 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rumpuser_pth.c,v 1.45 2015/09/18 10:56:25 pooka Exp $  */
+/*     $NetBSD: rumpuser_pth.c,v 1.46 2017/12/27 09:01:53 ozaki-r Exp $        */
 
 /*
  * Copyright (c) 2007-2010 Antti Kantee.  All Rights Reserved.
@@ -28,7 +28,7 @@
 #include "rumpuser_port.h"
 
 #if !defined(lint)
-__RCSID("$NetBSD: rumpuser_pth.c,v 1.45 2015/09/18 10:56:25 pooka Exp $");
+__RCSID("$NetBSD: rumpuser_pth.c,v 1.46 2017/12/27 09:01:53 ozaki-r Exp $");
 #endif /* !lint */
 
 #include <sys/queue.h>
@@ -159,6 +159,13 @@
        *mtxp = mtx;
 }
 
+int
+rumpuser_mutex_spin_p(struct rumpuser_mtx *mtx)
+{
+
+       return (mtx->flags & RUMPUSER_MTX_SPIN) != 0;
+}
+
 static void
 mtxenter(struct rumpuser_mtx *mtx)
 {
diff -r 447b8d326956 -r 877f04050f59 lib/librumpuser/rumpuser_pth_dummy.c
--- a/lib/librumpuser/rumpuser_pth_dummy.c      Wed Dec 27 08:45:45 2017 +0000
+++ b/lib/librumpuser/rumpuser_pth_dummy.c      Wed Dec 27 09:01:53 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rumpuser_pth_dummy.c,v 1.17 2014/06/17 06:43:21 alnsn Exp $    */
+/*     $NetBSD: rumpuser_pth_dummy.c,v 1.18 2017/12/27 09:01:53 ozaki-r Exp $  */
 
 /*
  * Copyright (c) 2009 Antti Kantee.  All Rights Reserved.
@@ -28,7 +28,7 @@
 #include "rumpuser_port.h"
 
 #if !defined(lint)
-__RCSID("$NetBSD: rumpuser_pth_dummy.c,v 1.17 2014/06/17 06:43:21 alnsn Exp $");
+__RCSID("$NetBSD: rumpuser_pth_dummy.c,v 1.18 2017/12/27 09:01:53 ozaki-r Exp $");
 #endif /* !lint */
 
 #include <sys/time.h>
@@ -98,6 +98,13 @@
        *mtx = calloc(1, sizeof(struct rumpuser_mtx));
 }
 
+int
+rumpuser_mutex_spin_p(struct rumpuser_mtx *mtx)
+{
+
+       return false; /* XXX */
+}
+
 void
 rumpuser_mutex_enter(struct rumpuser_mtx *mtx)
 {
diff -r 447b8d326956 -r 877f04050f59 sys/rump/include/rump/rumpuser.h
--- a/sys/rump/include/rump/rumpuser.h  Wed Dec 27 08:45:45 2017 +0000
+++ b/sys/rump/include/rump/rumpuser.h  Wed Dec 27 09:01:53 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rumpuser.h,v 1.114 2015/01/03 17:24:20 pooka Exp $     */
+/*     $NetBSD: rumpuser.h,v 1.115 2017/12/27 09:01:53 ozaki-r Exp $   */
 
 /*
  * Copyright (c) 2007-2013 Antti Kantee.  All Rights Reserved.
@@ -194,6 +194,7 @@
 void rumpuser_mutex_exit(struct rumpuser_mtx *);
 void rumpuser_mutex_destroy(struct rumpuser_mtx *);
 void rumpuser_mutex_owner(struct rumpuser_mtx *, struct lwp **);
+int  rumpuser_mutex_spin_p(struct rumpuser_mtx *);
 
 struct rumpuser_rw;
 enum rumprwlock { RUMPUSER_RW_READER, RUMPUSER_RW_WRITER };
diff -r 447b8d326956 -r 877f04050f59 sys/rump/librump/rumpkern/locks.c
--- a/sys/rump/librump/rumpkern/locks.c Wed Dec 27 08:45:45 2017 +0000
+++ b/sys/rump/librump/rumpkern/locks.c Wed Dec 27 09:01:53 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: locks.c,v 1.77 2017/12/27 08:45:45 ozaki-r Exp $       */
+/*     $NetBSD: locks.c,v 1.78 2017/12/27 09:01:53 ozaki-r Exp $       */
 
 /*
  * Copyright (c) 2007-2011 Antti Kantee.  All Rights Reserved.
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: locks.c,v 1.77 2017/12/27 08:45:45 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: locks.c,v 1.78 2017/12/27 09:01:53 ozaki-r Exp $");
 
 #include <sys/param.h>
 #include <sys/kmem.h>
@@ -50,7 +50,12 @@
 #ifdef LOCKDEBUG
 #include <sys/lockdebug.h>
 
-static lockops_t mutex_lockops = {
+static lockops_t mutex_spin_lockops = {
+       .lo_name = "mutex",
+       .lo_type = LOCKOPS_SPIN,
+       .lo_dump = NULL,
+};
+static lockops_t mutex_adaptive_lockops = {
        .lo_name = "mutex",
        .lo_type = LOCKOPS_SLEEP,
        .lo_dump = NULL,
@@ -129,7 +134,10 @@
        if (isspin)
                ruflags |= RUMPUSER_MTX_SPIN;
        rumpuser_mutex_init((struct rumpuser_mtx **)mtx, ruflags);
-       ALLOCK(mtx, &mutex_lockops);
+       if (isspin)
+               ALLOCK(mtx, &mutex_spin_lockops);
+       else
+               ALLOCK(mtx, &mutex_adaptive_lockops);
 }
 
 void
@@ -145,7 +153,8 @@
 {
 
        WANTLOCK(mtx, 0);
-       BARRIER(mtx, 1);
+       if (!rumpuser_mutex_spin_p(RUMPMTX(mtx)))
+               BARRIER(mtx, 1);
        rumpuser_mutex_enter(RUMPMTX(mtx));
        LOCKED(mtx, false);
 }
@@ -154,8 +163,8 @@
 mutex_spin_enter(kmutex_t *mtx)
 {
 
+       KASSERT(rumpuser_mutex_spin_p(RUMPMTX(mtx)));
        WANTLOCK(mtx, 0);
-       BARRIER(mtx, 1);
        rumpuser_mutex_enter_nowrap(RUMPMTX(mtx));
        LOCKED(mtx, false);
 }



Home | Main Index | Thread Index | Old Index