Skip to content

Commit 1c88580

Browse files
francisyyandavem330
authored andcommitted
tcp: SOF_TIMESTAMPING_OPT_STATS option for SO_TIMESTAMPING
This patch exports the sender chronograph stats via the socket SO_TIMESTAMPING channel. Currently we can instrument how long a particular application unit of data was queued in TCP by tracking SOF_TIMESTAMPING_TX_SOFTWARE and SOF_TIMESTAMPING_TX_SCHED. Having these sender chronograph stats exported simultaneously along with these timestamps allow further breaking down the various sender limitation. For example, a video server can tell if a particular chunk of video on a connection takes a long time to deliver because TCP was experiencing small receive window. It is not possible to tell before this patch without packet traces. To prepare these stats, the user needs to set SOF_TIMESTAMPING_OPT_STATS and SOF_TIMESTAMPING_OPT_TSONLY flags while requesting other SOF_TIMESTAMPING TX timestamps. When the timestamps are available in the error queue, the stats are returned in a separate control message of type SCM_TIMESTAMPING_OPT_STATS, in a list of TLVs (struct nlattr) of types: TCP_NLA_BUSY_TIME, TCP_NLA_RWND_LIMITED, TCP_NLA_SNDBUF_LIMITED. Unit is microsecond. Signed-off-by: Francis Yan <francisyyan@gmail.com> Signed-off-by: Yuchung Cheng <ycheng@google.com> Signed-off-by: Soheil Hassas Yeganeh <soheil@google.com> Acked-by: Neal Cardwell <ncardwell@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent efd9017 commit 1c88580

File tree

20 files changed

+90
-5
lines changed

20 files changed

+90
-5
lines changed

Documentation/networking/timestamping.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,16 @@ SOF_TIMESTAMPING_OPT_TSONLY:
182182
the timestamp even if sysctl net.core.tstamp_allow_data is 0.
183183
This option disables SOF_TIMESTAMPING_OPT_CMSG.
184184

185+
SOF_TIMESTAMPING_OPT_STATS:
186+
187+
Optional stats that are obtained along with the transmit timestamps.
188+
It must be used together with SOF_TIMESTAMPING_OPT_TSONLY. When the
189+
transmit timestamp is available, the stats are available in a
190+
separate control message of type SCM_TIMESTAMPING_OPT_STATS, as a
191+
list of TLVs (struct nlattr) of types. These stats allow the
192+
application to associate various transport layer stats with
193+
the transmit timestamps, such as how long a certain block of
194+
data was limited by peer's receiver window.
185195

186196
New applications are encouraged to pass SOF_TIMESTAMPING_OPT_ID to
187197
disambiguate timestamps and SOF_TIMESTAMPING_OPT_TSONLY to operate

arch/alpha/include/uapi/asm/socket.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,6 @@
9797

9898
#define SO_CNX_ADVICE 53
9999

100+
#define SCM_TIMESTAMPING_OPT_STATS 54
101+
100102
#endif /* _UAPI_ASM_SOCKET_H */

arch/frv/include/uapi/asm/socket.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,5 +90,7 @@
9090

9191
#define SO_CNX_ADVICE 53
9292

93+
#define SCM_TIMESTAMPING_OPT_STATS 54
94+
9395
#endif /* _ASM_SOCKET_H */
9496

arch/ia64/include/uapi/asm/socket.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,6 @@
9999

100100
#define SO_CNX_ADVICE 53
101101

102+
#define SCM_TIMESTAMPING_OPT_STATS 54
103+
102104
#endif /* _ASM_IA64_SOCKET_H */

arch/m32r/include/uapi/asm/socket.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,6 @@
9090

9191
#define SO_CNX_ADVICE 53
9292

93+
#define SCM_TIMESTAMPING_OPT_STATS 54
94+
9395
#endif /* _ASM_M32R_SOCKET_H */

arch/mips/include/uapi/asm/socket.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,6 @@
108108

109109
#define SO_CNX_ADVICE 53
110110

111+
#define SCM_TIMESTAMPING_OPT_STATS 54
112+
111113
#endif /* _UAPI_ASM_SOCKET_H */

