Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 7 Sep 2011 12:41:54 -0600
From:      Manish Vachharajani <manishv@lineratesystems.com>
To:        Peter Jeremy <peterjeremy@acm.org>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: excessive use of gettimeofday(2) and other syscalls
Message-ID:  <CAHRgBhSxiN=KBvN=Ve5cmXY_PtCuivQY1jC87O-D7QRE9qiOqA@mail.gmail.com>
In-Reply-To: <20110907061741.GC96277@server.vk2pj.dyndns.org>
References:  <20110906220115.GA25048@freebsd.org> <CAHRgBhRe8n%2BV3nSzRn4_fctHB1nie2ACk7oRVOPJqqKaMUgKrg@mail.gmail.com> <CAF6rxg=kzHP4zr_=LGnJDUQu-xEwgpy6QN=Lk4jqXa6hs=epKg@mail.gmail.com> <CAHRgBhT%2BKi%2BYPiK%2Bhn=fJ91eA=31tOaTPe_5xLSHQawa=%2BFD0Q@mail.gmail.com> <CAHwLALMwOu8wc5W03dar5fhkWkjN6f7eDGAT4a1u%2BK4eHHSsng@mail.gmail.com> <20110907061741.GC96277@server.vk2pj.dyndns.org>

next in thread | previous in thread | raw e-mail | index | archive | help
This is great info, thanks.  Is it worth having some kind of
environment variable tunable (or even compile time tunable) to have a
"fast" gettimeofday then?  Is there a complimentary body of code that
assumes gettimeofday is precise?

Manish

On Wed, Sep 7, 2011 at 12:17 AM, Peter Jeremy <peterjeremy@acm.org> wrote:
> On 2011-Sep-06 16:44:48 -0600, Manish Vachharajani <manishv@lineratesyste=
ms.com> 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). =A0As 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(). =A0This is intended to be much cheaper
> than gettimeofday().
>
> On 2011-Sep-06 21:15:55 -0400, Rayson Ho <raysonlogin@gmail.com> 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. =A0In order to reduce the cost where the resolution isn't
> important, FreeBSD provides several non-standard clock types for
> clock_gettime(2). =A0This 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.
>
> --
> Peter Jeremy
>



--=20
Manish Vachharajani
Founder
LineRate Systems
manishv@lineratesystems.com
(609)635-9531 M



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAHRgBhSxiN=KBvN=Ve5cmXY_PtCuivQY1jC87O-D7QRE9qiOqA>