Monotonicity of gettimeofday()
Monotonicity of gettimeofday()
Posted Feb 20, 2003 18:21 UTC (Thu) by jzbiciak (guest, #5246)In reply to: Kernel release status by zooko
Parent article: Kernel release status
I was under the impression that (a) gettimeofday always returned UTC and thus was immune to daylight savings time, and that (b) it tended to be monotonic and protocols like NTP try to keep it that way unless there is a gigantic drift.
If you have ntpd always running, then you may see slight changes in the rate of time passage, but you shouldn't see major discontinuities or time going backwards (until 2038 at least...). The man page for adjtime (under Solaris at least) echos this view:
The adjustment is effected by speeding up (if that amount of
time is positive) or slowing down (if that amount of time is
negative) the system's clock by some small percentage, gen-
erally a fraction of one percent. The time is always a mono-
tonically increasing function. A time correction from an
earlier call to adjtime() may not be finished when adjtime()
is called again.
I looked in kernel/time.c for Linux 2.4.20, and it mentions that Linux's time-keeping paradigm is based on NTP-style updates described in David L. Mill's paper on said topic. I looked in that paper, and it indicated that monotonicity is a goal of that algorithm.
I think it's safe to say, under normal circumstances, gettimeofday() is atomic. Only large time-setting events (eg. during bootup, or on restart of a dead NTP daemon) should you see any large shift in time, forwards or backwards.
