]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
net-timestamp: COMPLETION timestamp on packet tx completion
authorPauli Virtanen <pav@iki.fi>
Tue, 18 Mar 2025 19:06:42 +0000 (21:06 +0200)
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Tue, 25 Mar 2025 16:48:05 +0000 (12:48 -0400)
Add SOF_TIMESTAMPING_TX_COMPLETION, for requesting a software timestamp
when hardware reports a packet completed.

Completion tstamp is useful for Bluetooth, as hardware timestamps do not
exist in the HCI specification except for ISO packets, and the hardware
has a queue where packets may wait.  In this case the software SND
timestamp only reflects the kernel-side part of the total latency
(usually small) and queue length (usually 0 unless HW buffers
congested), whereas the completion report time is more informative of
the true latency.

It may also be useful in other cases where HW TX timestamps cannot be
obtained and user wants to estimate an upper bound to when the TX
probably happened.

Signed-off-by: Pauli Virtanen <pav@iki.fi>
Reviewed-by: Willem de Bruijn <willemb@google.com>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Documentation/networking/timestamping.rst
include/linux/skbuff.h
include/uapi/linux/errqueue.h
include/uapi/linux/net_tstamp.h
net/core/skbuff.c
net/ethtool/common.c
net/socket.c

index 61ef9da10e284d43265b371f272d8ca299785056..b8fef8101176dcf3e85e58d19234049380a00baa 100644 (file)
@@ -140,6 +140,14 @@ SOF_TIMESTAMPING_TX_ACK:
   cumulative acknowledgment. The mechanism ignores SACK and FACK.
   This flag can be enabled via both socket options and control messages.
 
+SOF_TIMESTAMPING_TX_COMPLETION:
+  Request tx timestamps on packet tx completion.  The completion
+  timestamp is generated by the kernel when it receives packet a
+  completion report from the hardware. Hardware may report multiple
+  packets at once, and completion timestamps reflect the timing of the
+  report and not actual tx time. This flag can be enabled via both
+  socket options and control messages.
+
 
 1.3.2 Timestamp Reporting
 ^^^^^^^^^^^^^^^^^^^^^^^^^
index cd8294cdc249680da4dca77fe7965b73709cf068..b974a277975a8a7b6f40c362542e9e8522539009 100644 (file)
@@ -478,8 +478,8 @@ enum {
        /* device driver is going to provide hardware time stamp */
        SKBTX_IN_PROGRESS = 1 << 2,
 
-       /* reserved */
-       SKBTX_RESERVED = 1 << 3,
+       /* generate software time stamp on packet tx completion */
+       SKBTX_COMPLETION_TSTAMP = 1 << 3,
 
        /* generate wifi status information (where possible) */
        SKBTX_WIFI_STATUS = 1 << 4,
@@ -498,7 +498,8 @@ enum {
 
 #define SKBTX_ANY_SW_TSTAMP    (SKBTX_SW_TSTAMP    | \
                                 SKBTX_SCHED_TSTAMP | \
-                                SKBTX_BPF)
+                                SKBTX_BPF          | \
+                                SKBTX_COMPLETION_TSTAMP)
 #define SKBTX_ANY_TSTAMP       (SKBTX_HW_TSTAMP | \
                                 SKBTX_ANY_SW_TSTAMP)
 
index 3c70e8ac14b8d9a3adb7ad71dd0677b9cf9ecb60..1ea47309d7726114e976cfbe26c1d8a07f48015d 100644 (file)
@@ -73,6 +73,7 @@ enum {
        SCM_TSTAMP_SND,         /* driver passed skb to NIC, or HW */
        SCM_TSTAMP_SCHED,       /* data entered the packet scheduler */
        SCM_TSTAMP_ACK,         /* data acknowledged by peer */
+       SCM_TSTAMP_COMPLETION,  /* packet tx completion */
 };
 
 #endif /* _UAPI_LINUX_ERRQUEUE_H */
index 55b0ab51096c153c6e1f81d0b0c231dddfa13494..383213de612a8b4fa42d157b3909bcdb5196e446 100644 (file)
@@ -44,8 +44,9 @@ enum {
        SOF_TIMESTAMPING_BIND_PHC = (1 << 15),
        SOF_TIMESTAMPING_OPT_ID_TCP = (1 << 16),
        SOF_TIMESTAMPING_OPT_RX_FILTER = (1 << 17),
+       SOF_TIMESTAMPING_TX_COMPLETION = (1 << 18),
 
-       SOF_TIMESTAMPING_LAST = SOF_TIMESTAMPING_OPT_RX_FILTER,
+       SOF_TIMESTAMPING_LAST = SOF_TIMESTAMPING_TX_COMPLETION,
        SOF_TIMESTAMPING_MASK = (SOF_TIMESTAMPING_LAST - 1) |
                                 SOF_TIMESTAMPING_LAST
 };
@@ -58,7 +59,8 @@ enum {
 #define SOF_TIMESTAMPING_TX_RECORD_MASK        (SOF_TIMESTAMPING_TX_HARDWARE | \
                                         SOF_TIMESTAMPING_TX_SOFTWARE | \
                                         SOF_TIMESTAMPING_TX_SCHED | \
-                                        SOF_TIMESTAMPING_TX_ACK)
+                                        SOF_TIMESTAMPING_TX_ACK | \
+                                        SOF_TIMESTAMPING_TX_COMPLETION)
 
 /**
  * struct so_timestamping - SO_TIMESTAMPING parameter
index ab8acb737b93299f503e5c298b87e18edd59d555..6cbf77bc61fce74c934628fd74b3a2cb7809e464 100644 (file)
@@ -5523,6 +5523,8 @@ static bool skb_tstamp_tx_report_so_timestamping(struct sk_buff *skb,
                                                    SKBTX_SW_TSTAMP);
        case SCM_TSTAMP_ACK:
                return TCP_SKB_CB(skb)->txstamp_ack & TSTAMP_ACK_SK;
+       case SCM_TSTAMP_COMPLETION:
+               return skb_shinfo(skb)->tx_flags & SKBTX_COMPLETION_TSTAMP;
        }
 
        return false;
index 7e3c16856c1a8f93ac1f7a2090d7cff763db005f..0cb6da1f692a0a91ead82c1a10555d06a662ccd7 100644 (file)
@@ -476,6 +476,7 @@ const char sof_timestamping_names[][ETH_GSTRING_LEN] = {
        [const_ilog2(SOF_TIMESTAMPING_BIND_PHC)]     = "bind-phc",
        [const_ilog2(SOF_TIMESTAMPING_OPT_ID_TCP)]   = "option-id-tcp",
        [const_ilog2(SOF_TIMESTAMPING_OPT_RX_FILTER)] = "option-rx-filter",
+       [const_ilog2(SOF_TIMESTAMPING_TX_COMPLETION)] = "tx-completion",
 };
 static_assert(ARRAY_SIZE(sof_timestamping_names) == __SOF_TIMESTAMPING_CNT);
 
index b64ecf2722e7b8df2e724780acb78a4a3f0cc244..e3d879b53278183c625180fb0bd54d9b99323386 100644 (file)
@@ -689,6 +689,9 @@ void __sock_tx_timestamp(__u32 tsflags, __u8 *tx_flags)
        if (tsflags & SOF_TIMESTAMPING_TX_SCHED)
                flags |= SKBTX_SCHED_TSTAMP;
 
+       if (tsflags & SOF_TIMESTAMPING_TX_COMPLETION)
+               flags |= SKBTX_COMPLETION_TSTAMP;
+
        *tx_flags = flags;
 }
 EXPORT_SYMBOL(__sock_tx_timestamp);