Anyways, I'm going to try to dig around some more and try to find the
HPET timer API. Theoretically, that should be more accurate then what
I'm seeing with gtod(). I saw Steve's MPDelayUntil() comment, but it
makes no indication what the method is,
Huh? I posted links to the documentation and sample code, which I
assumed you could read.
You calculate a time in the future in AbsoluteTime units and call
MPDelayUntil(), which delays until that time is past.
and it seems unlikely that it
would be any better then this. I'm guessing it's just a wrapper
around nanosleep().
You would be wrong. It's a high-performance, high-accuracy call from
the original Mac OS Driver Services library that was moved up to
Multiprocessor Sevices library. It does not rely on converting unix
time units to processor time units.
for (i = 0; i < 5; i ++) {
sleep_until = AddAbsoluteToAbsolute(UpTime(), fiveSeconds);
// what you wrote
// sleep_until = AddAbsoluteToAbsolute(sleep_until,
fiveSeconds); // this won't drift
// MPDelayUntil(&sleep_until); // would just until 5 sec from start
last = UpTime();
do {
count++;
now = UpTime();
if (now == last)
fail ++;
else if (SubAbsoluteFromAbsolute(now, endTime) == 0)
back ++;
last = now;
} while (timercmp(&now, &sleep_until, <));
printf("Ran gtod() %lu times in 5 seconds.\n", count);
printf("%f gtod()/usec\n", (float)count / 5000 / 1000);
printf("Failed to increment %lu times\n", fail);
printf("Back in time %lu times\n", back);
printf("-------------\n");
count = 0;
fail = 0;
back = 0;
}
exit(0);
}
Note that AbsoluteTime may be declared as a struct, but you can cast to UInt64.
What are you really trying to do?
-Steve
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/darwin-dev/email@hidden