tcp: add tcpi_bytes_acked to tcp_info

This patch tracks total number of bytes acked for a TCP socket.
This is the sum of all changes done to tp->snd_una, and allows
for precise tracking of delivered data.

RFC4898 named this : tcpEStatsAppHCThruOctetsAcked

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_acked was placed near tp->snd_una for
best data locality and minimal performance impact.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Acked-by: 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>
Signed-off-by: David S. Miller <davem@davemloft.net>
Change-Id: I975b11b049d6bde1b6802dc4331a9da93c371c9b
This commit is contained in:
Eric Dumazet 2015-04-28 15:28:17 -07:00 committed by surblazer
parent 3e12c5a9d4
commit 45970b0b74
4 changed files with 22 additions and 4 deletions

View file

@ -171,6 +171,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 */
}; };
/* for TCP_MD5SIG socket option */ /* for TCP_MD5SIG socket option */
@ -322,6 +323,10 @@ struct tcp_sock {
u32 rcv_wup; /* rcv_nxt on last window update sent */ u32 rcv_wup; /* rcv_nxt on last window update sent */
u32 snd_nxt; /* Next sequence we send */ u32 snd_nxt; /* Next sequence we send */
u64 bytes_acked; /* RFC4898 tcpEStatsAppHCThruOctetsAcked
* sum(delta(snd_una)), or how many bytes
* were acked.
*/
u32 snd_una; /* First byte we want an ack for */ u32 snd_una; /* First byte we want an ack for */
u32 snd_sml; /* Last byte of the most recently transmitted small packet */ u32 snd_sml; /* Last byte of the most recently transmitted small packet */
u32 rcv_tstamp; /* timestamp of last received ACK (for keepalives) */ u32 rcv_tstamp; /* timestamp of last received ACK (for keepalives) */

View file

@ -542,7 +542,7 @@ static inline int tcp_bound_to_half_wnd(struct tcp_sock *tp, int pktsize)
} }
/* tcp.c */ /* tcp.c */
extern void tcp_get_info(const struct sock *, struct tcp_info *); void tcp_get_info(struct sock *, struct tcp_info *);
/* Read 'sendfile()'-style from a TCP socket */ /* Read 'sendfile()'-style from a TCP socket */
typedef int (*sk_read_actor_t)(read_descriptor_t *, struct sk_buff *, typedef int (*sk_read_actor_t)(read_descriptor_t *, struct sk_buff *,

View file

@ -2498,7 +2498,7 @@ EXPORT_SYMBOL(compat_tcp_setsockopt);
#endif #endif
/* Return information about state of tcp endpoint in API format. */ /* Return information about state of tcp endpoint in API format. */
void tcp_get_info(const struct sock *sk, struct tcp_info *info) void tcp_get_info(struct sock *sk, struct tcp_info *info)
{ {
const struct tcp_sock *tp = tcp_sk(sk); const struct tcp_sock *tp = tcp_sk(sk);
const struct inet_connection_sock *icsk = inet_csk(sk); const struct inet_connection_sock *icsk = inet_csk(sk);
@ -2566,6 +2566,10 @@ void tcp_get_info(const struct sock *sk, struct tcp_info *info)
info->tcpi_max_pacing_rate = sk->sk_max_pacing_rate != ~0U ? info->tcpi_max_pacing_rate = sk->sk_max_pacing_rate != ~0U ?
sk->sk_max_pacing_rate : ~0ULL; sk->sk_max_pacing_rate : ~0ULL;
spin_lock_bh(&sk->sk_lock.slock);
info->tcpi_bytes_acked = tp->bytes_acked;
spin_unlock_bh(&sk->sk_lock.slock);
if (sk->sk_socket) { if (sk->sk_socket) {
struct file *filep = sk->sk_socket->file; struct file *filep = sk->sk_socket->file;
if (filep) if (filep)

View file

@ -3534,6 +3534,15 @@ static inline int tcp_may_update_window(const struct tcp_sock *tp,
(ack_seq == tp->snd_wl1 && nwin > tp->snd_wnd); (ack_seq == tp->snd_wl1 && nwin > tp->snd_wnd);
} }
/* If we update tp->snd_una, also update tp->bytes_acked */
static void tcp_snd_una_update(struct tcp_sock *tp, u32 ack)
{
u32 delta = ack - tp->snd_una;
tp->bytes_acked += delta;
tp->snd_una = ack;
}
/* 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
@ -3569,7 +3578,7 @@ static int tcp_ack_update_window(struct sock *sk, const struct sk_buff *skb, u32
} }
} }
tp->snd_una = ack; tcp_snd_una_update(tp, ack);
return flag; return flag;
} }
@ -3815,7 +3824,7 @@ static int tcp_ack(struct sock *sk, const struct sk_buff *skb, int flag)
* Note, we use the fact that SND.UNA>=SND.WL2. * Note, we use the fact that SND.UNA>=SND.WL2.
*/ */
tcp_update_wl(tp, ack_seq); tcp_update_wl(tp, ack_seq);
tp->snd_una = ack; tcp_snd_una_update(tp, ack);
flag |= FLAG_WIN_UPDATE; flag |= FLAG_WIN_UPDATE;
tcp_ca_event(sk, CA_EVENT_FAST_ACK); tcp_ca_event(sk, CA_EVENT_FAST_ACK);