Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 16 Mar 2017 08:35:28 +0000 (UTC)
From:      Mateusz Guzik <mjg@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r315395 - stable/11/sys/kern
Message-ID:  <201703160835.v2G8ZSp2033079@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mjg
Date: Thu Mar 16 08:35:27 2017
New Revision: 315395
URL: https://svnweb.freebsd.org/changeset/base/315395

Log:
  MFC r309784,r309783:
  Use a consistent snapshot of the lock state in owner_mtx().
  
  ==
  
  Return a non-NULL owner only if the lock is exclusively held in owner_sx().
  
  Fix some whitespace bugs while here.
  
  ============
  
  While here the correct commit message for the previous commit:
  
  MFC r313855 r313865 r313875 r313877 r313878 r313901 r313908 r313928 r313944 r314185 r314476 r314187
  
      locks: let primitives for modules unlock without always goging to the slsow path
  
      It is only needed if the LOCK_PROFILING is enabled. It has to always check if
      the lock is about to be released which requires an avoidable read if the option
      is not specified..
  
  ==
  
      sx: fix compilation on UP kernels after r313855
  
      sx primitives use inlines as opposed to macros. Change the tested condition
      to LOCK_DEBUG which covers the case, but is slightly overzelaous.
  
  ==
  
      mtx: microoptimize lockstat handling in __mtx_lock_sleep
  
      This saves a function call and multiple branches after the lock is acquired.
  
  ==
  
      mtx: restrict r313875 to kernels without LOCK_PROFILING
  
  ==
  
      mtx: get rid of file/line args from slow paths if they are unused
  
      This denotes changes which went in by accident in r313877.
  
      On most production kernels both said parameters are zeroed and have nothing
      reading them in either __mtx_lock_sleep or __mtx_unlock_sleep. Thus this change
      stops passing them by internal consumers which this is the case.
  
      Kernel modules use _flags variants which are not affected kbi-wise.
  
  ==
  
      sx: fix mips builld after r313855
  
      The namespace in this file really needs cleaning up. In the meantime
      let inline primitives be defined as long as LOCK_DEBUG is not enabled.
  
  ==
  
      mtx: plug the 'opts' argument when not used
  
      git-svn-id: svn+ssh://svn.freebsd.org/base/head@313908 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
  
  ==
  
      locks: clean up trylock primitives
  
      In particular thius reduces accesses of the lock itself.
  
  ==
  
      locks: make trylock routines check for 'unowned' value
  
      Since fcmpset can fail without lock contention e.g. on arm, it was possible
      to get spurious failures when the caller was expecting the primitive to succeed.
  
  ==
  
      mtx: microoptimize lockstat handling in spin mutexes and thread lock
  
      While here make the code compilablle on kernels with LOCK_PROFILING but without
      KDTRACE_HOOKS.
  
  ==
  
      KDTRACE_HOOKS isn't guaranteed to be defined. Change to check to see
      if it is defined or not rather than if it is non-zero.
  
  ==
  
      locks: fix compilation with KTR wihout KTR_LOCKS
  
      While here wrap the overly long line.

Modified:
  stable/11/sys/kern/kern_mutex.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sys/kern/kern_mutex.c
==============================================================================
--- stable/11/sys/kern/kern_mutex.c	Thu Mar 16 08:29:09 2017	(r315394)
+++ stable/11/sys/kern/kern_mutex.c	Thu Mar 16 08:35:27 2017	(r315395)
@@ -211,10 +211,13 @@ unlock_spin(struct lock_object *lock)
 int
 owner_mtx(const struct lock_object *lock, struct thread **owner)
 {
-	const struct mtx *m = (const struct mtx *)lock;
+	const struct mtx *m;
+	uintptr_t x;
 
-	*owner = mtx_owner(m);
-	return (mtx_unowned(m) == 0);
+	m = (const struct mtx *)lock;
+	x = m->mtx_lock;
+	*owner = (struct thread *)(x & ~MTX_FLAGMASK);
+	return (x != MTX_UNOWNED);
 }
 #endif
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201703160835.v2G8ZSp2033079>