Re: gettimeofday() resolution in Linux?
From: Lennart Sorensen
Date: Thu Apr 10 2008 - 11:04:34 EST
On Thu, Apr 10, 2008 at 03:40:59PM +0100, Jack Harvard 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.
The timer resolution, not the time resolution.
> 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()"
On many systems gettimeofday uses the TSC, but on many multicore systems
the TSC on each core may be out of sync, in which case the cpu you are
running on may give a different gettimeofday result than another cpu,
which is probably a bad thing for some processes.
> 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.
I don't think that would work well.
--
Len Sorensen
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/