From owner-cvs-all@FreeBSD.ORG Wed Oct 17 04:15:42 2007 Return-Path: Delivered-To: cvs-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 07A7716A418; Wed, 17 Oct 2007 04:15:42 +0000 (UTC) (envelope-from jroberson@chesapeake.net) Received: from webaccess-cl.virtdom.com (webaccess-cl.virtdom.com [216.240.101.25]) by mx1.freebsd.org (Postfix) with ESMTP id B97CF13C447; Wed, 17 Oct 2007 04:15:41 +0000 (UTC) (envelope-from jroberson@chesapeake.net) Received: from [192.168.1.104] (cpe-66-91-190-165.hawaii.res.rr.com [66.91.190.165]) (authenticated bits=0) by webaccess-cl.virtdom.com (8.13.6/8.13.6) with ESMTP id l9H4Fbu2020277 (version=TLSv1/SSLv3 cipher=DHE-DSS-AES256-SHA bits=256 verify=NO); Wed, 17 Oct 2007 00:15:39 -0400 (EDT) (envelope-from jroberson@chesapeake.net) Date: Tue, 16 Oct 2007 21:18:15 -0700 (PDT) From: Jeff Roberson X-X-Sender: jroberson@10.0.0.1 To: Kris Kennaway In-Reply-To: <47150841.2080306@FreeBSD.org> Message-ID: <20071016211711.B598@10.0.0.1> References: <200710160736.l9G7a3oI087966@repoman.freebsd.org> <471480AB.7090500@FreeBSD.org> <4714F750.9010804@freebsd.org> <47150841.2080306@FreeBSD.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: cvs-src@freebsd.org, src-committers@freebsd.org, Jason Evans , cvs-all@freebsd.org, David Xu Subject: Re: cvs commit: src/lib/libthr/thread thr_pspinlock.c X-BeenThere: cvs-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: CVS commit messages for the entire tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 17 Oct 2007 04:15:42 -0000 On Tue, 16 Oct 2007, 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. One thing that was suggested was to spin for a set number of times in user-space before entering the syscall which could continue to spin as long as the target was running. The initial few spins would catch quite a few cases and avoid the syscall overhead. Then the spin in kernel could last for longer and avoid the switch overhead. Sort of a hybrid approach. Jeff > > Kris >