Lines Matching +full:avg +full:- +full:samples
1 // SPDX-License-Identifier: GPL-2.0-only
8 * "CUBIC: A New TCP-Friendly High-Speed TCP Variant"
41 /* Number of delay samples for detecting the increase of delay */
62 /* Note parameters that are used for precomputing scale factors are read-only */
77 " 1: packet-train 2: delay 3: both packet-train and delay");
97 u8 sample_cnt; /* number of samples to decide curr_rtt */
107 ca->cnt = 0; in bictcp_reset()
108 ca->last_max_cwnd = 0; in bictcp_reset()
109 ca->last_cwnd = 0; in bictcp_reset()
110 ca->last_time = 0; in bictcp_reset()
111 ca->bic_origin_point = 0; in bictcp_reset()
112 ca->bic_K = 0; in bictcp_reset()
113 ca->delay_min = 0; in bictcp_reset()
114 ca->epoch_start = 0; in bictcp_reset()
115 ca->ack_cnt = 0; in bictcp_reset()
116 ca->tcp_cwnd = 0; in bictcp_reset()
117 ca->found = 0; in bictcp_reset()
122 return tcp_sk(sk)->tcp_mstamp; in bictcp_clock_us()
130 ca->round_start = ca->last_ack = bictcp_clock_us(sk); in bictcp_hystart_reset()
131 ca->end_seq = tp->snd_nxt; in bictcp_hystart_reset()
132 ca->curr_rtt = ~0U; in bictcp_hystart_reset()
133 ca->sample_cnt = 0; in bictcp_hystart_reset()
146 tcp_sk(sk)->snd_ssthresh = initial_ssthresh; in bictcp_init()
156 delta = now - tcp_sk(sk)->lsndtime; in bictcp_cwnd_event()
161 if (ca->epoch_start && delta > 0) { in bictcp_cwnd_event()
162 ca->epoch_start += delta; in bictcp_cwnd_event()
163 if (after(ca->epoch_start, now)) in bictcp_cwnd_event()
164 ca->epoch_start = now; in bictcp_cwnd_event()
171 * Newton-Raphson iteration.
172 * Avg err ~= 0.195%
179 * Precomputed then refined by hand - Willy Tarreau in cubic_root()
182 * v = cbrt(x << 18) - 1 in cubic_root()
202 b = ((b * 84) >> 8) - 1; in cubic_root()
208 * Newton-Raphson iteration in cubic_root()
213 x = (2 * x + (u32)div64_u64(a, (u64)x * (u64)(x - 1))); in cubic_root()
226 ca->ack_cnt += acked; /* count the number of ACKed packets */ in bictcp_update()
228 if (ca->last_cwnd == cwnd && in bictcp_update()
229 (s32)(tcp_jiffies32 - ca->last_time) <= HZ / 32) in bictcp_update()
232 /* The CUBIC function can update ca->cnt at most once per jiffy. in bictcp_update()
233 * On all cwnd reduction events, ca->epoch_start is set to 0, in bictcp_update()
234 * which will force a recalculation of ca->cnt. in bictcp_update()
236 if (ca->epoch_start && tcp_jiffies32 == ca->last_time) in bictcp_update()
239 ca->last_cwnd = cwnd; in bictcp_update()
240 ca->last_time = tcp_jiffies32; in bictcp_update()
242 if (ca->epoch_start == 0) { in bictcp_update()
243 ca->epoch_start = tcp_jiffies32; /* record beginning */ in bictcp_update()
244 ca->ack_cnt = acked; /* start counting */ in bictcp_update()
245 ca->tcp_cwnd = cwnd; /* syn with cubic */ in bictcp_update()
247 if (ca->last_max_cwnd <= cwnd) { in bictcp_update()
248 ca->bic_K = 0; in bictcp_update()
249 ca->bic_origin_point = cwnd; in bictcp_update()
252 * (wmax-cwnd) * (srtt>>3 / HZ) / c * 2^(3*bictcp_HZ) in bictcp_update()
254 ca->bic_K = cubic_root(cube_factor in bictcp_update()
255 * (ca->last_max_cwnd - cwnd)); in bictcp_update()
256 ca->bic_origin_point = ca->last_max_cwnd; in bictcp_update()
260 /* cubic function - calc*/ in bictcp_update()
267 * time = (t - K) / 2^bictcp_HZ in bictcp_update()
274 t = (s32)(tcp_jiffies32 - ca->epoch_start); in bictcp_update()
275 t += usecs_to_jiffies(ca->delay_min); in bictcp_update()
280 if (t < ca->bic_K) /* t - K */ in bictcp_update()
281 offs = ca->bic_K - t; in bictcp_update()
283 offs = t - ca->bic_K; in bictcp_update()
285 /* c/rtt * (t-K)^3 */ in bictcp_update()
287 if (t < ca->bic_K) /* below origin*/ in bictcp_update()
288 bic_target = ca->bic_origin_point - delta; in bictcp_update()
290 bic_target = ca->bic_origin_point + delta; in bictcp_update()
292 /* cubic function - calc bictcp_cnt*/ in bictcp_update()
294 ca->cnt = cwnd / (bic_target - cwnd); in bictcp_update()
296 ca->cnt = 100 * cwnd; /* very small increment*/ in bictcp_update()
303 if (ca->last_max_cwnd == 0 && ca->cnt > 20) in bictcp_update()
304 ca->cnt = 20; /* increase cwnd 5% per RTT */ in bictcp_update()
312 while (ca->ack_cnt > delta) { /* update tcp cwnd */ in bictcp_update()
313 ca->ack_cnt -= delta; in bictcp_update()
314 ca->tcp_cwnd++; in bictcp_update()
317 if (ca->tcp_cwnd > cwnd) { /* if bic is slower than tcp */ in bictcp_update()
318 delta = ca->tcp_cwnd - cwnd; in bictcp_update()
320 if (ca->cnt > max_cnt) in bictcp_update()
321 ca->cnt = max_cnt; in bictcp_update()
328 ca->cnt = max(ca->cnt, 2U); in bictcp_update()
340 if (hystart && after(ack, ca->end_seq)) in bictcp_cong_avoid()
346 bictcp_update(ca, tp->snd_cwnd, acked); in bictcp_cong_avoid()
347 tcp_cong_avoid_ai(tp, ca->cnt, acked); in bictcp_cong_avoid()
355 ca->epoch_start = 0; /* end of epoch */ in bictcp_recalc_ssthresh()
358 if (tp->snd_cwnd < ca->last_max_cwnd && fast_convergence) in bictcp_recalc_ssthresh()
359 ca->last_max_cwnd = (tp->snd_cwnd * (BICTCP_BETA_SCALE + beta)) in bictcp_recalc_ssthresh()
362 ca->last_max_cwnd = tp->snd_cwnd; in bictcp_recalc_ssthresh()
364 return max((tp->snd_cwnd * beta) / BICTCP_BETA_SCALE, 2U); in bictcp_recalc_ssthresh()
377 * slow start we begin with small TSO packets and ca->delay_min would
388 rate = READ_ONCE(sk->sk_pacing_rate); in hystart_ack_delay()
404 /* first detection parameter - ack-train detection */ in hystart_update()
405 if ((s32)(now - ca->last_ack) <= hystart_ack_delta_us) { in hystart_update()
406 ca->last_ack = now; in hystart_update()
408 threshold = ca->delay_min + hystart_ack_delay(sk); in hystart_update()
411 * ca->delay_min/2. in hystart_update()
415 if (sk->sk_pacing_status == SK_PACING_NONE) in hystart_update()
418 if ((s32)(now - ca->round_start) > threshold) { in hystart_update()
419 ca->found = 1; in hystart_update()
421 now - ca->round_start, threshold, in hystart_update()
422 ca->delay_min, hystart_ack_delay(sk), tp->snd_cwnd); in hystart_update()
427 tp->snd_cwnd); in hystart_update()
428 tp->snd_ssthresh = tp->snd_cwnd; in hystart_update()
435 if (ca->curr_rtt > delay) in hystart_update()
436 ca->curr_rtt = delay; in hystart_update()
437 if (ca->sample_cnt < HYSTART_MIN_SAMPLES) { in hystart_update()
438 ca->sample_cnt++; in hystart_update()
440 if (ca->curr_rtt > ca->delay_min + in hystart_update()
441 HYSTART_DELAY_THRESH(ca->delay_min >> 3)) { in hystart_update()
442 ca->found = 1; in hystart_update()
447 tp->snd_cwnd); in hystart_update()
448 tp->snd_ssthresh = tp->snd_cwnd; in hystart_update()
461 if (sample->rtt_us < 0) in bictcp_acked()
464 /* Discard delay samples right after fast recovery */ in bictcp_acked()
465 if (ca->epoch_start && (s32)(tcp_jiffies32 - ca->epoch_start) < HZ) in bictcp_acked()
468 delay = sample->rtt_us; in bictcp_acked()
473 if (ca->delay_min == 0 || ca->delay_min > delay) in bictcp_acked()
474 ca->delay_min = delay; in bictcp_acked()
477 if (!ca->found && tcp_in_slow_start(tp) && hystart && in bictcp_acked()
478 tp->snd_cwnd >= hystart_low_window) in bictcp_acked()
498 /* Precompute a bunch of the scaling factors that are used per-packet in cubictcp_register()
503 / (BICTCP_BETA_SCALE - beta); in cubictcp_register()
507 /* calculate the "K" for (wmax-cwnd) = c/rtt * K^3 in cubictcp_register()
508 * so K = cubic_root( (wmax-cwnd)*rtt/c ) in cubictcp_register()
517 * HZ < 1,000,00 (corresponding to 10 nano-second) in cubictcp_register()