Subject: Problem with clock_gettime()
To: netbsd user <netbsd-users@netbsd.org>
From: Ian McIntosh <ianm@cat.co.za>
List: netbsd-users
Date: 11/24/2003 10:18:22
This is a multi-part message in MIME format.

------=_NextPart_000_0164_01C3B274.4A2B2D80
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi

I have encountered an interesting problem in NetBSD 1.5.1 with =
clock_gettime.=20
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=20
variable and then when I call it again the time returned is before the =
time in the=20
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=20
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=3Dnow;
while (1)
{
    clock_gettime(CLOCK_REALTIME, &now);
    if (now<old)
        assert;   // asserts and stops program.......time has gone =
backwards
    old=3Dnow;
}

I have operators to correctly compare timespec values and make them =3D =
and so on.
Anyone have any ideas that can explain this? If so I would very much =
like to know.

Thanks=20
Ian

------=_NextPart_000_0164_01C3B274.4A2B2D80
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.3502.5390" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hi</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I have encountered an interesting =
problem in NetBSD=20
1.5.1 with clock_gettime. </FONT></DIV>
<DIV><FONT face=3DArial size=3D2>I am currently running tests with a =
custom designed=20
PCI frame grabber. My current</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>test is to stress the PCI bus a little =
to try and=20
determine the maximum DMA transfer</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>rate I could possibly get. When doing =
this I have=20
noticed some strange behaviour</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>with clock_gettime(). I can call =
clock_gettime()=20
and store the result in a temporary </FONT></DIV>
<DIV><FONT face=3DArial size=3D2>variable and then when I call it again =
the time=20
returned is before the time in the </FONT></DIV>
<DIV><FONT face=3DArial size=3D2>temporary variable (indicating that =
time has gone=20
backwards????). The time difference</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>is only ever a few milli-seconds. I =
have even=20
tested this when the bus is not that stressed</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>but is still fairly busy. The problem =
only appears=20
when the bus is busy for extended periods </FONT></DIV>
<DIV><FONT face=3DArial size=3D2>of time. </FONT><FONT face=3DArial =
size=3D2>When the=20
bus is not busy then everything seems fine.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Here is the core of the test program I=20
run.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>timespec now,old;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>clock_gettime(CLOCK_REALTIME,=20
&amp;now)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>old=3Dnow;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>while (1)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>{</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; =
clock_gettime(CLOCK_REALTIME,=20
&amp;now);</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; if =
(now&lt;old)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
assert;&nbsp;&nbsp; // asserts and stops program.......time has gone=20
backwards</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; =
old=3Dnow;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>}</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I have operators to correctly compare =
timespec=20
values and make them =3D and so on.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Anyone have any ideas that can explain =
this? If so=20
I would very much like to know.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Thanks </FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Ian</FONT></DIV></BODY></HTML>

------=_NextPart_000_0164_01C3B274.4A2B2D80--