From owner-cvs-src@FreeBSD.ORG Mon Oct 29 21:29:37 2007 Return-Path: Delivered-To: cvs-src@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 10C1F16A417; Mon, 29 Oct 2007 21:29:37 +0000 (UTC) (envelope-from kris@FreeBSD.org) Received: from weak.local (pointyhat.freebsd.org [IPv6:2001:4f8:fff6::2b]) by mx1.freebsd.org (Postfix) with ESMTP id E809413C4B2; Mon, 29 Oct 2007 21:29:34 +0000 (UTC) (envelope-from kris@FreeBSD.org) Message-ID: <472650BF.5060706@FreeBSD.org> Date: Mon, 29 Oct 2007 22:29:35 +0100 From: Kris Kennaway User-Agent: Thunderbird 2.0.0.6 (Macintosh/20070728) MIME-Version: 1.0 To: Daniel Eischen References: <200710292101.l9TL1mAE049561@repoman.freebsd.org> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: cvs-src@freebsd.org, src-committers@freebsd.org, cvs-all@freebsd.org 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: Mon, 29 Oct 2007 21:29:37 -0000 Daniel Eischen wrote: > On Mon, 29 Oct 2007, Kris Kennaway wrote: > >> kris 2007-10-29 21:01:47 UTC >> >> FreeBSD src repository >> >> Modified files: >> lib/libthr/thread thr_mutex.c >> lib/libkse/thread thr_mutex.c >> include pthread.h >> Log: >> Add a new "non-portable" mutex type, PTHREAD_MUTEX_ADAPTIVE_NP. This >> is also implemented in glibc and is used by a number of existing >> applications (mysql, firefox, etc). >> >> This mutex type is a default mutex with the additional property that >> it spins briefly when attempting to acquire a contested lock, doing >> trylock operations in userland before entering the kernel to block if >> eventually unsuccessful. >> >> The expectation is that applications requesting this mutex type know >> that the mutex is likely to be only held for very brief periods, so it >> is faster to spin in userland and probably succeed in acquiring the >> mutex, than to enter the kernel and sleep, only to be woken up almost >> immediately. This can help significantly in certain cases when >> pthread mutexes are heavily contended and held for brief durations >> (such as mysql). >> >> Spin up to 200 times before entering the kernel, which represents only >> a few us on modern CPUs. No performance degradation was observed with >> this value and it is sufficient to avoid a large performance drop in >> mysql performance in the heavily contended pthread mutex case. >> >> The libkse implementation is a NOP. > > The libkse implementation already spins for a bit. The default > number of spins is 500. OK, cool. > I'm not sure that another mutex type is warranted, the default > mutex implementation should be adaptive I think. The point being that certain existing applications already know about this mutex name and will use it automatically when it exists. I am a bit wary of making this the default type though. The algorithm is a pessimization when the conditions described above are not true. Kris