Click_gettimeofday H E L P ! ! !

Eddie Kohler kohler at icir.org
Mon Nov 11 09:22:55 EST 2002


Hi Simona, you need to be more specific.

> It returns the following stranges results in microsecond, for example:
> 35
> 45
> 43
> 9340
> 34834
> 70933

Do you mean that a sequence of calls to gettimeofday() return those results
in the tv_usec field? And you are confused because it returns 45 before 43,
but 45 > 43?

Well, those results are not necessarily strange. You understand that
gettimeofday() returns results in a structure that has both tv_sec and
tv_usec components, right? Maybe the tv_sec value incremented between 45
and 43.

Also, you might have NTP running (the network time protocol). NTP
synchronizes your system's time with some external time source. Depending
on how it is configured, it may set the system clock backwards.

Anyway, gettimeofday() is not completely reliable, and when using it, it is
best to program defensively. (At user level, click_gettimeofday() is
*exactly* equivalent to gettimeofday().) NTP exists, people put their
laptop computers to sleep (so the program sees a sudden jump forward in
time), people reset their clocks. Your program should deal with those
situations, because they happen far more often than you might suppose.

Eddie




More information about the click mailing list