net: extend ndo_get_tstamp and implement in gve
Subsystems (6)
v2 cover net: extend ndo_get_tstamp and implement in gve
This series extends ndo_get_tstamp to support other timestamp types and implements it in the gve driver.
Changes in v2:
- Fixed 32-bit compile issues in gve_ptp.c by using div64_u64 helpers.
- Fixed a div by zero case in gve_hwts_realtime_update.
- Added kdoc for ndo_get_tstamp.
Kevin Yang (2):
net: extend ndo_get_tstamp for other timestamp types
gve: implement ndo_get_tstamp
Documentation/networking/timestamping.rst | 21 ++++ drivers/net/ethernet/engleder/tsnep_main.c | 8 +- drivers/net/ethernet/google/gve/gve.h | 8 ++ drivers/net/ethernet/google/gve/gve_adminq.h | 4 +- drivers/net/ethernet/google/gve/gve_main.c | 27 +++++ drivers/net/ethernet/google/gve/gve_ptp.c | 107 ++++++++++++++++++- drivers/net/ethernet/intel/igc/igc_main.c | 8 +- include/linux/netdevice.h | 21 ++-- 8 files changed, 188 insertions(+), 16 deletions(-)
Signature · 1 line
2.52.0.457.g6b5491de43-goog
PATCH v2 1/2 net: extend ndo_get_tstamp for other timestamp types
Network device hardware timestamps (hwtstamps) and the system's clock (ktime) often originate from different clock domains. This makes it hard to directly calculate the duration between a hardware-timestamped event and a system-time event by simple subtraction.
This patch extends ndo_get_tstamp to allow a netdev to provide a hwtstamp into the system's CLOCK_REALTIME domain. This allows a driver to either perform a conversion by estimating or, if the clocks are kept synchronized, return the original timestamp directly. Other clock domains, e.g. CLOCK_MONOTONIC_RAW can also be added when a use surfaces.
This is useful for features that need to measure the delay between a packet's hardware arrival/departure and a later software event. For example, the TCP stack can use this to measure precise packet receive delays, which is a requirement for the upcoming TCP Swift [1] congestion control algorithm.
[1] Kumar, Gautam, et al. "Swift: Delay is simple and effective for congestion control in the datacenter." Proceedings of the Annual conference of the ACM Special Interest Group on Data Communication on the applications, technologies, architectures, and protocols for computer communication. 2020.
--- Documentation/networking/timestamping.rst | 21 +++++++++++++++++++++ drivers/net/ethernet/engleder/tsnep_main.c | 8 +++++--- drivers/net/ethernet/intel/igc/igc_main.c | 8 +++++--- include/linux/netdevice.h | 21 ++++++++++++++------- 4 files changed, 45 insertions(+), 13 deletions(-)
Documentation/networking/timestamping.rst +21 -0
@@ -671,6 +671,27 @@ Time stamps for outgoing packets are to be generated as follows: software time stamping and therefore could lead to unexpected deltas between time stamps. +3.1.1 netdev_tstamp_type and ndo_get_tstamp +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +The ``ndo_get_tstamp`` operation allows the stack to convert a hardware timestamp +to a specific time domain or format. The ``type`` argument specifies the +requested timestamp type: + +- ``NETDEV_TSTAMP_PHC``: The hardware timestamp in its PTP Hardware Clock + domain. +- ``NETDEV_TSTAMP_CYCLE``: The hardware timestamp as a cycle counter. +- ``NETDEV_TSTAMP_REALTIME``: The hardware timestamp converted to system time + (``CLOCK_REALTIME``). + +For ``NETDEV_TSTAMP_REALTIME``, the driver is responsible for converting the +hardware timestamp to system time. In that case, ``ndo_get_tstamp`` does not +provide an accuracy guarantee. A device might use a disciplined clock that is +synchronized with ``CLOCK_REALTIME``. Or, the driver might estimate the system +time. The accuracy primarily depends on the physical hardware and driver +implementation. + + 3.2 Special considerations for stacked PTP Hardware Clocks ----------------------------------------------------------
drivers/net/ethernet/engleder/tsnep_main.c +5 -3
@@ -2275,15 +2275,17 @@ static int tsnep_netdev_set_features(struct net_device *netdev,static ktime_t tsnep_netdev_get_tstamp (struct net_device *netdev,const struct skb_shared_hwtstamps *hwtstamps, -bool cycles) +enum netdev_tstamp_type type) {struct tsnep_rx_inline *rx_inline = hwtstamps->netdev_data;u64 timestamp; -if (cycles) +if (type ==NETDEV_TSTAMP_CYCLE ) timestamp =__le64_to_cpu (rx_inline->counter); -else +else if (type ==NETDEV_TSTAMP_PHC ) timestamp =__le64_to_cpu (rx_inline->timestamp); +else +return 0 ;return ns_to_ktime (timestamp); }
drivers/net/ethernet/intel/igc/igc_main.c +5 -3
@@ -6947,7 +6947,7 @@ int igc_xsk_wakeup(struct net_device *dev, u32 queue_id, u32 flags)static ktime_t igc_get_tstamp (struct net_device *dev,const struct skb_shared_hwtstamps *hwtstamps, -bool cycles) +enum netdev_tstamp_type type) {struct igc_adapter *adapter =netdev_priv (dev);struct igc_inline_rx_tstamps *tstamp;
@@ -6955,10 +6955,12 @@ static ktime_t igc_get_tstamp(struct net_device *dev, tstamp = hwtstamps->netdev_data; -if (cycles) +if (type ==NETDEV_TSTAMP_CYCLE ) timestamp =igc_ptp_rx_pktstamp (adapter, tstamp->timer1); -else +else if (type ==NETDEV_TSTAMP_PHC ) timestamp =igc_ptp_rx_pktstamp (adapter, tstamp->timer0); +else +return 0 ;return timestamp; }
include/linux/netdevice.h +14 -7
@@ -1062,6 +1062,12 @@ struct netdev_net_notifier {struct notifier_block *nb; }; +enum netdev_tstamp_type { +NETDEV_TSTAMP_PHC =0 , +NETDEV_TSTAMP_CYCLE , +NETDEV_TSTAMP_REALTIME , +}; +/* * This structure defines the management hooks for network devices. * The following hooks can be defined; unless noted otherwise, they are
@@ -1406,11 +1412,10 @@ struct netdev_net_notifier {* Get the forwarding path to reach the real device from the HW destination address * ktime_t (*ndo_get_tstamp)(struct net_device *dev, * const struct skb_shared_hwtstamps *hwtstamps, -* bool cycles); -* Get hardware timestamp based on normal/adjustable time or free running -* cycle counter. This function is required if physical clock supports a -* free running cycle counter. -* +* enum netdev_tstamp_type type); +* Get hardware timestamp based on the type requested, or return 0 if the +* requested type is not supported. This function is required if physical +* clock supports a free running cycle counter. * int (*ndo_hwtstamp_get)(struct net_device *dev, * struct kernel_hwtstamp_config *kernel_config); * Get the currently configured hardware timestamping parameters for the
@@ -1661,7 +1666,7 @@ struct net_device_ops { struct net_device_path *path);ktime_t (*ndo_get_tstamp)(struct net_device *dev,const struct skb_shared_hwtstamps *hwtstamps, -bool cycles); +enum netdev_tstamp_type type);int (*ndo_hwtstamp_get)(struct net_device *dev,struct kernel_hwtstamp_config *kernel_config); int (*ndo_hwtstamp_set)(struct net_device *dev,
@@ -5236,9 +5241,11 @@ static inline ktime_t netdev_get_tstamp(struct net_device *dev, bool cycles) {const struct net_device_ops *ops = dev->netdev_ops; +enum netdev_tstamp_type type = cycles ?NETDEV_TSTAMP_CYCLE : +NETDEV_TSTAMP_PHC ;if (ops->ndo_get_tstamp) -return ops->ndo_get_tstamp (dev, hwtstamps, cycles); +return ops->ndo_get_tstamp (dev, hwtstamps, type);return hwtstamps->hwtstamp; }
Signature · 1 line
2.52.0.457.g6b5491de43-goog
PATCH v2 2/2 gve: implement ndo_get_tstamp
In reply to Kevin YangThis patch implements ndo_get_tstamp in gve to support converting a hwtstamp to the system's realtime clock.
The implementation does not assume the NIC clock is disciplined, in other word, the NIC clock can be free-running. A periodic job, embedded in gve's ptp_aux_work, updates the offset and slope for the conversion.
--- drivers/net/ethernet/google/gve/gve.h | 8 ++ drivers/net/ethernet/google/gve/gve_adminq.h | 4 +- drivers/net/ethernet/google/gve/gve_main.c | 27 +++++ drivers/net/ethernet/google/gve/gve_ptp.c | 107 ++++++++++++++++++- 4 files changed, 143 insertions(+), 3 deletions(-)
drivers/net/ethernet/google/gve/gve.h +8 -0
@@ -774,6 +774,13 @@ struct gve_flow_rule {struct gve_flow_spec mask; }; +struct gve_tstamp_conversion { +u64 last_sync_ns; +seqlock_t lock;/* protects tc and cc */ +struct timecounter tc; +struct cyclecounter cc; +}; +struct gve_flow_rules_cache {bool rules_cache_synced;/* False if the driver's rules_cache is outdated */ struct gve_adminq_queried_flow_rule *rules_cache;
@@ -925,6 +932,7 @@ struct gve_priv {struct gve_nic_ts_report *nic_ts_report;dma_addr_t nic_ts_report_bus;u64 last_sync_nic_counter;/* Clock counter from last NIC TS report */ +struct gve_tstamp_conversion ts_real; };enum gve_service_task_flags_bit {
drivers/net/ethernet/google/gve/gve_adminq.h +2 -2
@@ -411,8 +411,8 @@ static_assert(sizeof(struct gve_adminq_report_nic_ts) == 16);struct gve_nic_ts_report {__be64 nic_timestamp;/* NIC clock in nanoseconds */ -__be64 reserved1; -__be64 reserved2; +__be64 cycle_pre; +__be64 cycle_post;__be64 reserved3;__be64 reserved4; };
drivers/net/ethernet/google/gve/gve_main.c +27 -0
@@ -2198,6 +2198,32 @@ static int gve_set_ts_config(struct net_device *dev,return 0 ; } +static ktime_t gve_get_tstamp (struct net_device *dev, +const struct skb_shared_hwtstamps *hwtstamps, +enum netdev_tstamp_type type) +{ +struct gve_priv *priv =netdev_priv (dev); +unsigned int seq; +u64 ns; + +if (type ==NETDEV_TSTAMP_PHC ) +return hwtstamps->hwtstamp; + +if (type !=NETDEV_TSTAMP_REALTIME ) +return 0 ; + +/* Skip if never synced */ +if (!READ_ONCE (priv->ts_real.last_sync_ns)) +return 0 ; + +do { + seq =read_seqbegin (&priv->ts_real.lock); + ns =timecounter_cyc2time (&priv->ts_real.tc, + hwtstamps->hwtstamp); + }while (read_seqretry (&priv->ts_real.lock, seq)); +return ns_to_ktime (ns); +} +static const struct net_device_ops gve_netdev_ops = { .ndo_start_xmit = gve_start_xmit, .ndo_features_check = gve_features_check,
@@ -2209,6 +2235,7 @@ static const struct net_device_ops gve_netdev_ops = { .ndo_bpf = gve_xdp, .ndo_xdp_xmit = gve_xdp_xmit, .ndo_xsk_wakeup = gve_xsk_wakeup, + .ndo_get_tstamp = gve_get_tstamp, .ndo_hwtstamp_get = gve_get_ts_config, .ndo_hwtstamp_set = gve_set_ts_config, };
drivers/net/ethernet/google/gve/gve_ptp.c +106 -1
135 lines not on this page · raw message
Signature · 1 line
2.52.0.457.g6b5491de43-goog
Re: [PATCH net-next v2 1/2] net: extend ndo_get_tstamp for other timestamp types
In reply to Kevin YangQuoted 19 lines · Kevin Yang
Network device hardware timestamps (hwtstamps) and the system's clock (ktime) often originate from different clock domains. This makes it hard to directly calculate the duration between a hardware-timestamped event and a system-time event by simple subtraction.
This patch extends
ndo_get_tstampto allow a netdev to provide a hwtstamp into the system'sCLOCK_REALTIMEdomain. This allows a driver to either perform a conversion by estimating or, if the clocks are kept synchronized, return the original timestamp directly. Other clock domains, e.g.CLOCK_MONOTONIC_RAWcan also be added when a use surfaces.This is useful for features that need to measure the delay between a packet's hardware arrival/departure and a later software event. For example, the TCP stack can use this to measure precise packet receive delays, which is a requirement for the upcoming TCP Swift [1] congestion control algorithm.
Quoted 8 lines
[1] Kumar, Gautam, et al. "Swift: Delay is simple and effective for congestion control in the datacenter." Proceedings of the Annual conference of the ACM Special Interest Group on Data Communication on the applications, technologies, architectures, and protocols for computer communication. 2020.
Signed-off-by Kevin Yang <[email protected]>Reviewed-by Willem de Bruijn <[email protected]>
Like Jakub in his reply
https://lore.kernel.org/netdev/[email protected]/
for me also the question why this is a driver implementation came to my mind.
With vclocks it is already possible to get timestamps for arbitrary clock domains in parallel. So it is already possible to synchronize the hwtstamp to CLOCK_REALTIME, CLOCK_MONOTONIC, ... in parallel. Therefore, user space synchronisation is needed, but e.g. ptp4l does a much better synchronisation job than your solution.
Maybe CLOCK_REALTIME is not supported by ptp4l, because due to daytime saving this clock jumps. IMO these jumps will also be problem for your solution, as it will lead to wrong delays two times a year. So usually CLOCK_TAI or CLOCK_MONOTONIC would be a better choice.
To sum up: IMO you suggest a driver specific in-kernel solution where already a driver independent user space solution with higher accuracy exists.
Gerhard
Willem de Bruijn
maintainerRe: [PATCH net-next v2 1/2] net: extend ndo_get_tstamp for other timestamp types
Quoted 40 lines · Gerhard Engleder
Quoted 19 lines · Kevin Yang
Network device hardware timestamps (hwtstamps) and the system's clock (ktime) often originate from different clock domains. This makes it hard to directly calculate the duration between a hardware-timestamped event and a system-time event by simple subtraction.
This patch extends
ndo_get_tstampto allow a netdev to provide a hwtstamp into the system'sCLOCK_REALTIMEdomain. This allows a driver to either perform a conversion by estimating or, if the clocks are kept synchronized, return the original timestamp directly. Other clock domains, e.g.CLOCK_MONOTONIC_RAWcan also be added when a use surfaces.This is useful for features that need to measure the delay between a packet's hardware arrival/departure and a later software event. For example, the TCP stack can use this to measure precise packet receive delays, which is a requirement for the upcoming TCP Swift [1] congestion control algorithm.
Quoted 8 lines
[1] Kumar, Gautam, et al. "Swift: Delay is simple and effective for congestion control in the datacenter." Proceedings of the Annual conference of the ACM Special Interest Group on Data Communication on the applications, technologies, architectures, and protocols for computer communication. 2020.
Signed-off-by Kevin Yang <[email protected]>Reviewed-by Willem de Bruijn <[email protected]>Like Jakub in his reply
https://lore.kernel.org/netdev/[email protected]/
for me also the question why this is a driver implementation came to my mind.With vclocks it is already possible to get timestamps for arbitrary clock domains in parallel. So it is already possible to synchronize the hwtstamp to
CLOCK_REALTIME,CLOCK_MONOTONIC, ... in parallel. Therefore, user space synchronisation is needed, but e.g. ptp4l does a much better synchronisation job than your solution.
Quoted 8 lines
Maybe
CLOCK_REALTIMEis not supported by ptp4l, because due to daytime saving this clock jumps. IMO these jumps will also be problem for your solution, as it will lead to wrong delays two times a year. So usuallyCLOCK_TAIorCLOCK_MONOTONICwould be a better choice.To sum up: IMO you suggest a driver specific in-kernel solution where already a driver independent user space solution with higher accuracy exists.
Definitely a promising alternative.
With multiple netdevices, a TCP listener socket may receive packets from all devices. This would need new infrastructure to lookup the correct vclock for a given net_device, cannot hardcode a choice with SOF_TIMESTAMPING_BIND_PHC.
And this needs to happen for every packet, so with minimal overhead.
Though for established connections the expectation will be that packets generally arrive on the same netdevice. Bar infrequent path changes such as from sk_rethink_txhash on the peer. So there this value can perhaps be cached.
It would still have to be learned by the kernel, no explicit setsockopt.
Re: [PATCH net-next v2 1/2] net: extend ndo_get_tstamp for other timestamp types
Quoted 59 lines · Willem de Bruijn
Quoted 40 lines · Gerhard Engleder
Quoted 19 lines · Kevin Yang
Network device hardware timestamps (hwtstamps) and the system's clock (ktime) often originate from different clock domains. This makes it hard to directly calculate the duration between a hardware-timestamped event and a system-time event by simple subtraction.
This patch extends
ndo_get_tstampto allow a netdev to provide a hwtstamp into the system'sCLOCK_REALTIMEdomain. This allows a driver to either perform a conversion by estimating or, if the clocks are kept synchronized, return the original timestamp directly. Other clock domains, e.g.CLOCK_MONOTONIC_RAWcan also be added when a use surfaces.This is useful for features that need to measure the delay between a packet's hardware arrival/departure and a later software event. For example, the TCP stack can use this to measure precise packet receive delays, which is a requirement for the upcoming TCP Swift [1] congestion control algorithm.
Quoted 8 lines
[1] Kumar, Gautam, et al. "Swift: Delay is simple and effective for congestion control in the datacenter." Proceedings of the Annual conference of the ACM Special Interest Group on Data Communication on the applications, technologies, architectures, and protocols for computer communication. 2020.
Signed-off-by Kevin Yang <[email protected]>Reviewed-by Willem de Bruijn <[email protected]>Like Jakub in his reply
https://lore.kernel.org/netdev/[email protected]/
for me also the question why this is a driver implementation came to my mind.With vclocks it is already possible to get timestamps for arbitrary clock domains in parallel. So it is already possible to synchronize the hwtstamp to
CLOCK_REALTIME,CLOCK_MONOTONIC, ... in parallel. Therefore, user space synchronisation is needed, but e.g. ptp4l does a much better synchronisation job than your solution.Quoted 8 lines
Maybe
CLOCK_REALTIMEis not supported by ptp4l, because due to daytime saving this clock jumps. IMO these jumps will also be problem for your solution, as it will lead to wrong delays two times a year. So usuallyCLOCK_TAIorCLOCK_MONOTONICwould be a better choice.To sum up: IMO you suggest a driver specific in-kernel solution where already a driver independent user space solution with higher accuracy exists.
Definitely a promising alternative.
With multiple netdevices, a TCP listener socket may receive packets from all devices. This would need new infrastructure to lookup the correct vclock for a given
net_device, cannot hardcode a choice withSOF_TIMESTAMPING_BIND_PHC.And this needs to happen for every packet, so with minimal overhead.
Quoted 7 lines
Though for established connections the expectation will be that packets generally arrive on the same netdevice. Bar infrequent path changes such as from
sk_rethink_txhashon the peer. So there this value can perhaps be cached.It would still have to be learned by the kernel, no explicit setsockopt.
Maybe it would also be an option, that the kernel learns with which clock domain the timestamps of the PHC and vclocks correlate. Then the TCP stack could calculate the delay if it finds a valid e.g. CLOCK_MONOTONIC timestamp in the packet. This would make the TCP listener socket independent from the devices. Just an idea, without thinking about implementation details.
Gerhard
Willem de Bruijn
maintainerRe: [PATCH net-next v2 1/2] net: extend ndo_get_tstamp for other timestamp types
Quoted 68 lines · Gerhard Engleder
Quoted 59 lines · Willem de Bruijn
Quoted 40 lines · Gerhard Engleder
Quoted 19 lines · Kevin Yang
Network device hardware timestamps (hwtstamps) and the system's clock (ktime) often originate from different clock domains. This makes it hard to directly calculate the duration between a hardware-timestamped event and a system-time event by simple subtraction.
This patch extends
ndo_get_tstampto allow a netdev to provide a hwtstamp into the system'sCLOCK_REALTIMEdomain. This allows a driver to either perform a conversion by estimating or, if the clocks are kept synchronized, return the original timestamp directly. Other clock domains, e.g.CLOCK_MONOTONIC_RAWcan also be added when a use surfaces.This is useful for features that need to measure the delay between a packet's hardware arrival/departure and a later software event. For example, the TCP stack can use this to measure precise packet receive delays, which is a requirement for the upcoming TCP Swift [1] congestion control algorithm.
Quoted 8 lines
[1] Kumar, Gautam, et al. "Swift: Delay is simple and effective for congestion control in the datacenter." Proceedings of the Annual conference of the ACM Special Interest Group on Data Communication on the applications, technologies, architectures, and protocols for computer communication. 2020.
Signed-off-by Kevin Yang <[email protected]>Reviewed-by Willem de Bruijn <[email protected]>Like Jakub in his reply
https://lore.kernel.org/netdev/[email protected]/
for me also the question why this is a driver implementation came to my mind.With vclocks it is already possible to get timestamps for arbitrary clock domains in parallel. So it is already possible to synchronize the hwtstamp to
CLOCK_REALTIME,CLOCK_MONOTONIC, ... in parallel. Therefore, user space synchronisation is needed, but e.g. ptp4l does a much better synchronisation job than your solution.Quoted 8 lines
Maybe
CLOCK_REALTIMEis not supported by ptp4l, because due to daytime saving this clock jumps. IMO these jumps will also be problem for your solution, as it will lead to wrong delays two times a year. So usuallyCLOCK_TAIorCLOCK_MONOTONICwould be a better choice.To sum up: IMO you suggest a driver specific in-kernel solution where already a driver independent user space solution with higher accuracy exists.
Definitely a promising alternative.
With multiple netdevices, a TCP listener socket may receive packets from all devices. This would need new infrastructure to lookup the correct vclock for a given
net_device, cannot hardcode a choice withSOF_TIMESTAMPING_BIND_PHC.And this needs to happen for every packet, so with minimal overhead.
Quoted 7 lines
Though for established connections the expectation will be that packets generally arrive on the same netdevice. Bar infrequent path changes such as from
sk_rethink_txhashon the peer. So there this value can perhaps be cached.It would still have to be learned by the kernel, no explicit setsockopt.
Quoted 6 lines
Maybe it would also be an option, that the kernel learns with which clock domain the timestamps of the PHC and vclocks correlate. Then the TCP stack could calculate the delay if it finds a valid e.g.
CLOCK_MONOTONICtimestamp in the packet. This would make the TCP listener socket independent from the devices. Just an idea, without thinking about implementation details.
I think we're on the same page.
- use the existing vclocks
- look up the right vclock based on the original incoming iface
- cache this known clock with an established socket
But I also have not looked at how/whether the lookup infra can be implemented to find a vclock automatically, i.e., without userspace admin.
In some cases shinfo hwtstamp raw format may actually be the CLOCK_REALTIME that TCP requires. But if the raw clock is not realtime, we'll have to adjust based on timecounter/cyclecounter.
Re: [PATCH net-next v2 1/2] net: extend ndo_get_tstamp for other timestamp types
Just to clarify, the ptp vclocks approach is not contradictory to this patch.
I think converting the timestamp should be a net_device ndo function. Since
- a TCP socket may receive packets from multiple net_devices
- only the driver is aware of the device clock's details and whether a conversion is actually required
That conversion is implemented per device:
- Some devices can identify the correct vclock and call ptp_convert_timestamp(&hwtstamp, vclock). This is a valid approach, but it requires the system admin to run phc2sys to sync the vclock to REALTIME(or MONOTONIC), alongside necessary lookup infrastructure.
- Some devices may already sync their clock to REALTIME natively. In this case, hwtstamp is returned as-is without conversion.
- Some devices may handle conversion internally without using PTP. This is the case for our current GVE patch.
With that, I think this patch (extending ndo_get_tstamp) has value regardless of the specific driver implementation.
As for the second patch and the question of why GVE does not use vclocks:
The current GVE patch is simple and self-contained. Switching to vclocks would likely require adding PTP infrastructure to look up a vclock without user interaction, which complicates development compared to the current approach. Also, ptp_convert_timestamp involves a mutex lock, this might raise performance concerns since the usage is on the TCP RX fast path.
Quoted 90 lines · Willem de Bruijn
Quoted 68 lines · Gerhard Engleder
Quoted 59 lines · Willem de Bruijn
Quoted 40 lines · Gerhard Engleder
Quoted 19 lines · Kevin Yang
Network device hardware timestamps (hwtstamps) and the system's clock (ktime) often originate from different clock domains. This makes it hard to directly calculate the duration between a hardware-timestamped event and a system-time event by simple subtraction.
This patch extends
ndo_get_tstampto allow a netdev to provide a hwtstamp into the system'sCLOCK_REALTIMEdomain. This allows a driver to either perform a conversion by estimating or, if the clocks are kept synchronized, return the original timestamp directly. Other clock domains, e.g.CLOCK_MONOTONIC_RAWcan also be added when a use surfaces.This is useful for features that need to measure the delay between a packet's hardware arrival/departure and a later software event. For example, the TCP stack can use this to measure precise packet receive delays, which is a requirement for the upcoming TCP Swift [1] congestion control algorithm.
Quoted 8 lines
[1] Kumar, Gautam, et al. "Swift: Delay is simple and effective for congestion control in the datacenter." Proceedings of the Annual conference of the ACM Special Interest Group on Data Communication on the applications, technologies, architectures, and protocols for computer communication. 2020.
Signed-off-by Kevin Yang <[email protected]>Reviewed-by Willem de Bruijn <[email protected]>Like Jakub in his reply
https://lore.kernel.org/netdev/[email protected]/
for me also the question why this is a driver implementation came to my mind.With vclocks it is already possible to get timestamps for arbitrary clock domains in parallel. So it is already possible to synchronize the hwtstamp to
CLOCK_REALTIME,CLOCK_MONOTONIC, ... in parallel. Therefore, user space synchronisation is needed, but e.g. ptp4l does a much better synchronisation job than your solution.Quoted 8 lines
Maybe
CLOCK_REALTIMEis not supported by ptp4l, because due to daytime saving this clock jumps. IMO these jumps will also be problem for your solution, as it will lead to wrong delays two times a year. So usuallyCLOCK_TAIorCLOCK_MONOTONICwould be a better choice.To sum up: IMO you suggest a driver specific in-kernel solution where already a driver independent user space solution with higher accuracy exists.
Definitely a promising alternative.
With multiple netdevices, a TCP listener socket may receive packets from all devices. This would need new infrastructure to lookup the correct vclock for a given
net_device, cannot hardcode a choice withSOF_TIMESTAMPING_BIND_PHC.And this needs to happen for every packet, so with minimal overhead.
Quoted 7 lines
Though for established connections the expectation will be that packets generally arrive on the same netdevice. Bar infrequent path changes such as from
sk_rethink_txhashon the peer. So there this value can perhaps be cached.It would still have to be learned by the kernel, no explicit setsockopt.
Quoted 6 lines
Maybe it would also be an option, that the kernel learns with which clock domain the timestamps of the PHC and vclocks correlate. Then the TCP stack could calculate the delay if it finds a valid e.g.
CLOCK_MONOTONICtimestamp in the packet. This would make the TCP listener socket independent from the devices. Just an idea, without thinking about implementation details.I think we're on the same page.
- use the existing vclocks
- look up the right vclock based on the original incoming iface
- cache this known clock with an established socketBut I also have not looked at how/whether the lookup infra can be implemented to find a vclock automatically, i.e., without userspace admin.
In some cases shinfo hwtstamp raw format may actually be the
CLOCK_REALTIMEthat TCP requires. But if the raw clock is not realtime, we'll have to adjust based on timecounter/cyclecounter.