nxp-archive / openil_linuxptp

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

how to unsterdand the effect about phc2sys and how to use it int HW timestamp synchronization? #26

Closed ZChidori closed 1 year ago

janruh commented 2 years ago

Can you please specify more precisely and detailed what your question is? What do you already understand, what exactly don't you understand?

ZChidori commented 2 years ago

As the man 8 shows that "Phc is used to synchronize the system clock to a PTP hardware clock (PHC)" so my understanding is it means the computer system timestamp will adjust to synchronize to the ethernet card,but when i need this computer to play the master role in a ptp4l domain,is it can be slave and master at the same time? What if the master computer running ptp4l service with phc2sys disabled? What'll happen every slave computer enabled phy2sys? And How will phc2sys work If the master clock changed by bmca? Thx a lot 4 your answer.

janruh commented 2 years ago

As the man 8 shows that "Phc is used to synchronize the system clock to a PTP hardware clock (PHC)" so my understanding is it means the computer system timestamp will adjust to synchronize to the ethernet card

Correct, if you use phc2sys as follows it will synchronize Linux CLOCK_REALTIME, which is the system time, to the NIC's clock: (1) phc2sys -s eth0 -c CLOCK_REALTIME -m

but when i need this computer to play the master role in a ptp4l domain,is it can be slave and master at the same time?

If a node acts as grandmaster clock all subordinate nodes will synchronize to this node. The time that is being distributed to the subordinate nodes in the synchronization hierarchy by the grandmaster depends on the timestamping used by your grandmaster. If your grandmaster runs ptp4l with software timestamping your subordinate nodes will synchronize to your grandmasters CLOCK_REALTIME. If your grandmaster runs ptp4l with hardware timestamping your subordinate nodes will synchronize to your grandmaster's NIC's clock. If you want to use hardware timestamping but also synchronize subordinate nodes to CLOCK_REALTIME of your grandmaster you can use phc2sys to synchronize the grandmasters's NIC's clock to CLOCK_REALTIME: (2) phc2sys -s CLOCK_REALTIME -c eth0 -m

What if the master computer running ptp4l service with phc2sys disabled?

In this case as explained before, your subordinate nodes will synchronize to the grandmaster's NIC's clock.

What'll happen every slave computer enabled phy2sys?

This only makes sense if your subordinate nodes use hardware timestamping. In this case all your subordinate nodes will synchronize their CLOCK_REALTIME to their NIC's clock.

And How will phc2sys work If the master clock changed by bmca?

If the grandmaster changes and you are using phc2sys to synchronize CLOCK_REALTIME to the nodes's NIC as in (1) nothing changes for you since phc2sys is still just synchronizing CLOCK_REALTIME to the NIC's clock. For example, the node that was grandmaster before will now become a subordinate node and ptp4l will synchronize its NIC to the new grandmaster clock. If phc2sys is also running on that node as in (1), it will synchronize CLOCK_REALTIME to the NIC's clock. The new grandmaster clock will distribute the time of the NIC's clock to its subordinate nodes. If phc2sys is running it will continue to synchronize CLOCK_REALTIME to the NIC's clock which is now not being governed by ptp4l anymore since it is now grandmaster itself.

If you are using phc2sys to synchronize the grandmaster's NIC's clock to CLOCK_REALTIME as in (2), e.g. because the grandmaster clock is being synchronized to an external time source, such as GPS or NTP, you will have an issue since now the NIC of your former grandmaster is acting as a subordinate node being governed by ptp4l and at the same time phc2sys tries synchronizing the NIC's clock to CLOCK_REALTIME.

Thx a lot 4 your answer.

You are welcome.

ZChidori commented 2 years ago
If you want to use hardware timestamping but also synchronize subordinate nodes to CLOCK_REALTIME of your grandmaster you can use phc2sys to synchronize the grandmasters's NIC's clock to CLOCK_REALTIME:

I am not sure if I understand is correct the text before command (2):This case is refers to the slaves want to adjust their os time to be consistent with master time through hardware time stamping,so i can choose whether the target time comes from os① or nic② by ptp4l -H? Based on this,use "phc2sys -s [eth] -c [os]" in ① case and "phc2sys -c [eth] -s [os] in ② case? So to fit all bacm states in a ptp4l domain,i just use

phc2sys -a -rr
ptp4l -H -i [eth]

in all computers is okay,that's right?

janruh commented 2 years ago

Effectively, all phc2sys does is synchronize two clocks of your system. Mostly you would use it to synchronize your CLOCK_REALTIME to the NIC's clock. The ptp4l program on the other hand executes the actual clock synchronization protocol (IEEE1588, 1AS, ...) synchronizing your nodes to each other. Simply from commands I can't tell you if this would be alright for your use case. Try it out and see if the resulting synchronized time results in what you expected or need for your use case.