From owner-freebsd-current@FreeBSD.ORG Sat Oct 29 14:38:29 2005 Return-Path: X-Original-To: current@freebsd.org Delivered-To: freebsd-current@FreeBSD.ORG Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 8D35716A41F; Sat, 29 Oct 2005 14:38:29 +0000 (GMT) (envelope-from deischen@freebsd.org) Received: from mail.ntplx.net (mail.ntplx.net [204.213.176.10]) by mx1.FreeBSD.org (Postfix) with ESMTP id 27E2C43D45; Sat, 29 Oct 2005 14:38:29 +0000 (GMT) (envelope-from deischen@freebsd.org) Received: from sea.ntplx.net (sea.ntplx.net [204.213.176.11]) by mail.ntplx.net (8.13.5/8.13.5/NETPLEX) with ESMTP id j9TEcKwH017576; Sat, 29 Oct 2005 10:38:20 -0400 (EDT) Date: Sat, 29 Oct 2005 10:38:20 -0400 (EDT) From: Daniel Eischen X-X-Sender: eischen@sea.ntplx.net To: David Xu In-Reply-To: <43632D9A.30201@freebsd.org> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by AMaViS and Clam AntiVirus (mail.ntplx.net) Cc: current@freebsd.org, pertti.kosunen@pp.nic.fi, phk@phk.freebsd.dk, rwatson@freebsd.org, "M. Warner Losh" , jura@networks.ru Subject: Re: Timers and timing, was: MySQL Performance 6.0rc1 X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Daniel Eischen List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 29 Oct 2005 14:38:29 -0000 On Sat, 29 Oct 2005, David Xu wrote: > M. Warner Losh wrote: > > >Does this mean I can have a 1s wait, jump time back an hour and that > >the timeout will happen in a little under 1s? > > > >Warner > > > It is almost but not always, there is still a very small race window. POSIX also says that you are not guaranteed that your event occurred when you wake up (false wakeup) and that you should check for the event after waking up. Speaking of interfaces for time, Solaris has gethrtime() and gethrvtime(): http://docs.sun.com/app/docs/doc/817-0692/6mgfnkuga?q=gethrtime&a=view The gethrtime() function returns the current high-resolution real time. Time is expressed as nanoseconds since some arbitrary time in the past; it is not correlated in any way to the time of day, and thus is not subject to resetting or drifting by way of adjtime(2) or settimeofday(3C). The hi-res timer is ideally suited to performance measurement tasks, where cheap, accurate interval timing is required. The gethrvtime() function returns the current high-resolution LWP virtual time, expressed as total nanoseconds of execution time. This function requires that micro state accounting be enabled with the ptime utility (see proc(1)). The gethrtime() and gethrvtime() functions both return an hrtime_t, which is a 64-bit (long long) signed integer. We've been using gethrtime() for timestamps in our Solaris applications for several years. As an API, the autoconf scripts might already detect it. -- DE