Jiri Slaby c43558
From: Neal Cardwell <ncardwell@google.com>
Jiri Slaby c43558
Date: Fri, 14 Jul 2017 17:49:23 -0400
Jiri Slaby c43558
Subject: [PATCH] tcp_bbr: introduce bbr_init_pacing_rate_from_rtt() helper
Jiri Slaby c43558
References: bnc#1060662
Thomas Zimmermann 1d81d2
Patch-mainline: v4.12.6
Jiri Slaby c43558
Git-commit: 79135b89b8af304456bd67916b80116ddf03d7b6
Jiri Slaby c43558
Jiri Slaby c43558
[ Upstream commit 79135b89b8af304456bd67916b80116ddf03d7b6 ]
Jiri Slaby c43558
Jiri Slaby c43558
Introduce a helper to initialize the BBR pacing rate unconditionally,
Jiri Slaby c43558
based on the current cwnd and RTT estimate. This is a pure refactor,
Jiri Slaby c43558
but is needed for two following fixes.
Jiri Slaby c43558
Jiri Slaby c43558
Fixes: 0f8782ea1497 ("tcp_bbr: add BBR congestion control")
Jiri Slaby c43558
Signed-off-by: Neal Cardwell <ncardwell@google.com>
Jiri Slaby c43558
Signed-off-by: Yuchung Cheng <ycheng@google.com>
Jiri Slaby c43558
Signed-off-by: Soheil Hassas Yeganeh <soheil@google.com>
Jiri Slaby c43558
Signed-off-by: David S. Miller <davem@davemloft.net>
Jiri Slaby c43558
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Jiri Slaby c43558
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Jiri Slaby c43558
---
Jiri Slaby c43558
 net/ipv4/tcp_bbr.c | 23 ++++++++++++++++++-----
Jiri Slaby c43558
 1 file changed, 18 insertions(+), 5 deletions(-)
Jiri Slaby c43558
Jiri Slaby c43558
diff --git a/net/ipv4/tcp_bbr.c b/net/ipv4/tcp_bbr.c
Jiri Slaby c43558
index 14e0eba7aa7a..e69c8b44568a 100644
Jiri Slaby c43558
--- a/net/ipv4/tcp_bbr.c
Jiri Slaby c43558
+++ b/net/ipv4/tcp_bbr.c
Jiri Slaby c43558
@@ -222,6 +222,23 @@ static u32 bbr_bw_to_pacing_rate(struct sock *sk, u32 bw, int gain)
Jiri Slaby c43558
 	return rate;
Jiri Slaby c43558
 }
Jiri Slaby c43558
 
Jiri Slaby c43558
+/* Initialize pacing rate to: high_gain * init_cwnd / RTT. */
Jiri Slaby c43558
+static void bbr_init_pacing_rate_from_rtt(struct sock *sk)
Jiri Slaby c43558
+{
Jiri Slaby c43558
+	struct tcp_sock *tp = tcp_sk(sk);
Jiri Slaby c43558
+	u64 bw;
Jiri Slaby c43558
+	u32 rtt_us;
Jiri Slaby c43558
+
Jiri Slaby c43558
+	if (tp->srtt_us) {		/* any RTT sample yet? */
Jiri Slaby c43558
+		rtt_us = max(tp->srtt_us >> 3, 1U);
Jiri Slaby c43558
+	} else {			 /* no RTT sample yet */
Jiri Slaby c43558
+		rtt_us = USEC_PER_MSEC;	 /* use nominal default RTT */
Jiri Slaby c43558
+	}
Jiri Slaby c43558
+	bw = (u64)tp->snd_cwnd * BW_UNIT;
Jiri Slaby c43558
+	do_div(bw, rtt_us);
Jiri Slaby c43558
+	sk->sk_pacing_rate = bbr_bw_to_pacing_rate(sk, bw, bbr_high_gain);
Jiri Slaby c43558
+}
Jiri Slaby c43558
+
Jiri Slaby c43558
 /* Pace using current bw estimate and a gain factor. In order to help drive the
Jiri Slaby c43558
  * network toward lower queues while maintaining high utilization and low
Jiri Slaby c43558
  * latency, the average pacing rate aims to be slightly (~1%) lower than the
Jiri Slaby c43558
@@ -806,7 +823,6 @@ static void bbr_init(struct sock *sk)
Jiri Slaby c43558
 {
Jiri Slaby c43558
 	struct tcp_sock *tp = tcp_sk(sk);
Jiri Slaby c43558
 	struct bbr *bbr = inet_csk_ca(sk);
Jiri Slaby c43558
-	u64 bw;
Jiri Slaby c43558
 
Jiri Slaby c43558
 	bbr->prior_cwnd = 0;
Jiri Slaby c43558
 	bbr->tso_segs_goal = 0;	 /* default segs per skb until first ACK */
Jiri Slaby c43558
@@ -822,11 +838,8 @@ static void bbr_init(struct sock *sk)
Jiri Slaby c43558
 
Jiri Slaby c43558
 	minmax_reset(&bbr->bw, bbr->rtt_cnt, 0);  /* init max bw to 0 */
Jiri Slaby c43558
 
Jiri Slaby c43558
-	/* Initialize pacing rate to: high_gain * init_cwnd / RTT. */
Jiri Slaby c43558
-	bw = (u64)tp->snd_cwnd * BW_UNIT;
Jiri Slaby c43558
-	do_div(bw, (tp->srtt_us >> 3) ? : USEC_PER_MSEC);
Jiri Slaby c43558
 	sk->sk_pacing_rate = 0;		/* force an update of sk_pacing_rate */
Jiri Slaby c43558
-	bbr_set_pacing_rate(sk, bw, bbr_high_gain);
Jiri Slaby c43558
+	bbr_init_pacing_rate_from_rtt(sk);
Jiri Slaby c43558
 
Jiri Slaby c43558
 	bbr->restore_cwnd = 0;
Jiri Slaby c43558
 	bbr->round_start = 0;
Jiri Slaby c43558
-- 
Jiri Slaby c43558
2.14.2
Jiri Slaby c43558