On Mon, Mar 20, 2023 at 10:36 PM Gregory Nutt <spudan...@gmail.com> wrote:

>
> > NuttX offers a function clock_synchronize() that synchronizes system
> clock
> > with clock from RTC (internal or external). The synchronization is done
> > during board initialization and I suppose this can also be called from an
> > application level if required.
> I think clock_synchronize() is okay for startup initialization, but
> would be inappropriate at run time.  That is because it could cause the
> current time to apparently jump backward.  That could be fatal under
> certain circumstances as described for adjtime() in
> https://github.com/apache/nuttx/issues/8858
>

I remember once reading about how FreeBSD handles this (I think it was
FreeBSD; this was a long time ago):

If there is a difference between the system clock and the reference clock,
the system clock is _not_ assigned the reference clock's time, exactly
because of the "clock running backwards" problem. Rather, when the clock is
advanced, the advancement is adjusted by a small amount, so that the system
clock always runs forwards, never backwards, and over time the system clock
gradually comes into synchronization with the reference clock.

We probably need something like that to avoid the same problem.

Cheers
Nathan

Reply via email to