Source-Changes-HG archive

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

[src/netbsd-8]: src/sys Pull up following revision(s) (requested by hannken i...



details:   https://anonhg.NetBSD.org/src/rev/06ea23d4c790
branches:  netbsd-8
changeset: 434385:06ea23d4c790
user:      martin <martin%NetBSD.org@localhost>
date:      Fri Nov 17 14:34:02 2017 +0000

description:
Pull up following revision(s) (requested by hannken in ticket #309):
        sys/sys/vnode_impl.h: revision 1.17
        sys/kern/vfs_vnode.c: revision 1.99, 1.100

Change the VSTATE_ASSERT_UNLOCKED code by pushing the potential lock
handling into the backend and doing an optimistic (unlocked) check
first. Always taking the vnode interlock makes this assertion otherwise
very heavy for multi-processor machines.
-
Fix non-DIAGNOSTICS build by adjusting _vstate_assert here too.

diffstat:

 sys/kern/vfs_vnode.c |  34 ++++++++++++++++++++++++++--------
 sys/sys/vnode_impl.h |  14 ++++----------
 2 files changed, 30 insertions(+), 18 deletions(-)

diffs (101 lines):

diff -r a80c302e55be -r 06ea23d4c790 sys/kern/vfs_vnode.c
--- a/sys/kern/vfs_vnode.c      Wed Nov 08 22:26:58 2017 +0000
+++ b/sys/kern/vfs_vnode.c      Fri Nov 17 14:34:02 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vfs_vnode.c,v 1.93.2.2 2017/08/25 05:46:46 snj Exp $   */
+/*     $NetBSD: vfs_vnode.c,v 1.93.2.3 2017/11/17 14:34:02 martin Exp $        */
 
 /*-
  * Copyright (c) 1997-2011 The NetBSD Foundation, Inc.
@@ -156,7 +156,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_vnode.c,v 1.93.2.2 2017/08/25 05:46:46 snj Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_vnode.c,v 1.93.2.3 2017/11/17 14:34:02 martin Exp $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
@@ -242,17 +242,34 @@
        vstate_assert_wait_stable((vp), __func__, __LINE__)
 
 void
-_vstate_assert(vnode_t *vp, enum vnode_state state, const char *func, int line)
+_vstate_assert(vnode_t *vp, enum vnode_state state, const char *func, int line,
+    bool has_lock)
 {
        vnode_impl_t *vip = VNODE_TO_VIMPL(vp);
 
+       if (!has_lock) {
+               /*
+                * Prevent predictive loads from the CPU, but check the state
+                * without loooking first.
+                */
+               membar_enter();
+               if (state == VS_ACTIVE && vp->v_usecount > 0 &&
+                   (vip->vi_state == VS_LOADED || vip->vi_state == VS_BLOCKED))
+                       return;
+               if (vip->vi_state == state)
+                       return;
+               mutex_enter((vp)->v_interlock);
+       }
+
        KASSERTMSG(mutex_owned(vp->v_interlock), "at %s:%d", func, line);
 
-       if (state == VS_ACTIVE && vp->v_usecount > 0 &&
-           (vip->vi_state == VS_LOADED || vip->vi_state == VS_BLOCKED))
+       if ((state == VS_ACTIVE && vp->v_usecount > 0 &&
+           (vip->vi_state == VS_LOADED || vip->vi_state == VS_BLOCKED)) ||
+           vip->vi_state == state) {
+               if (!has_lock)
+                       mutex_exit((vp)->v_interlock);
                return;
-       if (vip->vi_state == state)
-               return;
+       }
        vnpanic(vp, "state is %s, usecount %d, expected %s at %s:%d",
            vstate_name(vip->vi_state), vp->v_usecount,
            vstate_name(state), func, line);
@@ -329,7 +346,8 @@
 #define VSTATE_WAIT_STABLE(vp) \
        vstate_wait_stable((vp))
 void
-_vstate_assert(vnode_t *vp, enum vnode_state state, const char *func, int line)
+_vstate_assert(vnode_t *vp, enum vnode_state state, const char *func, int line,
+    bool has_lock)
 {
 
 }
diff -r a80c302e55be -r 06ea23d4c790 sys/sys/vnode_impl.h
--- a/sys/sys/vnode_impl.h      Wed Nov 08 22:26:58 2017 +0000
+++ b/sys/sys/vnode_impl.h      Fri Nov 17 14:34:02 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vnode_impl.h,v 1.13.6.2 2017/08/25 05:46:46 snj Exp $  */
+/*     $NetBSD: vnode_impl.h,v 1.13.6.3 2017/11/17 14:34:02 martin Exp $       */
 
 /*-
  * Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -88,20 +88,14 @@
 /*
  * Vnode state assertion.
  */
-void _vstate_assert(vnode_t *, enum vnode_state, const char *, int );
+void _vstate_assert(vnode_t *, enum vnode_state, const char *, int, bool);
 
 #if defined(DIAGNOSTIC) 
 
 #define VSTATE_ASSERT(vp, state) \
-       do { \
-               _vstate_assert((vp), (state), __func__, __LINE__); \
-       } while (/*CONSTCOND*/ 0)
+       _vstate_assert((vp), (state), __func__, __LINE__, true)
 #define VSTATE_ASSERT_UNLOCKED(vp, state) \
-       do { \
-               mutex_enter((vp)->v_interlock); \
-               _vstate_assert((vp), (state), __func__, __LINE__); \
-               mutex_exit((vp)->v_interlock); \
-       } while (/*CONSTCOND*/ 0)
+       _vstate_assert((vp), (state), __func__, __LINE__, false)
 
 #else /* defined(DIAGNOSTIC) */
 



Home | Main Index | Thread Index | Old Index