From: Mike Brady <4265913+mikebrady@users.noreply.github.com> Date: Tue, 14 Dec 2021 16:15:25 +0000 (+0000) Subject: Try to improve the reliability of restarting a "silent clock" device. Also turn off... X-Git-Tag: 1.2~65^2 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=7768493b7eda2930994e9739af1db4ab02a42204;p=thirdparty%2Fnqptp.git Try to improve the reliability of restarting a "silent clock" device. Also turn off history (mostly) to see if we can make things simpler. --- diff --git a/nqptp-clock-sources.h b/nqptp-clock-sources.h index 4d9a853..b6d14d6 100644 --- a/nqptp-clock-sources.h +++ b/nqptp-clock-sources.h @@ -34,7 +34,8 @@ typedef enum { } clock_flags; // 8 samples per seconds -#define MAX_TIMING_SAMPLES 47 +// #define MAX_TIMING_SAMPLES 47 +#define MAX_TIMING_SAMPLES 1 typedef struct { uint64_t local_time, clock_time; } timing_samples; diff --git a/nqptp-message-handlers.c b/nqptp-message-handlers.c index 4783762..c3ca155 100644 --- a/nqptp-message-handlers.c +++ b/nqptp-message-handlers.c @@ -41,6 +41,7 @@ void handle_control_port_messages(char *buf, ssize_t recv_len, for (i = 0; i < MAX_CLOCKS; i++) { clock_private_info[i].flags &= ~(1 << clock_is_a_timing_peer); // turn off peer flag (but not the master flag!) + clock_private_info[i].announcements_without_followups = 0; // to allow a possibly silent clocks to be revisited when added to a timing peer list } while (ip_list != NULL) { @@ -58,7 +59,7 @@ void handle_control_port_messages(char *buf, ssize_t recv_len, // now find and mark the best clock in the timing peer list as the master update_master(); - + debug(2, "Timing group start"); for (i = 0; i < MAX_CLOCKS; i++) { if ((clock_private_info[i].flags & (1 << clock_is_a_timing_peer)) != 0) @@ -270,6 +271,13 @@ void handle_follow_up(char *buf, __attribute__((unused)) ssize_t recv_len, clock_private_info->local_to_source_time_offset = offset; int64_t jitter = 0; + + int64_t time_since_previous_offset = 0; + + if (clock_private_info->previous_offset_time != 0) { + time_since_previous_offset = reception_time - clock_private_info->previous_offset_time; + } + if ((clock_private_info->flags & (1 << clock_is_becoming_master)) != 0) { // we definitely have at least one sample since the request was made to @@ -360,7 +368,7 @@ void handle_follow_up(char *buf, __attribute__((unused)) ssize_t recv_len, clock_private_info->flags |= 1 << clock_is_master; clock_private_info->previous_offset_time = 0; debug_log_nqptp_status(2); - } else if (clock_private_info->previous_offset_time != 0) { + } else if ((clock_private_info->previous_offset_time != 0) && (time_since_previous_offset < 5000000000)) { // i.e. if it's not becoming a master and there has been a previous follow_up int64_t time_since_last_sync = reception_time - clock_private_info->last_sync_time; int64_t sync_timeout = 15000000000; // nanoseconds @@ -413,13 +421,17 @@ void handle_follow_up(char *buf, __attribute__((unused)) ssize_t recv_len, } } else { clock_private_info->last_sync_time = reception_time; + if (time_since_previous_offset >= 5000000000) { + debug(1,"Long interval: %f seconds since previous follow_up", time_since_previous_offset * 1E-9); + clock_private_info->mastership_start_time = reception_time; // mastership is reset to this time... + clock_private_info->previous_offset_time = 0; + } } clock_private_info->previous_offset = offset; clock_private_info->previous_offset_time = reception_time; if ((clock_private_info->flags & (1 << clock_is_master)) != 0) { - update_master_clock_info(clock_private_info->clock_id, (const char *)&clock_private_info->ip, reception_time, offset, clock_private_info->mastership_start_time); debug(3, "clock: %" PRIx64 ", time: %" PRIu64 ", offset: %" PRId64 ", jitter: %+f ms.", diff --git a/nqptp.c b/nqptp.c index 64f85c6..e38cc1c 100644 --- a/nqptp.c +++ b/nqptp.c @@ -89,6 +89,8 @@ int epoll_fd; void update_master_clock_info(uint64_t master_clock_id, const char *ip, uint64_t local_time, uint64_t local_to_master_offset, uint64_t mastership_start_time) { + + //debug(1,"update_master_clock_info start"); if (shared_memory->master_clock_id != master_clock_id) debug_log_nqptp_status(1); int rc = pthread_mutex_lock(&shared_memory->shm_mutex); @@ -108,6 +110,7 @@ void update_master_clock_info(uint64_t master_clock_id, const char *ip, uint64_t rc = pthread_mutex_unlock(&shared_memory->shm_mutex); if (rc != 0) warn("Can't release mutex after updating master clock!"); + //debug(1,"update_master_clock_info done"); } void goodbye(void) { @@ -515,7 +518,7 @@ uint64_t broadcasting_task(uint64_t call_time, __attribute__((unused)) void *pri msg->announce.grandmasterPriority1 = 250; } - msg->announce.grandmasterPriority1 = 250; + msg->announce.grandmasterPriority2 = clocks_private[i].grandmasterPriority2; ret = sendto(s, msg, msg_length, 0, res->ai_addr, res->ai_addrlen); if (ret == -1) debug(1, "result of second sendto is %d.", ret);