Skip to content

Commit ccbf3bf

Browse files
edumazetdavem330
authored andcommitted
tcp: shortcut listeners in tcp_get_info()
Being lockless in tcp_get_info() is hard, because we need to add specific synchronization in TCP fast path, like seqcount. Following patch will change inet_diag_dump_icsk() to no longer hold any lock for non listeners, so that we can properly acquire socket lock in get_tcp_info() and let it return more consistent counters. Signed-off-by: Eric Dumazet <edumazet@google.com> Signed-off-by: Yuchung Cheng <ycheng@google.com> Acked-by: Soheil Hassas Yeganeh <soheil@google.com> Acked-by: Neal Cardwell <ncardwell@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 721ad32 commit ccbf3bf

1 file changed

Lines changed: 24 additions & 17 deletions

File tree

‎net/ipv4/tcp.c‎

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2721,6 +2721,27 @@ void tcp_get_info(struct sock *sk, struct tcp_info *info)
27212721

27222722
info->tcpi_state = sk_state_load(sk);
27232723

2724+
/* Report meaningful fields for all TCP states, including listeners */
2725+
rate = READ_ONCE(sk->sk_pacing_rate);
2726+
rate64 = rate != ~0U ? rate : ~0ULL;
2727+
put_unaligned(rate64, &info->tcpi_pacing_rate);
2728+
2729+
rate = READ_ONCE(sk->sk_max_pacing_rate);
2730+
rate64 = rate != ~0U ? rate : ~0ULL;
2731+
put_unaligned(rate64, &info->tcpi_max_pacing_rate);
2732+
2733+
info->tcpi_reordering = tp->reordering;
2734+
info->tcpi_snd_cwnd = tp->snd_cwnd;
2735+
2736+
if (info->tcpi_state == TCP_LISTEN) {
2737+
/* listeners aliased fields :
2738+
* tcpi_unacked -> Number of children ready for accept()
2739+
* tcpi_sacked -> max backlog
2740+
*/
2741+
info->tcpi_unacked = sk->sk_ack_backlog;
2742+
info->tcpi_sacked = sk->sk_max_ack_backlog;
2743+
return;
2744+
}
27242745
info->tcpi_ca_state = icsk->icsk_ca_state;
27252746
info->tcpi_retransmits = icsk->icsk_retransmits;
27262747
info->tcpi_probes = icsk->icsk_probes_out;
@@ -2748,13 +2769,9 @@ void tcp_get_info(struct sock *sk, struct tcp_info *info)
27482769
info->tcpi_snd_mss = tp->mss_cache;
27492770
info->tcpi_rcv_mss = icsk->icsk_ack.rcv_mss;
27502771

2751-
if (info->tcpi_state == TCP_LISTEN) {
2752-
info->tcpi_unacked = sk->sk_ack_backlog;
2753-
info->tcpi_sacked = sk->sk_max_ack_backlog;
2754-
} else {
2755-
info->tcpi_unacked = tp->packets_out;
2756-
info->tcpi_sacked = tp->sacked_out;
2757-
}
2772+
info->tcpi_unacked = tp->packets_out;
2773+
info->tcpi_sacked = tp->sacked_out;
2774+
27582775
info->tcpi_lost = tp->lost_out;
27592776
info->tcpi_retrans = tp->retrans_out;
27602777
info->tcpi_fackets = tp->fackets_out;
@@ -2768,23 +2785,13 @@ void tcp_get_info(struct sock *sk, struct tcp_info *info)
27682785
info->tcpi_rtt = tp->srtt_us >> 3;
27692786
info->tcpi_rttvar = tp->mdev_us >> 2;
27702787
info->tcpi_snd_ssthresh = tp->snd_ssthresh;
2771-
info->tcpi_snd_cwnd = tp->snd_cwnd;
27722788
info->tcpi_advmss = tp->advmss;
2773-
info->tcpi_reordering = tp->reordering;
27742789

27752790
info->tcpi_rcv_rtt = jiffies_to_usecs(tp->rcv_rtt_est.rtt)>>3;
27762791
info->tcpi_rcv_space = tp->rcvq_space.space;
27772792

27782793
info->tcpi_total_retrans = tp->total_retrans;
27792794

2780-
rate = READ_ONCE(sk->sk_pacing_rate);
2781-
rate64 = rate != ~0U ? rate : ~0ULL;
2782-
put_unaligned(rate64, &info->tcpi_pacing_rate);
2783-
2784-
rate = READ_ONCE(sk->sk_max_pacing_rate);
2785-
rate64 = rate != ~0U ? rate : ~0ULL;
2786-
put_unaligned(rate64, &info->tcpi_max_pacing_rate);
2787-
27882795
do {
27892796
start = u64_stats_fetch_begin_irq(&tp->syncp);
27902797
put_unaligned(tp->bytes_acked, &info->tcpi_bytes_acked);

0 commit comments

Comments
 (0)