Source-Changes-HG archive

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

[src/prg-localcount2]: src Introduce mutex_ownable(9) and use it in localcoun...



details:   https://anonhg.NetBSD.org/src/rev/63c15937951a
branches:  prg-localcount2
changeset: 823527:63c15937951a
user:      pgoyette <pgoyette%NetBSD.org@localhost>
date:      Sun Apr 30 04:56:55 2017 +0000

description:
Introduce mutex_ownable(9) and use it in localcount_release(9).

Commit of same code to head is awaiting discussion on tech-kern.

diffstat:

 distrib/sets/lists/comp/mi        |   5 ++++-
 share/man/man9/Makefile           |   3 ++-
 share/man/man9/mutex.9            |  17 ++++++++++++++++-
 sys/kern/kern_mutex.c             |  22 ++++++++++++++++++++--
 sys/kern/subr_localcount.c        |   5 +++--
 sys/rump/librump/rumpkern/locks.c |  15 +++++++++++++--
 sys/sys/mutex.h                   |   3 ++-
 7 files changed, 60 insertions(+), 10 deletions(-)

diffs (217 lines):

diff -r 5f1eaac86474 -r 63c15937951a distrib/sets/lists/comp/mi
--- a/distrib/sets/lists/comp/mi        Sat Apr 29 11:12:14 2017 +0000
+++ b/distrib/sets/lists/comp/mi        Sun Apr 30 04:56:55 2017 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: mi,v 1.2125.2.2 2017/04/28 06:00:33 pgoyette Exp $
+#      $NetBSD: mi,v 1.2125.2.3 2017/04/30 04:56:55 pgoyette Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 ./etc/mtree/set.comp                           comp-sys-root
@@ -10836,6 +10836,7 @@
 ./usr/share/man/cat9/mutex_enter.0             comp-sys-catman         .cat
 ./usr/share/man/cat9/mutex_exit.0              comp-sys-catman         .cat
 ./usr/share/man/cat9/mutex_init.0              comp-sys-catman         .cat
+./usr/share/man/cat9/mutex_ownable.0           comp-sys-catman         .cat
 ./usr/share/man/cat9/mutex_owned.0             comp-sys-catman         .cat
 ./usr/share/man/cat9/mutex_spin_enter.0                comp-sys-catman         .cat
 ./usr/share/man/cat9/mutex_spin_exit.0         comp-sys-catman         .cat
@@ -18278,6 +18279,7 @@
 ./usr/share/man/html9/mutex_enter.html         comp-sys-htmlman        html
 ./usr/share/man/html9/mutex_exit.html          comp-sys-htmlman        html
 ./usr/share/man/html9/mutex_init.html          comp-sys-htmlman        html
+./usr/share/man/html9/mutex_ownable.html       comp-sys-htmlman        html
 ./usr/share/man/html9/mutex_owned.html         comp-sys-htmlman        html
 ./usr/share/man/html9/mutex_spin_enter.html    comp-sys-htmlman        html
 ./usr/share/man/html9/mutex_spin_exit.html     comp-sys-htmlman        html
@@ -25876,6 +25878,7 @@
 ./usr/share/man/man9/mutex_enter.9             comp-sys-man            .man
 ./usr/share/man/man9/mutex_exit.9              comp-sys-man            .man
 ./usr/share/man/man9/mutex_init.9              comp-sys-man            .man
+./usr/share/man/man9/mutex_ownable.9           comp-sys-man            .man
 ./usr/share/man/man9/mutex_owned.9             comp-sys-man            .man
 ./usr/share/man/man9/mutex_spin_enter.9                comp-sys-man            .man
 ./usr/share/man/man9/mutex_spin_exit.9         comp-sys-man            .man
diff -r 5f1eaac86474 -r 63c15937951a share/man/man9/Makefile
--- a/share/man/man9/Makefile   Sat Apr 29 11:12:14 2017 +0000
+++ b/share/man/man9/Makefile   Sun Apr 30 04:56:55 2017 +0000
@@ -1,4 +1,4 @@
-#       $NetBSD: Makefile,v 1.409.2.2 2017/04/28 06:00:33 pgoyette Exp $
+#       $NetBSD: Makefile,v 1.409.2.3 2017/04/30 04:56:55 pgoyette Exp $
 
 #      Makefile for section 9 (kernel function and variable) manual pages.
 
@@ -516,6 +516,7 @@
 MLINKS+=mstohz.9 hztoms.9
 MLINKS+=mutex.9 mutex_init.9 mutex.9 mutex_destroy.9 mutex.9 mutex_enter.9 \
        mutex.9 mutex_exit.9 mutex.9 mutex_tryenter.9 mutex.9 mutex_owned.9 \
+       mutex.9 mutex_ownable.9 \
        mutex.9 mutex_spin_enter.9 mutex.9 mutex_spin_exit.9
 MLINKS+=m_tag.9 m_tag_copy.9 \
        m_tag.9 m_tag_copy_chain.9 \
diff -r 5f1eaac86474 -r 63c15937951a share/man/man9/mutex.9
--- a/share/man/man9/mutex.9    Sat Apr 29 11:12:14 2017 +0000
+++ b/share/man/man9/mutex.9    Sun Apr 30 04:56:55 2017 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: mutex.9,v 1.26 2013/09/04 10:17:58 skrll Exp $
+.\"    $NetBSD: mutex.9,v 1.26.16.1 2017/04/30 04:56:55 pgoyette Exp $
 .\"
 .\" Copyright (c) 2007, 2009 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -36,6 +36,7 @@
 .Nm mutex_destroy ,
 .Nm mutex_enter ,
 .Nm mutex_exit ,
+.Nm mutex_ownable ,
 .Nm mutex_owned ,
 .Nm mutex_spin_enter ,
 .Nm mutex_spin_exit ,
