Mail Archives: djgpp-workers/1997/02/18/04:56:50
*My* problem with uclock() is illustrated by the following C++ program
------------------------------------
#include <stdlib.h>
#include <time.h>
#include <iostream.h>
int main(int argc, char** argv)
{
if (argc != 2)
{
cerr << "usage: test <number of iterations>\n";
exit(1);
}
int n = atoi(argv[1]);
uclock_t t0 = uclock();
uclock_t t = 0;
for (int i = 0; i < n; i++)
{
t = uclock();
if (t < t0)
{
cerr << i << " t/t0: "
<< t << "/" << t0 << "\n";
}
t0 = t;
}
exit(0);
} // main(int, char**)
------------------------------------
Some examples of its output:
------------------------------------
E:\home\t2>uctest 1200
200 t/t0: -59013/6432
E:\home\t2>uctest 1200
287 t/t0: -55922/9218
E:\home\t2>uctest 1200
183 t/t0: -59539/5887
E:\home\t2>uctest 1200
E:\home\t2>uctest 1200
E:\home\t2>uctest 1200
E:\home\t2>uctest 1200
12 t/t0: -64616/411
------------------------------------
That was all in a Win95 DOS box. On further investigation
I found that there was no such problem in Win95's DOS mode
nor in my previous version of DOS. Hmmm.
So far as investigating why this is so, I tried the
following little program (heavily based on uclock.c)
------------------------------------
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/* DJ's copyright acknowledged :-), ITM 1997 */
#include <time.h>
#include <pc.h>
#include <libc/farptrgs.h>
#include <go32.h>
int
main(int argc, char** argv)
{
#define N 7
unsigned char lsb, msb;
unsigned long tics, otics;
uclock_t rv[N];
int i;
for (i = 0; i < N; i++)
{
/* Make sure the numbers we get are consistent */
do {
otics = _farpeekl(_dos_ds, 0x46c);
outportb(0x43, 0x00);
lsb = inportb(0x40);
msb = inportb(0x40);
tics = _farpeekl(_dos_ds, 0x46c);
} while (otics != tics);
/* calculate absolute time */
msb ^= 0xff;
lsb ^= 0xff;
/* rv[i] = ((uclock_t)tics << 16) | (msb << 8) | lsb; */
rv[i] = (msb << 8) | lsb;
}
printf("%u\n", rv[0]);
for (i = 1; i < N; i++)
{
printf("%+d\n", rv[i] - rv[i - 1]);
}
uclock();
for (i = 0; i < N; i++)
{
/* Make sure the numbers we get are consistent */
do {
otics = _farpeekl(_dos_ds, 0x46c);
outportb(0x43, 0x00);
lsb = inportb(0x40);
msb = inportb(0x40);
tics = _farpeekl(_dos_ds, 0x46c);
} while (otics != tics);
/* calculate absolute time */
msb ^= 0xff;
lsb ^= 0xff;
/* rv[i] = ((uclock_t)tics << 16) | (msb << 8) | lsb; */
rv[i] = (msb << 8) | lsb;
}
printf("%u\n", rv[0]);
for (i = 1; i < N; i++)
{
printf("%+d\n", rv[i] - rv[i - 1]);
}
return 0;
#undef N
}
------------------------------------
Win95 DOS box:
E:\home\t2>uc2
46271
+124
+60
+60
+60
+60
+60
58976
+43
+30
+29
+30
+29
+30
(very occasionally I get a large negative number instead of +30 or +29
but that's probably just wrapping)
Reboot.
DOS prompt only:
40813
+38
+16
+18
+16
+16
+16
35
+19
+8
+9
+8
+8
+8
Reboot.
Previous version of DOS (6.x):
24023
+40
+16
+18
+16
+16
+18
36
+20
+8
+8
+8
+8
+8
It looks to me like the timer mode is changed in all three cases.
Does this get me anywhere?
Regards,
--
Ian Miller, Dorset, UK
DJGPP 2.01, Win95 DOS box (LFN undefined, FNCASE=y)
- Raw text -