From owner-cvs-src@FreeBSD.ORG Tue Oct 30 23:24:54 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 3846216A41A; Tue, 30 Oct 2007 23:24:54 +0000 (UTC) (envelope-from bsddiy@126.com) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 0925613C4B0; Tue, 30 Oct 2007 23:24:54 +0000 (UTC) (envelope-from bsddiy@126.com) Received: from alona.my.domain (root@localhost [127.0.0.1]) by freefall.freebsd.org (8.14.1/8.14.1) with ESMTP id l9UNOnda010653; Tue, 30 Oct 2007 23:24:51 GMT (envelope-from bsddiy@126.com) Message-ID: <4727BD4A.7010301@126.com> Date: Wed, 31 Oct 2007 07:24:58 +0800 From: David Xu User-Agent: Thunderbird 2.0.0.0 (X11/20070613) MIME-Version: 1.0 To: Ken Smith References: <200710292101.l9TL1mAE049561@repoman.freebsd.org> <47268F17.1000106@freebsd.org> <4726E9AB.4050209@FreeBSD.org> <4726F130.2060709@freebsd.org> <4726F7E9.2060403@FreeBSD.org> <4726FB01.4060704@freebsd.org> <47270410.2020802@FreeBSD.org> <47272EC0.1030204@freebsd.org> <1193750770.25313.7.camel@opus.cse.buffalo.edu> In-Reply-To: <1193750770.25313.7.camel@opus.cse.buffalo.edu> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: src-committers@FreeBSD.org, cvs-src@FreeBSD.org, Kris Kennaway , cvs-all@FreeBSD.org, Daniel Eischen , David Xu Subject: Re: cvs commit: src/lib/libthr/thread thr_mutex.c src/lib/libkse/thread thr_mutex.c src/include pthread.h 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: Tue, 30 Oct 2007 23:24:54 -0000 Ken Smith wrote: > On Tue, 2007-10-30 at 21:16 +0800, David Xu wrote: >> Kris Kennaway wrote: >>> PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP is just in . >>> >>> /* >>> * Static initialization values. >>> */ >>> #define PTHREAD_MUTEX_INITIALIZER NULL >>> #define PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP NULL >>> #define PTHREAD_COND_INITIALIZER NULL >>> #define PTHREAD_RWLOCK_INITIALIZER NULL >>> >>>>>> I remembered mysql uses this macro to initialize spin mutex, and you >>>>>> indead needs a patch to let it work >>>>> >>>>> No, with the code I committed mysql detects and uses it out of the >>>>> box, without requiring any patches. It is easy to measure the >>>>> resulting 30% performance improvement at high loads ;-) >>>>> >>>> see above, I didn't see any code set PTHREAD_MUTEX_ADAPTIVE_NP type. >>> The code is already in mysql for use with glibc. It basically does >>> >>> #ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP >>> /* >>> * Use PTHREAD_MUTEX_ADAPTIVE_NP for the mutexes we know will benefit >>> * from it >>> */ >>> ... >>> #endif >>> >>> so it just works. >>> >> I can not find code in libthr setting mutex's member field m_type to >> PTHREAD_MUTEX_ADAPTIVE_NP by your change, so how can it work as >> expected ? >> > > Wouldn't you expect that it's mysql that's setting the mutex's member > field? Something like this chunk of code from mysql perhaps? > > #ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP > /* > Set mutex type to "fast" a.k.a "adaptive" > > In this case the thread may steal the mutex from some other thread > that is waiting for the same mutex. This will save us some > context switches but may cause a thread to 'starve forever' while > waiting for the mutex (not likely if the code within the mutex is > short). > */ > pthread_mutexattr_init(&my_fast_mutexattr); > pthread_mutexattr_settype(&my_fast_mutexattr, > PTHREAD_MUTEX_ADAPTIVE_NP); > #endif > Yes, I saw the code before. but PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP also can be used as: pthread_mutex_t mymutex = PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP; The above line initializes a mutex as adaptive mutex, but our PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP is defined as NULL, so obviously it create a confusion from begin, it is wrong. Regards, David Xu