]> CyberLeo.Net >> Repos - FreeBSD/stable/8.git/commit
Merge 233103, 233912 from head:
authordavidxu <davidxu@ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f>
Thu, 3 May 2012 03:05:18 +0000 (03:05 +0000)
committerdavidxu <davidxu@ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f>
Thu, 3 May 2012 03:05:18 +0000 (03:05 +0000)
commit872d2b706dd3fbf2d42a287c8985db52e71c0424
tree33a119b39fa2c65db81264fd77ccf4d7bf0b82ab
parent65924cada9fe6e9feb298ff9b75be78db8038880
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/8:
And add code to detect if the UMTX_OP_MUTEX_WAKE2 is available.

PR: threads/167308

git-svn-id: svn://svn.freebsd.org/base/stable/8@234937 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
lib/libthr/thread/thr_private.h
lib/libthr/thread/thr_umtx.c
lib/libthr/thread/thr_umtx.h
sys/kern/kern_umtx.c
sys/sys/umtx.h