Commit 0263598c authored by Wei Wang's avatar Wei Wang Committed by David S. Miller

tcp: extract the function to compute delivery rate

Refactor the code to extract the function to compute delivery rate.
This function will be used in later commit.
Signed-off-by: default avatarWei Wang <weiwan@google.com>
Acked-by: default avatarYuchung Cheng <ycheng@google.com>
Acked-by: default avatarSoheil Hassas Yeganeh <soheil@google.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 6a95befc
...@@ -388,6 +388,19 @@ static int retrans_to_secs(u8 retrans, int timeout, int rto_max) ...@@ -388,6 +388,19 @@ static int retrans_to_secs(u8 retrans, int timeout, int rto_max)
return period; return period;
} }
static u64 tcp_compute_delivery_rate(const struct tcp_sock *tp)
{
u32 rate = READ_ONCE(tp->rate_delivered);
u32 intv = READ_ONCE(tp->rate_interval_us);
u64 rate64 = 0;
if (rate && intv) {
rate64 = (u64)rate * tp->mss_cache * USEC_PER_SEC;
do_div(rate64, intv);
}
return rate64;
}
/* Address-family independent initialization for a tcp_sock. /* Address-family independent initialization for a tcp_sock.
* *
* NOTE: A lot of things set to zero explicitly by call to * NOTE: A lot of things set to zero explicitly by call to
...@@ -2716,7 +2729,7 @@ void tcp_get_info(struct sock *sk, struct tcp_info *info) ...@@ -2716,7 +2729,7 @@ void tcp_get_info(struct sock *sk, struct tcp_info *info)
{ {
const struct tcp_sock *tp = tcp_sk(sk); /* iff sk_type == SOCK_STREAM */ const struct tcp_sock *tp = tcp_sk(sk); /* iff sk_type == SOCK_STREAM */
const struct inet_connection_sock *icsk = inet_csk(sk); const struct inet_connection_sock *icsk = inet_csk(sk);
u32 now, intv; u32 now;
u64 rate64; u64 rate64;
bool slow; bool slow;
u32 rate; u32 rate;
...@@ -2815,13 +2828,9 @@ void tcp_get_info(struct sock *sk, struct tcp_info *info) ...@@ -2815,13 +2828,9 @@ void tcp_get_info(struct sock *sk, struct tcp_info *info)
info->tcpi_data_segs_out = tp->data_segs_out; info->tcpi_data_segs_out = tp->data_segs_out;
info->tcpi_delivery_rate_app_limited = tp->rate_app_limited ? 1 : 0; info->tcpi_delivery_rate_app_limited = tp->rate_app_limited ? 1 : 0;
rate = READ_ONCE(tp->rate_delivered); rate64 = tcp_compute_delivery_rate(tp);
intv = READ_ONCE(tp->rate_interval_us); if (rate64)
if (rate && intv) {
rate64 = (u64)rate * tp->mss_cache * USEC_PER_SEC;
do_div(rate64, intv);
info->tcpi_delivery_rate = rate64; info->tcpi_delivery_rate = rate64;
}
unlock_sock_fast(sk, slow); unlock_sock_fast(sk, slow);
} }
EXPORT_SYMBOL_GPL(tcp_get_info); EXPORT_SYMBOL_GPL(tcp_get_info);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment