From owner-freebsd-arch@FreeBSD.ORG Tue Jun 5 16:56:11 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 C513F106567B; Tue, 5 Jun 2012 16:56:11 +0000 (UTC) (envelope-from luigi@onelab2.iet.unipi.it) Received: from onelab2.iet.unipi.it (onelab2.iet.unipi.it [131.114.59.238]) by mx1.freebsd.org (Postfix) with ESMTP id 782AF8FC0C; Tue, 5 Jun 2012 16:56:11 +0000 (UTC) Received: by onelab2.iet.unipi.it (Postfix, from userid 275) id 9F9CA7300B; Tue, 5 Jun 2012 19:14:46 +0200 (CEST) Date: Tue, 5 Jun 2012 19:14:46 +0200 From: Luigi Rizzo To: John Baldwin Message-ID: <20120605171446.GA28387@onelab2.iet.unipi.it> References: <201206051008.29568.jhb@freebsd.org> <86haupvk4a.fsf@ds4.des.no> <201206051222.12627.jhb@freebsd.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <201206051222.12627.jhb@freebsd.org> User-Agent: Mutt/1.4.2.3i Cc: Gianni , Alan Cox , Alexander Kabaev , Attilio Rao , Konstantin Belousov , freebsd-arch@freebsd.org, Konstantin Belousov , Dag-Erling Sm??rgrav Subject: Fast vs slow syscalls (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:56:11 -0000 On Tue, Jun 05, 2012 at 12:22:12PM -0400, John Baldwin wrote: > On Tuesday, June 05, 2012 11:44:37 am Dag-Erling Sm??rgrav wrote: > > 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 > > Yes, we know getpid() is slow, I think the question is does it matter that > it's slow in something other than a microbenchmark. Can you name the > application that you've seen use getpid()? i think the important question is, for any function X: Q1 "does it require horrible hacks or a huge amount of work to make X syscall-free ?" rather than Q2 "does it matter to make X fast" If the answer to Q1 is "no" then there is no question we should try to implement it. Clearly the answer changes depending on the infrastructure we have in place (e.g. without some shared kernel page we could not export gettimeofday() calibration data, or PID numbers, etc). And if we really want to educate people to use syscalls in a sensible way (which I do see as a valuable goal, just not always) we could always use an environment variable, LIBC_OPTIONS, which enables or disables certain optimizations, similar to MALLOC_OPTIONS. cheers luigi or > -- > John Baldwin > _______________________________________________ > freebsd-arch@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-arch > To unsubscribe, send any mail to "freebsd-arch-unsubscribe@freebsd.org"