]> git.ipfire.org Git - thirdparty/nqptp.git/commitdiff
Try to improve the reliability of restarting a "silent clock" device. Also turn off...
authorMike Brady <4265913+mikebrady@users.noreply.github.com>
Tue, 14 Dec 2021 16:15:25 +0000 (16:15 +0000)
committerMike Brady <4265913+mikebrady@users.noreply.github.com>
Tue, 14 Dec 2021 16:15:25 +0000 (16:15 +0000)
nqptp-clock-sources.h
nqptp-message-handlers.c
nqptp.c

index 4d9a853d843c581047f51180d3683131a48aabbd..b6d14d67730dc5dc82343ae5f79673dd499e69de 100644 (file)
@@ -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;
index 47837620d4876d7dab13329f5ee0ea3b22908507..c3ca15571a22c611212788cdf2454aa1a7417edc 100644 (file)
@@ -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 64f85c6986ce1d44ba33a7730bd6ee661363ed14..e38cc1c9c6ef6f41bec2ad029b9e269fe228917d 100644 (file)
--- 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);