]> CyberLeo.Net >> Repos - FreeBSD/stable/9.git/commit
Merge 233103, 233912 from head:
authordavidxu <davidxu@ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f>
Tue, 17 Apr 2012 09:09:14 +0000 (09:09 +0000)
committerdavidxu <davidxu@ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f>
Tue, 17 Apr 2012 09:09:14 +0000 (09:09 +0000)
commit138a1fc180b45f493d7758a5fe7163f6802a9643
tree23a4169d6f91070b66afd4af496ed619a50081eb
parent540203df85c43f265a2cbc1f6403a8df2d0aff69
Merge 233103, 233912 from head:

233103:
Some software think a mutex can be destroyed after it owned it, for
example, it uses a serialization point like following:
pthread_mutex_lock(&mutex);
pthread_mutex_unlock(&mutex);
pthread_mutex_destroy(&muetx);
They think a previous lock holder should have already left the mutex and
is no longer referencing it, so they destroy it. To be maximum compatible
with such code, we use IA64 version to unlock the mutex in kernel, remove
the two steps unlocking code.

233912:
umtx operation UMTX_OP_MUTEX_WAKE has a side-effect that it accesses
a mutex after a thread has unlocked it, it event writes data to the mutex
memory to clear contention bit, there is a race that other threads
can lock it and unlock it, then destroy it, so it should not write
data to the mutex memory if there isn't any waiter.
The new operation UMTX_OP_MUTEX_WAKE2 try to fix the problem. It
requires thread library to clear the lock word entirely, then
call the WAKE2 operation to check if there is any waiter in kernel,
and try to wake up a thread, if necessary, the contention bit is set again
by the operation. This also mitgates the chance that other threads find
the contention bit and try to enter kernel to compete with each other
to wake up sleeping thread, this is unnecessary. With this change, the
mutex owner is no longer holding the mutex until it reaches a point
where kernel umtx queue is locked, it releases the mutex as soon as
possible.
Performance is improved when the mutex is contensted heavily.  On Intel
i3-2310M, the runtime of a benchmark program is reduced from 26.87 seconds
to 2.39 seconds, it even is better than UMTX_OP_MUTEX_WAKE which is
deprecated now. http://people.freebsd.org/~davidxu/bench/mutex_perf.c

Special code for stable/9:
And add code to detect if the UMTX_OP_MUTEX_WAKE2 is available.

git-svn-id: svn://svn.freebsd.org/base/stable/9@234372 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
lib/libthr/thread/thr_private.h
lib/libthr/thread/thr_umtx.c
lib/libthr/thread/thr_umtx.h