HeadlinesBriefing favicon HeadlinesBriefing.com

Linux Timestamps Optimized for Nanosecond Precision

Hacker News •
×

A developer discovered that standard timestamping on Linux consumes nearly 50 nanoseconds per call, consuming the entire time budget for a low-latency distributed tracing system targeting just 100 ns per span. This bottleneck prompted exploration of alternatives to the conventional vDSO approach for clock_gettime() calls.

By implementing custom timers that bypass vDSO and directly use the CPU's Time Stamp Counter, the team achieved a 30% improvement in timestamp performance. The TSC provides constant-rate timing unaffected by frequency scaling, though it requires careful handling to maintain accuracy and avoid serialization issues.

The detailed analysis includes a simplified version of the vDSO's do_hres() function, revealing how Linux handles high-resolution clocks through memory-mapped data pages shared between kernel and userspace. This approach remains relevant across Linux kernel versions, though vDSO layout changed in version 6.15.