判断网口是否支持PTP时间同步的方法
PTP是一种比NTP精度更高的基于网络的高精度时间同步协议,虽然工作在传输层,但要求网口具有额外的时钟电路,下面介绍一下判断网口是否支持PTP同步的方法。
首先安装ethtool工具,在Debian/Ubuntu下安装命令为:
sudo apt install ethtool
然后使用ifconfig查看需要查询的网口硬件的名称,如eth0、enp4s0这种,然后使用ethtool查看网口对ptp的支持,以我台式机上的PCIe千兆网卡enp4s0为例:
ethtool -T enp4s0
输出结果为:
Time stamping parameters for enp4s0:
Capabilities:
software-transmit (SOF_TIMESTAMPING_TX_SOFTWARE)
software-receive (SOF_TIMESTAMPING_RX_SOFTWARE)
software-system-clock (SOF_TIMESTAMPING_SOFTWARE)
PTP Hardware Clock: none
Hardware Transmit Timestamp Modes: none
Hardware Receive Filter Modes: none
可以看到这里返回PTP Hardware Clock为none,但包括software-transmit、software-receive、software-system-clock,说明这个PCIe网卡不具有PTP的时钟硬件,不支持PTP的硬件时间戳,但支持PTP的软件时间戳,而查询我台式机的主板板载网口enp0s31f6的返回信息为:
Time stamping parameters for enp0s31f6:
Capabilities:
hardware-transmit (SOF_TIMESTAMPING_TX_HARDWARE)
software-transmit (SOF_TIMESTAMPING_TX_SOFTWARE)
hardware-receive (SOF_TIMESTAMPING_RX_HARDWARE)
software-receive (SOF_TIMESTAMPING_RX_SOFTWARE)
software-system-clock (SOF_TIMESTAMPING_SOFTWARE)
hardware-raw-clock (SOF_TIMESTAMPING_RAW_HARDWARE)
PTP Hardware Clock: 0
Hardware Transmit Timestamp Modes:
off (HWTSTAMP_TX_OFF)
on (HWTSTAMP_TX_ON)
Hardware Receive Filter Modes:
none (HWTSTAMP_FILTER_NONE)
all (HWTSTAMP_FILTER_ALL)
ptpv1-l4-sync (HWTSTAMP_FILTER_PTP_V1_L4_SYNC)
ptpv1-l4-delay-req (HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ)
ptpv2-l4-sync (HWTSTAMP_FILTER_PTP_V2_L4_SYNC)
ptpv2-l4-delay-req (HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ)
ptpv2-l2-sync (HWTSTAMP_FILTER_PTP_V2_L2_SYNC)
ptpv2-l2-delay-req (HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ)
ptpv2-event (HWTSTAMP_FILTER_PTP_V2_EVENT)
ptpv2-sync (HWTSTAMP_FILTER_PTP_V2_SYNC)
ptpv2-delay-req (HWTSTAMP_FILTER_PTP_V2_DELAY_REQ)
这里PTP Hardware Clock后面是0,且包括software-transmit、software-receive、software-system-clock和hardware-transmit、hardware-receive、hardware-raw-clock,说明存在PTP硬件时钟,既支持PTP的软件时间戳也支持PTP硬件时间戳。
One thought on “判断网口是否支持PTP时间同步的方法”