arch/mn10300/include/uapi/asm/socket.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,6 @@
9090

9191
#define SO_CNX_ADVICE 53
9292

93+
#define SCM_TIMESTAMPING_OPT_STATS 54
94+
9395
#endif /* _ASM_SOCKET_H */

arch/parisc/include/uapi/asm/socket.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,6 @@
8989

9090
#define SO_CNX_ADVICE 0x402E
9191

92+
#define SCM_TIMESTAMPING_OPT_STATS 0x402F
93+
9294
#endif /* _UAPI_ASM_SOCKET_H */

arch/powerpc/include/uapi/asm/socket.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,6 @@
9797

9898
#define SO_CNX_ADVICE 53
9999

100+
#define SCM_TIMESTAMPING_OPT_STATS 54
101+
100102
#endif /* _ASM_POWERPC_SOCKET_H */

arch/s390/include/uapi/asm/socket.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,6 @@
9696

9797
#define SO_CNX_ADVICE 53
9898

99+
#define SCM_TIMESTAMPING_OPT_STATS 54
100+
99101
#endif /* _ASM_SOCKET_H */

arch/sparc/include/uapi/asm/socket.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@
8686

8787
#define SO_CNX_ADVICE 0x0037
8888

89+
#define SCM_TIMESTAMPING_OPT_STATS 0x0038
90+
8991
/* Security levels - as per NRL IPv6 - don't actually do anything */
9092
#define SO_SECURITY_AUTHENTICATION 0x5001
9193
#define SO_SECURITY_ENCRYPTION_TRANSPORT 0x5002

arch/xtensa/include/uapi/asm/socket.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,6 @@
101101

102102
#define SO_CNX_ADVICE 53
103103

104+
#define SCM_TIMESTAMPING_OPT_STATS 54
105+
104106
#endif /* _XTENSA_SOCKET_H */

include/linux/tcp.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,4 +428,6 @@ static inline void tcp_saved_syn_free(struct tcp_sock *tp)
428428
tp->saved_syn = NULL;
429429
}
430430

431+
struct sk_buff *tcp_get_timestamping_opt_stats(const struct sock *sk);
432+
431433
#endif /* _LINUX_TCP_H */

include/uapi/asm-generic/socket.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,6 @@
9292

9393
#define SO_CNX_ADVICE 53
9494

95+
#define SCM_TIMESTAMPING_OPT_STATS 54
96+
9597
#endif /* __ASM_GENERIC_SOCKET_H */

include/uapi/linux/net_tstamp.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ enum {
2525
SOF_TIMESTAMPING_TX_ACK = (1<<9),
2626
SOF_TIMESTAMPING_OPT_CMSG = (1<<10),
2727
SOF_TIMESTAMPING_OPT_TSONLY = (1<<11),
28+
SOF_TIMESTAMPING_OPT_STATS = (1<<12),
2829

29-
SOF_TIMESTAMPING_LAST = SOF_TIMESTAMPING_OPT_TSONLY,
30+
SOF_TIMESTAMPING_LAST = SOF_TIMESTAMPING_OPT_STATS,
3031
SOF_TIMESTAMPING_MASK = (SOF_TIMESTAMPING_LAST - 1) |
3132
SOF_TIMESTAMPING_LAST
3233
};

include/uapi/linux/tcp.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,14 @@ struct tcp_info {
220220
__u64 tcpi_sndbuf_limited; /* Time (usec) limited by send buffer */
221221
};
222222

223+
/* netlink attributes types for SCM_TIMESTAMPING_OPT_STATS */
224+
enum {
225+
TCP_NLA_PAD,
226+
TCP_NLA_BUSY, /* Time (usec) busy sending data */
227+
TCP_NLA_RWND_LIMITED, /* Time (usec) limited by receive window */
228+
TCP_NLA_SNDBUF_LIMITED, /* Time (usec) limited by send buffer */
229+
};
230+
223231
/* for TCP_MD5SIG socket option */
224232
#define TCP_MD5SIG_MAXKEYLEN 80
225233

