Hi everyone,
We are using Linux kernel API that implements RFC2783 for PPS edge detection,
but the GPSd implementation has an issue for our use case: it uses timestamps
from realtime clock provided by the kernel, this means that if the clock is
step back into the past, GPSd loses a single PPS, which is critical for our
system. Why doesn't GPSd use sequence numbers to detect edge changes like we
suggest in the following diff:
diff --git a/gpsd/ppsthread.c b/gpsd/ppsthread.c
index 739aa0862..7c6344e27 100644
--- a/gpsd/ppsthread.c
+++ b/gpsd/ppsthread.c
@@ -130,6 +130,7 @@ struct inner_context_t {
#if defined(HAVE_SYS_TIMEPPS_H)
int pps_caps; // RFC2783 getcaps()
pps_handle_t kernelpps_handle;
+ pps_handle_t prev_pi;
#endif // defined(HAVE_SYS_TIMEPPS_H)
};
@@ -655,8 +656,11 @@ static int get_edge_rfc2783(struct inner_context_t
*inner_context,
}
// find the last edge
- TS_SUB(&pi_diff, &pi.assert_timestamp, &pi.clear_timestamp);
- if (TS_GZ(&pi_diff)) {
+ /* Determine the last edge using RFC2783 sequence numbers.
+ * Rationale: system time can slew or go backwards, making timestamp
+ * comparison unreliable. Sequence numbers monotonically increase per
+ * edge type, so use them to identify the most recent edge. */
+ if (pi.assert_sequence > inner_context->prev_pi.assert_sequence) {
// assert after clear
*edge = 1;
*prev_edge = 0;
@@ -677,6 +681,7 @@ static int get_edge_rfc2783(struct inner_context_t
*inner_context,
*prev_clock_ts = pi.assert_timestamp;
*clock_ts = pi.clear_timestamp;
}
+ inner_context->prev_pi = pi;
/*
* pps_seq_t is uint32_t on NetBSD, so cast to
* unsigned long as a wider-or-equal type to
This email message and any attachments are intended solely for the use of the
addressees hereof.
This message and any attachments may contain information that is confidential,
privileged and exempt from disclosure under applicable law.
If you are not the intended recipient of this message, you are prohibited from
reading, disclosing, reproducing, distributing, disseminating or otherwise
using this transmission.
If you have received this message in error, please promptly notify the sender
at Ceragon by reply E-mail and immediately delete this message from your system.