From owner-freebsd-hackers@FreeBSD.ORG Wed Sep 7 06:17:45 2011 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D4DB61065676 for ; Wed, 7 Sep 2011 06:17:45 +0000 (UTC) (envelope-from peterjeremy@acm.org) Received: from mail27.syd.optusnet.com.au (mail27.syd.optusnet.com.au [211.29.133.168]) by mx1.freebsd.org (Postfix) with ESMTP id 60A3A8FC15 for ; Wed, 7 Sep 2011 06:17:45 +0000 (UTC) Received: from server.vk2pj.dyndns.org (c220-239-116-103.belrs4.nsw.optusnet.com.au [220.239.116.103]) by mail27.syd.optusnet.com.au (8.13.1/8.13.1) with ESMTP id p876HgkU020730 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Wed, 7 Sep 2011 16:17:43 +1000 X-Bogosity: Ham, spamicity=0.000000 Received: from server.vk2pj.dyndns.org (localhost.vk2pj.dyndns.org [127.0.0.1]) by server.vk2pj.dyndns.org (8.14.4/8.14.4) with ESMTP id p876HfFu030747 for ; Wed, 7 Sep 2011 16:17:41 +1000 (EST) (envelope-from peter@server.vk2pj.dyndns.org) Received: (from peter@localhost) by server.vk2pj.dyndns.org (8.14.4/8.14.4/Submit) id p876Hf19030746 for freebsd-hackers@freebsd.org; Wed, 7 Sep 2011 16:17:41 +1000 (EST) (envelope-from peter) Date: Wed, 7 Sep 2011 16:17:41 +1000 From: Peter Jeremy To: freebsd-hackers@freebsd.org Message-ID: <20110907061741.GC96277@server.vk2pj.dyndns.org> References: <20110906220115.GA25048@freebsd.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="24zk1gE8NUlDmwG9" Content-Disposition: inline In-Reply-To: X-PGP-Key: http://members.optusnet.com.au/peterjeremy/pubkey.asc User-Agent: Mutt/1.5.21 (2010-09-15) Subject: Re: excessive use of gettimeofday(2) and other syscalls X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 07 Sep 2011 06:17:45 -0000 --24zk1gE8NUlDmwG9 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2011-Sep-06 16:44:48 -0600, Manish Vachharajani wrote: >Under 7.3 (haven't checked 8 or 9) this issue crops up because the >time system call calls gettimeofday under the hood (see >lib/libc/gen/time.c). As a result, the kernel tries to get an >accurate subsecond resolution time that simply gets chopped to the >nearest second. Under 8.x and later, time(3) uses clock_gettime(CLOCK_SECOND,...) rather than gettimeofday(). This is intended to be much cheaper than gettimeofday(). On 2011-Sep-06 21:15:55 -0400, Rayson Ho wrote: >IMO, the time returned by gettimeofday does not need to be high >precision. There are higher resolution time APIs on Linux and I >believe the application programmers know when to use the slower but >more accurate clock API. There are 3 standard APIs for returning time of day: time(3) provides second precision gettimeofday(2) provides microsecond precision clock_gettime(2) provides nanosecond precision By default, FreeBSD attempts to provide resolution as close as possible to the precision - which makes the 2 system calls fairly expensive. In order to reduce the cost where the resolution isn't important, FreeBSD provides several non-standard clock types for clock_gettime(2). This approach differs from Linux - and it seems that there is a non-trivial body of code that assumes that calling gettimeofday() is very cheap. There is probably a good case for an API that provides a resolution of the order of a tick but there is no standard for this. --=20 Peter Jeremy --24zk1gE8NUlDmwG9 Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.18 (FreeBSD) iEYEARECAAYFAk5nDIUACgkQ/opHv/APuIduQQCggDolZcIxgmfW1vJz/75czqM/ r9gAni6p+QQ8d+mRGkOEQaaqowuNxURU =e7EY -----END PGP SIGNATURE----- --24zk1gE8NUlDmwG9--