【工程师分享】测试MPSoC GEM 的1588功能

作者:付汉杰,hankf@xilinx.com,文章转载自:博客园

MPSoC的MAC支持1588。在Linux Kernel的配置项中使能CONFIG_MACB_USE_HWSTAMP,并在Linux rootfs添加Linux ptp/ethtool,就可以运行1588的软件命令ptp4l。

PetaLinux下,配置Linux rootfs命令是petalinux-config -c rootfs。1588在Linux用户态的应用程序软件包是Linuxptp,可执行文件是ptp4l。

1. 在zcu106之间运行1588
下面的命令,在zcu106之间运行1588。运行顺序是先在第一块单板(master)启动1588 master;再在第二块单板(slave)上启动1588 slave;接下来在第一块单板(master)终止1588 master,模拟1588 master故障;最后再在第一块单板(master)启动1588 master。

1.1. master
1588 master的命令是ptp4l -i eth0 -m。运行记录如下:

root@zcu106_vcu_trd:~# # master
root@zcu106_vcu_trd:~# uname -a
Linux zcu106_vcu_trd 5.4.0-xilinx-v2020.2 #1 SMP Wed Feb 24 10:06:51 UTC 2021 aarch64 GNU/Linux
root@zcu106_vcu_trd:~# ifconfig eth0
eth0      Link encap:Ethernet  HWaddr 00:0A:35:04:D2:38
          inet addr:10.164.16.102  Bcast:10.164.16.255  Mask:255.255.255.0
          inet6 addr: fe80::20a:35ff:fe04:d238/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:381 errors:0 dropped:0 overruns:0 frame:0
          TX packets:438 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:37123 (36.2 KiB)  TX bytes:49863 (48.6 KiB)
          Interrupt:31

root@zcu106_vcu_trd:~# ptp4l -i eth0  -m
ptp4l[577.050]: selected /dev/ptp0 as PTP clock
ptp4l[577.051]: port 1: INITIALIZING to LISTENING on INIT_COMPLETE
ptp4l[577.051]: port 0: INITIALIZING to LISTENING on INIT_COMPLETE
ptp4l[583.599]: port 1: LISTENING to MASTER on ANNOUNCE_RECEIPT_TIMEOUT_EXPIRES
ptp4l[583.599]: selected local clock 000a35.fffe.04d238 as best master
ptp4l[583.600]: assuming the grand master role
^C
root@zcu106_vcu_trd:~# ptp4l -i eth0  -m
ptp4l[637.574]: selected /dev/ptp0 as PTP clock
ptp4l[637.575]: port 1: INITIALIZING to LISTENING on INIT_COMPLETE
ptp4l[637.575]: port 0: INITIALIZING to LISTENING on INIT_COMPLETE
ptp4l[644.708]: port 1: LISTENING to MASTER on ANNOUNCE_RECEIPT_TIMEOUT_EXPIRES
ptp4l[644.708]: selected local clock 000a35.fffe.04d238 as best master
ptp4l[644.708]: assuming the grand master role
^Croot@zcu106_vcu_trd:~#

上面的1588 master,先启动,再停止,再启动。

1.2. slave
1588 slave的命令是ptp4l -i eth0 -s -m。运行记录如下:

root@zcu106_vcu_trd:~# # slave
root@zcu106_vcu_trd:~# uname -a
Linux zcu106_vcu_trd 5.4.0-xilinx-v2020.2 #1 SMP Wed Feb 24 10:06:51 UTC 2021 aarch64 GNU/Linux
root@zcu106_vcu_trd:~# ifconfig eth0
eth0      Link encap:Ethernet  HWaddr 06:51:E5:C2:71:88
          inet addr:10.164.16.8  Bcast:10.164.16.255  Mask:255.255.255.0
          inet6 addr: fe80::451:e5ff:fec2:7188/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:880 errors:0 dropped:26 overruns:0 frame:0
          TX packets:484 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:62884 (61.4 KiB)  TX bytes:51650 (50.4 KiB)
          Interrupt:31

