ntp: allow TX-only HW timestamping by default

If no rxfilter is specified in the hwtimestamp directive and the NIC
doesn't support the all or ntp filter, enable TX-only HW timestamping
with the none filter.
This commit is contained in:
Miroslav Lichvar 2017-08-23 11:33:37 +02:00
parent 3e93068c43
commit aee42fada8
4 changed files with 42 additions and 25 deletions

2
conf.c
View file

@ -1281,7 +1281,7 @@ parse_hwtimestamp(char *line)
iface->name = Strdup(p); iface->name = Strdup(p);
iface->minpoll = 0; iface->minpoll = 0;
iface->nocrossts = 0; iface->nocrossts = 0;
iface->rxfilter = CNF_HWTS_RXFILTER_NTP; iface->rxfilter = CNF_HWTS_RXFILTER_ANY;
iface->precision = 100.0e-9; iface->precision = 100.0e-9;
iface->tx_comp = 0.0; iface->tx_comp = 0.0;
iface->rx_comp = 0.0; iface->rx_comp = 0.0;

7
conf.h
View file

@ -118,9 +118,10 @@ extern char *CNF_GetHwclockFile(void);
extern int CNF_GetInitSources(void); extern int CNF_GetInitSources(void);
extern double CNF_GetInitStepThreshold(void); extern double CNF_GetInitStepThreshold(void);
#define CNF_HWTS_RXFILTER_NONE 0 #define CNF_HWTS_RXFILTER_ANY 0
#define CNF_HWTS_RXFILTER_NTP 1 #define CNF_HWTS_RXFILTER_NONE 1
#define CNF_HWTS_RXFILTER_ALL 2 #define CNF_HWTS_RXFILTER_NTP 2
#define CNF_HWTS_RXFILTER_ALL 3
typedef struct { typedef struct {
char *name; char *name;

View file

@ -1886,11 +1886,12 @@ be enabled by the *xleave* option in the <<server,*server*>> or the
This directive is supported on Linux 3.19 and newer. The NIC must support HW This directive is supported on Linux 3.19 and newer. The NIC must support HW
timestamping, which can be verified with the *ethtool -T* command. The list of timestamping, which can be verified with the *ethtool -T* command. The list of
capabilities should include _SOF_TIMESTAMPING_RAW_HARDWARE_, capabilities should include _SOF_TIMESTAMPING_RAW_HARDWARE_,
_SOF_TIMESTAMPING_TX_HARDWARE_, _SOF_TIMESTAMPING_RX_HARDWARE_, and the receive _SOF_TIMESTAMPING_TX_HARDWARE_, and _SOF_TIMESTAMPING_RX_HARDWARE_. Receive
filters should include _HWTSTAMP_FILTER_ALL_ or _HWTSTAMP_FILTER_NTP_ALL_. When filter _HWTSTAMP_FILTER_ALL_, or _HWTSTAMP_FILTER_NTP_ALL_, is necessary for
*chronyd* is running, no other process (e.g. a PTP daemon) should be working timestamping of received packets. Timestamping of packets received from bridged
with the NIC clock. HW timestamping of packets received from bridged and bonded and bonded interfaces is supported on Linux 4.13 and newer. When *chronyd* is
interfaces is supported on Linux 4.13 and newer. running, no other process (e.g. a PTP daemon) should be working with the NIC
clock.
+ +
If the kernel supports software timestamping, it will be enabled for all If the kernel supports software timestamping, it will be enabled for all
interfaces. The source of timestamps (i.e. hardware, kernel, or daemon) is interfaces. The source of timestamps (i.e. hardware, kernel, or daemon) is
@ -1925,15 +1926,21 @@ is 0.
Some hardware can precisely cross timestamp the NIC clock with the system Some hardware can precisely cross timestamp the NIC clock with the system
clock. This option disables the use of the cross timestamping. clock. This option disables the use of the cross timestamping.
*rxfilter* _filter_::: *rxfilter* _filter_:::
This option selects the receive timestamping filter. Possible values are: This option selects the receive timestamping filter. The _filter_ can be one of
_all_, _ntp_, and _none_. The default value is _ntp_, which enables the following:
timestamping of NTP packets (_HWTSTAMP_FILTER_NTP_ALL_) if it is supported, or _all_::::
timestamping of all packets (_HWTSTAMP_FILTER_ALL_). Setting *rxfilter* to Enables timestamping of all received packets.
_all_ forces timestamping of all packets, which can be useful when the NIC _ntp_::::
supports both filters and NTP packets are received from or on a non-standard Enables timestamping of received NTP packets.
UDP port (e.g. specified by the *port* directive). Setting *rxfilter* to _none_ _none_::::
disables receive HW timestamping and allows transmit HW timestamping to be Disables timestamping of received packets.
enabled when the NIC supports only PTP-specific receive filters. :::
The most specific filter for timestamping NTP packets which is supported by the
NIC is selected by default. Some NICs can timestamp only PTP packets, which
limits the selection to the _none_ filter. Forcing timestamping of all packets
with the _all_ filter when the NIC supports both _all_ and _ntp_ filters can be
useful when packets are received from or on a non-standard UDP port (e.g.
specified by the *port* directive).
:: ::
+ +
Examples of the directive are: Examples of the directive are:

View file

@ -154,17 +154,25 @@ add_interface(CNF_HwTsInterface *conf_iface)
ts_config.tx_type = HWTSTAMP_TX_ON; ts_config.tx_type = HWTSTAMP_TX_ON;
switch (conf_iface->rxfilter) { switch (conf_iface->rxfilter) {
case CNF_HWTS_RXFILTER_ANY:
#ifdef HAVE_LINUX_TIMESTAMPING_RXFILTER_NTP
if (ts_info.rx_filters & (1 << HWTSTAMP_FILTER_NTP_ALL))
ts_config.rx_filter = HWTSTAMP_FILTER_NTP_ALL;
else
#endif
if (ts_info.rx_filters & (1 << HWTSTAMP_FILTER_ALL))
ts_config.rx_filter = HWTSTAMP_FILTER_ALL;
else
ts_config.rx_filter = HWTSTAMP_FILTER_NONE;
break;
case CNF_HWTS_RXFILTER_NONE: case CNF_HWTS_RXFILTER_NONE:
ts_config.rx_filter = HWTSTAMP_FILTER_NONE; ts_config.rx_filter = HWTSTAMP_FILTER_NONE;
break; break;
case CNF_HWTS_RXFILTER_NTP:
#ifdef HAVE_LINUX_TIMESTAMPING_RXFILTER_NTP #ifdef HAVE_LINUX_TIMESTAMPING_RXFILTER_NTP
if (ts_info.rx_filters & (1 << HWTSTAMP_FILTER_NTP_ALL)) { case CNF_HWTS_RXFILTER_NTP:
ts_config.rx_filter = HWTSTAMP_FILTER_NTP_ALL; ts_config.rx_filter = HWTSTAMP_FILTER_NTP_ALL;
break; break;
}
#endif #endif
/* Fall through */
default: default:
ts_config.rx_filter = HWTSTAMP_FILTER_ALL; ts_config.rx_filter = HWTSTAMP_FILTER_ALL;
break; break;
@ -203,7 +211,8 @@ add_interface(CNF_HwTsInterface *conf_iface)
iface->clock = HCL_CreateInstance(UTI_Log2ToDouble(MAX(conf_iface->minpoll, MIN_PHC_POLL))); iface->clock = HCL_CreateInstance(UTI_Log2ToDouble(MAX(conf_iface->minpoll, MIN_PHC_POLL)));
LOG(LOGS_INFO, "Enabled HW timestamping on %s", iface->name); LOG(LOGS_INFO, "Enabled HW timestamping %son %s",
ts_config.rx_filter == HWTSTAMP_FILTER_NONE ? "(TX only) " : "", iface->name);
return 1; return 1;
} }