Module Name: src
Committed By: pgoyette
Date: Sun Apr 30 04:56:55 UTC 2017
Modified Files:
src/distrib/sets/lists/comp [prg-localcount2]: mi
src/share/man/man9 [prg-localcount2]: Makefile mutex.9
src/sys/kern [prg-localcount2]: kern_mutex.c subr_localcount.c
src/sys/rump/librump/rumpkern [prg-localcount2]: locks.c
src/sys/sys [prg-localcount2]: mutex.h
Log Message:
Introduce mutex_ownable(9) and use it in localcount_release(9).
Commit of same code to head is awaiting discussion on tech-kern.
To generate a diff of this commit:
cvs rdiff -u -r1.2125.2.2 -r1.2125.2.3 src/distrib/sets/lists/comp/mi
cvs rdiff -u -r1.409.2.2 -r1.409.2.3 src/share/man/man9/Makefile
cvs rdiff -u -r1.26 -r1.26.16.1 src/share/man/man9/mutex.9
cvs rdiff -u -r1.64 -r1.64.4.1 src/sys/kern/kern_mutex.c
cvs rdiff -u -r1.1.6.1 -r1.1.6.2 src/sys/kern/subr_localcount.c
cvs rdiff -u -r1.73 -r1.73.4.1 src/sys/rump/librump/rumpkern/locks.c
cvs rdiff -u -r1.20 -r1.20.52.1 src/sys/sys/mutex.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/distrib/sets/lists/comp/mi
diff -u src/distrib/sets/lists/comp/mi:1.2125.2.2 src/distrib/sets/lists/comp/mi:1.2125.2.3
--- src/distrib/sets/lists/comp/mi:1.2125.2.2 Fri Apr 28 06:00:33 2017
+++ src/distrib/sets/lists/comp/mi Sun Apr 30 04:56:55 2017
@@ -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
Index: src/share/man/man9/Makefile
diff -u src/share/man/man9/Makefile:1.409.2.2 src/share/man/man9/Makefile:1.409.2.3
--- src/share/man/man9/Makefile:1.409.2.2 Fri Apr 28 06:00:33 2017
+++ src/share/man/man9/Makefile Sun Apr 30 04:56:55 2017
@@ -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+=module.9 module_autoload.9 \
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 \
Index: src/share/man/man9/mutex.9
diff -u src/share/man/man9/mutex.9:1.26 src/share/man/man9/mutex.9:1.26.16.1
--- src/share/man/man9/mutex.9:1.26 Wed Sep 4 10:17:58 2013
+++ src/share/man/man9/mutex.9 Sun Apr 30 04:56:55 2017
@@ -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 @@ if it is not already equal or higher.
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.
Index: src/sys/kern/kern_mutex.c
diff -u src/sys/kern/kern_mutex.c:1.64 src/sys/kern/kern_mutex.c:1.64.4.1
--- src/sys/kern/kern_mutex.c:1.64 Thu Jan 26 04:11:56 2017
+++ src/sys/kern/kern_mutex.c Sun Apr 30 04:56:55 2017
@@ -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_owner(kmutex_t *mtx)
}
/*
+ * 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.
Index: src/sys/kern/subr_localcount.c
diff -u src/sys/kern/subr_localcount.c:1.1.6.1 src/sys/kern/subr_localcount.c:1.1.6.2
--- src/sys/kern/subr_localcount.c:1.1.6.1 Thu Apr 27 05:36:37 2017
+++ src/sys/kern/subr_localcount.c Sun Apr 30 04:56:55 2017
@@ -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 @@ localcount_release(struct localcount *lc
*/
s = splsoftserial();
+ KASSERT(mutex_ownable(interlock));
if (__predict_false(lc->lc_totalp != NULL)) {
/*
* Slow path -- wake localcount_drain in case this is
Index: src/sys/rump/librump/rumpkern/locks.c
diff -u src/sys/rump/librump/rumpkern/locks.c:1.73 src/sys/rump/librump/rumpkern/locks.c:1.73.4.1
--- src/sys/rump/librump/rumpkern/locks.c:1.73 Fri Jan 27 09:50:47 2017
+++ src/sys/rump/librump/rumpkern/locks.c Sun Apr 30 04:56:55 2017
@@ -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 @@ mutex_exit(kmutex_t *mtx)
__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)
{
Index: src/sys/sys/mutex.h
diff -u src/sys/sys/mutex.h:1.20 src/sys/sys/mutex.h:1.20.52.1
--- src/sys/sys/mutex.h:1.20 Mon Feb 8 09:54:27 2010
+++ src/sys/sys/mutex.h Sun Apr 30 04:56:55 2017
@@ -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 @@ void mutex_spin_exit(kmutex_t *);
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);