From owner-freebsd-arch@FreeBSD.ORG Tue Jun 5 16:22:22 2012 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id DF196106566C; Tue, 5 Jun 2012 16:22:22 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from bigwig.baldwin.cx (bigknife-pt.tunnel.tserv9.chi1.ipv6.he.net [IPv6:2001:470:1f10:75::2]) by mx1.freebsd.org (Postfix) with ESMTP id AE2A28FC0A; Tue, 5 Jun 2012 16:22:22 +0000 (UTC) Received: from jhbbsd.localnet (unknown [209.249.190.124]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id 2775FB91A; Tue, 5 Jun 2012 12:22:22 -0400 (EDT) From: John Baldwin To: "Dag-Erling =?utf-8?q?Sm=C3=B8rgrav?=" Date: Tue, 5 Jun 2012 12:22:12 -0400 User-Agent: KMail/1.13.5 (FreeBSD/8.2-CBSD-20110714-p13; KDE/4.5.5; amd64; ; ) References: <201206051008.29568.jhb@freebsd.org> <86haupvk4a.fsf@ds4.des.no> In-Reply-To: <86haupvk4a.fsf@ds4.des.no> MIME-Version: 1.0 Content-Type: Text/Plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <201206051222.12627.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.7 (bigwig.baldwin.cx); Tue, 05 Jun 2012 12:22:22 -0400 (EDT) Cc: Gianni , Alan Cox , Alexander Kabaev , Attilio Rao , Konstantin Belousov , freebsd-arch@freebsd.org, Konstantin Belousov Subject: Re: Fwd: [RFC] Kernel shared variables X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 05 Jun 2012 16:22:23 -0000 On Tuesday, June 05, 2012 11:44:37 am Dag-Erling Sm=C3=B8rgrav wrote: > John Baldwin writes: > > So you call getpid() on each access to a shared resource? >=20 > I don't, but I've seen code that does, under the assumption that all the > world is Linux and getpid() is free. Here's a sample from RHEL6 on a > 3.1 GHz i5, using raise(0) as a baseline: >=20 > getpid(): 10,000,000 iterations in 24,400 ms > gettimeofday(0, 0): 10,000,000 iterations in 54,104 ms > raise(0): 10,000,000 iterations in 1,284,593 ms >=20 > The difference between the first two is due to the fact that while > getpid() just returns a constant, gettimeofday(0, 0) performs two > comparisons first. Passing an actual struct timeval to gettimeofday() > slows it down by a factor of about 6. >=20 > (strace confirms that no system calls occur for either getpid() or > gettimeofday(0, 0)) >=20 > Here is the same program running on FreeBSD 9.0-RELEASE in VirtualBox on > an otherwise idle 3.4 GHz i7: >=20 > getpid(): 10,000,000 iterations in 777,251 ms > gettimeofday(0, 0): 10,000,000 iterations in 799,808 ms > raise(0): 10,000,000 iterations in 2,142,275 ms Yes, we know getpid() is slow, I think the question is does it matter that= =20 it's slow in something other than a microbenchmark. Can you name the=20 application that you've seen use getpid()? =2D-=20 John Baldwin