-
Notifications
You must be signed in to change notification settings - Fork 41
Description
In #16, we explored the inherent sources of potential error for quanta
given that it's reaching out to the processor directly, and carries none of the calibration/edge case handling that a hardened usage like, say, by the OS, would provide.
None of this is to say that we couldn't do some of this work ourselves. Similarly, I don't believe that quanta
is grossly inaccurate. It shouldn't be. We do have to admit, though, that using quanta
as a drop-in replacement for Instant
where timing is not done purely for extremely hot loops may not be the most correct choice where both high resolution (nanoseconds) and high accuracy is required.
With all of that said, we have some potential options that I've been thinking of, and this is not necessarily an exhaustive list:
- we could only ever use the reference clock, and depend on OS-specific guarantees as our base assumptions (this lets us keep mockability,
recent
time, etc) - we can bake in our own calibration and try to account for all of the edge cases
- we could bifurcate
now
andraw
such that we still allow raw measurements, and could attempt to scale them to reference time, but we transformnow
into the more generalized/stable measurement
My belief is that #2 is achievable but that it would take a decently large effort to test all of this behavior, read existing sources, distill that into quanta
, etc. For example, how do we deal with the potential TSC offset across cores/sockets? Can the same solution to "different cores" be applied to "different sockets"? How do we deal with this across multiple OSes where I may not have any source to read to understand how they handle TSC synchronization?
Providing the most information we can to the users of the crate might be beneficial enough to allow them to make a smarter choice about where we have these pitfalls. For example, if we can show that Linux does a damn good job of synchronizing the TSC no matter the processor configuration, then the exposing that to the user means they can decide if they want to roll with the fast path TSC, or have quanta
fallback to the OS-based timing.
Long story short, we have some things to explore and think about!