Skip to content

Commit a44d6ea

Browse files
iamkafaidavem330
authored andcommitted
tcp: Add RFC4898 tcpEStatsPerfDataSegsOut/In
Per RFC4898, they count segments sent/received containing a positive length data segment (that includes retransmission segments carrying data). Unlike tcpi_segs_out/in, tcpi_data_segs_out/in excludes segments carrying no data (e.g. pure ack). The patch also updates the segs_in in tcp_fastopen_add_skb() so that segs_in >= data_segs_in property is kept. Together with retransmission data, tcpi_data_segs_out gives a better signal on the rxmit rate. v6: Rebase on the latest net-next v5: Eric pointed out that checking skb->len is still needed in tcp_fastopen_add_skb() because skb can carry a FIN without data. Hence, instead of open coding segs_in and data_segs_in, tcp_segs_in() helper is used. Comment is added to the fastopen case to explain why segs_in has to be reset and tcp_segs_in() has to be called before __skb_pull(). v4: Add comment to the changes in tcp_fastopen_add_skb() and also add remark on this case in the commit message. v3: Add const modifier to the skb parameter in tcp_segs_in() v2: Rework based on recent fix by Eric: commit a9d99ce ("tcp: fix tcpi_segs_in after connection establishment") Signed-off-by: Martin KaFai Lau <kafai@fb.com> Cc: Chris Rapier <rapier@psc.edu> Cc: Eric Dumazet <edumazet@google.com> Cc: Marcelo Ricardo Leitner <mleitner@redhat.com> Cc: Neal Cardwell <ncardwell@google.com> Cc: Yuchung Cheng <ycheng@google.com> Acked-by: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent efc21d9 commit a44d6ea

File tree

9 files changed

+34
-4
lines changed

9 files changed

+34
-4
lines changed

include/linux/tcp.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,19 @@ struct tcp_sock {
158158
u32 segs_in; /* RFC4898 tcpEStatsPerfSegsIn
159159
* total number of segments in.
160160
*/
161+
u32 data_segs_in; /* RFC4898 tcpEStatsPerfDataSegsIn
162+
* total number of data segments in.
163+
*/
161164
u32 rcv_nxt; /* What we want to receive next */
162165
u32 copied_seq; /* Head of yet unread data */
163166
u32 rcv_wup; /* rcv_nxt on last window update sent */
164167
u32 snd_nxt; /* Next sequence we send */
165168
u32 segs_out; /* RFC4898 tcpEStatsPerfSegsOut
166169
* The total number of segments sent.
167170
*/
171+
u32 data_segs_out; /* RFC4898 tcpEStatsPerfDataSegsOut
172+
* total number of data segments sent.
173+
*/
168174
u64 bytes_acked; /* RFC4898 tcpEStatsAppHCThruOctetsAcked
169175
* sum(delta(snd_una)), or how many bytes
170176
* were acked.

include/net/tcp.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1840,4 +1840,14 @@ static inline int tcp_inq(struct sock *sk)
18401840
return answ;
18411841
}
18421842

1843+
static inline void tcp_segs_in(struct tcp_sock *tp, const struct sk_buff *skb)
1844+
{
1845+
u16 segs_in;
1846+
1847+
segs_in = max_t(u16, 1, skb_shinfo(skb)->gso_segs);
1848+
tp->segs_in += segs_in;
1849+
if (skb->len > tcp_hdrlen(skb))
1850+
tp->data_segs_in += segs_in;
1851+
}
1852+
18431853
#endif /* _TCP_H */

include/uapi/linux/tcp.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ struct tcp_info {
199199

200200
__u32 tcpi_notsent_bytes;
201201
__u32 tcpi_min_rtt;
202+
__u32 tcpi_data_segs_in; /* RFC4898 tcpEStatsDataSegsIn */
203+
__u32 tcpi_data_segs_out; /* RFC4898 tcpEStatsDataSegsOut */
202204
};
203205

204206
/* for TCP_MD5SIG socket option */

net/ipv4/tcp.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2715,6 +2715,8 @@ void tcp_get_info(struct sock *sk, struct tcp_info *info)
27152715
info->tcpi_notsent_bytes = max(0, notsent_bytes);
27162716

27172717
info->tcpi_min_rtt = tcp_min_rtt(tp);
2718+
info->tcpi_data_segs_in = tp->data_segs_in;
2719+
info->tcpi_data_segs_out = tp->data_segs_out;
27182720
}
27192721
EXPORT_SYMBOL_GPL(tcp_get_info);
27202722

