Re: Accuracy bounds of ktime_get_boot_fast_ns

From: Thomas Gleixner
Date: Sat Jun 23 2018 - 16:16:31 EST


On Sat, 23 Jun 2018, Jason A. Donenfeld wrote:
> void foobar_create(struct foobar *f)
> {
> f->birthdate = ktime_get_boot_fast_ns();
> }
> bool foobar_has_expired(struct foobar *f)
> {
> return f->birthdate + DEATH_AGE_SEC * NSEC_PER_SEC <=
> ktime_get_boot_fast_ns();
> }
>
> I'm wondering if I can actually get away with this last iteration.
> I've read the comments around the various _fast_ns functions, and they
> all indicate that it might not be totally monotonic with respect to
> all cpus. But I wonder if that actually matters for my use case. For
> example, is it still correct within a 10th or so of a second? Or will
> it occasionally be wrong by massive multi-second leaps, which would
> make it unsuitable for my usage? In other words, I'm wondering if
> there's still a level of accuracy for a certain low degree of
> precision?

The step backwards would be in the low nanoseconds range, so nothing to
worry about. The slope is not adjusted by large jumps, it's a very smooth
adoption through NTP/PTP.

Thanks,

tglx