ntp: don't require previous HW TX timestamp to wait for another
Clients sockets are closed immediately after receiving valid response. Don't wait for the first early HW TX timestamp to enable waiting for late timestamps. It may take a long time or never come if the HW/driver is consistently slow. It's a chicken and egg problem. Instead, simply check if HW timestamping is enabled on at least one interface. Responses from NTP sources on other interfaces will always be saved (for 1 millisecond by default).
This commit is contained in:
parent
7bc7d00297
commit
3dc9f1ff92
6 changed files with 28 additions and 13 deletions
|
@ -215,9 +215,6 @@ struct NCR_Instance_Record {
|
|||
SPF_Instance filter;
|
||||
int filter_count;
|
||||
|
||||
/* Flag indicating HW transmit timestamps are expected */
|
||||
int had_hw_tx_timestamp;
|
||||
|
||||
/* Response waiting for a HW transmit timestamp of the request */
|
||||
struct SavedResponse *saved_response;
|
||||
|
||||
|
@ -794,8 +791,6 @@ NCR_ResetInstance(NCR_Instance instance)
|
|||
if (instance->filter)
|
||||
SPF_DropSamples(instance->filter);
|
||||
instance->filter_count = 0;
|
||||
|
||||
instance->had_hw_tx_timestamp = 0;
|
||||
}
|
||||
|
||||
/* ================================================== */
|
||||
|
@ -1966,7 +1961,7 @@ process_response(NCR_Instance inst, int saved, NTP_Local_Address *local_addr,
|
|||
response to the request, when at least one good response has already been
|
||||
accepted to avoid incorrectly confirming a tentative source. */
|
||||
if (valid_packet && synced_packet && !saved && !inst->valid_rx &&
|
||||
inst->had_hw_tx_timestamp && inst->local_tx.source != NTP_TS_HARDWARE &&
|
||||
NIO_IsHwTsEnabled() && inst->local_tx.source != NTP_TS_HARDWARE &&
|
||||
inst->report.total_good_count > 0) {
|
||||
if (save_response(inst, local_addr, rx_ts, message, info))
|
||||
return 1;
|
||||
|
@ -2692,8 +2687,6 @@ NCR_ProcessTxKnown(NCR_Instance inst, NTP_Local_Address *local_addr,
|
|||
message);
|
||||
|
||||
if (tx_ts->source == NTP_TS_HARDWARE) {
|
||||
inst->had_hw_tx_timestamp = 1;
|
||||
|
||||
if (has_saved_response(inst))
|
||||
process_saved_response(inst);
|
||||
}
|
||||
|
|
12
ntp_io.c
12
ntp_io.c
|
@ -278,6 +278,18 @@ NIO_Finalise(void)
|
|||
|
||||
/* ================================================== */
|
||||
|
||||
int
|
||||
NIO_IsHwTsEnabled(void)
|
||||
{
|
||||
#ifdef HAVE_LINUX_TIMESTAMPING
|
||||
return NIO_Linux_IsHwTsEnabled();
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* ================================================== */
|
||||
|
||||
int
|
||||
NIO_OpenClientSocket(NTP_Remote_Address *remote_addr)
|
||||
{
|
||||
|
|
3
ntp_io.h
3
ntp_io.h
|
@ -39,6 +39,9 @@ extern void NIO_Initialise(void);
|
|||
/* Function to finalise the module */
|
||||
extern void NIO_Finalise(void);
|
||||
|
||||
/* Function to check if HW timestamping is enabled on any interface */
|
||||
extern int NIO_IsHwTsEnabled(void);
|
||||
|
||||
/* Function to obtain a socket for sending client packets */
|
||||
extern int NIO_OpenClientSocket(NTP_Remote_Address *remote_addr);
|
||||
|
||||
|
|
|
@ -439,6 +439,14 @@ NIO_Linux_Finalise(void)
|
|||
|
||||
/* ================================================== */
|
||||
|
||||
int
|
||||
NIO_Linux_IsHwTsEnabled(void)
|
||||
{
|
||||
return ARR_GetSize(interfaces) > 0;
|
||||
}
|
||||
|
||||
/* ================================================== */
|
||||
|
||||
int
|
||||
NIO_Linux_SetTimestampSocketOptions(int sock_fd, int client_only, int *events)
|
||||
{
|
||||
|
|
|
@ -33,6 +33,8 @@ extern void NIO_Linux_Initialise(void);
|
|||
|
||||
extern void NIO_Linux_Finalise(void);
|
||||
|
||||
extern int NIO_Linux_IsHwTsEnabled(void);
|
||||
|
||||
extern int NIO_Linux_SetTimestampSocketOptions(int sock_fd, int client_only, int *events);
|
||||
|
||||
extern int NIO_Linux_ProcessMessage(SCK_Message *message, NTP_Local_Address *local_addr,
|
||||
|
|
|
@ -35,6 +35,7 @@ static struct timespec current_time;
|
|||
static NTP_Packet req_buffer, res_buffer;
|
||||
static int req_length, res_length;
|
||||
|
||||
#define NIO_IsHwTsEnabled() 1
|
||||
#define NIO_OpenServerSocket(addr) ((addr)->ip_addr.family != IPADDR_UNSPEC ? 100 : 0)
|
||||
#define NIO_CloseServerSocket(fd) assert(fd == 100)
|
||||
#define NIO_OpenClientSocket(addr) ((addr)->ip_addr.family != IPADDR_UNSPEC ? 101 : 0)
|
||||
|
@ -106,13 +107,9 @@ send_request(NCR_Instance inst, int late_hwts)
|
|||
}
|
||||
|
||||
if (late_hwts) {
|
||||
inst->had_hw_tx_timestamp = 1;
|
||||
inst->report.total_good_count++;
|
||||
} else {
|
||||
if (random() % 2)
|
||||
inst->had_hw_tx_timestamp = 0;
|
||||
else
|
||||
inst->report.total_good_count = 0;
|
||||
inst->report.total_good_count = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue