Skip to content

Commit

Permalink
ts2phc: Use CLOCK_MONOTONIC_RAW for NMEA PPS timestamp.
Browse files Browse the repository at this point in the history
In the calculation of the NMEA PPS timestamp is used an interval
measured by the CLOCK_MONOTONIC system clock. This clock may have a
large frequency error when another process (e.g. phc2sys or an NTP
client) is correcting a large time error by slewing.

This frequency error may cause the timestamp to overflow into the next
second and cause a one-second error in the measured offset, or the wrong
edge of the pulse to be rejected.

Switch from CLOCK_MONOTONIC to CLOCK_MONOTONIC_RAW to avoid the
impact of the system clock adjustments.

Signed-off-by: Miroslav Lichvar <[email protected]>
  • Loading branch information
mlichvar authored and richardcochran committed Jun 4, 2024
1 parent 1a307a1 commit d32aa83
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ts2phc_nmea_pps_source.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ static void *monitor_nmea_status(void *arg)
}
}
num = poll(&pfd, 1, NMEA_TMO);
clock_gettime(CLOCK_MONOTONIC, &rxtime);
clock_gettime(CLOCK_MONOTONIC_RAW, &rxtime);
clock_gettime(CLOCK_REALTIME, &rxtime_rt);
if (num < 0) {
pr_err("poll failed");
Expand Down Expand Up @@ -160,7 +160,7 @@ static int ts2phc_nmea_pps_source_getppstime(struct ts2phc_pps_source *src,
int64_t utc_time;
bool fix_valid;

clock_gettime(CLOCK_MONOTONIC, &now);
clock_gettime(CLOCK_MONOTONIC_RAW, &now);
local_t2 = timespec_to_tmv(now);

pthread_mutex_lock(&m->mutex);
Expand Down

0 comments on commit d32aa83

Please sign in to comment.