Roshan James, Christopher Hardin

The Time_stamp_counter module exposes a “local” time source that’s fast to query, monotonic, and accurate to nanoseconds is what you need in order to do fine-grained benchmarking. It does this by using the RDTSC x86 instruction, which reads a register that counts CPU cycles since it was last reset. Fetching values from this reguster can take as little as 2ns and gives you nanosecond resolution, whereas using the gettimeofday() system call, can take as much as 800ns on some systems, and only gives you μsecond resolution.

The time recovered from this register does need to be calibrated against system time occasionally. If you’re using Async and the global calibrator, this will happen automatically for you every few seconds. If there’s some discontinuity with system time, Time_stamp_counter will smooth out the discontinuity while maintaining monotonicity. I’ll see if I can find the graphs from the talk and put them up here.