提交 bdd1f9ed 编写于 作者: E Eric Dumazet 提交者: David S. Miller

tcp: add tcpi_bytes_received to tcp_info

This patch tracks total number of payload bytes received on a TCP socket.
This is the sum of all changes done to tp->rcv_nxt

RFC4898 named this : tcpEStatsAppHCThruOctetsReceived

This is a 64bit field, and can be fetched both from TCP_INFO
getsockopt() if one has a handle on a TCP socket, or from inet_diag
netlink facility (iproute2/ss patch will follow)

Note that tp->bytes_received was placed near tp->rcv_nxt for
best data locality and minimal performance impact.
Signed-off-by: NEric Dumazet <edumazet@google.com>
Cc: Yuchung Cheng <ycheng@google.com>
Cc: Matt Mathis <mattmathis@google.com>
Cc: Eric Salo <salo@google.com>
Cc: Martin Lau <kafai@fb.com>
Cc: Chris Rapier <rapier@psc.edu>
Acked-by: NYuchung Cheng <ycheng@google.com>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
上级 0df48c26
...@@ -145,6 +145,10 @@ struct tcp_sock { ...@@ -145,6 +145,10 @@ struct tcp_sock {
* read the code and the spec side by side (and laugh ...) * read the code and the spec side by side (and laugh ...)
* See RFC793 and RFC1122. The RFC writes these in capitals. * See RFC793 and RFC1122. The RFC writes these in capitals.
*/ */
u64 bytes_received; /* RFC4898 tcpEStatsAppHCThruOctetsReceived
* sum(delta(rcv_nxt)), or how many bytes
* were acked.
*/
u32 rcv_nxt; /* What we want to receive next */ u32 rcv_nxt; /* What we want to receive next */
u32 copied_seq; /* Head of yet unread data */ u32 copied_seq; /* Head of yet unread data */
u32 rcv_wup; /* rcv_nxt on last window update sent */ u32 rcv_wup; /* rcv_nxt on last window update sent */
......
...@@ -190,6 +190,7 @@ struct tcp_info { ...@@ -190,6 +190,7 @@ struct tcp_info {
__u64 tcpi_pacing_rate; __u64 tcpi_pacing_rate;
__u64 tcpi_max_pacing_rate; __u64 tcpi_max_pacing_rate;
__u64 tcpi_bytes_acked; /* RFC4898 tcpEStatsAppHCThruOctetsAcked */ __u64 tcpi_bytes_acked; /* RFC4898 tcpEStatsAppHCThruOctetsAcked */
__u64 tcpi_bytes_received; /* RFC4898 tcpEStatsAppHCThruOctetsReceived */
}; };
/* for TCP_MD5SIG socket option */ /* for TCP_MD5SIG socket option */
......
...@@ -2666,6 +2666,7 @@ void tcp_get_info(struct sock *sk, struct tcp_info *info) ...@@ -2666,6 +2666,7 @@ void tcp_get_info(struct sock *sk, struct tcp_info *info)
spin_lock_bh(&sk->sk_lock.slock); spin_lock_bh(&sk->sk_lock.slock);
info->tcpi_bytes_acked = tp->bytes_acked; info->tcpi_bytes_acked = tp->bytes_acked;
info->tcpi_bytes_received = tp->bytes_received;
spin_unlock_bh(&sk->sk_lock.slock); spin_unlock_bh(&sk->sk_lock.slock);
} }
EXPORT_SYMBOL_GPL(tcp_get_info); EXPORT_SYMBOL_GPL(tcp_get_info);
......
...@@ -206,6 +206,7 @@ static bool tcp_fastopen_create_child(struct sock *sk, ...@@ -206,6 +206,7 @@ static bool tcp_fastopen_create_child(struct sock *sk,
skb_set_owner_r(skb2, child); skb_set_owner_r(skb2, child);
__skb_queue_tail(&child->sk_receive_queue, skb2); __skb_queue_tail(&child->sk_receive_queue, skb2);
tp->syn_data_acked = 1; tp->syn_data_acked = 1;
tp->bytes_received = end_seq - TCP_SKB_CB(skb)->seq - 1;
} else { } else {
end_seq = TCP_SKB_CB(skb)->seq + 1; end_seq = TCP_SKB_CB(skb)->seq + 1;
} }
......
...@@ -3289,6 +3289,15 @@ static void tcp_snd_una_update(struct tcp_sock *tp, u32 ack) ...@@ -3289,6 +3289,15 @@ static void tcp_snd_una_update(struct tcp_sock *tp, u32 ack)
tp->snd_una = ack; tp->snd_una = ack;
} }
/* If we update tp->rcv_nxt, also update tp->bytes_received */
static void tcp_rcv_nxt_update(struct tcp_sock *tp, u32 seq)
{
u32 delta = seq - tp->rcv_nxt;
tp->bytes_received += delta;
tp->rcv_nxt = seq;
}
/* Update our send window. /* Update our send window.
* *
* Window update algorithm, described in RFC793/RFC1122 (used in linux-2.2 * Window update algorithm, described in RFC793/RFC1122 (used in linux-2.2
...@@ -4245,7 +4254,7 @@ static void tcp_ofo_queue(struct sock *sk) ...@@ -4245,7 +4254,7 @@ static void tcp_ofo_queue(struct sock *sk)
tail = skb_peek_tail(&sk->sk_receive_queue); tail = skb_peek_tail(&sk->sk_receive_queue);
eaten = tail && tcp_try_coalesce(sk, tail, skb, &fragstolen); eaten = tail && tcp_try_coalesce(sk, tail, skb, &fragstolen);
tp->rcv_nxt = TCP_SKB_CB(skb)->end_seq; tcp_rcv_nxt_update(tp, TCP_SKB_CB(skb)->end_seq);
if (!eaten) if (!eaten)
__skb_queue_tail(&sk->sk_receive_queue, skb); __skb_queue_tail(&sk->sk_receive_queue, skb);
if (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_FIN) if (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_FIN)
...@@ -4413,7 +4422,7 @@ static int __must_check tcp_queue_rcv(struct sock *sk, struct sk_buff *skb, int ...@@ -4413,7 +4422,7 @@ static int __must_check tcp_queue_rcv(struct sock *sk, struct sk_buff *skb, int
__skb_pull(skb, hdrlen); __skb_pull(skb, hdrlen);
eaten = (tail && eaten = (tail &&
tcp_try_coalesce(sk, tail, skb, fragstolen)) ? 1 : 0; tcp_try_coalesce(sk, tail, skb, fragstolen)) ? 1 : 0;
tcp_sk(sk)->rcv_nxt = TCP_SKB_CB(skb)->end_seq; tcp_rcv_nxt_update(tcp_sk(sk), TCP_SKB_CB(skb)->end_seq);
if (!eaten) { if (!eaten) {
__skb_queue_tail(&sk->sk_receive_queue, skb); __skb_queue_tail(&sk->sk_receive_queue, skb);
skb_set_owner_r(skb, sk); skb_set_owner_r(skb, sk);
...@@ -4506,7 +4515,7 @@ static void tcp_data_queue(struct sock *sk, struct sk_buff *skb) ...@@ -4506,7 +4515,7 @@ static void tcp_data_queue(struct sock *sk, struct sk_buff *skb)
eaten = tcp_queue_rcv(sk, skb, 0, &fragstolen); eaten = tcp_queue_rcv(sk, skb, 0, &fragstolen);
} }
tp->rcv_nxt = TCP_SKB_CB(skb)->end_seq; tcp_rcv_nxt_update(tp, TCP_SKB_CB(skb)->end_seq);
if (skb->len) if (skb->len)
tcp_event_data_recv(sk, skb); tcp_event_data_recv(sk, skb);
if (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_FIN) if (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_FIN)
...@@ -5254,7 +5263,7 @@ void tcp_rcv_established(struct sock *sk, struct sk_buff *skb, ...@@ -5254,7 +5263,7 @@ void tcp_rcv_established(struct sock *sk, struct sk_buff *skb,
tcp_rcv_rtt_measure_ts(sk, skb); tcp_rcv_rtt_measure_ts(sk, skb);
__skb_pull(skb, tcp_header_len); __skb_pull(skb, tcp_header_len);
tp->rcv_nxt = TCP_SKB_CB(skb)->end_seq; tcp_rcv_nxt_update(tp, TCP_SKB_CB(skb)->end_seq);
NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_TCPHPHITSTOUSER); NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_TCPHPHITSTOUSER);
eaten = 1; eaten = 1;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册