Skip to content

Commit 071d508

Browse files
yuchungchengdavem330
authored andcommitted
tcp: add tcp_in_slow_start helper
Add a helper to test the slow start condition in various congestion control modules and other places. This is to prepare a slight improvement in policy as to exactly when to slow start. Signed-off-by: Yuchung Cheng <ycheng@google.com> Signed-off-by: Neal Cardwell <ncardwell@google.com> Signed-off-by: Eric Dumazet <edumazet@google.com> Signed-off-by: Nandita Dukkipati <nanditad@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 1007f59 commit 071d508

11 files changed

+19
-14
lines changed

include/net/tcp.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -989,6 +989,11 @@ static inline unsigned int tcp_packets_in_flight(const struct tcp_sock *tp)
989989

990990
#define TCP_INFINITE_SSTHRESH 0x7fffffff
991991

992+
static inline bool tcp_in_slow_start(const struct tcp_sock *tp)
993+
{
994+
return tp->snd_cwnd <= tp->snd_ssthresh;
995+
}
996+
992997
static inline bool tcp_in_initial_slowstart(const struct tcp_sock *tp)
993998
{
994999
return tp->snd_ssthresh >= TCP_INFINITE_SSTHRESH;
@@ -1065,7 +1070,7 @@ static inline bool tcp_is_cwnd_limited(const struct sock *sk)
10651070
const struct tcp_sock *tp = tcp_sk(sk);
10661071

10671072
/* If in slow start, ensure cwnd grows to twice what was ACKed. */
1068-
if (tp->snd_cwnd <= tp->snd_ssthresh)
1073+
if (tcp_in_slow_start(tp))
10691074
return tp->snd_cwnd < 2 * tp->max_packets_out;
10701075

10711076
return tp->is_cwnd_limited;

net/ipv4/tcp_bic.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ static void bictcp_cong_avoid(struct sock *sk, u32 ack, u32 acked)
146146
if (!tcp_is_cwnd_limited(sk))
147147
return;
148148

149-
if (tp->snd_cwnd <= tp->snd_ssthresh)
149+
if (tcp_in_slow_start(tp))
150150
tcp_slow_start(tp, acked);
151151
else {
152152
bictcp_update(ca, tp->snd_cwnd);

net/ipv4/tcp_cong.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ void tcp_reno_cong_avoid(struct sock *sk, u32 ack, u32 acked)
413413
return;
414414

415415
/* In "safe" area, increase. */
416-
if (tp->snd_cwnd <= tp->snd_ssthresh) {
416+
if (tcp_in_slow_start(tp)) {
417417
acked = tcp_slow_start(tp, acked);
418418
if (!acked)
419419
return;

net/ipv4/tcp_cubic.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ static void bictcp_cong_avoid(struct sock *sk, u32 ack, u32 acked)
320320
if (!tcp_is_cwnd_limited(sk))
321321
return;
322322

323-
if (tp->snd_cwnd <= tp->snd_ssthresh) {
323+
if (tcp_in_slow_start(tp)) {
324324
if (hystart && after(ack, ca->end_seq))
325325
bictcp_hystart_reset(sk);
326326
acked = tcp_slow_start(tp, acked);
@@ -439,7 +439,7 @@ static void bictcp_acked(struct sock *sk, u32 cnt, s32 rtt_us)
439439
ca->delay_min = delay;
440440

441441
/* hystart triggers when cwnd is larger than some threshold */
442-
if (hystart && tp->snd_cwnd <= tp->snd_ssthresh &&
442+
if (hystart && tcp_in_slow_start(tp) &&
443443
tp->snd_cwnd >= hystart_low_window)
444444
hystart_update(sk, delay);
445445
}

net/ipv4/tcp_highspeed.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ static void hstcp_cong_avoid(struct sock *sk, u32 ack, u32 acked)
116116
if (!tcp_is_cwnd_limited(sk))
117117
return;
118118

119-
if (tp->snd_cwnd <= tp->snd_ssthresh)
119+
if (tcp_in_slow_start(tp))
120120
tcp_slow_start(tp, acked);
121121
else {
122122
/* Update AIMD parameters.

net/ipv4/tcp_htcp.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ static void htcp_cong_avoid(struct sock *sk, u32 ack, u32 acked)
236236
if (!tcp_is_cwnd_limited(sk))
237237
return;
238238

239-
if (tp->snd_cwnd <= tp->snd_ssthresh)
239+
if (tcp_in_slow_start(tp))
240240
tcp_slow_start(tp, acked);
241241
else {
242242
/* In dangerous area, increase slowly.

net/ipv4/tcp_illinois.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ static void tcp_illinois_cong_avoid(struct sock *sk, u32 ack, u32 acked)
268268
return;
269269

270270
/* In slow start */
271-
if (tp->snd_cwnd <= tp->snd_ssthresh)
271+
if (tcp_in_slow_start(tp))
272272
tcp_slow_start(tp, acked);
273273

274274
else {

net/ipv4/tcp_metrics.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ void tcp_update_metrics(struct sock *sk)
461461
tcp_metric_set(tm, TCP_METRIC_CWND,
462462
tp->snd_cwnd);
463463
}
464-
} else if (tp->snd_cwnd > tp->snd_ssthresh &&
464+
} else if (!tcp_in_slow_start(tp) &&
465465
icsk->icsk_ca_state == TCP_CA_Open) {
466466
/* Cong. avoidance phase, cwnd is reliable. */
467467
if (!tcp_metric_locked(tm, TCP_METRIC_SSTHRESH))

net/ipv4/tcp_scalable.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ static void tcp_scalable_cong_avoid(struct sock *sk, u32 ack, u32 acked)
2222
if (!tcp_is_cwnd_limited(sk))
2323
return;
2424

25-
if (tp->snd_cwnd <= tp->snd_ssthresh)
25+
if (tcp_in_slow_start(tp))
2626
tcp_slow_start(tp, acked);
2727
else
2828
tcp_cong_avoid_ai(tp, min(tp->snd_cwnd, TCP_SCALABLE_AI_CNT),

net/ipv4/tcp_vegas.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ static void tcp_vegas_cong_avoid(struct sock *sk, u32 ack, u32 acked)
225225
*/
226226
diff = tp->snd_cwnd * (rtt-vegas->baseRTT) / vegas->baseRTT;
227227

228-
if (diff > gamma && tp->snd_cwnd <= tp->snd_ssthresh) {
228+
if (diff > gamma && tcp_in_slow_start(tp)) {
229229
/* Going too fast. Time to slow down
230230
* and switch to congestion avoidance.
231231
*/
@@ -240,7 +240,7 @@ static void tcp_vegas_cong_avoid(struct sock *sk, u32 ack, u32 acked)
240240
tp->snd_cwnd = min(tp->snd_cwnd, (u32)target_cwnd+1);
241241
tp->snd_ssthresh = tcp_vegas_ssthresh(tp);
242242

243-
} else if (tp->snd_cwnd <= tp->snd_ssthresh) {
243+
} else if (tcp_in_slow_start(tp)) {
244244
/* Slow start. */
245245
tcp_slow_start(tp, acked);
246246
} else {
@@ -281,7 +281,7 @@ static void tcp_vegas_cong_avoid(struct sock *sk, u32 ack, u32 acked)
281281
vegas->minRTT = 0x7fffffff;
282282
}
283283
/* Use normal slow start */
284-
else if (tp->snd_cwnd <= tp->snd_ssthresh)
284+
else if (tcp_in_slow_start(tp))
285285
tcp_slow_start(tp, acked);
286286
}
287287

net/ipv4/tcp_veno.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ static void tcp_veno_cong_avoid(struct sock *sk, u32 ack, u32 acked)
150150

151151
veno->diff = (tp->snd_cwnd << V_PARAM_SHIFT) - target_cwnd;
152152

153-
if (tp->snd_cwnd <= tp->snd_ssthresh) {
153+
if (tcp_in_slow_start(tp)) {
154154
/* Slow start. */
155155
tcp_slow_start(tp, acked);
156156
} else {

0 commit comments

Comments
 (0)