LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 03-17-2011, 06:30 AM   #1
rk_linux
LQ Newbie
 
Registered: Mar 2011
Posts: 3

Rep: Reputation: 0
clock gettime variation


Hi,

I need high precision timer which returns the accurate value
till 99.99 percentile. I am running clock_gettime(MONOTONIC_RAW,..)
in a tight loop and measuring the timing difference between consecutive calls.

For 99.8 percentile I see timediff of 100 nano sec but then there are few values(5 out of 10000 calls) which are in millisec. At this moment I am clueless what may be the reason behind it.

I am using linux debian kernel 2.6.28, with core scheduling on core 0. The timing measurement are done with program tied to the other core. I have also disabled ntp.

Any possible explanation what may be the reason for such measurement
outliers?


Thanks !
 
Old 03-17-2011, 12:26 PM   #2
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by rk_linux View Post
Hi,

I need high precision timer which returns the accurate value
till 99.99 percentile. I am running clock_gettime(MONOTONIC_RAW,..)
in a tight loop and measuring the timing difference between consecutive calls.

For 99.8 percentile I see timediff of 100 nano sec but then there are few values(5 out of 10000 calls) which are in millisec. At this moment I am clueless what may be the reason behind it.

I am using linux debian kernel 2.6.28, with core scheduling on core 0. The timing measurement are done with program tied to the other core. I have also disabled ntp.

Any possible explanation what may be the reason for such measurement
outliers?


Thanks !
What assumption do you have WRT time measurements and program execution time ? I.e. do you expect execution time of the same program/piece of code to be the same from call o call ? What do you know about how computer HW works ? Do you understand hoW OS works WRT task switching ?
 
Old 03-17-2011, 12:54 PM   #3
rk_linux
LQ Newbie
 
Registered: Mar 2011
Posts: 3

Original Poster
Rep: Reputation: 0
In this context, what I am measuring is the overhead of syscall clock_gettime(). I am pining
the measurement program to a given core. I have restricted kernel scheduling to just one core (not same as measurement
program core). By this I am making sure that my task is not rescheduled.

I think I should pose my questions differently, what is the possible explanation of this variation and what could be
done to minimize it?

The variation from nanosec to millisec will have huge impact if you are taking real time measurements.
 
Old 03-17-2011, 03:14 PM   #4
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by rk_linux View Post
In this context, what I am measuring is the overhead of syscall clock_gettime(). I am pining
the measurement program to a given core. I have restricted kernel scheduling to just one core (not same as measurement
program core). By this I am making sure that my task is not rescheduled.

I think I should pose my questions differently, what is the possible explanation of this variation and what could be
done to minimize it?

The variation from nanosec to millisec will have huge impact if you are taking real time measurements.
Regarding
Quote:
I am using linux debian kernel 2.6.28, with core scheduling on core 0. The timing measurement are done with program tied to the other core.
- does this mean that the program doing measurements is never suspended/resumed by kernel ?

My understanding of the quote is that kernel is pinned to one core, and your program to the other, but IMO this doesn't mean your program can not be suspended/resumed. Suppose your program needs IO, an the IO device is busy - your program will be suspended by kernel until IO is available. Also, I think that pinning a program to a core does not prevent other programs from using the same core. I.e. I think that pinning a program to a core reduces task switching overhead of the pinned program, but does not prevent other programs from using the same core.

Now, the function you've chosen, according to my understanding of its manpage, gives you wallclock duration (and not CPU cycles duration). So any task suspension/resumption can cause such and bigger variations.
 
Old 03-17-2011, 03:43 PM   #5
rk_linux
LQ Newbie
 
Registered: Mar 2011
Posts: 3

Original Poster
Rep: Reputation: 0
[QUOTE=Sergei Steshenko;4294292]Regarding
- does this mean that the program doing measurements is never suspended/resumed by kernel ?

Sorry for not being clear earlier, I have excluded all but one of the CPU cores from the default scheduler, and ensured that the measurement code runs on the other core. That excludes the possibility of that core being used by other
program or the program being suspended/resumed.
 
Old 03-17-2011, 08:42 PM   #6
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by rk_linux View Post
...That excludes the possibility of that core being used by other
program or the program being suspended/resumed.
So, again, suppose your supposedly excluded program executes a, say' 'printf' statement, which ultimately translates into a system call. Since you have a system call, how can you prevent the system (kernel) from suspending/resuming your task ?

I am writing my conclusions based on my general understanding how things work; my understanding can be wrong. If you think your understanding of why/how you can achieve the sate that your task is neither suspended no resumed id correct, could you point me to some documentation stating that ?
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
variation in value returned from gettimeofday() blue bottle Programming 9 01-05-2011 07:34 AM
making an own variation of a bootcd shorun Linux - General 1 07-30-2007 04:56 PM
Scripts Variation shipon_97 Linux - Newbie 2 03-14-2007 12:10 PM
Variation of LFS into /pkg shevegen Linux From Scratch 0 05-05-2006 11:35 PM
delay(), gettime() inside dos.h and conio.h in LINUX slickenside Programming 6 01-31-2004 05:13 PM

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

All times are GMT -5. The time now is 12:38 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