svn commit: r313996 - in head/sys: kern sys
Mateusz Guzik
mjg at FreeBSD.org
Mon Feb 20 19:08:37 UTC 2017
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)
More information about the svn-src-all
mailing list