测量 IEEE 1588 需要使用 linuxptp 这个工程, 官网是
https://linuxptp.sourceforge.net/
获取代码可以通过git
git clone git://git.code.sf.net/p/linuxptp/code linuxptp
如果是当前环境本地编译的话, 直接在下载好的代码路径make就可以.
如果需要在开发板上面使用的话,就需要交叉编译,将makefile里面的gcc替换为你平台的toolchain就可以了.
编译好之后, 我们需要的就只有1个文件, 就是 ptp4l.
下面开始测试:
我的环境 : 开发板上的双网口,使用网线直连, 可以ping通.
看下网口对ptp协议的支持情况:
通过 https://linuxptp.sourceforge.net/ 第5节的介绍得知, 当前的网卡既支持 Hardware 模式, 又支持 software 模式.
看一下 ptp4l 的版本,验证交叉编译的正确性.
# ./ptp4l -v
4.4-dirty
因为是串口连接, 所以只有一个中端, 就决定, 一个网口后台跑 server, 一个网口前台跑 client.
./ptp4l -2 -i eth0 -m -H &
//eth0 作为server端,硬件时间戳 -m print messages to stdout 是输出信息到串口. -H是HARDWARE模式, & 是后台运行
./ptp4l -2 -i eth1 -m -H -s
//eth1 作为client端,硬件时间戳 -m print messages to stdout 是输出信息到串口. -H是HARDWARE模式, -s 是 client only synchronization mode,就是从模式
输出的log如下
# ./ptp4l -2 -i eth0 -m -S &
# ptp4l[159.928]: port 1 (eth0): INITIALIZING to LISTENING on INIT_COMPLETE
ptp4l[159.928]: port 0 (/var/run/ptp4l): INITIALIZING to LISTENING on INIT_COMPLETE
ptp4l[159.929]: port 0 (/var/run/ptp4lro): INITIALIZING to LISTENING on INIT_COMPLETE
#
#
# ptp4l[167.408]: port 1 (eth0): LISTENING to MASTER on ANNOUNCE_RECEIPT_TIMEOUT_EXPIRES
ptp4l[167.408]: selected local clock fefefe.fffe.1b951a as best master
ptp4l[167.408]: port 1 (eth0): assuming the grand master role
#
#
# ./ptp4l -2 -i eth1 -m -S -s
ptp4l[171.096]: port 1 (eth1): INITIALIZING to LISTENING on INIT_COMPLETE
ptp4l[171.096]: uds: removed existing /var/run/ptp4l
ptp4l[171.096]: port 0 (/var/run/ptp4l): INITIALIZING to LISTENING on INIT_COMPLETE
ptp4l[171.097]: uds: removed existing /var/run/ptp4lro
ptp4l[171.097]: port 0 (/var/run/ptp4lro): INITIALIZING to LISTENING on INIT_COMPLETE
ptp4l[171.420]: port 1 (eth1): new foreign master fefefe.fffe.1b951a-1
ptp4l[175.428]: selected best master clock fefefe.fffe.1b951a
ptp4l[175.428]: foreign master not using PTP timescale
ptp4l[175.428]: port 1 (eth1): LISTENING to UNCALIBRATED on RS_SLAVE
ptp4l[177.448]: master offset -8166 s0 freq -0 path delay 42458
ptp4l[178.452]: master offset -3083 s0 freq -0 path delay 42458
ptp4l[179.456]: master offset -5625 s0 freq -0 path delay 39833
ptp4l[180.460]: master offset -4322 s0 freq -0 path delay 39822
ptp4l[181.464]: master offset -3281 s0 freq -0 path delay 39822
ptp4l[182.468]: master offset -1124 s0 freq -0 path delay 39833
ptp4l[183.472]: master offset -3739 s0 freq -0 path delay 40781
ptp4l[184.476]: master offset -2792 s0 freq -0 path delay 41292
ptp4l[185.480]: master offset -4125 s0 freq -0 path delay 41292
ptp4l[186.484]: master offset -3489 s0 freq -0 path delay 41031
ptp4l[187.488]: master offset -1438 s0 freq -0 path delay 40771
ptp4l[188.492]: master offset -4395 s0 freq -0 path delay 41020
ptp4l[189.496]: master offset -3811 s0 freq -0 path delay 41020
ptp4l[190.500]: master offset -1917 s0 freq -0 path delay 40417
ptp4l[191.504]: master offset -7333 s0 freq -0 path delay 40833
ptp4l[192.508]: master offset 2501 s0 freq -0 path delay 40833
ptp4l[193.512]: master offset -5239 s2 freq +182 path delay 41281
ptp4l[193.512]: port 1 (eth1): UNCALIBRATED to SLAVE on MASTER_CLOCK_SELECTED
ptp4l[194.516]: master offset -2542 s2 freq -75 path delay 41083
ptp4l[195.520]: master offset -7000 s2 freq -527 path delay 41083
ptp4l[196.524]: master offset -4708 s2 freq -303 path delay 40833
ptp4l[197.528]: master offset -3500 s2 freq -186 path delay 40000
ptp4l[198.532]: master offset -5155 s2 freq -356 path delay 40322
ptp4l[199.536]: master offset -3530 s2 freq -197 path delay 40322
ptp4l[200.540]: master offset 11553 s2 freq +1323 path delay 40322
ptp4l[201.544]: master offset -4188 s2 freq -256 path delay 40729
ptp4l[202.548]: master offset -4114 s2 freq -252 path delay 40322
ptp4l[203.552]: master offset -864 s2 freq +72 path delay 40322
ptp4l[204.556]: master offset -3405 s2 freq -186 path delay 40322
ptp4l[205.560]: master offset -5437 s2 freq -394 path delay 40729
ptp4l[206.564]: master offset -4562 s2 freq -311 path delay 40729
ptp4l[207.568]: master offset -6562 s2 freq -518 path delay 40729
ptp4l[208.572]: master offset -5979 s2 freq -466 path delay 40729
ptp4l[209.576]: master offset -5187 s2 freq -392 path delay 40729
ptp4l[210.580]: master offset -5041 s2 freq -382 path delay 39041
ptp4l[211.584]: master offset -3166 s2 freq -198 path delay 39041
ptp4l[212.588]: master offset -2916 s2 freq -176 path delay 39041
ptp4l[213.592]: master offset -5166 s2 freq -406 path delay 39416
ptp4l[214.596]: master offset -4187 s2 freq -312 path delay 39270
ptp4l[215.600]: master offset -4353 s2 freq -333 path delay 39270
ptp4l[216.604]: master offset -2292 s2 freq -129 path delay 39000
ptp4l[217.608]: master offset -3208 s2 freq -224 path delay 39000
ptp4l[218.612]: master offset -1083 s2 freq -13 path delay 38917
ptp4l[219.616]: master offset -1104 s2 freq -16 path delay 39146
ptp4l[220.620]: master offset -3125 s2 freq -221 path delay 39375
ptp4l[221.624]: master offset -4239 s2 freq -337 path delay 39406
ptp4l[222.628]: master offset 3510 s2 freq +442 path delay 39406
ptp4l[223.632]: master offset -1603 s2 freq -71 path delay 39562
ptp4l[224.636]: master offset -4198 s2 freq -335 path delay 39739
ptp4l[225.640]: master offset -4780 s2 freq -398 path delay 39739
ptp4l[226.644]: master offset -1989 s2 freq -121 path delay 39739
ptp4l[227.648]: master offset -5000 s2 freq -427 path delay 40083
ptp4l[228.652]: master offset -5041 s2 freq -436 path delay 40083
ptp4l[229.656]: master offset -5562 s2 freq -494 path delay 40437
ptp4l[230.660]: master offset -1645 s2 freq -104 path delay 40562
ptp4l[231.664]: master offset -3978 s2 freq -341 path delay 40437
ptp4l[232.668]: master offset -5854 s2 freq -534 path delay 40562
ptp4l[233.672]: master offset -6750 s2 freq -631 path delay 40542
ptp4l[234.676]: master offset -5083 s2 freq -469 path delay 40542
ptp4l[235.680]: master offset -5635 s2 freq -530 path delay 40052
ptp4l[236.684]: master offset 6615 s2 freq +702 path delay 40052
ptp4l[237.688]: master offset -6114 s2 freq -577 path delay 40198
ptp4l[238.692]: master offset -4230 s2 freq -393 path delay 39396
ptp4l[239.696]: master offset -4354 s2 freq -410 path delay 39396
ptp4l[240.700]: master offset -1083 s2 freq -84 path delay 39333
ptp4l[241.704]: master offset -4813 s2 freq -462 path delay 39396
ptp4l[242.708]: master offset -3104 s2 freq -294 path delay 39396
ptp4l[243.712]: master offset -4166 s2 freq -404 path delay 39375
ptp4l[244.716]: master offset 4354 s2 freq +452 path delay 39646
ptp4l[245.720]: master offset -4229 s2 freq -410 path delay 39646
ptp4l[246.724]: master offset -4656 s2 freq -458 path delay 40656
ptp4l[247.728]: master offset -6958 s2 freq -695 path delay 41500
ptp4l[248.732]: master offset -4344 s2 freq -438 path delay 39677
ptp4l[249.736]: master offset -3927 s2 freq -400 path delay 39677
ptp4l[250.740]: master offset -2521 s2 freq -262 path delay 39729
ptp4l[251.744]: master offset -6406 s2 freq -657 path delay 40656
ptp4l[252.748]: master offset -1271 s2 freq -145 path delay 39729
ptp4l[253.752]: master offset -2145 s2 freq -234 path delay 39729
ptp4l[254.756]: master offset -3042 s2 freq -327 path delay 39875
ptp4l[255.760]: master offset 1458 s2 freq +124 path delay 39875
ptp4l[256.764]: master offset 281 s2 freq +7 path delay 39552
ptp4l[257.768]: master offset -4969 s2 freq -523 path delay 39552
ptp4l[258.772]: master offset 1479 s2 freq +123 path delay 39187
ptp4l[259.776]: master offset -7125 s2 freq -744 path delay 39875
可以看到软模式执行良好. 我的环境, 硬模式有问题,出错log如下,还不知道原因.
# ./ptp4l -2 -i eth0 -m -H &
# ptp4l[38041.506]: selected /dev/ptp0 as PTP clock
ptp4l[38041.548]: port 1 (eth0): INITIALIZING to LISTENING on INIT_COMPLETE
ptp4l[38041.548]: port 0 (/var/run/ptp4l): INITIALIZING to LISTENING on INIT_COMPLETE
ptp4l[38041.548]: port 0 (/var/run/ptp4lro): INITIALIZING to LISTENING on INIT_COMPLETE
# ./ptp4l -2 -i eth1 -m -H -s
ptp4l[38048.235]: selected /dev/ptp1 as PTP clock
ptp4l[38048.276]: port 1 (eth1): INITIALIZING to LISTENING on INIT_COMPLETE
ptp4l[38048.276]: uds: removed existing /var/run/ptp4l
ptp4l[38048.276]: port 0 (/var/run/ptp4l): INITIALIZING to LISTENING on INIT_COMPLETE
ptp4l[38048.276]: uds: removed existing /var/run/ptp4lro
ptp4l[38048.277]: port 0 (/var/run/ptp4lro): INITIALIZING to LISTENING on INIT_COMPLETE
ptp4l[38049.376]: port 1 (eth0): LISTENING to MASTER on ANNOUNCE_RECEIPT_TIMEOUT_EXPIRES
ptp4l[38049.376]: selected local clock fefefe.fffe.1b951a as best master
ptp4l[38049.376]: port 1 (eth0): assuming the grand master role
ptp4l[38049.380]: port 1 (eth1): new foreign master fefefe.fffe.1b951a-1
ptp4l[38050.380]: port 1 (eth1): received SYNC without timestamp
ptp4l[38050.392]: timed out while polling for tx timestamp
ptp4l[38050.392]: increasing tx_timestamp_timeout or increasing kworker priority may correct this issue, but a driver bug likely causes it
ptp4l[38050.392]: port 1 (eth0): send sync failed
ptp4l[38050.392]: port 1 (eth0): MASTER to FAULTY on FAULT_DETECTED (FT_UNSPECIFIED)
ptp4l[38055.048]: selected local clock fefefe.fffe.1b951b as best master
ptp4l[38066.472]: port 1 (eth0): FAULTY to LISTENING on INIT_COMPLETE
ptp4l[38074.144]: port 1 (eth0): LISTENING to MASTER on ANNOUNCE_RECEIPT_TIMEOUT_EXPIRES
ptp4l[38074.144]: port 1 (eth0): assuming the grand master role
ptp4l[38075.148]: port 1 (eth1): received SYNC without timestamp
ptp4l[38075.160]: timed out while polling for tx timestamp
ptp4l[38075.160]: increasing tx_timestamp_timeout or increasing kworker priority may correct this issue, but a driver bug likely causes it
ptp4l[38075.160]: port 1 (eth0): send sync failed
ptp4l[38075.160]: port 1 (eth0): MASTER to FAULTY on FAULT_DETECTED (FT_UNSPECIFIED)
参考文章:
12 – 利用LinuxPTP进行时间同步(软/硬件时间戳) – 研一-腾讯云开发者社区-腾讯云
Linux下交叉编译 linuxptp-CSDN博客
linuxptp时钟同步测试_ptp时钟测试-CSDN博客
Linuxptp使用总结_linuxptp版权-CSDN博客
RT-Thread : IEEE1588/PTP 协议的实现_stm32 ptp-CSDN博客
IEEE1588v2解析(3)--PTP的路径时延测量方法介绍_1588测试操作指导-CSDN博客
数据采集和测试中的时间精度协议(PTP) | HBM
linux下ptp性能测试_ptp测试软件-CSDN博客
PTP简介-IEEE1588协议-CSDN博客
SSZTAU5 Technical article | TI.com
以太网帧
PTP(Precision Time Protocol)高精度时间同步协议+linuxptp代码学习_【ptp(precision time protocol)高精度时间同步协议+linuxptp代码学-CSDN博客
【时间同步】IEEE-1588总结_ieee1588-CSDN博客
手把手教你解决PL2303驱动在Win10无法使用-CSDN博客