LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-06-2009, 03:48 AM   #1
overberg
LQ Newbie
 
Registered: Mar 2009
Posts: 23

Rep: Reputation: 0
gethrtime () returns 14 digit integer


I am reading gethrtime () the moment an interrupt occurred. I expected a nanosec int value but got a 14 digit value.

Am I perhaps doing something wrong?

Thanks.

My code is as follows:
Code:
void get_timestamp {
 hrtime_t my_timestamp;
 
 my_timestamp = gethrtime();
 rtl_printf("Interrupt Timestamp = %lld\n", long long my_timestamp);
}
 
Old 08-06-2009, 08:01 AM   #2
fantas
Member
 
Registered: Jun 2007
Location: Bavaria
Distribution: slackware, xubuntu
Posts: 143

Rep: Reputation: 22
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
 
Old 08-12-2009, 02:42 AM   #3
overberg
LQ Newbie
 
Registered: Mar 2009
Posts: 23

Original Poster
Rep: Reputation: 0
Thanks for the reply.

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.



Start Time - Stop Time = Difference
29239402799104, 29239656855264, 254056160
29240402964256, 29240657030176, 254065920
29241403127104, 29241657177504, 254050400
29242403292192, 29242657352192, 254060000
29243403457216, 29243657498400, 254041184
29244403620160, 29244657672544, 254052384
 
Old 08-12-2009, 06:54 AM   #4
dmail
Member
 
Registered: Oct 2005
Posts: 970

Rep: Reputation: Disabled
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
 
Old 08-13-2009, 10:55 AM   #5
fantas
Member
 
Registered: Jun 2007
Location: Bavaria
Distribution: slackware, xubuntu
Posts: 143

Rep: Reputation: 22
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Substitue single-digit, two-digit, and 3-digit numbers with text using sed dmason165 Programming 13 08-07-2009 10:38 AM
Two-digit integer value doesn't increment ahmedb72 Linux - Newbie 5 07-12-2009 05:37 AM
gethrtime() in AIX jayakant82 AIX 0 01-06-2009 07:52 AM
gethrtime() in AIX Sunilsbjoshi Programming 1 03-09-2007 06:37 AM
gethrtime() in AIX Sunilsbjoshi AIX 0 03-09-2007 06:10 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:22 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration