This is the mail archive of the
glibc-bugs@sources.redhat.com
mailing list for the glibc project.
clock_getres problem
- From: "aaron.gage" <aaron dot gage at oceanoptics dot com>
- To: <glibc-bugs at sources dot redhat dot com>
- Date: Tue, 14 Jun 2005 14:42:37 -0400
- Subject: clock_getres problem
Greetings. I am trying to figure out a discrepancy between what is returned
by clock_getres() and repeated calls to clock_gettime(). These come from
librt, but it is bundled with glibc, so I thought this would be the right
place to ask.
On a Fedora Core 3 machine (Pentium 4) with glibc package
glibc-2.3.5-0.fc3.1, I have run this code:
struct timespec ts;
clock_getres(CLOCK_REALTIME, &ts);
printf("Clock resolution: %d.%09d\n", ts.tv_sec, ts.tv_nsec);
The result is "Clock resolution: 0.000999848" or approximately 1
millisecond.
However, if I do the following:
long lastns = 0;
int i = 0;
while(i < 50) {
clock_gettime(CLOCK_REALTIME, &ts);
ns = ts.tv_nsec;
if(ns != lastns) {
printf("%d ", ns - lastns);
lastns = ns;
i++;
}
}
then I get back values ranging from 3000-5000 nanoseconds (3-5
microseconds).
That is, clock_getres() is reporting 1ms resolution, but the clock is really
able to provide 3-5us resolution. Why doesn't clock_getres() report this?
Is there any way to get these to agree?
Thanks.
--Aaron
===
Dr. Aaron Gage (aaron.gage@oceanoptics.com)
Software Development for Ocean Optics, Inc.
http://www.OceanOptics.com