LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 07-02-2015, 09:19 AM   #1
rainman1985_2010
Member
 
Registered: Oct 2010
Posts: 47

Rep: Reputation: 0
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
 
Old 07-02-2015, 10:03 AM   #2
genss
Member
 
Registered: Nov 2013
Posts: 741

Rep: Reputation: Disabled
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
 
Old 07-03-2015, 05:10 PM   #3
metaschima
Senior Member
 
Registered: Dec 2013
Distribution: Slackware
Posts: 1,982

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Quote:
Originally Posted by genss View Post
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.
 
  


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
Does clock_gettime function work at any hardware ? temp9713 Linux - Hardware 1 09-12-2012 10:26 AM
difference in time recorded by clock_gettime() and TSC blue bottle Programming 7 01-26-2011 03:29 AM
POSIX.4 clock_gettime function collinss Programming 2 09-13-2005 06:55 AM
timing a function saajii Programming 1 10-25-2004 02:37 AM
POSIX.4 clock_gettime function collinss Linux - General 1 11-24-2003 12:12 PM

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

All times are GMT -5. The time now is 08:45 PM.

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