svn commit: r311194 - head/sys/kern
Mateusz Guzik
mjg at FreeBSD.org
Tue Jan 3 23:08:12 UTC 2017
Author: mjg
Date: Tue Jan 3 23:08:11 2017
New Revision: 311194
URL: https://svnweb.freebsd.org/changeset/base/311194
Log:
Reduce lock accesses in thread lock similarly to r311172.
Modified:
head/sys/kern/kern_mutex.c
Modified: head/sys/kern/kern_mutex.c
==============================================================================
--- head/sys/kern/kern_mutex.c Tue Jan 3 23:07:40 2017 (r311193)
+++ head/sys/kern/kern_mutex.c Tue Jan 3 23:08:11 2017 (r311194)
@@ -754,7 +754,7 @@ void
thread_lock_flags_(struct thread *td, int opts, const char *file, int line)
{
struct mtx *m;
- uintptr_t tid;
+ uintptr_t tid, v;
struct lock_delay_arg lda;
#ifdef LOCK_PROFILING
int contested = 0;
@@ -796,10 +796,15 @@ retry:
m->lock_object.lo_name, file, line));
WITNESS_CHECKORDER(&m->lock_object,
opts | LOP_NEWORDER | LOP_EXCLUSIVE, file, line, NULL);
+ v = MTX_READ_VALUE(m);
for (;;) {
- if (m->mtx_lock == MTX_UNOWNED && _mtx_obtain_lock(m, tid))
- break;
- if (m->mtx_lock == tid) {
+ if (v == MTX_UNOWNED) {
+ if (_mtx_obtain_lock(m, tid))
+ break;
+ v = MTX_READ_VALUE(m);
+ continue;
+ }
+ if (v == tid) {
m->mtx_recurse++;
break;
}
@@ -810,7 +815,7 @@ retry:
&contested, &waittime);
/* Give interrupts a chance while we spin. */
spinlock_exit();
- while (m->mtx_lock != MTX_UNOWNED) {
+ do {
if (lda.spin_cnt < 10000000) {
lock_delay(&lda);
} else {
@@ -824,7 +829,8 @@ retry:
}
if (m != td->td_lock)
goto retry;
- }
+ v = MTX_READ_VALUE(m);
+ } while (v != MTX_UNOWNED);
spinlock_enter();
}
if (m == td->td_lock)
More information about the svn-src-all
mailing list