Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 20 Feb 2017 19:08:36 +0000 (UTC)
From:      Mateusz Guzik <mjg@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r313996 - in head/sys: kern sys
Message-ID:  <201702201908.v1KJ8aEE036715@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mjg
Date: Mon Feb 20 19:08:36 2017
New Revision: 313996
URL: https://svnweb.freebsd.org/changeset/base/313996

Log:
  mtx: fix spin mutexes interaction with failed fcmpset
  
  While doing so move recursion support down to the fallback routine.

Modified:
  head/sys/kern/kern_mutex.c
  head/sys/sys/mutex.h

Modified: head/sys/kern/kern_mutex.c
==============================================================================
--- head/sys/kern/kern_mutex.c	Mon Feb 20 17:33:25 2017	(r313995)
+++ head/sys/kern/kern_mutex.c	Mon Feb 20 19:08:36 2017	(r313996)
@@ -696,6 +696,14 @@ _mtx_lock_spin_cookie(volatile uintptr_t
 	lock_delay_arg_init(&lda, &mtx_spin_delay);
 	m = mtxlock2mtx(c);
 
+	if (__predict_false(v == MTX_UNOWNED))
+		v = MTX_READ_VALUE(m);
+
+	if (__predict_false(v == tid)) {
+		m->mtx_recurse++;
+		return;
+	}
+
 	if (LOCK_LOG_TEST(&m->lock_object, opts))
 		CTR1(KTR_LOCK, "_mtx_lock_spin: %p spinning", m);
 	KTR_STATE1(KTR_SCHED, "thread", sched_tdname((struct thread *)tid),

Modified: head/sys/sys/mutex.h
==============================================================================
--- head/sys/sys/mutex.h	Mon Feb 20 17:33:25 2017	(r313995)
+++ head/sys/sys/mutex.h	Mon Feb 20 19:08:36 2017	(r313996)
@@ -223,12 +223,9 @@ void	thread_lock_flags_(struct thread *,
 	uintptr_t _v = MTX_UNOWNED;					\
 									\
 	spinlock_enter();						\
-	if (!_mtx_obtain_lock_fetch((mp), &_v, _tid)) {			\
-		if (_v == _tid)						\
-			(mp)->mtx_recurse++;				\
-		else							\
-			_mtx_lock_spin((mp), _v, _tid, (opts), (file), (line));\
-	} else 								\
+	if (!_mtx_obtain_lock_fetch((mp), &_v, _tid)) 			\
+		_mtx_lock_spin((mp), _v, _tid, (opts), (file), (line)); \
+	else 								\
 		LOCKSTAT_PROFILE_OBTAIN_LOCK_SUCCESS(spin__acquire,	\
 		    mp, 0, 0, file, line);				\
 } while (0)



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