diff --git a/candm.h b/candm.h index f226a9d..25f16c1 100644 --- a/candm.h +++ b/candm.h @@ -475,8 +475,6 @@ typedef struct { Float orig_latest_meas; Float latest_meas; Float latest_meas_err; - Float est_offset; - Float est_offset_err; int32_t EOR; } RPY_Source_Data; @@ -503,6 +501,8 @@ typedef struct { Float sd; Float resid_freq_ppm; Float skew_ppm; + Float est_offset; + Float est_offset_err; int32_t EOR; } RPY_Sourcestats; diff --git a/chrony.texi b/chrony.texi index 95b7232..9fc672f 100644 --- a/chrony.texi +++ b/chrony.texi @@ -3569,9 +3569,9 @@ An example report is @example @group 210 Number of sources = 1 -Name/IP Address NP NR Span Frequency Freq Skew Std Dev -======================================================================== -abc.def.ghi 11 5 46m -0.001 0.045 25us +Name/IP Address NP NR Span Frequency Freq Skew Offset Std Dev +=============================================================================== +abc.def.ghi 11 5 46m -0.001 0.045 1us 25us @end group @end example @@ -3609,6 +3609,9 @@ million. In this case, the computer's clock is estimated to be running This is the estimated error bounds on @code{Freq} (again in parts per million). +@item Offset +This is the estimated offset of the source. + @item Std Dev This is the estimated sample standard deviation. diff --git a/client.c b/client.c index 7d6043b..f27ce64 100644 --- a/client.c +++ b/client.c @@ -1553,9 +1553,8 @@ process_cmd_sources(char *line) int n_sources, i; int verbose = 0; - double orig_latest_meas, latest_meas, est_offset; + double orig_latest_meas, latest_meas, latest_meas_err; IPAddr ip_addr; - double latest_meas_err, est_offset_err; uint32_t latest_meas_ago; uint16_t poll, stratum; uint16_t state, mode; @@ -1583,7 +1582,7 @@ process_cmd_sources(char *line) printf("MS Name/IP address Stratum Poll LastRx Last sample\n"); printf("============================================================================\n"); - /* "MS NNNNNNNNNNNNNNNNNNNNNNNNN SS PP RRRR SSSSSSS[SSSSSSS] +/- SSSSSS" */ + /* "MS NNNNNNNNNNNNNNNNNNNNNNNNN SS PP RRRR SSSSSSS[SSSSSSS] +/- SSSSSS" */ for (i=0; idata.source_data.orig_latest_meas = UTI_FloatHostToNetwork(report.orig_latest_meas); tx_message->data.source_data.latest_meas = UTI_FloatHostToNetwork(report.latest_meas); tx_message->data.source_data.latest_meas_err = UTI_FloatHostToNetwork(report.latest_meas_err); - tx_message->data.source_data.est_offset = UTI_FloatHostToNetwork(report.est_offset); - tx_message->data.source_data.est_offset_err = UTI_FloatHostToNetwork(report.est_offset_err); } else { tx_message->status = htons(STT_NOSUCHSOURCE); } @@ -1395,8 +1393,12 @@ handle_sourcestats(CMD_Request *rx_message, CMD_Reply *tx_message) { int status; RPT_SourcestatsReport report; + struct timeval now_corr; + double local_clock_err; + + LCL_ReadCookedTime(&now_corr, &local_clock_err); status = SRC_ReportSourcestats(ntohl(rx_message->data.sourcestats.index), - &report); + &report, &now_corr); if (status) { tx_message->status = htons(STT_SUCCESS); @@ -1409,6 +1411,8 @@ handle_sourcestats(CMD_Request *rx_message, CMD_Reply *tx_message) tx_message->data.sourcestats.resid_freq_ppm = UTI_FloatHostToNetwork(report.resid_freq_ppm); tx_message->data.sourcestats.skew_ppm = UTI_FloatHostToNetwork(report.skew_ppm); tx_message->data.sourcestats.sd = UTI_FloatHostToNetwork(report.sd); + tx_message->data.sourcestats.est_offset = UTI_FloatHostToNetwork(report.est_offset); + tx_message->data.sourcestats.est_offset_err = UTI_FloatHostToNetwork(report.est_offset_err); } else { tx_message->status = htons(STT_NOSUCHSOURCE); } diff --git a/reports.h b/reports.h index 78e2d10..e2f1682 100644 --- a/reports.h +++ b/reports.h @@ -47,8 +47,6 @@ typedef struct { double orig_latest_meas; /* seconds */ double latest_meas; /* seconds */ double latest_meas_err; /* seconds */ - double est_offset; /* seconds */ - double est_offset_err; /* seconds */ } RPT_SourceReport ; typedef struct { @@ -73,6 +71,8 @@ typedef struct { double resid_freq_ppm; double skew_ppm; double sd; + double est_offset; + double est_offset_err; } RPT_SourcestatsReport; typedef struct { diff --git a/sources.c b/sources.c index d898b89..03b6fb6 100644 --- a/sources.c +++ b/sources.c @@ -956,7 +956,7 @@ SRC_ReportSource(int index, RPT_SourceReport *report, struct timeval *now) /* ================================================== */ int -SRC_ReportSourcestats(int index, RPT_SourcestatsReport *report) +SRC_ReportSourcestats(int index, RPT_SourcestatsReport *report, struct timeval *now) { SRC_Instance src; @@ -969,7 +969,7 @@ SRC_ReportSourcestats(int index, RPT_SourcestatsReport *report) report->ip_addr = *src->ip_addr; else report->ip_addr.family = IPADDR_UNSPEC; - SST_DoSourcestatsReport(src->stats, report); + SST_DoSourcestatsReport(src->stats, report, now); return 1; } } diff --git a/sources.h b/sources.h index 54d86ea..c1cfffc 100644 --- a/sources.h +++ b/sources.h @@ -146,7 +146,7 @@ extern int SRC_IsSyncPeer(SRC_Instance inst); extern int SRC_ReadNumberOfSources(void); extern int SRC_ReportSource(int index, RPT_SourceReport *report, struct timeval *now); -extern int SRC_ReportSourcestats(int index, RPT_SourcestatsReport *report); +extern int SRC_ReportSourcestats(int index, RPT_SourcestatsReport *report, struct timeval *now); extern SRC_Type SRC_GetType(int index); diff --git a/sourcestats.c b/sourcestats.c index 196c5d9..3dc61e0 100644 --- a/sourcestats.c +++ b/sourcestats.c @@ -845,8 +845,7 @@ SST_LoadFromFile(SST_Stats inst, FILE *in) void SST_DoSourceReport(SST_Stats inst, RPT_SourceReport *report, struct timeval *now) { - int n, nb; - double elapsed, sample_elapsed; + int n; struct timeval ago; if (inst->n_samples > 0) { @@ -858,27 +857,12 @@ SST_DoSourceReport(SST_Stats inst, RPT_SourceReport *report, struct timeval *now UTI_DiffTimevals(&ago, now, &inst->sample_times[n]); report->latest_meas_ago = ago.tv_sec; - - if (inst->n_samples > 3) { - UTI_DiffTimevalsToDouble(&elapsed, now, &inst->offset_time); - nb = inst->best_single_sample; - UTI_DiffTimevalsToDouble(&sample_elapsed, now, &(inst->sample_times[nb])); - report->est_offset = inst->estimated_offset + elapsed * inst->estimated_frequency; - report->est_offset_err = (inst->estimated_offset_sd + - sample_elapsed * inst->skew + - (0.5*inst->root_delays[nb] + inst->root_dispersions[nb])); - } else { - report->est_offset = report->latest_meas; - report->est_offset_err = report->latest_meas_err; - } } else { report->latest_meas_ago = 86400 * 365 * 10; report->orig_latest_meas = 0; report->latest_meas = 0; report->latest_meas_err = 0; report->stratum = 0; - report->est_offset = 0; - report->est_offset_err = 0; } } @@ -893,10 +877,11 @@ SST_Skew_Direction SST_LastSkewChange(SST_Stats inst) /* ================================================== */ void -SST_DoSourcestatsReport(SST_Stats inst, RPT_SourcestatsReport *report) +SST_DoSourcestatsReport(SST_Stats inst, RPT_SourcestatsReport *report, struct timeval *now) { double dspan; - int n; + double elapsed, sample_elapsed; + int n, nb; report->n_samples = inst->n_samples; report->n_runs = inst->nruns; @@ -905,8 +890,23 @@ SST_DoSourcestatsReport(SST_Stats inst, RPT_SourcestatsReport *report) n = inst->n_samples - 1; UTI_DiffTimevalsToDouble(&dspan, &inst->sample_times[n], &inst->sample_times[0]); report->span_seconds = (unsigned long) (dspan + 0.5); + + if (inst->n_samples > 3) { + UTI_DiffTimevalsToDouble(&elapsed, now, &inst->offset_time); + nb = inst->best_single_sample; + UTI_DiffTimevalsToDouble(&sample_elapsed, now, &(inst->sample_times[nb])); + report->est_offset = inst->estimated_offset + elapsed * inst->estimated_frequency; + report->est_offset_err = (inst->estimated_offset_sd + + sample_elapsed * inst->skew + + (0.5*inst->root_delays[nb] + inst->root_dispersions[nb])); + } else { + report->est_offset = inst->offsets[n]; + report->est_offset_err = 0.5*inst->root_delays[n] + inst->root_dispersions[n]; + } } else { report->span_seconds = 0; + report->est_offset = 0; + report->est_offset_err = 0; } report->resid_freq_ppm = 1.0e6 * inst->estimated_frequency; diff --git a/sourcestats.h b/sourcestats.h index 6baf5b6..0a5a82b 100644 --- a/sourcestats.h +++ b/sourcestats.h @@ -140,7 +140,7 @@ extern int SST_LoadFromFile(SST_Stats inst, FILE *in); extern void SST_DoSourceReport(SST_Stats inst, RPT_SourceReport *report, struct timeval *now); -extern void SST_DoSourcestatsReport(SST_Stats inst, RPT_SourcestatsReport *report); +extern void SST_DoSourcestatsReport(SST_Stats inst, RPT_SourcestatsReport *report, struct timeval *now); typedef enum { SST_Skew_Decrease,