You can do even faster, about 8ns (almost an additional 10x improvement) by using software perf events: PERF_COUNT_SW_TASK_CLOCK is thread CPU time, it can be read through a shared page (so no syscall, see perf_event_mmap_page), and then you add the delta since the last context switch with a single rdtsc call within a seqlock. This is not well documented unfortunately, and I'm not aware of open-source implementations…
Why do you need a seqlock? To make sure you're not context switched out between the read of the page value and the rdtsc? Presumably you mean you just double check the page value after the rdtsc to make sure it hasn't changed and retry if it has? Tbh I thought clock_gettime was a vdso based virtual syscall anyway
Yes, that's exactly what a seqlock (reader) is.