Which system hardware timer does clock_gettime
function in linux use internally to give nano seconds level resolution back to the user code when invoked to measure elapsed time for a given segment of code ?
Asked
Active
Viewed 314 times
0

Soumajit
- 342
- 2
- 4
- 16
-
You should have a look at the manpage of [`clock_gettime`](http://linux.die.net/man/3/clock_gettime). – Nidhoegger May 04 '15 at 14:09
-
[How is the microsecond time of linux gettimeofday() obtained and what is its accuracy?](http://stackoverflow.com/q/13230719/1504523) may shed some light on the scheme. – Arno May 04 '15 at 15:47
-
IIRC, Linux cannot give ns resolution. – edmz May 05 '15 at 11:29
1 Answers
0
Modern CPUs run at several GHz clock frequency. A frequency of 1 GHz equals a clock period of 1 ns. So running a (wide) counter at 1 GHz gives a time resolution in nanoseconds. This does not mean that the time is as accurate as it is displayed. The value has just such a high resolution.

Paebbels
- 15,573
- 13
- 70
- 139