From: <bdo...@la...> - 2006-08-13 05:48:53
|
On Sat, Aug 12, 2006 at 03:48:16PM +0200, karol skocik wrote: > Hi guys, > I am confused from behaviour of this piece of code: > > (let ((real-time (get-internal-real-time))) > (sleep 0.01) > (loop :for new-real-time = (get-internal-real-time) > :repeat 1000000000 > :do (if (> real-time new-real-time) > (error "!!!!!!!!!! real-time = ~a, new-real-time = ~a~%" real-time > new-real-time) > (setf real-time new-real-time)))) > > If I understand correctly, new-real-time should be always greater or > equal than time measured in executing previous iteration of loop. > However, this is not true. I often get error which looks like this : > > !!!!!!!!!! real-time = 1276670, new-real-time = 1276669 I haven't been able to reproduce this in about twenty minutes of runtime on my system. Looking at the implementation of GET-INTERNAL-REAL-TIME, though, its output is a pretty trivial computation from the results of gettimeofday(2). At first guess I'd say something is stepping the clock on your system backward to keep in time sync with something else. What I don't understand, however, is that both ntpdate and ntpd itself (on Linux, which I see you are running) will slowly slew the clock (effectively "changing the speed" of time) if the offset isn't above a certain threshold, to keep time always going in the right direction. (See the adjtime(2) and adjtimex(2) man pages.) I don't know of anything that would be stepping the clock backwards by about one millisecond intervals. You can try running this C program and see if you see similar behavior: #include <stdlib.h> #include <stdio.h> #include <sys/time.h> #include <time.h> int main() { struct timeval last, cur; gettimeofday(&last, NULL); for (;;) { gettimeofday(&cur, NULL); if ((cur.tv_sec < last.tv_sec) || ((cur.tv_sec == last.tv_sec) && (cur.tv_usec < last.tv_usec))) { printf("Time went backwards! last = %d.%06d cur = %d.%06d\n", last.tv_sec, last.tv_usec, cur.tv_sec, cur.tv_usec); } last = cur; } return 0; } -bcd -- *** Brian Downing <bdowning at lavos dot net> |