Subject: Re: HEADS UP: timecounters (branch simonb-timecounters) merged into
To: Mike Pumford <mpumford@black-star.demon.co.uk>
From: Frank Kardel <kardel@netbsd.org>
List: tech-kern
Date: 09/10/2006 08:22:05
This is a multi-part message in MIME format.
--------------010605080700050203060504
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
Mike Pumford wrote:
> Garrett D'Amore wrote:
>
>>
>> date; /bin/time sleep 10; date
>>
>> compare results against against a stop watch.
>>
> Looks like my acorn32 implementation passes this test.
>
> Phew. :-)
>
> Mike
>
Congrats, pls run t.c as an additional test to test that time does not ever
go backwards. You should *not* see any *negative* diff values from t.c
positive ones are usually ok due to scheduling.
Frank
--------------010605080700050203060504
Content-Type: text/plain;
name="t.c"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="t.c"
#include <stdio.h>
#include <time.h>
main()
{
int a;
struct timespec tsa;
struct timespec tsb;
struct timespec tsl;
if (clock_gettime(CLOCK_REALTIME, &tsa) == -1)
perror("clock_gettime(CLOCK_REALTIME, &tsa)");
tsl = tsa;
while (1) {
long long diff;
if (clock_gettime(CLOCK_REALTIME, &tsb) == -1)
perror("clock_gettime(CLOCK_REALTIME, &tsb)");
diff = 1000000000LL * (tsb.tv_sec - tsa.tv_sec) + tsb.tv_nsec - tsa.tv_nsec;
if (diff < 0 || diff > 8000000) {
printf("bad time TSA: 0x%x.%08x, TSB: 0x%x.%08x, diff = %lld nsec, ", tsa.tv_sec, tsa.tv_nsec, tsb.tv_sec, tsb.tv_nsec, diff);
diff = 1000000000LL * (tsb.tv_sec - tsl.tv_sec) + tsb.tv_nsec - tsl.tv_nsec;
printf("%lld nsec\n", diff);
tsl = tsb;
}
tsa.tv_sec = tsb.tv_sec;
tsa.tv_nsec = tsb.tv_nsec;
}
return 0;
}
--------------010605080700050203060504--