Skip to content

Commit 32efcc0

Browse files
Abdul Kabbanidavem330
authored andcommitted
tcp: export count for rehash attempts
Using IPv6 flow-label to swiftly route around avoid congested or disconnected network path can greatly improve TCP reliability. This patch adds SNMP counters and a OPT_STATS counter to track both host-level and connection-level statistics. Network administrators can use these counters to evaluate the impact of this new ability better. Export count for rehash attempts to 1) two SNMP counters: TcpTimeoutRehash (rehash due to timeouts), and TcpDuplicateDataRehash (rehash due to receiving duplicate packets) 2) Timestamping API SOF_TIMESTAMPING_OPT_STATS. Signed-off-by: Abdul Kabbani <[email protected]> Signed-off-by: Neal Cardwell <[email protected]> Signed-off-by: Yuchung Cheng <[email protected]> Signed-off-by: Kevin(Yudong) Yang <[email protected]> Signed-off-by: Eric Dumazet <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 6efca89 commit 32efcc0

File tree

7 files changed

+18
-1
lines changed

7 files changed

+18
-1
lines changed

include/linux/tcp.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,8 @@ struct tcp_sock {
386386
#define BPF_SOCK_OPS_TEST_FLAG(TP, ARG) 0
387387
#endif
388388

389+
u16 timeout_rehash; /* Timeout-triggered rehash attempts */
390+
389391
u32 rcv_ooopack; /* Received out-of-order packets, for tcpinfo */
390392

391393
/* Receiver side RTT estimation */

include/uapi/linux/snmp.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,8 @@ enum
285285
LINUX_MIB_TCPRCVQDROP, /* TCPRcvQDrop */
286286
LINUX_MIB_TCPWQUEUETOOBIG, /* TCPWqueueTooBig */
287287
LINUX_MIB_TCPFASTOPENPASSIVEALTKEY, /* TCPFastOpenPassiveAltKey */
288+
LINUX_MIB_TCPTIMEOUTREHASH, /* TCPTimeoutRehash */
289+
LINUX_MIB_TCPDUPLICATEDATAREHASH, /* TCPDuplicateDataRehash */
288290
__LINUX_MIB_MAX
289291
};
290292

include/uapi/linux/tcp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ enum {
311311
TCP_NLA_DSACK_DUPS, /* DSACK blocks received */
312312
TCP_NLA_REORD_SEEN, /* reordering events seen */
313313
TCP_NLA_SRTT, /* smoothed RTT in usecs */
314+
TCP_NLA_TIMEOUT_REHASH, /* Timeout-triggered rehash attempts */
314315
};
315316

316317
/* for TCP_MD5SIG socket option */

net/ipv4/proc.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,8 @@ static const struct snmp_mib snmp4_net_list[] = {
289289
SNMP_MIB_ITEM("TCPRcvQDrop", LINUX_MIB_TCPRCVQDROP),
290290
SNMP_MIB_ITEM("TCPWqueueTooBig", LINUX_MIB_TCPWQUEUETOOBIG),
291291
SNMP_MIB_ITEM("TCPFastOpenPassiveAltKey", LINUX_MIB_TCPFASTOPENPASSIVEALTKEY),
292+
SNMP_MIB_ITEM("TcpTimeoutRehash", LINUX_MIB_TCPTIMEOUTREHASH),
293+
SNMP_MIB_ITEM("TcpDuplicateDataRehash", LINUX_MIB_TCPDUPLICATEDATAREHASH),
292294
SNMP_MIB_SENTINEL
293295
};
294296

net/ipv4/tcp.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3337,6 +3337,7 @@ static size_t tcp_opt_stats_get_size(void)
33373337
nla_total_size(sizeof(u32)) + /* TCP_NLA_DSACK_DUPS */
33383338
nla_total_size(sizeof(u32)) + /* TCP_NLA_REORD_SEEN */
33393339
nla_total_size(sizeof(u32)) + /* TCP_NLA_SRTT */
3340+
nla_total_size(sizeof(u16)) + /* TCP_NLA_TIMEOUT_REHASH */
33403341
0;
33413342
}
33423343

@@ -3391,6 +3392,7 @@ struct sk_buff *tcp_get_timestamping_opt_stats(const struct sock *sk)
33913392
nla_put_u32(stats, TCP_NLA_DSACK_DUPS, tp->dsack_dups);
33923393
nla_put_u32(stats, TCP_NLA_REORD_SEEN, tp->reord_seen);
33933394
nla_put_u32(stats, TCP_NLA_SRTT, tp->srtt_us >> 3);
3395+
nla_put_u16(stats, TCP_NLA_TIMEOUT_REHASH, tp->timeout_rehash);
33943396

33953397
return stats;
33963398
}

net/ipv4/tcp_input.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4271,8 +4271,10 @@ static void tcp_rcv_spurious_retrans(struct sock *sk, const struct sk_buff *skb)
42714271
* The receiver remembers and reflects via DSACKs. Leverage the
42724272
* DSACK state and change the txhash to re-route speculatively.
42734273
*/
4274-
if (TCP_SKB_CB(skb)->seq == tcp_sk(sk)->duplicate_sack[0].start_seq)
4274+
if (TCP_SKB_CB(skb)->seq == tcp_sk(sk)->duplicate_sack[0].start_seq) {
42754275
sk_rethink_txhash(sk);
4276+
NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPDUPLICATEDATAREHASH);
4277+
}
42764278
}
42774279

42784280
static void tcp_send_dupack(struct sock *sk, const struct sk_buff *skb)

net/ipv4/tcp_timer.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,9 @@ static int tcp_write_timeout(struct sock *sk)
223223
dst_negative_advice(sk);
224224
} else {
225225
sk_rethink_txhash(sk);
226+
tp->timeout_rehash++;
227+
__NET_INC_STATS(sock_net(sk),
228+
LINUX_MIB_TCPTIMEOUTREHASH);
226229
}
227230
retry_until = icsk->icsk_syn_retries ? : net->ipv4.sysctl_tcp_syn_retries;
228231
expired = icsk->icsk_retransmits >= retry_until;
@@ -234,6 +237,9 @@ static int tcp_write_timeout(struct sock *sk)
234237
dst_negative_advice(sk);
235238
} else {
236239
sk_rethink_txhash(sk);
240+
tp->timeout_rehash++;
241+
__NET_INC_STATS(sock_net(sk),
242+
LINUX_MIB_TCPTIMEOUTREHASH);
237243
}
238244

239245
retry_until = net->ipv4.sysctl_tcp_retries2;

0 commit comments

Comments
 (0)