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 you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
The result sounds about right to me. The documentation of gethrtime tells that it is the time that is counted since some arbitrary point in the past (I would take a guess probably means the system start), and so a 14-digit nano-second value would fit right in here.
Let's take a look at nanoseconds, they are the 1 / 1000*1000*1000 part of a second, so basically by removing the right-most 9 digits from a decimal number you can get the full seconds. 14 minus 9 digits, there are 5 digits left, leaving a range of 10000 to 99999 seconds. Divided by 3600 you have the hours, leaving a range of 2.8 to 27.8 hours. If you started your system sometimes between these value in the past, this would support my theory about being relative to the system start.
If you want to verify correct timing you could take a time snapshot, e.g.
Code:
starttime = gethrtime();
// do something
stoptime = gethrtime() - starttime; // stoptime = nanoseconds elapsed since starttime
Below is data recorded using your suggestion.
It is not impossible, but unlikely that the delay (difference) can be around 250 milliseconds. We have recorded delays of 2.5 milliseconds in the past using an oscillioscope.
Whilst the values returned by the function are nanoseconds the resolution of the timer is dependant on the hardware that you are using. Which would suggest to me that your resolution is 254 milliseconds.
Quote:
Although the units of hi-res time are always the same
(nanoseconds), the actual resolution is hardware dependent.
Hi-res time is guaranteed to be monotonic (it won't go back-
ward, it won't periodically wrap) and linear (it won't occa-
sionally speed up or slow down for adjustment, like the time
of day can), but not necessarily unique: two sufficiently
proximate calls may return the same value.
Last edited by dmail; 08-12-2009 at 06:56 AM.
Reason: added quote from man
This would be my conclusion as well. Could it be that you can set the timer resolution at any arbitrary time ? I *think* I recall having done this some time back on an rt-patched kernel, but can't recall it offhand now.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.