net/core/skbuff.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3839,10 +3839,18 @@ void __skb_tstamp_tx(struct sk_buff *orig_skb,
38393839
if (!skb_may_tx_timestamp(sk, tsonly))
38403840
return;
38413841

3842-
if (tsonly)
3843-
skb = alloc_skb(0, GFP_ATOMIC);
3844-
else
3842+
if (tsonly) {
3843+
#ifdef CONFIG_INET
3844+
if ((sk->sk_tsflags & SOF_TIMESTAMPING_OPT_STATS) &&
3845+
sk->sk_protocol == IPPROTO_TCP &&
3846+
sk->sk_type == SOCK_STREAM)
3847+
skb = tcp_get_timestamping_opt_stats(sk);
3848+
else
3849+
#endif
3850+
skb = alloc_skb(0, GFP_ATOMIC);
3851+
} else {
38453852
skb = skb_clone(orig_skb, GFP_ATOMIC);
3853+
}
38463854
if (!skb)
38473855
return;
38483856

net/core/sock.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,13 @@ int sock_setsockopt(struct socket *sock, int level, int optname,
854854
sk->sk_tskey = 0;
855855
}
856856
}
857+
858+
if (val & SOF_TIMESTAMPING_OPT_STATS &&
859+
!(val & SOF_TIMESTAMPING_OPT_TSONLY)) {
860+
ret = -EINVAL;
861+
break;
862+
}
863+
857864
sk->sk_tsflags = val;
858865
if (val & SOF_TIMESTAMPING_RX_SOFTWARE)
859866
sock_enable_timestamp(sk,

net/ipv4/tcp.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2841,6 +2841,26 @@ void tcp_get_info(struct sock *sk, struct tcp_info *info)
28412841
}
28422842
EXPORT_SYMBOL_GPL(tcp_get_info);
28432843

2844+
struct sk_buff *tcp_get_timestamping_opt_stats(const struct sock *sk)
2845+
{
2846+
const struct tcp_sock *tp = tcp_sk(sk);
2847+
struct sk_buff *stats;
2848+
struct tcp_info info;
2849+
2850+
stats = alloc_skb(3 * nla_total_size_64bit(sizeof(u64)), GFP_ATOMIC);
2851+
if (!stats)
2852+
return NULL;
2853+
2854+
tcp_get_info_chrono_stats(tp, &info);
2855+
nla_put_u64_64bit(stats, TCP_NLA_BUSY,
2856+
info.tcpi_busy_time, TCP_NLA_PAD);
2857+
nla_put_u64_64bit(stats, TCP_NLA_RWND_LIMITED,
2858+
info.tcpi_rwnd_limited, TCP_NLA_PAD);
2859+
nla_put_u64_64bit(stats, TCP_NLA_SNDBUF_LIMITED,
2860+
info.tcpi_sndbuf_limited, TCP_NLA_PAD);
2861+
return stats;
2862+
}
2863+
28442864
static int do_tcp_getsockopt(struct sock *sk, int level,
28452865
int optname, char __user *optval, int __user *optlen)
28462866
{

net/socket.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,9 +693,14 @@ void __sock_recv_timestamp(struct msghdr *msg, struct sock *sk,
693693
(sk->sk_tsflags & SOF_TIMESTAMPING_RAW_HARDWARE) &&
694694
ktime_to_timespec_cond(shhwtstamps->hwtstamp, tss.ts + 2))
695695
empty = 0;
696-
if (!empty)
696+
if (!empty) {
697697
put_cmsg(msg, SOL_SOCKET,
698698
SCM_TIMESTAMPING, sizeof(tss), &tss);
699+
700+
if (skb->len && (sk->sk_tsflags & SOF_TIMESTAMPING_OPT_STATS))
701+
put_cmsg(msg, SOL_SOCKET, SCM_TIMESTAMPING_OPT_STATS,
702+
skb->len, skb->data);
703+
}
699704
}
700705
EXPORT_SYMBOL_GPL(__sock_recv_timestamp);
701706

0 commit comments

Comments
 (0)