nxp-archive / openil_linuxptp

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

WRONG ptpTimescale flag from ptp4l #51

Open KilledByBugs opened 1 month ago

KilledByBugs commented 1 month ago

Hi,

I was trying ptp4l on my NXP i.MX boards. Then, I tried PMC settings on my ptp4l (using the steps on the following page https://tsn.readthedocs.io/avb.html )

What I have done to set up the time sync and PMC previously:

  1. start ptp4l : ptp4l -m -i eth0 -f automotive-master_domain0.cfg --step_threshold=1 &

PS: The content of "automotive-master_domain0.cfg" file is:

[global]
# Options carried over from gPTP.
gmCapable               1
priority1               248
priority2               248
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
domainNumber            0

#
# Automotive Profile specific options
#
BMCA                    noop
masterOnly              1
  1. To set the system clocks (CLOCK_REALTIME and CLOCK_TAI), configure the UTC-TAI offset in the system:
    
    pmc -u -b 0 -t 1 "SET GRANDMASTER_SETTINGS_NP clockClass 248 \

clockAccuracy 0xfe offsetScaledLogVariance 0xffff \

currentUtcOffset 37 leap61 0 leap59 0 currentUtcOffsetValid 1 \

ptpTimescale 1 timeTraceable 1 frequencyTraceable 0 \

timeSource 0xa0"


3. **To check if the setting is successful:**
`pmc -u -b 0 -t 1 "GET GRANDMASTER_SETTINGS_NP"`

the output is:

sending: GET GRANDMASTER_SETTINGS_NP 484952.fffe.411081-0 seq 0 RESPONSE MANAGEMENT GRANDMASTER_SETTINGS_NP clockClass 248 clockAccuracy 0xfe offsetScaledLogVariance 0xffff currentUtcOffset 37 leap61 0 leap59 0 currentUtcOffsetValid 1 ptpTimescale 1 timeTraceable 1 frequencyTraceable 0 timeSource 0xa0


It seems good. That is the setting I want. 

4. **start phc2sys**
`phc2sys -c eth0 -s CLOCK_REALTIME --step_threshold=1 --transportSpecific=1 -w &`

After that, I checked the message captured from eth0. The message sent on ethernet was **WRONG**. The flags such as ptpTimescale are false which is different to the PMC settings. (The following picture is the message read by Wireshark.)
![Screenshot from 2024-07-30 14-38-31](https://github.com/user-attachments/assets/af88a94a-dafd-4018-a020-06b54fcd1888)
![Screenshot from 2024-07-30 14-38-25](https://github.com/user-attachments/assets/9d661f17-dd48-491d-b761-51df2d679bd3)
The message package captured by tcpdump is in the attachment file:
[logAfterPhc2sys.zip](https://github.com/user-attachments/files/16423213/logAfterPhc2sys.zip)

I also ran the '[check_clocks](https://tsn.readthedocs.io/_downloads/f329e8dec804247b1dbb5835bd949e6f/check_clocks.c)' to check the time sync. The output was:
> phc-tai delta is greater than 50 usec !
> TAI offset set in kernel is not correct !
> Please verify ptp4l and phc config and restart them if necessary to synchronize the clocks !

**What I have tried to solve the problem:**
1. disable NTP:  `timedatectl set-ntp false` and then restart ptp4l
2. make sure there is only one ptp4l, one phc2sys running: `ps -A | grep ptp4l` (there is only 1 ptp4l、 phc2sys)
However, those don't solve the problem. 

**My questions:** 
1. Can you suggest why the PMC setting doesn't work on the actual message sent from ptp4l? 
2. Is there any other thing that can affect the PMC setting I need to avoid?
3. Can you let me know how to solve the problem? (correct PMC setting, but WRONG flags on message)

Kind Regards,
Jim