The Fastest Linux Timestamps
Key point
By bypassing the vDSO on x86 Linux, timestamp latency was reduced by 30%.
Details
As the cost of stamping the start and end times of an OpenTelemetry span rose to 46-49ns, timestamps themselves turned out to be a non-negligible overhead in ultra-low-latency pipelines.
The core background is x86's invariant TSC and how Linux's vDSO works. A typical clock_gettime() is handled via the vDSO without entering the kernel, but even so it involves checking a sequence lock, reading the TSC, converting cycles to nanoseconds, and normalizing to seconds.
The article dissects the vDSO's do_hres() path, explaining the structure where the kernel updates a reference time and correction values in a data page, and userspace reads it to compute the current time. It notes that this process requires lfence + rdtsc or rdtscp, and that reading the TSC itself is not completely free either.
It then proposes a simpler path suited for tracing purposes.
- Since a monotonic clock only needs a difference, not an absolute time, the cycles difference can be converted directly to nanoseconds.
- Instead of reading the wall clock and monotonic clock separately twice, redundant computation can be eliminated by computing only the values that are needed.
- This approach cut timestamp processing time by 30% on x86 Linux, while maintaining the same precision as the standard system clock.
However, the author clearly states that this optimization is overkill for most programs. It's a technique that only matters for special cases like tracing in ultra-low-latency environments.
This summary was generated automatically by AI. Check the original for the author's claims and context. Copyright belongs to the original author.
Our guide explains how the AI works. Report summary errors, attribution issues, or removal requests via Contact.