Re: [chrony-dev] [PATCH] Mac OS X - Synchronise RTC from system time

[ Thread Index | Date Index | More chrony.tuxfamily.org/chrony-dev Archives ]


On Thu, Dec 03, 2015 at 08:44:16AM +1300, Bryan Christianson wrote:
> When the rtcsync directive is specified in the chronyd config file,
> chronyd will update the RTC via settimeofday() every 60 minutes if
> the time is syncronised to NTP.

Typo ------------^

> -This directive is supported only on Linux and cannot be used when the
> -normal RTC tracking is enabled, i.e. when the @code{rtcfile} directive
> -is used.  On other systems this directive does nothing.
> +On Linux the RTC copy is performed by the kernel every 11 minutes. This
> +directive cannot be used when the normal RTC tracking is enabled,
> +i.e. when the @code{rtcfile} directiveis used.

Another typo ----------------------------^

> @@ -101,6 +107,10 @@ clock_initialise(void)
>    drift_removal_interval = DRIFT_REMOVAL_INTERVAL;
>    current_drift_removal_interval = DRIFT_REMOVAL_INTERVAL;
>  
> +  if (gettimeofday(&last_rtc_sync, NULL) < 0) {
> +    LOG_FATAL(LOGF_SysMacOSX, "gettimeofday() failed");
> +  }
> +

There is a gettimeofday() call just below that, so last_rtc_sync could
be set to T0.

>    if (gettimeofday(&T0, NULL) < 0) {
>      LOG_FATAL(LOGF_SysMacOSX, "gettimeofday() failed");
>    }

> @@ -327,6 +339,21 @@ set_sync_status(int synchronised, double est_error, double max_error)
>    if (!synchronised) {
>      drift_removal_interval = MAX(drift_removal_interval, DRIFT_REMOVAL_INTERVAL);
>    } else {
> +    if (CNF_GetRtcSync()) {
> +      struct timeval now;
> +      double rtc_sync_elapsed;
> +
> +      if (gettimeofday(&now, NULL))
> +        LOG_FATAL(LOGF_SysMacOSX, "gettimeofday() failed");

To avoid the additional system call per clock update this could be
replaced with SCH_GetLastEventTime(NULL, NULL, &now) as a cheaper
alternative of getting current time.

> +      UTI_DiffTimevalsToDouble(&rtc_sync_elapsed, &now, &last_rtc_sync);
> +      if (rtc_sync_elapsed >= RTC_SYNC_INTERVAL) {

It might be better to use fabs(rtc_sync_elapsed) here to not get stuck
in case the clock is stepped back by a large amount since the last
update.

-- 
Miroslav Lichvar

-- 
To unsubscribe email chrony-dev-request@xxxxxxxxxxxxxxxxxxxx with "unsubscribe" in the subject.
For help email chrony-dev-request@xxxxxxxxxxxxxxxxxxxx with "help" in the subject.
Trouble?  Email listmaster@xxxxxxxxxxxxxxxxxxxx.


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/