root@zcu106_vcu_trd:~# ptp4l -i eth0 -s -m
ptp4l[577.398]: selected /dev/ptp0 as PTP clock
ptp4l[577.399]: port 1: INITIALIZING to LISTENING on INIT_COMPLETE
ptp4l[577.399]: port 0: INITIALIZING to LISTENING on INIT_COMPLETE
ptp4l[577.755]: port 1: new foreign master 000a35.fffe.04d238-1
ptp4l[581.755]: selected best master clock 000a35.fffe.04d238
ptp4l[581.755]: port 1: LISTENING to UNCALIBRATED on RS_SLAVE
ptp4l[583.754]: master offset       -701 s0 freq   +4079 path delay      2992
ptp4l[584.754]: master offset       -957 s2 freq   +3823 path delay      3037
ptp4l[584.754]: port 1: UNCALIBRATED to SLAVE on MASTER_CLOCK_SELECTED
ptp4l[585.754]: master offset       -727 s2 freq   +3096 path delay      3037
ptp4l[586.754]: master offset        430 s2 freq   +4035 path delay      3035
ptp4l[587.754]: master offset        437 s2 freq   +4171 path delay      3034
ptp4l[588.754]: master offset        351 s2 freq   +4216 path delay      3035
ptp4l[589.754]: master offset        222 s2 freq   +4192 path delay      3035
ptp4l[590.754]: master offset       -108 s2 freq   +3929 path delay      3047
ptp4l[605.754]: master offset        229 s2 freq   +4239 path delay      3019
ptp4l[606.754]: master offset         18 s2 freq   +4096 path delay      3035
ptp4l[607.754]: master offset       -156 s2 freq   +3928 path delay      3035
ptp4l[615.730]: port 1: SLAVE to LISTENING on ANNOUNCE_RECEIPT_TIMEOUT_EXPIRES
ptp4l[615.731]: selected local clock 0651e5.fffe.c27188 as best master
ptp4l[621.758]: selected local clock 0651e5.fffe.c27188 as best master
ptp4l[629.169]: selected local clock 0651e5.fffe.c27188 as best master
ptp4l[635.881]: selected local clock 0651e5.fffe.c27188 as best master
ptp4l[638.863]: selected best master clock 000a35.fffe.04d238
ptp4l[638.863]: port 1: LISTENING to UNCALIBRATED on RS_SLAVE
ptp4l[640.862]: master offset       4627 s2 freq   +8664 path delay      2932
ptp4l[640.862]: port 1: UNCALIBRATED to SLAVE on MASTER_CLOCK_SELECTED
ptp4l[641.862]: master offset        -22 s2 freq   +5403 path delay      2978
ptp4l[642.862]: master offset      -2147 s2 freq   +3271 path delay      3580
ptp4l[643.862]: master offset       -868 s2 freq   +3906 path delay      3279
ptp4l[644.862]: master offset       -644 s2 freq   +3870 path delay      3019
ptp4l[645.862]: master offset       -402 s2 freq   +3919 path delay      2978
ptp4l[646.863]: master offset       -103 s2 freq   +4097 path delay      2978
ptp4l[647.863]: master offset       -157 s2 freq   +4012 path delay      3001
ptp4l[648.863]: master offset       -350 s2 freq   +3772 path delay      3042
ptp4l[649.863]: master offset        126 s2 freq   +4143 path delay      3021
ptp4l[650.863]: master offset         40 s2 freq   +4095 path delay      3021

在1588 slave的打印中可以看到,slave先选择外部时钟master 000a35.fffe.04d238。当外部master退出后,再选择了本地时钟,0651e5.fffe.c27188。当外部master正常后,又选择了外部时钟master 000a35.fffe.04d238。
时钟的标识,是网卡的MAC地址。
master offset表示主从端时间差,单位是ns。s0,s1,s2 : 表示1588的不同状态,s0表示未锁定,s1表示正在同步,s2表示锁定。

2. PC机上运行1588
也可以在PC机上运行1588。首先在master和slave的PC机安装1588的Linux用户态应用程序,Linuxptp。

hankf@XSZGS4:~$ sudo apt install linuxptp
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libfwup1 libllvm9 linux-hwe-5.4-headers-5.4.0-51 linux-hwe-5.4-headers-5.4.0-52 linux-hwe-5.4-headers-5.4.0-53 linux-hwe-5.4-headers-5.4.0-56 linux-hwe-5.4-headers-5.4.0-58
  linux-hwe-5.4-headers-5.4.0-59 linux-hwe-5.4-headers-5.4.0-60 linux-hwe-5.4-headers-5.4.0-62 linux-hwe-5.4-headers-5.4.0-65 linux-hwe-5.4-headers-5.4.0-66 linux-hwe-5.4-headers-5.4.0-67
Use 'sudo apt autoremove' to remove them.
The following NEW packages will be installed:
  linuxptp