net/ipv4/tcp_fastopen.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,14 @@ void tcp_fastopen_add_skb(struct sock *sk, struct sk_buff *skb)
140140
return;
141141

142142
skb_dst_drop(skb);
143+
/* segs_in has been initialized to 1 in tcp_create_openreq_child().
144+
* Hence, reset segs_in to 0 before calling tcp_segs_in()
145+
* to avoid double counting. Also, tcp_segs_in() expects
146+
* skb->len to include the tcp_hdrlen. Hence, it should
147+
* be called before __skb_pull().
148+
*/
149+
tp->segs_in = 0;
150+
tcp_segs_in(tp, skb);
143151
__skb_pull(skb, tcp_hdrlen(skb));
144152
skb_set_owner_r(skb, sk);
145153

net/ipv4/tcp_ipv4.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1650,7 +1650,7 @@ int tcp_v4_rcv(struct sk_buff *skb)
16501650
sk_incoming_cpu_update(sk);
16511651

16521652
bh_lock_sock_nested(sk);
1653-
tcp_sk(sk)->segs_in += max_t(u16, 1, skb_shinfo(skb)->gso_segs);
1653+
tcp_segs_in(tcp_sk(sk), skb);
16541654
ret = 0;
16551655
if (!sock_owned_by_user(sk)) {
16561656
if (!tcp_prequeue(sk, skb))

net/ipv4/tcp_minisocks.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ int tcp_child_process(struct sock *parent, struct sock *child,
812812
int ret = 0;
813813
int state = child->sk_state;
814814

815-
tcp_sk(child)->segs_in += max_t(u16, 1, skb_shinfo(skb)->gso_segs);
815+
tcp_segs_in(tcp_sk(child), skb);
816816
if (!sock_owned_by_user(child)) {
817817
ret = tcp_rcv_state_process(child, skb);
818818
/* Wakeup parent, send SIGIO */

net/ipv4/tcp_output.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1003,8 +1003,10 @@ static int tcp_transmit_skb(struct sock *sk, struct sk_buff *skb, int clone_it,
10031003
if (likely(tcb->tcp_flags & TCPHDR_ACK))
10041004
tcp_event_ack_sent(sk, tcp_skb_pcount(skb));
10051005

1006-
if (skb->len != tcp_header_size)
1006+
if (skb->len != tcp_header_size) {
10071007
tcp_event_data_sent(tp, sk);
1008+
tp->data_segs_out += tcp_skb_pcount(skb);
1009+
}
10081010

10091011
if (after(tcb->end_seq, tp->snd_nxt) || tcb->seq == tcb->end_seq)
10101012
TCP_ADD_STATS(sock_net(sk), TCP_MIB_OUTSEGS,

net/ipv6/tcp_ipv6.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1443,7 +1443,7 @@ static int tcp_v6_rcv(struct sk_buff *skb)
14431443
sk_incoming_cpu_update(sk);
14441444

14451445
bh_lock_sock_nested(sk);
1446-
tcp_sk(sk)->segs_in += max_t(u16, 1, skb_shinfo(skb)->gso_segs);
1446+
tcp_segs_in(tcp_sk(sk), skb);
14471447
ret = 0;
14481448
if (!sock_owned_by_user(sk)) {
14491449
if (!tcp_prequeue(sk, skb))

0 commit comments

Comments
 (0)