version = NTP_VERSION;
}
- LCL_ReadCookedTime(&local_transmit, NULL);
+ /* This is accurate enough and cheaper than calling LCL_ReadCookedTime.
+ A more accurate time stamp will be taken later in this function. */
+ SCH_GetLastEventTime(&local_transmit, NULL, NULL);
+
REF_GetReferenceParams(&local_transmit,
&are_we_synchronised, &leap_status,
&our_stratum,
ReceiveBuffer message;
union sockaddr_in46 where_from;
unsigned int flags = 0;
- struct timeval now;
+ struct timeval now, now_raw;
double now_err;
NTP_Remote_Address remote_addr;
char cmsgbuf[256];
assert(initialised);
- SCH_GetLastEventTime(&now, &now_err, NULL);
+ SCH_GetLastEventTime(&now, &now_err, &now_raw);
iov.iov_base = message.arbitrary;
iov.iov_len = sizeof(message);
struct timeval tv;
memcpy(&tv, CMSG_DATA(cmsg), sizeof(tv));
- LCL_CookTime(&tv, &now, &now_err);
+
+ /* This should be more accurate than LCL_CookTime(&now_raw,...) */
+ UTI_AddDiffToTimeval(&now, &now_raw, &tv, &now);
}
#endif
}
double update_interval;
double elapsed;
double correction_rate;
- struct timeval now, raw_now;
+ struct timeval now, raw_now, ev_now, ev_raw_now;
assert(initialised);
}
LCL_ReadRawTime(&raw_now);
- LCL_CookTime(&raw_now, &now, NULL);
+
+ /* This is cheaper than calling LCL_CookTime */
+ SCH_GetLastEventTime(&ev_now, NULL, &ev_raw_now);
+ UTI_AddDiffToTimeval(&ev_now, &ev_raw_now, &raw_now, &now);
UTI_DiffTimevalsToDouble(&elapsed, &now, ref_time);
our_offset = offset + elapsed * frequency;
#include "reports.h"
#include "nameserv.h"
#include "mkdirpp.h"
+#include "sched.h"
/* ================================================== */
/* Flag indicating that we are initialised */
return;
}
- LCL_ReadCookedTime(&now, NULL);
+ /* This is accurate enough and cheaper than calling LCL_ReadCookedTime */
+ SCH_GetLastEventTime(&now, NULL, NULL);
/* Step 1 - build intervals about each source */
n_endpoints = 0;
/* ================================================== */
+void
+UTI_AddDiffToTimeval(struct timeval *a, struct timeval *b,
+ struct timeval *c, struct timeval *result)
+{
+ double diff;
+
+ UTI_DiffTimevalsToDouble(&diff, a, b);
+ UTI_AddDoubleToTimeval(c, diff, result);
+}
+
+/* ================================================== */
+
#define POOL_ENTRIES 16
#define BUFFER_LENGTH 64
static char buffer_pool[POOL_ENTRIES][BUFFER_LENGTH];
/* Calculate the average and difference (as a double) of two timevals */
extern void UTI_AverageDiffTimevals(struct timeval *earlier, struct timeval *later, struct timeval *average, double *diff);
+/* Calculate result = a - b + c */
+extern void UTI_AddDiffToTimeval(struct timeval *a, struct timeval *b, struct timeval *c, struct timeval *result);
+
/* Convert a timeval into a temporary string, largely for diagnostic
display */
extern char *UTI_TimevalToString(struct timeval *tv);