2

The Linux man page for clock_gettime(2) does a good job of explaining the difference in meaning between CLOCK_REALTIME and CLOCK_MONOTONIC. At any given time these two clocks will be offset by some varying offset. I want to keep track of this offset. A simple approximation would be

struct timespec rtime, mtime;
clock_gettime(CLOCK_REALTIME, &rtime);   
clock_gettime(CLOCK_MONOTONIC, &mtime);
// subtract the timespecs here.

But there is an unpredictable delay between the two calls. Can the kernel give me a reliable estimate of the offset in a single "atomic" operation?

BTW: I think the OP in Starting point for CLOCK_MONOTONIC wanted the same information. But the responders there seemed to be answering a different question, so I thought I would ask it in my own words.

Community
  • 1
  • 1
Adrian Ratnapala
  • 5,485
  • 2
  • 29
  • 39

1 Answers1

1

adjtimex will return information regarding the state of how the system clock varies with respect to prior adjtime calls. This might not be exactly what you asked for but it might give you enough or equivalent information for whatever your needs are.

rocky
  • 7,226
  • 3
  • 33
  • 74
  • I think you are right in the sense that the answer `adjtimex` or nothing. I suspect the answer probably really is nothing. – Adrian Ratnapala Jul 03 '15 at 12:00
  • Well, Linux is all open-source code. So in theory one could create a kernel module or modify the kernel to get whatever information you are looking for. But I doubt this is the way you or most people want to go in, and I'm not sure it would be worth the effort over adjtimex. – rocky Jul 03 '15 at 13:30
  • I was thinking about that. It might not even be a kernel module proper, just a change to the vdso(http://man7.org/linux/man-pages/man7/vdso.7.html). That would by way over the top for my needs, but perhaps a fun geek project. – Adrian Ratnapala Jul 04 '15 at 15:03