lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <e2e108260804100907i58fa5d36ma0cb415c10054a2d@mail.gmail.com>
Date:	Thu, 10 Apr 2008 18:07:14 +0200
From:	"Bart Van Assche" <bart.vanassche@...il.com>
To:	"Jack Harvard" <jack.harvard@...glemail.com>
Cc:	linux-kernel@...r.kernel.org
Subject: Re: gettimeofday() resolution in Linux?

On Thu, Apr 10, 2008 at 4:40 PM, Jack Harvard
<jack.harvard@...glemail.com> wrote:
>  I would like to ask a few questions about how Linux keeps time.
>
>  As far as I understand,
>  1. Linux's time resolution is 10ms, as defined by HZ=100.
>  2. gettimeofday() can get time in microseconds, but I'm not sure about
>  the accuracy of the time finer than 10ms. Sometimes gettimeofday( )
>  can even give me microseconds results rolled backwards in time, which
>  I suspect could be caused by its accuracy. My question here is "how
>  accurate is the time from gettimeofday()"
>  3. If I want to increase the time resolution to 1ms, I can possibly
>  change HZ=1000, but if I want 1usec resolution, how can I do that? It
>  would be too busy for the processor to handle so frequent timer
>  interrupts if I just increase HZ=1000000.

You should use clock_gettime(CLOCK_MONOTONIC) instead of
gettimeofday() for interval timing. As soon as NTP software is
running, the result of gettimeofday() can jump forward or backward in
time. The result of clock_gettime() is guaranteed to be monotonic, and
additionally the resolution of clock_gettime() is higher than
gettimeofday() -- 1 ns instead of 1 us.

Changing HZ only makes sense on very old hardware that does not have a
TSC or equivalent register (e.g. the Intel 486 CPU).

Bart.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