LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Does clock_gettime function use tsc for timing? (https://www.linuxquestions.org/questions/programming-9/does-clock_gettime-function-use-tsc-for-timing-4175547021/)

rainman1985_2010 07-02-2015 09:19 AM

Does clock_gettime function use tsc for timing?
 
Hi, everyone.

I need to measure time precisely and intend to use clock_gettime function. It's said that clock_gettime function uses TSC for timing, and TSC increments is constant relative to CPU clock. However, the CPU clock may be scaled back for power saving, which may leads to a relative change in the TSC increments. Does this mean that the time clock_gettime function gives may not be precise?

Thanks:)

genss 07-02-2015 10:03 AM

it uses the actual clock, not tsc

it may be inaccurate due to the time to do the system call and whatnot
CLOCK_MONOTONIC and CLOCK_MONOTONIC_RAW are vdso-s and dont do some special conversions so they are more accurate

metaschima 07-03-2015 05:10 PM

Quote:

Originally Posted by genss (Post 5386146)
it uses the actual clock, not tsc

it may be inaccurate due to the time to do the system call and whatnot
CLOCK_MONOTONIC and CLOCK_MONOTONIC_RAW are vdso-s and dont do some special conversions so they are more accurate

I agree, clock_gettime with CLOCK_MONOTONIC (or CLOCK_MONOTONIC_RAW) option is the most accurate.


All times are GMT -5. The time now is 10:05 PM.