From a7c9ad3e27989498fb4bc6c2c2ead792df35125d Mon Sep 17 00:00:00 2001 From: Mike Brady <4265913+mikebrady@users.noreply.github.com> Date: Mon, 20 Dec 2021 12:07:53 +0000 Subject: [PATCH] Modify code so that all the sampling stuff can be omitted. This is to try to simplify the code. --- nqptp-clock-sources.c | 2 ++ nqptp-clock-sources.h | 7 ++++++- nqptp-message-handlers.c | 10 ++++++++-- nqptp.c | 3 ++- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/nqptp-clock-sources.c b/nqptp-clock-sources.c index 90349c9..1faac43 100644 --- a/nqptp-clock-sources.c +++ b/nqptp-clock-sources.c @@ -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"); diff --git a/nqptp-clock-sources.h b/nqptp-clock-sources.h index b6d14d6..85720e7 100644 --- a/nqptp-clock-sources.h +++ b/nqptp-clock-sources.h @@ -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 diff --git a/nqptp-message-handlers.c b/nqptp-message-handlers.c index 88e95d3..1f7b6d2 100644 --- a/nqptp-message-handlers.c +++ b/nqptp-message-handlers.c @@ -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 e4a0bac..4389dd8 100644 --- 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); -- 2.47.2