0 upgraded, 1 newly installed, 0 to remove and 18 not upgraded.
Need to get 112 kB of archives.
After this operation, 418 kB of additional disk space will be used.
Get:1 http://hk.archive.ubuntu.com/ubuntu bionic/universe amd64 linuxptp amd64 1.8-1 [112 kB]
Fetched 112 kB in 3s (33.0 kB/s)   
Selecting previously unselected package linuxptp.
(Reading database ... 477696 files and directories currently installed.)
Preparing to unpack .../linuxptp_1.8-1_amd64.deb ...
Unpacking linuxptp (1.8-1) ...
Setting up linuxptp (1.8-1) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...

2.1. master
然后运行1588 master。

hankf@XSZGS4:~$ sudo ptp4l -i ens12f2 -m
[sudo] password for hankf:
ptp4l[4247020.499]: selected /dev/ptp4 as PTP clock
ptp4l[4247020.500]: driver changed our HWTSTAMP options
ptp4l[4247020.500]: tx_type   1 not 1
ptp4l[4247020.500]: rx_filter 1 not 12
ptp4l[4247020.500]: port 1: INITIALIZING to LISTENING on INITIALIZE
ptp4l[4247020.500]: port 0: INITIALIZING to LISTENING on INITIALIZE
ptp4l[4247020.501]: port 1: link up
ptp4l[4247028.079]: port 1: LISTENING to MASTER on ANNOUNCE_RECEIPT_TIMEOUT_EXPIRES
ptp4l[4247028.079]: selected best master clock 6c92bf.fffe.ccc500
ptp4l[4247028.079]: assuming the grand master role
^C
hankf@XSZGS4:~$

2.2. Slave
运行1588 Slave。

xilinx@xszgs2:~$ ifconfig eno3
eno3: flags=4163  mtu 1500
        inet 10.164.177.202  netmask 255.255.255.0  broadcast 10.164.177.255
        inet6 fe80::f56c:dc30:fa49:b101  prefixlen 64  scopeid 0x20
        ether d0:94:66:55:0d:e9  txqueuelen 1000  (Ethernet)
        RX packets 39897217  bytes 48144750947 (48.1 GB)
        RX errors 107  dropped 6  overruns 107  frame 0
        TX packets 14982002  bytes 4367094180 (4.3 GB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 42  memory 0x9e800000-9effffff
              
xilinx@xszgs2:~$ ptp4l -i eno3 -s -m
ptp4l[3650610.080]: selected /dev/ptp2 as PTP clock
ptp4l[3650610.081]: Failed to open /dev/ptp2: Permission denied
failed to create a clock
xilinx@xszgs2:~$ sudo ptp4l -i eno3 -s -m
ptp4l[3650613.052]: selected /dev/ptp2 as PTP clock
ptp4l[3650613.071]: port 1: INITIALIZING to LISTENING on INITIALIZE
ptp4l[3650613.071]: port 0: INITIALIZING to LISTENING on INITIALIZE
ptp4l[3650613.072]: port 1: link up
ptp4l[3650614.597]: port 1: new foreign master 6c92bf.fffe.ccc500-1
ptp4l[3650618.597]: selected best master clock 6c92bf.fffe.ccc500
ptp4l[3650618.597]: port 1: LISTENING to UNCALIBRATED on RS_SLAVE
ptp4l[3650620.597]: master offset -496821638515 s0 freq      +0 path delay     25928
ptp4l[3650621.597]: master offset -496821663985 s1 freq  -25469 path delay     22934
ptp4l[3650622.597]: master offset      -3011 s2 freq  -28480 path delay     22934
ptp4l[3650622.599]: port 1: UNCALIBRATED to SLAVE on MASTER_CLOCK_SELECTED
ptp4l[3650623.596]: master offset       6729 s2 freq  -19643 path delay     13071
ptp4l[3650624.596]: master offset      -2000 s2 freq  -26353 path delay     13071
ptp4l[3650625.596]: master offset      -4376 s2 freq  -29329 path delay     13297
ptp4l[3650626.596]: master offset      -3468 s2 freq  -29734 path delay     13071
ptp4l[3650627.596]: master offset      -2191 s2 freq  -29498 path delay     13071
ptp4l[3650628.596]: master offset       -994 s2 freq  -28958 path delay     12936
ptp4l[3650629.596]: master offset       -435 s2 freq  -28697 path delay     12874
ptp4l[3650630.596]: master offset       -380 s2 freq  -28773 path delay     12874
ptp4l[3650631.596]: master offset       -176 s2 freq  -28683 path delay     12874
ptp4l[3650632.596]: master offset        161 s2 freq  -28398 path delay     12874

在1588 slave的打印中可以看到,PC机上slave报告的master offset和path delay,都远远大于在zcu106之间运行1588的数据。

3. 参考文档
MPSoC Ethernet Macb Driver

最新文章

最新文章