• ptp4l测试-LinuxPTP\ptp4l配置与问题排查


    目录

    一、前言

    1.1 什么是ptp4l

    1.2 描述

    1.3 官网连接

    1.4 目的

    1.5 平台

    二、 平台必要软件

    2.1 linux物理机

    2.2 imx6ull开发板

    三、检查硬件是否支持

    3.1 ifconfig查看当前网卡的名称

    3.2 ethtool检查驱动和网卡是否支持

    四、开启ptp4l服务

    4.1 方法一:官方推荐方法开启ptp4l服务

    4.2 方法二:执行摸索的开启ptp4l服务(虚拟机平台)


    一、前言

    1.1 什么是ptp4l

            ptp4l - PTP普通时钟/边界时钟/透明时钟协议栈

    1.2 描述

            ptp4l是一个Linux上PTP协议(IEEE 1588)的实现,支持普通时钟,边界时钟和透明时钟。

    1.3 官网连接

    1.4 目的

            配置ptp4l进行测试时,发现存在一些问题导致无法正常进行测试,下面对遇到的问题进行排查解决。

    1.5 平台

            master-linux物理机。 slave-linux虚拟机。确保双方能ping通。

    二、 平台必要软件

    2.1 linux物理机

    1、安装ethtool
    2、安装ptp4l

    2.2 imx6ull开发板

    //1、imx6ull支持IEEE 1588协议
    //2、内核配置ptp时钟
    //3、交叉编译或通过buildroot等安装ptp4l
    (后续补充)

    三、检查硬件是否支持

    3.1 ifconfig查看当前网卡的名称

    3.2 ethtool检查驱动和网卡是否支持

        为了使用 PTP ,网络接口的内核网络驱动程序必须支持软件或硬件时间戳功能。除了驱动程序中存在的硬件时间戳支持之外,NIC 还必须能够在物理硬件中支持此功能。验证特定驱动程序和 NIC 的时间戳功能的最佳方法是使用ethtool查询接口

        命令:ethtool -T {网口名称}

     

    注:针对虚拟机,只有软件时间戳。

    软件时间戳支持

    硬件时间戳支持

    SOF_TIMESTAMPING_SOFTWARE

    SOF_TIMESTAMPING_TX_SOFTWARE

    SOF_TIMESTAMPING_RX_SOFTWARE

    SOF_TIMESTAMPING_RAW_HARDWARE

    SOF_TIMESTAMPING_TX_HARDWARE

    SOF_TIMESTAMPING_RX_HARDWARE

    四、开启ptp4l服务

            下面提供两种开启ptp4l服务的方式,一种为官方推荐方法,另一种为我自己摸索的方法。

    4.1 方法一:官方推荐方法开启ptp4l服务

        参考README配置(路径:/usr/share/doc/linuxptp/README.Debian)

        根据README进行一步步设置,其中ExecStart是调用ptp4l,其配置项可以使用man ptp4l或者看下面我提取的配置项进行合理配置。

    1. 1. Default configuration
    2. The default configuration can be found in /etc/linuxptp/ptp4l.conf.
    3. This is the default.cfg provided by the upstream source.
    4. 2. Systemd services
    5. The service ptp4l invokes ptp4l on eth0 by default. To adjust the
    6. parameters, follow these steps:
    7. 1. create a directory /etc/systemd/system/ptp4l.service.d
    8. 2. place a file with its name ending in .conf there
    9. 3. put these lines into the file, with the parameters adjusted to your needs:
    10. [Service]
    11. ExecStart=
    12. ExecStart=/usr/sbin/ptp4l -f /etc/linuxptp/ptp4l.conf -i eth0
    13. The service phc2sys syncs the system clock with the PTP clock. It is not
    14. enabled and started by default. To activate this service, invoke the
    15. following commands as root:
    16. $ systemctl enable phc2sys
    17. $ systemctl start phc2sys
    18. It also uses eth0 as the default and can be customized as described above.
    19. The service timemaster also isn't enabled and started by default

    4.2 方法二:自行摸索的配置ptp4l服务方法(虚拟机平台)

        缘由:为什么不根据官方的方式配置服务?因为我是apt安装ptp4l后,直接systemctl start ptp4l启动,然后使用systemctl status ptp4l查看错误项进行排查的。而且排查过程中,发现不同系统(虚拟机、物理机)的ptp4l服务配置文件位置有所不同,因此可以适用我下面的方法。

            1、问题现象

        开启ptp4l服务后,检查服务命令:systemctl status ptp4l。看到启动的服务为failed

            2、资料查询 

        使用man ptp4l,查看Process一栏执行的命令是什么意思。

    1. PTP4l(8) System Manager's Manual PTP4l(8)
    2. NAME
    3. ptp4l - PTP Boundary/Ordinary Clock
    4. SYNOPSIS
    5. ptp4l [ -AEP246HSLmqsv ] [ -f config ] [ -p phc-device ] [ -l print-level ] [ -i interface ] [ long-options ] ...
    6. DESCRIPTION
    7. ptp4l is an implementation of the Precision Time Protocol (PTP) according to IEEE standard 1588 for Linux. It implements
    8. Boundary Clock (BC) and Ordinary Clock (OC).
    9. OPTIONS
    10. -A Select the delay mechanism automatically. Start with E2E and switch to P2P when a peer delay request is received.
    11. -E Select the delay request-response (E2E) mechanism. This is the default mechanism. All clocks on single PTP commu‐
    12. nication path must use the same mechanism. A warning will be printed when a peer delay request is received on
    13. port using the E2E mechanism.
    14. -P Select the peer delay (P2P) mechanism. A warning will be printed when a delay request is received on port using
    15. the P2P mechanism.
    16. -2 Select the IEEE 802.3 network transport.
    17. -4 Select the UDP IPv4 network transport. This is the default transport.
    18. -6 Select the UDP IPv6 network transport.
    19. -H Select the hardware time stamping. All ports specified by the -i option and in the configuration file must be at‐
    20. tached to the same PTP hardware clock (PHC). This is the default time stamping.
    21. -S Select the software time stamping.
    22. -L Select the legacy hardware time stamping.
    23. -f config
    24. Read configuration from the specified file. No configuration file is read by default.
    25. -i interface
    26. Specify a PTP port, it may be used multiple times. At least one port must be specified by this option or in the
    27. configuration file.
    28. -p phc-device
    29. (This option is deprecated.) Before Linux kernel v3.5 there was no way to discover the PHC device associated
    30. with a network interface. This option specifies the PHC device (e.g. /dev/ptp0) to be used when running on
    31. legacy kernels.
    32. -s Enable the slaveOnly mode.
    33. -l print-level
    34. Set the maximum syslog level of messages which should be printed or sent to the system logger. The default is 6
    35. (LOG_INFO).
    36. -m Print messages to the standard output.
    37. -q Don't send messages to the system logger.
    38. -v Prints the software version and exits.
    39. -h Display a help message.

            3、参数分析

        针对命令/usr/sbin/ptp4l -f /etc/linuxptp/ptp4l.conf -i eth0。

        其中-f 用于指定配置文件。  -i 用于指定网口。

        根据图片提示信息可看出,问题点是指定的网卡名称有误,通过3.1的ifconfig命令查看,当前的物理网口的接口为ens33

        而且由于是虚拟机平台,并且3.2 中也查看了网卡只支持软件时间戳功能。因此需要加上-S配置项。

            4、修改参数

        修改参数的第一步是找到配置文件所在位置。我经过测试虚拟机平台和物理机平台。发现ptp4l配置文件所在位置有所区别,因此各位同学也需要根据实际情况找到配置文件的位置

    1. 查找配置文件位置:
    2. cd /etc
    3. sudo grep "ExecStart=/usr/sbin/ptp4l -f /etc/linuxptp/ptp4l.conf" -R

            可以得知ptp4l配置文件的位置:/etc/systemd/system/multi-user.target.wants/ptp4l.service。修改网卡接口以及适用软时间戳。

               保存后,按照如下指令重新启动ptp4l即可:

    1. sudo systemctl daemon-reload #修改service后需要重新加载systemd manager configuration
    2. sudo systemctl restart ptp4l #重启ptp4l
    3. sudo systemctl status ptp4l #查看是否启动成功

    4.3 验证软时间戳时间同步

    测试平台:使用两个虚拟机,其中一个作为master,另一个作为slave
    前提:针对虚拟机,需要确保双方能够互相ping通
    master虚拟机启动指令:sudo ptp4l -i ens33 -S -m
    slave虚拟机启动指令:   sudo ptp4l -i ens33 -S -m -s

     

     

  • 相关阅读:
    基于粒子群优化算法的最优潮流(IEEE30节点(Matlab代码实现)
    YbtOJ「动态规划」第2章 区间DP
    Linux1024一篇通俗易懂的liunx命令操作总结(第十课)
    力扣刷题 day50:10-20
    【学习方法】手机越戒越上瘾?三招让你戒掉手机玩命学习!
    SpringBoot自定义banner,如何定制炫酷的banner提升项目B格?
    Effective Modern C++[实践]->优先选用别名声明,而非typedef
    容器镜像安全:安全漏洞扫描神器Trivy
    构建高效问题解答平台:使用Cpolar和Tipas在Ubuntu上搭建专属问答网站
    路由的控制与转发原理
  • 原文地址:https://blog.csdn.net/weixin_36432129/article/details/130859766