From owner-freebsd-threads@FreeBSD.ORG Wed Nov 17 19:30:02 2004 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 3C8A716A4CE; Wed, 17 Nov 2004 19:30:02 +0000 (GMT) Received: from silver.he.iki.fi (helenius.fi [193.64.42.241]) by mx1.FreeBSD.org (Postfix) with ESMTP id 8C71543D3F; Wed, 17 Nov 2004 19:30:01 +0000 (GMT) (envelope-from pete@he.iki.fi) Received: from [193.64.42.134] (h86.vuokselantie10.fi [193.64.42.134]) by silver.he.iki.fi (8.13.1/8.11.4) with ESMTP id iAHJU0LY054202; Wed, 17 Nov 2004 21:30:00 +0200 (EET) (envelope-from pete@he.iki.fi) Message-ID: <419BA6BA.4060304@he.iki.fi> Date: Wed, 17 Nov 2004 21:30:02 +0200 From: Petri Helenius User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.2) Gecko/20040803 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Daniel Eischen References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit cc: freebsd-threads@freebsd.org Subject: Re: mutex performance X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 17 Nov 2004 19:30:02 -0000 Daniel Eischen wrote: >On Wed, 17 Nov 2004, Petri Helenius wrote: > > > >>Do you feel that mutex performance could be improved from the current >>2-3 million lock/unlock operations per second on uncontested mutexes on >>~2.4Ghz prescott? Which seems to be about 1000 cycles per lock/unlock. >> >> > >I'm not sure what you're trying to say above. > > I have this: #include main() { register int i; pthread_mutexattr_t attr; pthread_mutex_t onepacket; pthread_mutexattr_init (&attr); pthread_mutexattr_settype (&attr,PTHREAD_MUTEX_ERRORCHECK); pthread_mutex_init (&onepacket,&attr); for (i = 0; i < 20000000;i++) { pthread_mutex_lock (&onepacket); pthread_mutex_unlock (&onepacket); } } And run it: > gcc -O3 -std=c99 -g -march=pentiumpro mutextest.c -o mutextest -lthr > time ./mutextest 12.291u 0.000s 0:12.29 100.0% 5+189k 0+0io 0pf+0w > gcc -O3 -std=c99 -g -march=pentiumpro mutextest.c -o mutextest -lpthread > time ./mutextest 7.008u 0.000s 0:07.01 99.8% 5+230k 0+0io 0pf+0w > gcc -O3 -std=c99 -g -march=pentiumpro mutextest.c -o mutextest -lc_r > time ./mutextest 5.887u 0.000s 0:05.88 100.0% 5+389k 0+0io 0pf+0w And I'm wondering how much I need to engineer around mutexes or holding them for longer and releasing just before yielding. I'm not saying it should/must be better, just trying to ask for the feel where to go. >I want to change libpthread locks to drop the 80386 support >and just use the atomic primitives for default mutex types. >In 6.0, we'll also change all the mutexes, CVs, and semaphores >so they aren't pointers -- that will save an indirection and >also allow them to be process shared. > > Do you have patches or is this on planning stage? Pete