nxp-archive / openil_linuxptp

PTP IEEE 1588 stack for Linux
GNU General Public License v2.0
136 stars 60 forks source link

802.1AS relay instance Sync Pkt timestamp #31

Open hi123ping opened 2 years ago

hi123ping commented 2 years ago

when ptp4l run in relay instance, does the precisetimestamp in sync packet received at slavestat port different from the precisetimestamp in sync packet sent at masterstat port ?

vladimiroltean commented 2 years ago

I recommend downloading the 802.1AS standard and reading the "Transport of time-synchronization information" chapter. The process "is mathematically [and functionally] equivalent to the mechanism described in IEEE Std 1588-2008 for a two-step, peer-to-peer transparent clock that is syntonized". However, the process is not identical. A time-aware bridge will send Sync messages with timestamps relative to its own local clock. The way in which the correctionField and the Follow_Up Information TLV is computed and populated is specific to 802.1AS. There are a few pages of explanations in the standard, I'm not sure I can just include them here.

hi123ping commented 2 years ago

I know 802.1as requirment about timestamp and local clock should freeruning. But I see in ptp4l the local clock is syncronized to the gm clock which from the timestamp and cummlative rate in packet. So, I wonder if we can config ptp4l not syncronizing with gm clock by config freerun field in gPTP.cfg?

vladimiroltean commented 2 years ago

Yes.

hi123ping commented 2 years ago

how do the phc2sys work with pps? when pps input as source, how do phc2sys sync the input pps to the phc?

vladimiroltean commented 2 years ago

According to the man page, if the source clock provides a device registered with the PPS subsystem (https://www.kernel.org/doc/html/latest/driver-api/pps.html), this can be specified to phc2sys using "-d /dev/pps0", and events received by the kernel from this char device will be associated with the beginning of each second of the source clock. Please note that I have never used this option, and it shouldn't be confused with electrical pulse-per-second signal connected to the external timestamping input of a PHC, coming from a timing device like a GPS. For the latter use case, ts2phc should be used.

hi123ping commented 2 years ago

if i use ts2phc to synch device time with gps, how does the ts2phc sync nanoseconds part ? what's the algorithm for adjusting frequency?

vladimiroltean commented 2 years ago

ts2phc assumes the reference clock is able to provide a PPS signal. This signal is timestamped by the external timestamping input module of the destination PHC, and a 64-bit nanosecond timestamp is produced. Since the goal is to synchronize the destination PHC to the reference clock, it is assumed that the sub-second portion of the 64-bit extts timestamp represents the error. If the error is smaller 0.5 seconds, the destination PHC is adjusted (slowed down) so that the error is minimized towards 0. If the error is larger than 0.5 seconds, the destination PHC is accelerated, assuming that it is closer to the next second. Absolute time of day is retrieved by ts2phc by parsing NMEA sentences from the GPS module.

hi123ping commented 2 years ago

how to config a device to run 802.1as relay instance?

vladimiroltean commented 2 years ago

ptp4l -i eth0 -i eth1 -f configs/gPTP.cfg

hi123ping commented 2 years ago

i have problem to set a device to be relay instatnce. My topo link is like A----(eth0) B (eth1)----C, B is configed a relay, that is ptp4l -i eth0 -i eth1 -f configs/gPTP.cfg, both A and C configd ptp4l with gPTP.cfg at one port. and i set priority1 of A, B,C to be 248,249,250 respectively. I expect the time-synchronization spanning tree is A---->B---->C, but B does not send announce and sync at eth1 port.

Why does B not send announce and sync , only send pdelay-req?

vladimiroltean commented 2 years ago

What is the measured path delay between eth1 and node C? If larger than neighborPropDelayThresh (by default 800 ns in gPTP.cfg), asCapable will be unset on that port.

hi123ping commented 2 years ago

thanks . As you said, when I set eighborPropDelayThresh to be a large number, i can capture the annouce and sync at eth1 port.

hi123ping commented 2 years ago

Another issue, neighborrateratio field always 0 at eth0 and eth1. Is there some parameter to enable calculate neighborrateratio and filled it in the TLV?

ibpswyz commented 2 years ago

@hi123ping Hi, I have the similar topology to yours. The command "sudo ptp4l -f configs/gPTP.cfg -m -i eno2 -i eno3" has been done on the relay instance. Did you encounter such a problem?

ptp4l[11336.974]: selected /dev/ptp1 as PTP clock
ptp4l[11336.974]: port 2 (eno3): PHC device mismatch
ptp4l[11336.974]: port 2 (eno3): /dev/ptp1 requested, ptp2 attached
ptp4l[11336.974]: failed to open port eno3 
failed to create a clock
hi123ping commented 2 years ago

@ibpswyz I think you need use "ethtool -T eno2" and "ethtool -T eno3" to check phc index attached to eno2 and eno3. you needuse the interfaces with same phc and you need use -p /dev/phc* in your cmd.

ibpswyz commented 2 years ago

@hi123ping Thanks for your reply. I check that eno2 and eno3 attach to different phc index. eno2: PTP hardware clock: 1 and eno3: PTP hardware clock: 2 my topo is like A ----(eno2) B (eno3). I try to specify a phc to be the PTP clock. I use '-p' on B : "sudo ptp4l -i eno2 -i eno3 -p /dev/ptp2 --step_threshold=1 -m" on B, ptp4l can run, but the clock can not be synchronized. "master offset" and "freq" keep increasing. I wonder if there is a way to make eno2 and eno3 attach to the same phc.