/* * set_freq - set clock frequency correction * * Used to step the frequency correction at startup, possibly again once * the frequency is measured (that is, transitioning from EVNT_NSET to * EVNT_FSET), and finally to switch between daemon and kernel loop * discipline at runtime. * * When the kernel loop discipline is available but the daemon loop is * in use, the kernel frequency correction is disabled (set to 0) to * ensure drift_comp is applied by only one of the loops. */ static void set_freq( double freq /* frequency update */ ) { const char * loop_desc; int ntp_adj_ret; drift_comp = freq; loop_desc = "ntpd"; #ifdef KERNEL_PLL if (pll_control) { ZERO(ntv); ntv.modes = MOD_FREQUENCY; if (kern_enable) { loop_desc = "kernel"; ntv.freq = DTOFREQ(drift_comp); } if ((ntp_adj_ret = ntp_adjtime(&ntv)) != 0) { ntp_adjtime_error_handler(__func__, &ntv, ntp_adj_ret, errno, 0, 0, __LINE__ - 1); } } #endif /* KERNEL_PLL */ mprintf_event(EVNT_FSET, NULL, "%s %.3f PPM", loop_desc, drift_comp * 1e6); }
/* * set_freq - set clock frequency */ static void set_freq( double freq /* frequency update */ ) { char tbuf[80]; drift_comp = freq; #ifdef KERNEL_PLL /* * If the kernel is enabled, update the kernel frequency. */ if (pll_control && kern_enable) { memset(&ntv, 0, sizeof(ntv)); ntv.modes = MOD_FREQUENCY; ntv.freq = DTOFREQ(drift_comp); ntp_adjtime(&ntv); snprintf(tbuf, sizeof(tbuf), "kernel %.3f PPM", drift_comp * 1e6); report_event(EVNT_FSET, NULL, tbuf); } else { snprintf(tbuf, sizeof(tbuf), "ntpd %.3f PPM", drift_comp * 1e6); report_event(EVNT_FSET, NULL, tbuf); } #else /* KERNEL_PLL */ snprintf(tbuf, sizeof(tbuf), "ntpd %.3f PPM", drift_comp * 1e6); report_event(EVNT_FSET, NULL, tbuf); #endif /* KERNEL_PLL */ }