From owner-freebsd-arch@FreeBSD.ORG Tue Jun 5 15:44:39 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 166C710656E9; Tue, 5 Jun 2012 15:44:39 +0000 (UTC) (envelope-from des@des.no) Received: from smtp.des.no (smtp.des.no [194.63.250.102]) by mx1.freebsd.org (Postfix) with ESMTP id C54408FC16; Tue, 5 Jun 2012 15:44:38 +0000 (UTC) Received: from ds4.des.no (smtp.des.no [194.63.250.102]) by smtp.des.no (Postfix) with ESMTP id BF56D603A; Tue, 5 Jun 2012 15:44:37 +0000 (UTC) Received: by ds4.des.no (Postfix, from userid 1001) id 93533961D; Tue, 5 Jun 2012 17:44:37 +0200 (CEST) From: =?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?= To: John Baldwin References: <201206041053.51802.jhb@freebsd.org> <86y5o1vrer.fsf@ds4.des.no> <201206051008.29568.jhb@freebsd.org> Date: Tue, 05 Jun 2012 17:44:37 +0200 In-Reply-To: <201206051008.29568.jhb@freebsd.org> (John Baldwin's message of "Tue, 5 Jun 2012 10:08:29 -0400") Message-ID: <86haupvk4a.fsf@ds4.des.no> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (berkeley-unix) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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 15:44:39 -0000 John Baldwin writes: > So you call getpid() on each access to a shared resource? 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: 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 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. (strace confirms that no system calls occur for either getpid() or gettimeofday(0, 0)) Here is the same program running on FreeBSD 9.0-RELEASE in VirtualBox on an otherwise idle 3.4 GHz i7: 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 DES --=20 Dag-Erling Sm=C3=B8rgrav - des@des.no