Skip to content

Commit cf33e25

Browse files
nealcardwelldavem330
authored andcommitted
tcp_bbr: centralize code to set gains
Centralize the code that sets gains used for computing cwnd and pacing rate. This simplifies the code and makes it easier to change the state machine or (in the future) dynamically change the gain values and ensure that the correct gain values are always used. Signed-off-by: Neal Cardwell <[email protected]> Signed-off-by: Yuchung Cheng <[email protected]> Signed-off-by: Soheil Hassas Yeganeh <[email protected]> Signed-off-by: Priyaranjan Jha <[email protected]> Signed-off-by: Eric Dumazet <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent a87c83d commit cf33e25

File tree

1 file changed

+30
-10
lines changed

1 file changed

+30
-10
lines changed

net/ipv4/tcp_bbr.c

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -521,8 +521,6 @@ static void bbr_advance_cycle_phase(struct sock *sk)
521521

522522
bbr->cycle_idx = (bbr->cycle_idx + 1) & (CYCLE_LEN - 1);
523523
bbr->cycle_mstamp = tp->delivered_mstamp;
524-
bbr->pacing_gain = bbr->lt_use_bw ? BBR_UNIT :
525-
bbr_pacing_gain[bbr->cycle_idx];
526524
}
527525

528526
/* Gain cycling: cycle pacing gain to converge to fair share of available bw. */
@@ -540,17 +538,13 @@ static void bbr_reset_startup_mode(struct sock *sk)
540538
struct bbr *bbr = inet_csk_ca(sk);
541539

542540
bbr->mode = BBR_STARTUP;
543-
bbr->pacing_gain = bbr_high_gain;
544-
bbr->cwnd_gain = bbr_high_gain;
545541
}
546542

547543
static void bbr_reset_probe_bw_mode(struct sock *sk)
548544
{
549545
struct bbr *bbr = inet_csk_ca(sk);
550546

551547
bbr->mode = BBR_PROBE_BW;
552-
bbr->pacing_gain = BBR_UNIT;
553-
bbr->cwnd_gain = bbr_cwnd_gain;
554548
bbr->cycle_idx = CYCLE_LEN - 1 - prandom_u32_max(bbr_cycle_rand);
555549
bbr_advance_cycle_phase(sk); /* flip to next phase of gain cycle */
556550
}
@@ -768,8 +762,6 @@ static void bbr_check_drain(struct sock *sk, const struct rate_sample *rs)
768762

769763
if (bbr->mode == BBR_STARTUP && bbr_full_bw_reached(sk)) {
770764
bbr->mode = BBR_DRAIN; /* drain queue we created */
771-
bbr->pacing_gain = bbr_drain_gain; /* pace slow to drain */
772-
bbr->cwnd_gain = bbr_high_gain; /* maintain cwnd */
773765
tcp_sk(sk)->snd_ssthresh =
774766
bbr_target_cwnd(sk, bbr_max_bw(sk), BBR_UNIT);
775767
} /* fall through to check if in-flight is already small: */
@@ -831,8 +823,6 @@ static void bbr_update_min_rtt(struct sock *sk, const struct rate_sample *rs)
831823
if (bbr_probe_rtt_mode_ms > 0 && filter_expired &&
832824
!bbr->idle_restart && bbr->mode != BBR_PROBE_RTT) {
833825
bbr->mode = BBR_PROBE_RTT; /* dip, drain queue */
834-
bbr->pacing_gain = BBR_UNIT;
835-
bbr->cwnd_gain = BBR_UNIT;
836826
bbr_save_cwnd(sk); /* note cwnd so we can restore it */
837827
bbr->probe_rtt_done_stamp = 0;
838828
}
@@ -860,13 +850,43 @@ static void bbr_update_min_rtt(struct sock *sk, const struct rate_sample *rs)
860850
bbr->idle_restart = 0;
861851
}
862852

853+
static void bbr_update_gains(struct sock *sk)
854+
{
855+
struct bbr *bbr = inet_csk_ca(sk);
856+
857+
switch (bbr->mode) {
858+
case BBR_STARTUP:
859+
bbr->pacing_gain = bbr_high_gain;
860+
bbr->cwnd_gain = bbr_high_gain;
861+
break;
862+
case BBR_DRAIN:
863+
bbr->pacing_gain = bbr_drain_gain; /* slow, to drain */
864+
bbr->cwnd_gain = bbr_high_gain; /* keep cwnd */
865+
break;
866+
case BBR_PROBE_BW:
867+
bbr->pacing_gain = (bbr->lt_use_bw ?
868+
BBR_UNIT :
869+
bbr_pacing_gain[bbr->cycle_idx]);
870+
bbr->cwnd_gain = bbr_cwnd_gain;
871+
break;
872+
case BBR_PROBE_RTT:
873+
bbr->pacing_gain = BBR_UNIT;
874+
bbr->cwnd_gain = BBR_UNIT;
875+
break;
876+
default:
877+
WARN_ONCE(1, "BBR bad mode: %u\n", bbr->mode);
878+
break;
879+
}
880+
}
881+
863882
static void bbr_update_model(struct sock *sk, const struct rate_sample *rs)
864883
{
865884
bbr_update_bw(sk, rs);
866885
bbr_update_cycle_phase(sk, rs);
867886
bbr_check_full_bw_reached(sk, rs);
868887
bbr_check_drain(sk, rs);
869888
bbr_update_min_rtt(sk, rs);
889+
bbr_update_gains(sk);
870890
}
871891

872892
static void bbr_main(struct sock *sk, const struct rate_sample *rs)

0 commit comments

Comments
 (0)