Subject: Problem with clock_gettime()
To: None <tech-kern@netbsd.org>
From: Ian McIntosh <ianm@cat.co.za>
List: tech-kern
Date: 11/24/2003 10:45:59
Hi
 
I have encountered an interesting problem in NetBSD 1.5.1 
with clock_gettime. I am currently running tests with a 
custom designed PCI frame grabber. My current test is to 
stress the PCI bus a little to try and determine the 
maximum DMA transfer rate I could possibly get. 
When doing this I have noticed some strange behaviour
with clock_gettime(). I can call clock_gettime() and 
store the result in a temporary variable and then 
when I call it again the time returned is before 
the time in the temporary variable (indicating that 
time has gone backwards????). The time difference
is only ever a few milli-seconds. I have even tested 
this when the bus is not that stressed but is still 
fairly busy. The problem only appears when the bus is 
busy for extended periods of time. When the bus is 
not busy then everything seems fine.
 
Here is the core of the test program I run.
 
timespec now,old;
clock_gettime(CLOCK_REALTIME, &now)
old=now;
while (1)
{
    clock_gettime(CLOCK_REALTIME, &now);
    if (now<old)
        assert;   // asserts and stops program.....
    // ..time has gone backwards
    old=now;
}
 
I have operators to correctly compare timespec values
and make them = and so on. Anyone have any ideas that 
can explain this? If so I would very much like to know.
 
Thanks 
Ian