From owner-cvs-src@FreeBSD.ORG Wed Oct 17 08:50:44 2007 Return-Path: Delivered-To: cvs-src@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 88F6316A418; Wed, 17 Oct 2007 08:50:44 +0000 (UTC) (envelope-from davidxu@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 55CA313C457; Wed, 17 Oct 2007 08:50:44 +0000 (UTC) (envelope-from davidxu@FreeBSD.org) Received: from [127.0.0.1] (root@localhost [127.0.0.1]) by freefall.freebsd.org (8.14.1/8.14.1) with ESMTP id l9H8odEZ056652; Wed, 17 Oct 2007 08:50:40 GMT (envelope-from davidxu@freebsd.org) Message-ID: <4715CD13.20205@freebsd.org> Date: Wed, 17 Oct 2007 16:51:31 +0800 From: David Xu User-Agent: Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.7.13) Gecko/20070516 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Kris Kennaway References: <200710160736.l9G7a3oI087966@repoman.freebsd.org> <471480AB.7090500@FreeBSD.org> <4714F750.9010804@freebsd.org> <47150841.2080306@FreeBSD.org> In-Reply-To: <47150841.2080306@FreeBSD.org> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Cc: cvs-src@FreeBSD.org, src-committers@FreeBSD.org, Jason Evans , cvs-all@FreeBSD.org Subject: Re: cvs commit: src/lib/libthr/thread thr_pspinlock.c X-BeenThere: cvs-src@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: CVS commit messages for the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 17 Oct 2007 08:50:44 -0000 Kris Kennaway wrote: > Jason Evans wrote: > >> Kris Kennaway wrote: >> >>> David Xu wrote: >>> >>>> FreeBSD src repository >>>> >>>> Modified files: >>>> lib/libthr/thread thr_pspinlock.c Log: >>>> Reverse the logic of UP and SMP. >>>> Submitted by: jasone >>>> Revision Changes Path >>>> 1.6 +1 -1 src/lib/libthr/thread/thr_pspinlock.c >>> >>> >>> Are there any common applications that use this? >> >> >> It's worth mentioning that this change, although correct, does not >> make a measurable performance difference for the tests I was running >> when I found the bug. It is possible that making the spinlocks >> adaptive would help, but I didn't look into this. >> >> (I was working on malloc performance enhancements that have turned out >> very nicely, but in the end I had to switch to hand-rolled "spin" >> mutexes that eventually convert to blocking, in order to avoid the >> possibility of unrecoverable priority inversion.) > > > BTW I am looking at adding a non-portable (sort of) pthread mutex type > that spins for a while when the lock is held, before blocking. This is > sometimes good for performance when the pthread mutex is highly > contended but held for short periods of time, and in fact Linux has such > a mutex that is used by mysql with performance benefits. > > The real fix would be to make them adaptive in the same way as kernel > mutexes (spin as long as the lock holder is running), but there is > currently no easy way for userland to peer into the kernel to check the > other thread's state. > > Kris > I have a patch to adaptively spin in userland, kernel is not involved. http://people.freebsd.org/~davidxu/patch/libthr_spin.patch I have not seen visible performance improvement in some tests, unlike kernel code, many user application code do not care parallel performance, they only care exclusive accessing to a resource, you can call them badly written code, so spinning is not always useful. However, with this patch, Sun's mutex ping-pong program's performance is massively improved, try it. Regards, David Xu