On Tue, Nov 23, 2021 at 02:14:20AM +0200, Vladimir Oltean wrote:
> Now that we are registering a clock even for the PPS source when it
> supports that (i.e. when it is a PHC), introduce a new API to retrieve
> its clock in order to add timestamps to it.
> 
> The timestamps are a mere approximation.

The time stamps are not an approximation.  They are quite exact.
The phase is definitely at the full second, but the ToD of that second
is only known implicitly.

The word you are looking for is "ambiguous".

> We configure the kernel to emit
> periodic output and then never hear back from that PHC again. We just
> assume that it emits periodic output as promised, and that each pulse is
> emitted at the beginning of each second. We rely on the PPS sinks to
> report an extts event first, and we know who generated that - the PPS
> source, of course. So then we proceed to read the PPS source's PHC time,
> and round that to what is the most plausible integer second in its time
> base. We believe that to be the 'timestamp'. This is fed into the servo
> algorithm.
> 
> The PHC PPS source can be synchronized to the extts events of a PHC
> slave, when in automatic mode.
> 
> Signed-off-by: Vladimir Oltean <olte...@gmail.com>
> ---
> v4->v5:
> - rebase on top of data structure renames
> v3->v4:
> Add one more paragraph to commit message.
> v2->v3:
> Implement ts2phc_master_get_clock() as part of ts2phc_master.c instead
> of ts2phc_phc_master.c.
> 
>  ts2phc.c                    | 45 ++++++++++++++++++++++++++++++++++++-
>  ts2phc_phc_pps_source.c     |  9 ++++++++
>  ts2phc_pps_source.c         |  8 +++++++
>  ts2phc_pps_source.h         |  2 ++
>  ts2phc_pps_source_private.h |  1 +
>  5 files changed, 64 insertions(+), 1 deletion(-)
> 
> diff --git a/ts2phc.c b/ts2phc.c
> index 0968ef28ca73..25c8bb3a5fa6 100644
> --- a/ts2phc.c
> +++ b/ts2phc.c
> @@ -482,6 +482,42 @@ static void ts2phc_synchronize_clocks(struct 
> ts2phc_private *priv, int autocfg)
>       }
>  }
>  
> +static int ts2phc_collect_pps_source_tstamp(struct ts2phc_private *priv)
> +{
> +     struct ts2phc_clock *pps_src_clock;
> +     struct timespec source_ts;
> +     int err;
> +
> +     pps_src_clock = ts2phc_pps_source_get_clock(priv->src);
> +     /*
> +      * PPS source isn't a PHC (it may be a generic or a GPS PPS source),
> +      * don't error out, just don't do anything. If it doesn't have a PHC,
> +      * there is nothing to synchronize, which is the only point of
> +      * collecting its perout timestamp in the first place.
> +      */
> +     if (!pps_src_clock)
> +             return 0;
> +
> +     err = ts2phc_pps_source_getppstime(priv->src, &source_ts);
> +     if (err < 0) {
> +             pr_err("source ts not valid");
> +             return err;
> +     }
> +
> +     /*
> +      * As long as the kernel doesn't support a proper API for reporting
> +      * a precise perout timestamp, we'll have to use this crude
> +      * approximation.
> +      */

Not crude and not an approximation.

> +     if (source_ts.tv_nsec > NS_PER_SEC / 2)
> +             source_ts.tv_sec++;
> +     source_ts.tv_nsec = 0;
> +
> +     ts2phc_clock_add_tstamp(pps_src_clock, timespec_to_tmv(source_ts));
> +
> +     return 0;
> +}

Thanks,
Richard


_______________________________________________
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel

Reply via email to