aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWei Wang <weiwan@google.com>2018-07-31 20:46:22 -0400
committerDavid S. Miller <davem@davemloft.net>2018-08-01 12:56:10 -0400
commitfb31c9b9f6c85b1bad569ecedbde78d9e37cd87b (patch)
tree7568903b4ab7b5784169b51d342ffb28ec6e31e2
parentba113c3aa79a7f941ac162d05a3620bdc985c58d (diff)
tcp: add data bytes retransmitted stats
Introduce a new TCP stat to record the number of bytes retransmitted (RFC4898 tcpEStatsPerfOctetsRetrans) and expose it in both tcp_info (TCP_INFO) and opt_stats (SOF_TIMESTAMPING_OPT_STATS). Signed-off-by: Wei Wang <weiwan@google.com> Signed-off-by: Eric Dumazet <edumazet@google.com> Acked-by: Neal Cardwell <ncardwell@google.com> Acked-by: Soheil Hassas Yeganeh <soheil@google.com> Acked-by: Yuchung Cheng <ycheng@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--include/linux/tcp.h3
-rw-r--r--include/uapi/linux/tcp.h2
-rw-r--r--net/ipv4/tcp.c5
-rw-r--r--net/ipv4/tcp_output.c1
4 files changed, 11 insertions, 0 deletions
diff --git a/include/linux/tcp.h b/include/linux/tcp.h
index d0798dcd2cab..fb67f9a51b95 100644
--- a/include/linux/tcp.h
+++ b/include/linux/tcp.h
@@ -333,6 +333,9 @@ struct tcp_sock {
333 * the first SYN. */ 333 * the first SYN. */
334 u32 undo_marker; /* snd_una upon a new recovery episode. */ 334 u32 undo_marker; /* snd_una upon a new recovery episode. */
335 int undo_retrans; /* number of undoable retransmissions. */ 335 int undo_retrans; /* number of undoable retransmissions. */
336 u64 bytes_retrans; /* RFC4898 tcpEStatsPerfOctetsRetrans
337 * Total data bytes retransmitted
338 */
336 u32 total_retrans; /* Total retransmits for entire connection */ 339 u32 total_retrans; /* Total retransmits for entire connection */
337 340
338 u32 urg_seq; /* Seq of received urgent pointer */ 341 u32 urg_seq; /* Seq of received urgent pointer */
diff --git a/include/uapi/linux/tcp.h b/include/uapi/linux/tcp.h
index 1c70ed287c3b..c31f5100b744 100644
--- a/include/uapi/linux/tcp.h
+++ b/include/uapi/linux/tcp.h
@@ -237,6 +237,7 @@ struct tcp_info {
237 __u32 tcpi_delivered_ce; 237 __u32 tcpi_delivered_ce;
238 238
239 __u64 tcpi_bytes_sent; /* RFC4898 tcpEStatsPerfHCDataOctetsOut */ 239 __u64 tcpi_bytes_sent; /* RFC4898 tcpEStatsPerfHCDataOctetsOut */
240 __u64 tcpi_bytes_retrans; /* RFC4898 tcpEStatsPerfOctetsRetrans */
240}; 241};
241 242
242/* netlink attributes types for SCM_TIMESTAMPING_OPT_STATS */ 243/* netlink attributes types for SCM_TIMESTAMPING_OPT_STATS */
@@ -260,6 +261,7 @@ enum {
260 TCP_NLA_DELIVERED, /* Data pkts delivered incl. out-of-order */ 261 TCP_NLA_DELIVERED, /* Data pkts delivered incl. out-of-order */
261 TCP_NLA_DELIVERED_CE, /* Like above but only ones w/ CE marks */ 262 TCP_NLA_DELIVERED_CE, /* Like above but only ones w/ CE marks */
262 TCP_NLA_BYTES_SENT, /* Data bytes sent including retransmission */ 263 TCP_NLA_BYTES_SENT, /* Data bytes sent including retransmission */
264 TCP_NLA_BYTES_RETRANS, /* Data bytes retransmitted */
263}; 265};
264 266
265/* for TCP_MD5SIG socket option */ 267/* for TCP_MD5SIG socket option */
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index 873cb9968ff5..5ed1be88e922 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -2595,6 +2595,7 @@ int tcp_disconnect(struct sock *sk, int flags)
2595 tcp_saved_syn_free(tp); 2595 tcp_saved_syn_free(tp);
2596 tp->compressed_ack = 0; 2596 tp->compressed_ack = 0;
2597 tp->bytes_sent = 0; 2597 tp->bytes_sent = 0;
2598 tp->bytes_retrans = 0;
2598 2599
2599 /* Clean up fastopen related fields */ 2600 /* Clean up fastopen related fields */
2600 tcp_free_fastopen_req(tp); 2601 tcp_free_fastopen_req(tp);
@@ -3203,6 +3204,7 @@ void tcp_get_info(struct sock *sk, struct tcp_info *info)
3203 info->tcpi_delivered = tp->delivered; 3204 info->tcpi_delivered = tp->delivered;
3204 info->tcpi_delivered_ce = tp->delivered_ce; 3205 info->tcpi_delivered_ce = tp->delivered_ce;
3205 info->tcpi_bytes_sent = tp->bytes_sent; 3206 info->tcpi_bytes_sent = tp->bytes_sent;
3207 info->tcpi_bytes_retrans = tp->bytes_retrans;
3206 unlock_sock_fast(sk, slow); 3208 unlock_sock_fast(sk, slow);
3207} 3209}
3208EXPORT_SYMBOL_GPL(tcp_get_info); 3210EXPORT_SYMBOL_GPL(tcp_get_info);
@@ -3228,6 +3230,7 @@ static size_t tcp_opt_stats_get_size(void)
3228 nla_total_size(sizeof(u32)) + /* TCP_NLA_DELIVERED */ 3230 nla_total_size(sizeof(u32)) + /* TCP_NLA_DELIVERED */
3229 nla_total_size(sizeof(u32)) + /* TCP_NLA_DELIVERED_CE */ 3231 nla_total_size(sizeof(u32)) + /* TCP_NLA_DELIVERED_CE */
3230 nla_total_size_64bit(sizeof(u64)) + /* TCP_NLA_BYTES_SENT */ 3232 nla_total_size_64bit(sizeof(u64)) + /* TCP_NLA_BYTES_SENT */
3233 nla_total_size_64bit(sizeof(u64)) + /* TCP_NLA_BYTES_RETRANS */
3231 0; 3234 0;
3232} 3235}
3233 3236
@@ -3277,6 +3280,8 @@ struct sk_buff *tcp_get_timestamping_opt_stats(const struct sock *sk)
3277 3280
3278 nla_put_u64_64bit(stats, TCP_NLA_BYTES_SENT, tp->bytes_sent, 3281 nla_put_u64_64bit(stats, TCP_NLA_BYTES_SENT, tp->bytes_sent,
3279 TCP_NLA_PAD); 3282 TCP_NLA_PAD);
3283 nla_put_u64_64bit(stats, TCP_NLA_BYTES_RETRANS, tp->bytes_retrans,
3284 TCP_NLA_PAD);
3280 3285
3281 return stats; 3286 return stats;
3282} 3287}
diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
index 861531fe0e97..50cabf7656f3 100644
--- a/net/ipv4/tcp_output.c
+++ b/net/ipv4/tcp_output.c
@@ -2871,6 +2871,7 @@ int __tcp_retransmit_skb(struct sock *sk, struct sk_buff *skb, int segs)
2871 if (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_SYN) 2871 if (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_SYN)
2872 __NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPSYNRETRANS); 2872 __NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPSYNRETRANS);
2873 tp->total_retrans += segs; 2873 tp->total_retrans += segs;
2874 tp->bytes_retrans += skb->len;
2874 2875
2875 /* make sure skb->data is aligned on arches that require it 2876 /* make sure skb->data is aligned on arches that require it
2876 * and check if ack-trimming & collapsing extended the headroom 2877 * and check if ack-trimming & collapsing extended the headroom