Read local time immediately after select()
This removes a small inaccuracy caused by delay between select() and file handler calls.
This commit is contained in:
parent
159a9519e8
commit
e9ae3d0a0b
5 changed files with 20 additions and 6 deletions
|
@ -436,7 +436,6 @@ read_from_socket(void *anything)
|
||||||
IPAddr remote_ip;
|
IPAddr remote_ip;
|
||||||
int i, ok;
|
int i, ok;
|
||||||
struct timeval now;
|
struct timeval now;
|
||||||
double local_time_err;
|
|
||||||
SourceRecord *src;
|
SourceRecord *src;
|
||||||
|
|
||||||
flags = 0;
|
flags = 0;
|
||||||
|
@ -444,7 +443,7 @@ read_from_socket(void *anything)
|
||||||
his_addr_len = sizeof(his_addr);
|
his_addr_len = sizeof(his_addr);
|
||||||
|
|
||||||
/* Get timestamp */
|
/* Get timestamp */
|
||||||
LCL_ReadCookedTime(&now, &local_time_err);
|
SCH_GetFileReadyTime(&now);
|
||||||
|
|
||||||
sock_fd = (long)anything;
|
sock_fd = (long)anything;
|
||||||
status = recvfrom (sock_fd, (char *)&msg, message_length, flags,
|
status = recvfrom (sock_fd, (char *)&msg, message_length, flags,
|
||||||
|
|
3
ntp_io.c
3
ntp_io.c
|
@ -275,7 +275,6 @@ read_from_socket(void *anything)
|
||||||
unsigned int flags = 0;
|
unsigned int flags = 0;
|
||||||
struct timeval now;
|
struct timeval now;
|
||||||
NTP_Remote_Address remote_addr;
|
NTP_Remote_Address remote_addr;
|
||||||
double local_clock_err;
|
|
||||||
char cmsgbuf[256];
|
char cmsgbuf[256];
|
||||||
struct msghdr msg;
|
struct msghdr msg;
|
||||||
struct iovec iov;
|
struct iovec iov;
|
||||||
|
@ -283,7 +282,7 @@ read_from_socket(void *anything)
|
||||||
|
|
||||||
assert(initialised);
|
assert(initialised);
|
||||||
|
|
||||||
LCL_ReadCookedTime(&now, &local_clock_err);
|
SCH_GetFileReadyTime(&now);
|
||||||
|
|
||||||
iov.iov_base = message.arbitrary;
|
iov.iov_base = message.arbitrary;
|
||||||
iov.iov_len = sizeof(message);
|
iov.iov_len = sizeof(message);
|
||||||
|
|
|
@ -872,7 +872,6 @@ read_from_device(void *any)
|
||||||
struct rtc_time rtc_raw;
|
struct rtc_time rtc_raw;
|
||||||
struct tm rtc_tm;
|
struct tm rtc_tm;
|
||||||
time_t rtc_t;
|
time_t rtc_t;
|
||||||
double read_err;
|
|
||||||
int error = 0;
|
int error = 0;
|
||||||
|
|
||||||
status = read(fd, &data, sizeof(data));
|
status = read(fd, &data, sizeof(data));
|
||||||
|
@ -905,7 +904,7 @@ read_from_device(void *any)
|
||||||
/* Read RTC time, sandwiched between two polls of the system clock
|
/* Read RTC time, sandwiched between two polls of the system clock
|
||||||
so we can bound any error. */
|
so we can bound any error. */
|
||||||
|
|
||||||
LCL_ReadCookedTime(&sys_time, &read_err);
|
SCH_GetFileReadyTime(&sys_time);
|
||||||
|
|
||||||
status = ioctl(fd, RTC_RD_TIME, &rtc_raw);
|
status = ioctl(fd, RTC_RD_TIME, &rtc_raw);
|
||||||
if (status < 0) {
|
if (status < 0) {
|
||||||
|
|
13
sched.c
13
sched.c
|
@ -71,6 +71,9 @@ typedef struct {
|
||||||
|
|
||||||
static FileHandlerEntry file_handlers[FD_SET_SIZE];
|
static FileHandlerEntry file_handlers[FD_SET_SIZE];
|
||||||
|
|
||||||
|
/* Last timestamp when a file descriptor became readable */
|
||||||
|
static struct timeval last_fdready;
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
/* Variables to handler the timer queue */
|
/* Variables to handler the timer queue */
|
||||||
|
@ -225,6 +228,14 @@ SCH_RemoveInputFileHandler(int fd)
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
|
void
|
||||||
|
SCH_GetFileReadyTime(struct timeval *tv)
|
||||||
|
{
|
||||||
|
*tv = last_fdready;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
#define TQE_ALLOC_QUANTUM 32
|
#define TQE_ALLOC_QUANTUM 32
|
||||||
|
|
||||||
static TimerQueueEntry *
|
static TimerQueueEntry *
|
||||||
|
@ -514,6 +525,7 @@ SCH_MainLoop(void)
|
||||||
int status;
|
int status;
|
||||||
struct timeval tv, *ptv;
|
struct timeval tv, *ptv;
|
||||||
struct timeval now;
|
struct timeval now;
|
||||||
|
double err;
|
||||||
|
|
||||||
if (!initialised) {
|
if (!initialised) {
|
||||||
CROAK("Should be initialised");
|
CROAK("Should be initialised");
|
||||||
|
@ -551,6 +563,7 @@ SCH_MainLoop(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
status = select(one_highest_fd, &rd, NULL, NULL, ptv);
|
status = select(one_highest_fd, &rd, NULL, NULL, ptv);
|
||||||
|
LCL_ReadCookedTime(&last_fdready, &err);
|
||||||
|
|
||||||
if (status < 0) {
|
if (status < 0) {
|
||||||
if (!need_to_exit)
|
if (!need_to_exit)
|
||||||
|
|
4
sched.h
4
sched.h
|
@ -60,6 +60,10 @@ extern void SCH_AddInputFileHandler
|
||||||
);
|
);
|
||||||
extern void SCH_RemoveInputFileHandler(int fd);
|
extern void SCH_RemoveInputFileHandler(int fd);
|
||||||
|
|
||||||
|
/* Get the time (cooked) when file descriptor became ready, intended for use
|
||||||
|
in file handlers */
|
||||||
|
extern void SCH_GetFileReadyTime(struct timeval *tv);
|
||||||
|
|
||||||
/* This queues a timeout to elapse at a given (raw) local time */
|
/* This queues a timeout to elapse at a given (raw) local time */
|
||||||
extern SCH_TimeoutID SCH_AddTimeout(struct timeval *tv, SCH_TimeoutHandler, SCH_ArbitraryArgument);
|
extern SCH_TimeoutID SCH_AddTimeout(struct timeval *tv, SCH_TimeoutHandler, SCH_ArbitraryArgument);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue