Skip to content

Commit 46f6fa4

Browse files
kbowers-jumpripatel-fd
authored andcommitted
fd_clock
By popular demand, here is an API for synchronizing various cheap-inaccurate-weird-unit local tickcounters (e.g. fd_tickcount / RDTSC, FPGA hardware timestamps, NIC hardware timestamps, etc) to slow-accurate-normal-unit reference clocks (fd_log_wallclock / clock_gettime / CLOCK_REALTIME, etc). This allows users to accurately, cheaply, monotonically, concurrently, consistently and deterministically convert various rando cheap tickcount reads in HPC critical paths in a distributed application to an equivalent of the system clock. For example, using fd_clock on the pair fd_tickcount / fd_log_wallclock for typical Linux x86 allows the fd_tickcount to act like fd_log_wallclock with quantization limited sync accuracy (~<1 ns), a couple of times lower latency (O(1) ns to convert RDTSC) with over an order of magnitude small jitter (also O(1) ns to convert) and no interthread sync error (shared memory interprocess persistent data structure ... threads system wide can concurrently use a synchronization lockfree parallel). Because this requires FD_HAS_DOUBLE, this is considered an optional util and must be included explicitly to use. Note that fd_tickcount / fd_log_wallclock were given fd_clock_func_t compatible variants. IMPORTANT SAFETY TIP! When compiling for non-x86 targets, fd_tickcount by default falls back fd_log_wallclock. While fd_clock will still synchronize the pair fd_tickcount / fd_log_wallcount reasonably, it really is just synchronizing the wallclock to itself with no practical benefit. Production non-x86 targets should provide an appropriate target specific implementation for fd_tickcount to benefit from this API in this case.
1 parent f72cd62 commit 46f6fa4

File tree

8 files changed

+1654
-4
lines changed

8 files changed

+1654
-4
lines changed

src/util/clock/Local.mk

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
ifdef FD_HAS_DOUBLE
2+
$(call add-hdrs,fd_clock.h)
3+
$(call add-objs,fd_clock,fd_util)
4+
$(call make-unit-test,test_clock,test_clock,fd_util)
5+
$(call run-unit-test,test_clock)
6+
endif

0 commit comments

Comments
 (0)