]> git.ipfire.org Git - thirdparty/nqptp.git/commitdiff
Modify code so that all the sampling stuff can be omitted. This is to try to simplify...
authorMike Brady <4265913+mikebrady@users.noreply.github.com>
Mon, 20 Dec 2021 12:07:53 +0000 (12:07 +0000)
committerMike Brady <4265913+mikebrady@users.noreply.github.com>
Mon, 20 Dec 2021 12:07:53 +0000 (12:07 +0000)
nqptp-clock-sources.c
nqptp-clock-sources.h
nqptp-message-handlers.c
nqptp.c

index 90349c9a31227ce00ce48c6ee71460da9b5bace6..1faac43391912899eb2ee22236543d2718c55e2d 100644 (file)
@@ -86,7 +86,9 @@ int create_clock_source_record(char *sender_string,
       strncpy((char *)&clocks_private_info[i].ip, sender_string,
               FIELD_SIZEOF(clock_source_private_data, ip) - 1);
       clocks_private_info[i].family = family;
+#ifdef MAX_TIMING_SAMPLES
       clocks_private_info[i].vacant_samples = MAX_TIMING_SAMPLES;
+#endif
       clocks_private_info[i].in_use = 1;
       debug(2, "create record for ip: %s, family: %s.", &clocks_private_info[i].ip,
             clocks_private_info[i].family == AF_INET6 ? "IPv6" : "IPv4");
index b6d14d67730dc5dc82343ae5f79673dd499e69de..85720e7914af68fb36127f50f9250fe779aae0b7 100644 (file)
@@ -35,10 +35,13 @@ typedef enum {
 
 // 8 samples per seconds
 // #define MAX_TIMING_SAMPLES 47
-#define MAX_TIMING_SAMPLES 1
+// #define MAX_TIMING_SAMPLES 1
+
+#ifdef MAX_TIMING_SAMPLES
 typedef struct {
   uint64_t local_time, clock_time;
 } timing_samples;
+#endif
 
 // information about each clock source
 typedef struct {
@@ -63,10 +66,12 @@ typedef struct {
   uint64_t announce_times[4]; // we'll check qualification and currency using these
   int is_one_of_ours;         // true if it is one of our own clocks
 
+#ifdef MAX_TIMING_SAMPLES
   timing_samples samples[MAX_TIMING_SAMPLES];
   int vacant_samples; // the number of elements in the timing_samples array that are not yet used
   int next_sample_goes_here; // point to where in the timing samples array the next entries should
                              // go
+#endif
 
   // these are for finding the best clock to use
   // See Figure 27 and 27 pp 89 -- 90 for the Data set comparison algorithm
index 88e95d3bf059128a1e96bdb06cf91db3a12b6c4d..1f7b6d20262c51189d2f6272aab3dbce13094858 100644 (file)
@@ -250,6 +250,7 @@ void handle_follow_up(char *buf, __attribute__((unused)) ssize_t recv_len,
 
   clock_private_info->announcements_without_followups = 0; // we've seen a followup
 
+#ifdef MAX_TIMING_SAMPLES
   clock_private_info->samples[clock_private_info->next_sample_goes_here].local_time =
       reception_time;
   clock_private_info->samples[clock_private_info->next_sample_goes_here].clock_time =
@@ -262,6 +263,7 @@ void handle_follow_up(char *buf, __attribute__((unused)) ssize_t recv_len,
   // if we have need to wrap.
   if (clock_private_info->next_sample_goes_here == MAX_TIMING_SAMPLES)
     clock_private_info->next_sample_goes_here = 0;
+#endif
 
   debug(2, "FOLLOWUP from %" PRIx64 ", %s.", clock_private_info->clock_id, &clock_private_info->ip);
   uint64_t offset = preciseOriginTimestamp - reception_time;
@@ -283,6 +285,7 @@ void handle_follow_up(char *buf, __attribute__((unused)) ssize_t recv_len,
     // we definitely have at least one sample since the request was made to
     // designate it a master, so we assume it is legitimate. That is, we assume
     // that the clock originator knows that it a clock master by now.
+#ifdef MAX_TIMING_SAMPLES
     uint64_t oldest_acceptable_master_clock_time =
         clock_private_info->source_time + 1150000000; // ns.
 
@@ -357,13 +360,14 @@ void handle_follow_up(char *buf, __attribute__((unused)) ssize_t recv_len,
     clock_private_info->mastership_start_time = age_of_oldest_legitimate_sample;
     int64_t offset_difference =
         best_offset_so_far - clock_private_info->local_to_source_time_offset;
-
     debug(2, "Lookback difference: %f ms with %d samples checked of %d samples total.",
           0.000001 * offset_difference, samples_checked, number_of_samples);
     clock_private_info->local_to_source_time_offset = best_offset_so_far;
-
     debug(2, "Master sampling started %f ms before becoming master.",
           0.000001 * (reception_time - age_of_oldest_legitimate_sample));
+#else
+    clock_private_info->mastership_start_time = clock_private_info->local_time;
+#endif
     clock_private_info->flags &= ~(1 << clock_is_becoming_master);
     clock_private_info->flags |= 1 << clock_is_master;
     clock_private_info->previous_offset_time = 0;
@@ -418,6 +422,8 @@ void handle_follow_up(char *buf, __attribute__((unused)) ssize_t recv_len,
               clock_private_info->ip);
       // leave the offset as it was coming in and take it as a sync time
       clock_private_info->last_sync_time = reception_time;
+      clock_private_info->mastership_start_time = reception_time; // mastership is reset to this time...
+      clock_private_info->previous_offset_time = 0;
     }
   } else {
     clock_private_info->last_sync_time = reception_time;
diff --git a/nqptp.c b/nqptp.c
index e4a0bac604337783dc9a1f3383e077b30389c721..4389dd81556049dcee2ca390f19dd9a9a092c2cb 100644 (file)
--- a/nqptp.c
+++ b/nqptp.c
@@ -89,7 +89,7 @@ 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);
@@ -105,6 +105,7 @@ void update_master_clock_info(uint64_t master_clock_id, const char *ip, uint64_t
             FIELD_SIZEOF(struct shm_structure, master_clock_ip) - 1);
   else
     shared_memory->master_clock_ip[0] = '\0';
+  shared_memory->master_clock_start_time = mastership_start_time;
   shared_memory->local_time = local_time;
   shared_memory->local_to_master_time_offset = local_to_master_offset;
   rc = pthread_mutex_unlock(&shared_memory->shm_mutex);