Thread: [Linuxptp-users] Dynamically sync clocks with phc2sys depending on master/slave
PTP IEEE 1588 stack for Linux
Brought to you by:
rcochran
From: Peter B. <pe...@be...> - 2021-10-12 20:03:56
|
Hi, I'm currently working on a network product using gPTP configuration for PTP sync. The device shall be a AVB endpoint handling audio and according to Avnu specifications all endpoint shall be capable of being master on the network. Some plugins for AVB (such as gstreamer and alsa-plugins) require that system time (CLOCK_REALTIME) is in sync with PHC to get correct timing. I see different cases depending on if the device is master or slave. If the device is slave I would like to sync PHC to CLOCK_REALTIME. The other way around, if device is master I would like to sync CLOCK_REALTIME to PHC. To the question; is there a way to use phc2sys and handle this automatically? What I currently do manually is (linuxptp version 3.1): $ ptp4l -i eth1 -f /etc/linuxptp/gPTP.cfg On the device becoming master: $ phc2sys -c eth1 -s CLOCK_REALTIME --step_threshold=1 --transportSpecific=1 -w On the device becoming slave: $ phc2sys -c CLOCK_REALTIME -s eth1 --step_threshold=1 --transportSpecific=1 -w It would be good if the above could be dynamic. Starting everything as services and let the system sync itself. /Peter |
From: Richard C. <ric...@gm...> - 2021-10-12 22:20:06
|
On Tue, Oct 12, 2021 at 09:47:21PM +0200, Peter Bergin wrote: > Hi, > > I'm currently working on a network product using gPTP configuration for PTP > sync. The device shall be a AVB endpoint handling audio and according to > Avnu specifications all endpoint shall be capable of being master on the > network. Some plugins for AVB (such as gstreamer and alsa-plugins) require > that system time (CLOCK_REALTIME) is in sync with PHC to get correct timing. > I see different cases depending on if the device is master or slave. If the > device is slave I would like to sync PHC to CLOCK_REALTIME. The other way > around, if device is master I would like to sync CLOCK_REALTIME to PHC. > > To the question; is there a way to use phc2sys and handle this > automatically? phc2sys has an automatic mode. See the man page for details. Thanks, Richard |
From: Peter B. <pe...@be...> - 2021-10-13 07:51:13
|
Hi, On 2021-10-13 00:19, Richard Cochran wrote: > On Tue, Oct 12, 2021 at 09:47:21PM +0200, Peter Bergin wrote: >> Hi, >> >> I'm currently working on a network product using gPTP configuration for PTP >> sync. The device shall be a AVB endpoint handling audio and according to >> Avnu specifications all endpoint shall be capable of being master on the >> network. Some plugins for AVB (such as gstreamer and alsa-plugins) require >> that system time (CLOCK_REALTIME) is in sync with PHC to get correct timing. >> I see different cases depending on if the device is master or slave. If the >> device is slave I would like to sync PHC to CLOCK_REALTIME. The other way >> around, if device is master I would like to sync CLOCK_REALTIME to PHC. >> >> To the question; is there a way to use phc2sys and handle this >> automatically? > phc2sys has an automatic mode. See the man page for details. > Thanks! My bad, should have read man pages better. And I did try '-a' but had issues with it. To summarize for other users: $ ./phc2sys -a -r -r -q -m phc2sys[412816.955]: Waiting for ptp4l... phc2sys[412817.956]: Waiting for ptp4l... I had trouble communicating over UDS between ptp4l and phc2sys. The problem was that I'm working with gPTP (IEEE 802.11AS) and the setting transportSpecific didn't match between ptp4l and phc2sys. So the solution was, as stated in the man page, to add '--transportSpecific=1' when starting phc2sys and the issue was solved. ptp4l just silently drops messages if transportSpecific don't match (and ignore_transport_specific=0). I tried to debug this issue with help of debug messages (-l 7) but couldn't find it that way. Would it be a good thing to add debug prints when that happens to improve visibility? Or would that flood the log in some cases? diff --git a/port.c b/port.c index fa49663..1c04fc5 100644 --- a/port.c +++ b/port.c @@ -699,6 +699,8 @@ static int port_ignore(struct port *p, struct ptp_message *m) } if (p->match_transport_specific && msg_transport_specific(m) != p->transportSpecific) { + pr_debug("port %hu: transport_specific did not match, will drop message", + portnum(p)); return 1; } if (pid_eq(&m->header.sourcePortIdentity, &p->portIdentity)) { diff --git a/tc.c b/tc.c index 0346ba9..705f54c 100644 --- a/tc.c +++ b/tc.c @@ -478,6 +478,8 @@ int tc_ignore(struct port *p, struct ptp_message *m) if (p->match_transport_specific && msg_transport_specific(m) != p->transportSpecific) { + pr_debug("port %hu: transport_specific did not match, will drop message", + portnum(p)); return 1; } if (pid_eq(&m->header.sourcePortIdentity, &p->portIdentity)) { Thanks, /Peter |
From: Keller, J. E <jac...@in...> - 2021-10-13 17:41:30
|
On 10/13/2021 12:50 AM, Peter Bergin wrote: > Hi, > > On 2021-10-13 00:19, Richard Cochran wrote: >> On Tue, Oct 12, 2021 at 09:47:21PM +0200, Peter Bergin wrote: >>> Hi, >>> >>> I'm currently working on a network product using gPTP configuration for PTP >>> sync. The device shall be a AVB endpoint handling audio and according to >>> Avnu specifications all endpoint shall be capable of being master on the >>> network. Some plugins for AVB (such as gstreamer and alsa-plugins) require >>> that system time (CLOCK_REALTIME) is in sync with PHC to get correct timing. >>> I see different cases depending on if the device is master or slave. If the >>> device is slave I would like to sync PHC to CLOCK_REALTIME. The other way >>> around, if device is master I would like to sync CLOCK_REALTIME to PHC. >>> >>> To the question; is there a way to use phc2sys and handle this >>> automatically? >> phc2sys has an automatic mode. See the man page for details. >> > Thanks! My bad, should have read man pages better. And I did try '-a' > but had issues with it. To summarize for other users: > > $ ./phc2sys -a -r -r -q -m > phc2sys[412816.955]: Waiting for ptp4l... > phc2sys[412817.956]: Waiting for ptp4l... > > I had trouble communicating over UDS between ptp4l and phc2sys. The > problem was that I'm working with gPTP (IEEE 802.11AS) and the setting > transportSpecific didn't match between ptp4l and phc2sys. So the > solution was, as stated in the man page, to add '--transportSpecific=1' > when starting phc2sys and the issue was solved. > > ptp4l just silently drops messages if transportSpecific don't match (and > ignore_transport_specific=0). I tried to debug this issue with help of > debug messages (-l 7) but couldn't find it that way. Would it be a good > thing to add debug prints when that happens to improve visibility? Or > would that flood the log in some cases? > > diff --git a/port.c b/port.c > index fa49663..1c04fc5 100644 > --- a/port.c > +++ b/port.c > @@ -699,6 +699,8 @@ static int port_ignore(struct port *p, struct > ptp_message *m) > } > if (p->match_transport_specific && > msg_transport_specific(m) != p->transportSpecific) { > + pr_debug("port %hu: transport_specific did not match, > will drop message", > + portnum(p)); > return 1; > } > if (pid_eq(&m->header.sourcePortIdentity, &p->portIdentity)) { > diff --git a/tc.c b/tc.c > index 0346ba9..705f54c 100644 > --- a/tc.c > +++ b/tc.c > @@ -478,6 +478,8 @@ int tc_ignore(struct port *p, struct ptp_message *m) > > if (p->match_transport_specific && > msg_transport_specific(m) != p->transportSpecific) { > + pr_debug("port %hu: transport_specific did not match, > will drop message", > + portnum(p)); > return 1; > } > if (pid_eq(&m->header.sourcePortIdentity, &p->portIdentity)) { > > > Thanks, > /Peter > I'm ok with the debug prints. These would only display at the highest log level, so it would only clutter logs for those who are already debugging. Thanks, Jake > > > _______________________________________________ > Linuxptp-users mailing list > Lin...@li... > https://lists.sourceforge.net/lists/listinfo/linuxptp-users > |
From: Peter B. <pe...@be...> - 2021-10-14 09:04:36
|
Hi again, > phc2sys has an automatic mode. See the man page for details. I have some follow up question as I still can not see that I get this correct. I hope some experienced linuxptp users can help out. I can not get sync between CLOCK_REALTIME and PHC as I expect. I have two devices connected through a AVB Switch running gPTP config like the example from the repo. Only changed priority to 246 in order to become master instead of the AVB Switch. Both devices runnin glinuxptp version 3.1.1. Here is the config file used for ptp4l: # # 802.1AS example configuration containing those attributes which # differ from the defaults. See the file, default.cfg, for the # complete list of available options. # [global] gmCapable 1 priority1 246 priority2 246 logAnnounceInterval 0 logSyncInterval -3 syncReceiptTimeout 3 neighborPropDelayThresh 800 min_neighbor_prop_delay -20000000 assume_two_step 1 path_trace_enabled 1 follow_up_info 1 transportSpecific 0x1 ptp_dst_mac 01:80:C2:00:00:0E network_transport L2 delay_mechanism P2P On the first device I start and configure the linuxptp applications like this: $ ptp4l -i eth1 -f gPTP.cfg $ pmc -u -b 0 -t 1 "SET GRANDMASTER_SETTINGS_NP clockClass 246 \ clockAccuracy 0xfe offsetScaledLogVariance 0xffff \ currentUtcOffset 37 leap61 0 leap59 0 currentUtcOffsetValid 1 \ ptpTimescale 1 timeTraceable 1 frequencyTraceable 0 \ timeSource 0xa0" $ phc2sys -a -r -r --transportSpecific=1 -E ntpshm With this configuration this PTP device becomes master on the network. phc2sys starts to sync PHC from CLOCK_REALTIME. What I now expect is that CLOCK_REALTIME (in UTC) will be exactly 37 seconds behind PHC (in TAI) but I can not see this happen. $ date;phc_ctl eth1 get;phc_ctl eth1 cmp Thu Oct 14 08:56:37 UTC 2021 phc_ctl[573.296]: clock time is 1634201797.174712670 or Thu Oct 14 08:56:37 2021 phc_ctl[573.303]: offset from CLOCK_REALTIME is 1472ns The log file from phc2sys output like this: phc2sys[524]: [599.261] eth1 sys offset -37000001462 s0 freq +0 delay 875 phc2sys[524]: [600.262] eth1 sys offset -37000001467 s0 freq +0 delay 875 As phc_ctl does not compensate for UTC-TAI as I interpret the code I expected to see the 37 sec diff in the output from that utility and in the log file I expect something close to 0 offset. I think I have some bad configuration in my setup. Can someone help me understand how to proper setup this in order to get a good sync on the master side between the clocks? And I assume that I can use the same setting on the slave device to get it correct in that end to? I also think it is strange I can not get better precision than around 1.4 ms between the clocks. Thanks, /Peter |
From: Vinicius C. G. <vin...@in...> - 2021-10-13 23:44:43
|
Hi, Peter Bergin <pe...@be...> writes: > Hi, > > On 2021-10-13 00:19, Richard Cochran wrote: >> On Tue, Oct 12, 2021 at 09:47:21PM +0200, Peter Bergin wrote: >>> Hi, >>> >>> I'm currently working on a network product using gPTP configuration for PTP >>> sync. The device shall be a AVB endpoint handling audio and according to >>> Avnu specifications all endpoint shall be capable of being master on the >>> network. Some plugins for AVB (such as gstreamer and alsa-plugins) require >>> that system time (CLOCK_REALTIME) is in sync with PHC to get correct timing. >>> I see different cases depending on if the device is master or slave. If the >>> device is slave I would like to sync PHC to CLOCK_REALTIME. The other way >>> around, if device is master I would like to sync CLOCK_REALTIME to PHC. >>> >>> To the question; is there a way to use phc2sys and handle this >>> automatically? >> phc2sys has an automatic mode. See the man page for details. >> > Thanks! My bad, should have read man pages better. And I did try '-a' > but had issues with it. To summarize for other users: > > $ ./phc2sys -a -r -r -q -m > phc2sys[412816.955]: Waiting for ptp4l... > phc2sys[412817.956]: Waiting for ptp4l... One thing that could be missing is for phc2sys to use the same config file as ptp4l, this should be more convenient, something like this: $ ./phc2sys -a -r -r -q -m -f /etc/linuxptp/gPTP.cfg Cheers, -- Vinicius |
From: Peter B. <pe...@be...> - 2021-10-14 08:07:18
|
Hi Vincius, On 2021-10-14 01:44, Vinicius Costa Gomes wrote: > One thing that could be missing is for phc2sys to use the same config > file as ptp4l, this should be more convenient, something like this: > > $ ./phc2sys -a -r -r -q -m -f /etc/linuxptp/gPTP.cfg sure it can be more convenient but I think I have to check all settings then at make sure they work for both applications. The man page for phc2sys has a quite clear warning about this, probably for a reason: WARNING Be cautious when the same configuration file is used for both ptp4l and phc2sys. Keep in mind, that values specified in the configuration file take precedence over their default values. If a certain option, which is common to ptp4l and phc2sys, is specified to a non- default value in the configuration file (p.e., for ptp4l), then this non-default value applies also for phc2sys. This might be not what is expected. It is recommended to use seperate configuration files for ptp4l and phc2sys in order to avoid any unexpected behavior. But along the road when I get full control of the applications this can probably be a good solution. Thanks, /Peter |