@@ -52,6 +53,8 @@
 .Ft void
 .Fn mutex_exit "kmutex_t *mtx"
 .Ft int
+.Fn mutex_ownable "kmutex_t *mtx"
+.Ft int
 .Fn mutex_owned "kmutex_t *mtx"
 .Ft void
 .Fn mutex_spin_enter "kmutex_t *mtx"
@@ -172,6 +175,18 @@
 Release a mutex.
 The mutex must have been previously acquired by the caller.
 Mutexes may be released out of order as needed.
+.It Fn mutex_ownable "mtx"
+.Pp
+When compiled with LOCKDEBUG (see
+.Xr options 4 ) ,
+ensure that the current process can successfully acquire mtx.
+If mtx is already owned by the current process, the system will panic
+with a "locking against myself" error.
+.Pp
+This function is needed because
+.Fn mutex_owned
+does not differentiate if a spin mutex is owned by the current process
+vs owned by another process.
 .It Fn mutex_owned "mtx"
 .Pp
 For adaptive mutexes, return non-zero if the current LWP holds the mutex.
diff -r 5f1eaac86474 -r 63c15937951a sys/kern/kern_mutex.c
--- a/sys/kern/kern_mutex.c     Sat Apr 29 11:12:14 2017 +0000
+++ b/sys/kern/kern_mutex.c     Sun Apr 30 04:56:55 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_mutex.c,v 1.64 2017/01/26 04:11:56 christos Exp $ */
+/*     $NetBSD: kern_mutex.c,v 1.64.4.1 2017/04/30 04:56:55 pgoyette Exp $     */
 
 /*-
  * Copyright (c) 2002, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -40,7 +40,7 @@
 #define        __MUTEX_PRIVATE
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_mutex.c,v 1.64 2017/01/26 04:11:56 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_mutex.c,v 1.64.4.1 2017/04/30 04:56:55 pgoyette Exp $");
 
 #include <sys/param.h>
 #include <sys/atomic.h>
@@ -831,6 +831,24 @@
 }
 
 /*
+ * mutex_ownable:
+ *
+ *     When compiled with LOCKDEBUG defined, ensure that the
+ *     mutex is available.  We cannot use !mutex_owned()
+ *     since that won't work correctly for spin mutexes.
+ */
+int
+mutex_ownable(kmutex_t *mtx)
+{
+
+#ifdef LOCKDEBUG
+       mutex_enter(mtx);
+       mutex_exit(mtx);
+#endif
+       return 1;
+}
+
+/*
  * mutex_tryenter:
  *
  *     Try to acquire the mutex; return non-zero if we did.
diff -r 5f1eaac86474 -r 63c15937951a sys/kern/subr_localcount.c
--- a/sys/kern/subr_localcount.c        Sat Apr 29 11:12:14 2017 +0000
+++ b/sys/kern/subr_localcount.c        Sun Apr 30 04:56:55 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: subr_localcount.c,v 1.1.6.1 2017/04/27 05:36:37 pgoyette Exp $ */
+/*     $NetBSD: subr_localcount.c,v 1.1.6.2 2017/04/30 04:56:55 pgoyette Exp $ */
 
 /*-
  * Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -44,7 +44,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_localcount.c,v 1.1.6.1 2017/04/27 05:36:37 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_localcount.c,v 1.1.6.2 2017/04/30 04:56:55 pgoyette Exp $");
 
 #include <sys/param.h>
 #include <sys/localcount.h>
@@ -229,6 +229,7 @@
         */
        s = splsoftserial();
 
+       KASSERT(mutex_ownable(interlock));
        if (__predict_false(lc->lc_totalp != NULL)) {
                /*
                 * Slow path -- wake localcount_drain in case this is
diff -r 5f1eaac86474 -r 63c15937951a sys/rump/librump/rumpkern/locks.c
--- a/sys/rump/librump/rumpkern/locks.c Sat Apr 29 11:12:14 2017 +0000
+++ b/sys/rump/librump/rumpkern/locks.c Sun Apr 30 04:56:55 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: locks.c,v 1.73 2017/01/27 09:50:47 ozaki-r Exp $       */
+/*     $NetBSD: locks.c,v 1.73.4.1 2017/04/30 04:56:55 pgoyette 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.73 2017/01/27 09:50:47 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: locks.c,v 1.73.4.1 2017/04/30 04:56:55 pgoyette Exp $");
 
 #include <sys/param.h>
 #include <sys/kmem.h>
@@ -183,6 +183,17 @@
 __strong_alias(mutex_spin_exit,mutex_exit);
 
 int
+mutex_ownable(kmutex_t *mtx)
+{
+
+#ifdef RUMP_LOCKDEBUG
+       mutex_enter(mtx);
+       mutex_exit(mtx);
+#endif
+       return 1;
+}
+
+int
 mutex_owned(kmutex_t *mtx)
 {
 
diff -r 5f1eaac86474 -r 63c15937951a sys/sys/mutex.h
--- a/sys/sys/mutex.h   Sat Apr 29 11:12:14 2017 +0000
+++ b/sys/sys/mutex.h   Sun Apr 30 04:56:55 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mutex.h,v 1.20 2010/02/08 09:54:27 skrll Exp $ */
+/*     $NetBSD: mutex.h,v 1.20.52.1 2017/04/30 04:56:55 pgoyette Exp $ */
 
 /*-
  * Copyright (c) 2002, 2006, 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -204,6 +204,7 @@
 int    mutex_tryenter(kmutex_t *);
 
 int    mutex_owned(kmutex_t *);
+int    mutex_ownable(kmutex_t *);
 lwp_t  *mutex_owner(kmutex_t *);
 
 void   mutex_obj_init(void);



Home | Main Index | Thread Index | Old Index