ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If it makes any difference, this is virtual server on Xen.
The problem:
~~~~~~~~~~~~
I want to use sys_clock_gettime(CLOCK_REALTIME_HR) but the compiler complains that CLOCK_REALTIME_HR is not defined.
Anybody has some experience with that? Knows what I'm doing wrong?
More details:
~~~~~~~~~~~~~
This is from 'man 2 clock_gettime':
clock_gettime returns the current timespec value of tp for the specific clock, which_clock. The values that clockid_t currently supports for POSIX.1b timers, as defined in include/linux/time.h, are:
CLOCK_REALTIME_HR
High resolution version of CLOCK_REALTIME.
But I can't find this CLOCK_REALTIME_HR in /usr/include/linux/time.h.
I tried including <linux/time.h>, it doesn't make it any better.
Thanks, but we rather have a higher resolution timer. The CLOCK_REALTIME_HR seems like the right solution, we are just having trouble compiling it. Any help would be appreciated. A better solution, if someone has such a solution to suggest, is also welcomed.
Unfortunately the resolution of this clock is too low for us. On other Unix machines we use gethrtime(), but this function is not available in Linux. Is there some other replacement or do we have to resort to Assembly?
Unfortunately the resolution of this clock is too low for us. On other Unix machines we use gethrtime(), but this function is not available in Linux. Is there some other replacement or do we have to resort to Assembly?
CLOCK_REALTIME is the same as CLOCK_REALTIME_HR, so I'm not sure why you're saying that it is insufficient. If CLOCK_REALTIME is insufficient, CLOCK_REALTIME_HR would also be insufficient.
CLOCK_REALTIME is the same as CLOCK_REALTIME_HR, so I'm not sure why you're saying that it is insufficient. If CLOCK_REALTIME is insufficient, CLOCK_REALTIME_HR would also be insufficient.
Hmm.. That's disappointing. I did not think Linux will have any disadvantage on other Unix machines we use (HP-UX, AIX).
Maybe we can set it as a requirement of our product to install these high resolution timers patches. I'll have to consult my bosses on that :-). One thing is for sure, we can not do with the 1 millisecond resolution the system calls offer now.
Hmm.. That's disappointing. I did not think Linux will have any disadvantage on other Unix machines we use (HP-UX, AIX).
Maybe we can set it as a requirement of our product to install these high resolution timers patches. I'll have to consult my bosses on that :-). One thing is for sure, we can not do with the 1 millisecond resolution the system calls offer now.
Thanks for the info,
Sela.
Did you read the manpage for the clock_* functions? It would answer most of your questions. clock_getres gives you the clock resolution on your system, if your kernel is tickless it will return one nanosecond.
This code prints "Clock res = 0s:1ns" on my system:
Ah, sorry. Now that I've re-read you post I see that you are using an ancient kernel. The merging of bits from Ingo Molnar's realtime patch into the vanilla kernel started around 2.6.18 AFAIK, so I think it can be tickless. Also check out kernel preemption.
Last edited by haikan; 08-09-2009 at 05:17 PM.
Reason: Added some info...
Already did that, the resolution is a bit below one millisecond. That's not a high enough resolution for us.
Thank you.
I suspect that you do not even know what a millisecond is. FYI, it is 1/1000 of a second. A microsecond is 1/1000000 of a second. A nanosecond is 1/1000000000 of a second.
If your POS system can't even do millisecond resolution, then you and your client need serious help.
I suspect that you do not even know what a millisecond is. FYI, it is 1/1000 of a second. A microsecond is 1/1000000 of a second. A nanosecond is 1/1000000000 of a second.
If your POS system can't even do millisecond resolution, then you and your client need serious help.
I think you're being unfair. His kernel version is 2.6.18, and back then system calls that set timeouts was limited by the resolution of the software clock, which measures time in jiffies. In 2.6.18 jiffies could be 0.01, 0.004, or 0.001 seconds, depending on the kernel configuration. High resolution timers wasn't introduced until 2.6.21.
My advice to the OP would be to upgrade the kernel to at least version 2.6.21, or if you can't then apply the realtime patches for your kernel version.
1. If you think you *need* microsecond (or nanosecond) granularity, you possibly have a design problem (for example, relying on polling instead of blocking). I would suggest revisiting the original requirements, and considering other design alternatives.
2. If you think you're actually going to *get* nanosecond resolution, you're probably mistaken (even with decent hardware, up-to-date kernels, and realtime extensions)(and *certainly* with most other, non-Linux multitasking, preemptable operating systems; including most/all flavors of Unix and Windows).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.