From: Mike Brady <4265913+mikebrady@users.noreply.github.com> Date: Thu, 25 Nov 2021 20:29:51 +0000 (+0000) Subject: Only install a service file if there isn't one there already. X-Git-Tag: 1.2~75 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cd39871771a34b230ce3e95fd5dce2fd98b93056;p=thirdparty%2Fnqptp.git Only install a service file if there isn't one there already. --- diff --git a/Makefile.am b/Makefile.am index 660d6cf..ed4c275 100644 --- a/Makefile.am +++ b/Makefile.am @@ -21,7 +21,8 @@ install-exec-hook: if BUILD_FOR_LINUX if INSTALL_SYSTEMD_STARTUP [ -e $(DESTDIR)$(libdir)/systemd/system ] || mkdir -p $(DESTDIR)$(libdir)/systemd/system - cp nqptp.service $(DESTDIR)$(libdir)/systemd/system +# don't replace a service file if it already exists... + [ -e $(DESTDIR)$(libdir)/systemd/system/nqptp.service ] || cp nqptp.service $(DESTDIR)$(libdir)/systemd/system endif endif # no installer for FreeBSD yet diff --git a/nqptp-clock-sources.h b/nqptp-clock-sources.h index 3085ab1..0094f3c 100644 --- a/nqptp-clock-sources.h +++ b/nqptp-clock-sources.h @@ -43,6 +43,7 @@ typedef struct { typedef struct { char ip[64]; // 64 is nicely aligned and bigger than INET6_ADDRSTRLEN (46) int family; // AF_INET or AF_INET6 + int follow_up_number; int announcements_without_followups; // add 1 for every announce, reset with a followup uint64_t clock_id; uint64_t local_time; // the local time when the offset was calculated diff --git a/nqptp-message-handlers.c b/nqptp-message-handlers.c index 31dc9f8..87cd6c4 100644 --- a/nqptp-message-handlers.c +++ b/nqptp-message-handlers.c @@ -232,6 +232,7 @@ void handle_follow_up(char *buf, __attribute__((unused)) ssize_t recv_len, struct ptp_follow_up_message *msg = (struct ptp_follow_up_message *)buf; + uint16_t seconds_hi = nctohs(&msg->follow_up.preciseOriginTimestamp[0]); uint32_t seconds_low = nctohl(&msg->follow_up.preciseOriginTimestamp[2]); uint32_t nanoseconds = nctohl(&msg->follow_up.preciseOriginTimestamp[6]); @@ -242,6 +243,8 @@ void handle_follow_up(char *buf, __attribute__((unused)) ssize_t recv_len, preciseOriginTimestamp = preciseOriginTimestamp + nanoseconds; // update our sample information + if (clock_private_info->follow_up_number < 100) + clock_private_info->follow_up_number++; clock_private_info->announcements_without_followups = 0; // we've seen a followup @@ -359,38 +362,27 @@ void handle_follow_up(char *buf, __attribute__((unused)) ssize_t recv_len, } else if (clock_private_info->previous_offset_time != 0) { // 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 = 60000000000; // nanoseconds + int64_t sync_timeout = 15000000000; // nanoseconds debug(2, "Sync interval: %f seconds.", 0.000000001 * time_since_last_sync); if (time_since_last_sync < sync_timeout) { // Do acceptance checking. // If the new offset is greater, by any amount, than the old offset, - // accept it. - // If it is less than the new offset by up to what a reasonable drift divergence would allow, + // or if it is less by up to 10 mS, // accept it. // Otherwise, reject it - // A drift divergence of 100 ppm would give 12.5 us per 125 ms. - jitter = offset - clock_private_info->previous_offset; - uint64_t jitter_timing_interval = reception_time - clock_private_info->previous_offset_time; - long double jitterppm = 0.0; - if (jitter_timing_interval != 0) { - jitterppm = (0.001 * (jitter * 1000000000)) / jitter_timing_interval; - debug(2, "jitter: %" PRId64 " in: %" PRId64 " ns, %+f ppm ", jitter, jitter_timing_interval, - jitterppm); - } - if (jitterppm >= -1000) { - // we take a positive or small negative jitter as a sync event - // as we have a new figure for the difference between the local clock and the - // remote clock which is almost the same or greater than our previous estimate + if (jitter > -10000000) { + // we take any positive or a limited negative jitter as a sync event + if (jitter < 0) + offset = clock_private_info->previous_offset + jitter/32; + else + offset = clock_private_info->previous_offset + jitter/32; clock_private_info->last_sync_time = reception_time; } else { - // let our previous estimate drop fall back by this many nanoseconds - jitter = -10 * 1000; // this is nanoseconds in, supposedly, 125 milliseconds. 12.5 us / - // 125 ms is 100 ppm. - offset = clock_private_info->previous_offset + jitter; + offset = clock_private_info->previous_offset; // forget the present sample... } } else { if ((clock_private_info->flags & (1 << clock_is_master)) != 0) @@ -407,6 +399,7 @@ void handle_follow_up(char *buf, __attribute__((unused)) ssize_t recv_len, 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.",