public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* clock_getres problem
@ 2005-06-14 18:42 aaron.gage
  0 siblings, 0 replies; only message in thread
From: aaron.gage @ 2005-06-14 18:42 UTC (permalink / raw)
  To: glibc-bugs

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



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2005-06-14 18:42 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-06-14 18:42 clock_getres problem aaron.gage

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).