Discussion:
[Linuxptp-devel] phc2sys -a -r in master-only ordinary clock system
Belogaj, Dmitrij
2016-08-16 12:57:22 UTC
Permalink
Dear Richard Cochran,
dear Linuxptp-devel members,

First of all, thank You, Richard, for the amazing product! The set of tools and the ptp4l daemon provide invaluable help in 1588 integration into a system.

My name is Dmitrij Belogaj, I am an application engineer at Intel, and right now I am struggling with an issue on a "master-only ordinary clock" (MOOC) system.
Somehow I am already familiar with the linuxptp source code and try to adapt it to our needs.
Couple of days ago I got stuck at one issue, for which I found a quick-hack solution. However, I would like to understand why You have implemented the code exactly how it is now.
Maybe, there are some reasons unobvious for me.

You all know the "phc2sys -a -r" call to automatically synchronize the clocks across the system including the CLOCK_REALTIME.
Now imagine please a MOOC system with one PHC and the CLOCK_REALTIME. The PHC is the reference clock used by 1588 master for timestamping. The PHC itself is synchronized to the GPS by HW means. Now, I want to synchronize the CLOCK_REALTIME to the PHC. However, when I start "phc2sys -a -r", I get "nothing to synchronize" message.

During source code analysis I've found the function reconfigure(node) in the phc2sys.c. In the LIST_FOREACH(...) loop there are counted source and destination clocks. Since the PHC is a PS_MASTER clock, it's being counted as a destination clock:

switch (c->state) {
case PS_FAULTY:
case PS_DISABLED:
case PS_LISTENING:
case PS_PRE_MASTER:
case PS_MASTER:
case PS_PASSIVE:
pr_info("selecting %s for synchronization", c->device);
dst_cnt++;
break;
case PS_UNCALIBRATED:
src_cnt++;
break;
case PS_SLAVE:
src = c;
src_cnt++;
break;
}
Since there is neither PS_SLAVE nor PS_UNCALIBRATED clocks in the system, but only the master PHC and the CLOCK_REALTIME, the phc2sys rejects synchronizing them.
Without long speculations I have moved the PS_MASTER case next to PS_SLAVE like this:

switch (c->state) {
case PS_FAULTY:
case PS_DISABLED:
case PS_LISTENING:
case PS_PRE_MASTER:
case PS_PASSIVE:
pr_info("selecting %s for synchronization", c->device);
dst_cnt++;
break;
case PS_UNCALIBRATED:
src_cnt++;
break;
case PS_SLAVE:
case PS_MASTER:
src = c;
src_cnt++;
break;
}
and the CLOCK_REALTIME has synchronized to the PHC immediately without problems.
And now, I have the question mentioned above: what was the reason to hard-code the PS_MASTER to the destination clocks? I agree that in Boundary Clock systems the master side is a driven one, and exactly the slave side (with this highest clock quality) is a driving one, the reference one. But on the MOOC system the choice is pretty limited to the master PHC only.
How do You think, would it be correct to add handling for the MOOC case to the code? Let's say, if after the LIST_FOREACH() loop the src_cnt remains 0, but there is a PS_MASTER clock found, it should be taken as a source.
Maybe, You see some pitfalls here?

Thank You in advance.

Best regards,
Dmitrij Belogaj
Richard Cochran
2016-08-16 15:19:34 UTC
Permalink
Post by Belogaj, Dmitrij
And now, I have the question mentioned above: what was the reason to
hard-code the PS_MASTER to the destination clocks? I agree that in
Boundary Clock systems the master side is a driven one, and exactly
the slave side (with this highest clock quality) is a driving one,
the reference one.
You answered your own question. That is the reason.
Post by Belogaj, Dmitrij
But on the MOOC system the choice is pretty
limited to the master PHC only. How do You think, would it be
correct to add handling for the MOOC case to the code? Let's say, if
after the LIST_FOREACH() loop the src_cnt remains 0, but there is a
PS_MASTER clock found, it should be taken as a source.
You have a single port GM, and the PHC is synchronized to GPS. Just
run phc2sys without the -a option and specify the offset with -O and
the PHC with -s. Since the GPS program knows what is going on, it can
call out to phc2sys (and ptp4l for that matter), depending the
synchronization state of the receiver.

HTH,
Richard



------------------------------------------------------------------------------
Belogaj, Dmitrij
2016-08-17 08:00:57 UTC
Permalink
Hello Richard,

Thank You for the answers.

I forgot to mention that it was decided to use the -a option to get UtcOffset and leap announcements from ptp4l.
Without -a but with -O, we do not get the automatic kernel leap and UtcOffset mechanism as via pmc -> uds -> ptp4l -> (phc2sys -a -r) -> CLOCK_REALTIME. All this should be independent from the method used to synchronize the GM's PHC. Just assume the PHC has a free running TAI time with sufficient accuracy.

Best Regards,
Dmitrij.

-----Original Message-----
From: Richard Cochran [mailto:***@gmail.com]
Sent: Tuesday, August 16, 2016 5:20 PM
To: Belogaj, Dmitrij <***@intel.com>
Cc: linuxptp-***@lists.sourceforge.net
Subject: Re: [Linuxptp-devel] phc2sys -a -r in master-only ordinary clock system
Post by Belogaj, Dmitrij
And now, I have the question mentioned above: what was the reason to
hard-code the PS_MASTER to the destination clocks? I agree that in
Boundary Clock systems the master side is a driven one, and exactly
the slave side (with this highest clock quality) is a driving one, the
reference one.
You answered your own question. That is the reason.
Post by Belogaj, Dmitrij
But on the MOOC system the choice is pretty limited to the master PHC
only. How do You think, would it be correct to add handling for the
MOOC case to the code? Let's say, if after the LIST_FOREACH() loop the
src_cnt remains 0, but there is a PS_MASTER clock found, it should be
taken as a source.
You have a single port GM, and the PHC is synchronized to GPS. Just run phc2sys without the -a option and specify the offset with -O and the PHC with -s. Since the GPS program knows what is going on, it can call out to phc2sys (and ptp4l for that matter), depending the synchronization state of the receiver.

HTH,
Richard



------------------------------------------------------------------------------
Richard Cochran
2016-08-17 09:40:34 UTC
Permalink
Post by Belogaj, Dmitrij
Hello Richard,
Thank You for the answers.
I forgot to mention that it was decided to use the -a option to get UtcOffset and leap announcements from ptp4l.
Without -a but with -O, we do not get the automatic kernel leap and UtcOffset mechanism as via pmc -> uds -> ptp4l -> (phc2sys -a -r) -> CLOCK_REALTIME. All this should be independent from the method used to synchronize the GM's PHC. Just assume the PHC has a free running TAI time with sufficient accuracy.
If you are the GM, then you had better well know the leap seconds.
The GM is expected to provide this information! Last time I checked,
the GPS system does in fact provide leap second notification.

We cannot reasonably provide a GM implementation that works for
everybody. The HW details are simply too diverse. All the bit and
pieces are there, and it is up to you to integrate them.

In any case, you idea of handling the MASTER state like SLAVE in
automatic mode is all wrong. The right way would be to detect if all
ports are in the MASTER state, but that is much more work, I think.

Thanks,
Richard


------------------------------------------------------------------------------
Loading...