Skip to content

Commit 983e0e4

Browse files
pvVudentz
authored andcommitted
net-timestamp: COMPLETION timestamp on packet tx completion
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>
1 parent b257e02 commit 983e0e4

File tree

7 files changed

+23
-5
lines changed

7 files changed

+23
-5
lines changed

Documentation/networking/timestamping.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,14 @@ SOF_TIMESTAMPING_TX_ACK:
140140
cumulative acknowledgment. The mechanism ignores SACK and FACK.
141141
This flag can be enabled via both socket options and control messages.
142142

143+
SOF_TIMESTAMPING_TX_COMPLETION:
144+
Request tx timestamps on packet tx completion. The completion
145+
timestamp is generated by the kernel when it receives packet a
146+
completion report from the hardware. Hardware may report multiple
147+
packets at once, and completion timestamps reflect the timing of the
148+
report and not actual tx time. This flag can be enabled via both
149+
socket options and control messages.
150+
143151

144152
1.3.2 Timestamp Reporting
145153
^^^^^^^^^^^^^^^^^^^^^^^^^

include/linux/skbuff.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -478,8 +478,8 @@ enum {
478478
/* device driver is going to provide hardware time stamp */
479479
SKBTX_IN_PROGRESS = 1 << 2,
480480

481-
/* reserved */
482-
SKBTX_RESERVED = 1 << 3,
481+
/* generate software time stamp on packet tx completion */
482+
SKBTX_COMPLETION_TSTAMP = 1 << 3,
483483

484484
/* generate wifi status information (where possible) */
485485
SKBTX_WIFI_STATUS = 1 << 4,
@@ -498,7 +498,8 @@ enum {
498498

499499
#define SKBTX_ANY_SW_TSTAMP (SKBTX_SW_TSTAMP | \
500500
SKBTX_SCHED_TSTAMP | \
501-
SKBTX_BPF)
501+
SKBTX_BPF | \
502+
SKBTX_COMPLETION_TSTAMP)
502503
#define SKBTX_ANY_TSTAMP (SKBTX_HW_TSTAMP | \
503504
SKBTX_ANY_SW_TSTAMP)
504505

include/uapi/linux/errqueue.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ enum {
7373
SCM_TSTAMP_SND, /* driver passed skb to NIC, or HW */
7474
SCM_TSTAMP_SCHED, /* data entered the packet scheduler */
7575
SCM_TSTAMP_ACK, /* data acknowledged by peer */
76+
SCM_TSTAMP_COMPLETION, /* packet tx completion */
7677
};
7778

7879
#endif /* _UAPI_LINUX_ERRQUEUE_H */

include/uapi/linux/net_tstamp.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ enum {
4444
SOF_TIMESTAMPING_BIND_PHC = (1 << 15),
4545
SOF_TIMESTAMPING_OPT_ID_TCP = (1 << 16),
4646
SOF_TIMESTAMPING_OPT_RX_FILTER = (1 << 17),
47+
SOF_TIMESTAMPING_TX_COMPLETION = (1 << 18),
4748

48-
SOF_TIMESTAMPING_LAST = SOF_TIMESTAMPING_OPT_RX_FILTER,
49+
SOF_TIMESTAMPING_LAST = SOF_TIMESTAMPING_TX_COMPLETION,
4950
SOF_TIMESTAMPING_MASK = (SOF_TIMESTAMPING_LAST - 1) |
5051
SOF_TIMESTAMPING_LAST
5152
};
@@ -58,7 +59,8 @@ enum {
5859
#define SOF_TIMESTAMPING_TX_RECORD_MASK (SOF_TIMESTAMPING_TX_HARDWARE | \
5960
SOF_TIMESTAMPING_TX_SOFTWARE | \
6061
SOF_TIMESTAMPING_TX_SCHED | \
61-
SOF_TIMESTAMPING_TX_ACK)
62+
SOF_TIMESTAMPING_TX_ACK | \
63+
SOF_TIMESTAMPING_TX_COMPLETION)
6264

6365
/**
6466
* struct so_timestamping - SO_TIMESTAMPING parameter

net/core/skbuff.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5523,6 +5523,8 @@ static bool skb_tstamp_tx_report_so_timestamping(struct sk_buff *skb,
55235523
SKBTX_SW_TSTAMP);
55245524
case SCM_TSTAMP_ACK:
55255525
return TCP_SKB_CB(skb)->txstamp_ack & TSTAMP_ACK_SK;
5526+
case SCM_TSTAMP_COMPLETION:
5527+
return skb_shinfo(skb)->tx_flags & SKBTX_COMPLETION_TSTAMP;
55265528
}
55275529

55285530
return false;

net/ethtool/common.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,7 @@ const char sof_timestamping_names[][ETH_GSTRING_LEN] = {
476476
[const_ilog2(SOF_TIMESTAMPING_BIND_PHC)] = "bind-phc",
477477
[const_ilog2(SOF_TIMESTAMPING_OPT_ID_TCP)] = "option-id-tcp",
478478
[const_ilog2(SOF_TIMESTAMPING_OPT_RX_FILTER)] = "option-rx-filter",
479+
[const_ilog2(SOF_TIMESTAMPING_TX_COMPLETION)] = "tx-completion",
479480
};
480481
static_assert(ARRAY_SIZE(sof_timestamping_names) == __SOF_TIMESTAMPING_CNT);
481482

net/socket.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,9 @@ void __sock_tx_timestamp(__u32 tsflags, __u8 *tx_flags)
689689
if (tsflags & SOF_TIMESTAMPING_TX_SCHED)
690690
flags |= SKBTX_SCHED_TSTAMP;
691691

692+
if (tsflags & SOF_TIMESTAMPING_TX_COMPLETION)
693+
flags |= SKBTX_COMPLETION_TSTAMP;
694+
692695
*tx_flags = flags;
693696
}
694697
EXPORT_SYMBOL(__sock_tx_timestamp);

0 commit comments

Comments
 (0)