Timers and timing, was: MySQL Performance 6.0rc1

Daniel Eischen deischen at freebsd.org
Sat Oct 29 07:38:29 PDT 2005


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



More information about the freebsd-current mailing list