Lines Matching +full:min +full:- +full:sample +full:- +full:rate +full:- +full:hz
1 // SPDX-License-Identifier: GPL-2.0-only
8 * "CUBIC: A New TCP-Friendly High-Speed TCP Variant"
37 #define BICTCP_HZ 10 /* BIC HZ 2^10 = 1024 */
64 /* Note parameters that are used for precomputing scale factors are read-only */
79 " 1: packet-train 2: delay 3: both packet-train and delay");
94 u32 delay_min; /* min delay (usec) */
110 ca->found = 0;
115 return tcp_sk(sk)->tcp_mstamp;
123 ca->round_start = ca->last_ack = bictcp_clock_us(sk);
124 ca->end_seq = tp->snd_nxt;
125 ca->curr_rtt = ~0U;
126 ca->sample_cnt = 0;
139 tcp_sk(sk)->snd_ssthresh = initial_ssthresh;
149 delta = now - tcp_sk(sk)->lsndtime;
154 if (ca->epoch_start && delta > 0) {
155 ca->epoch_start += delta;
156 if (after(ca->epoch_start, now))
157 ca->epoch_start = now;
164 * Newton-Raphson iteration.
172 * Precomputed then refined by hand - Willy Tarreau
175 * v = cbrt(x << 18) - 1
195 b = ((b * 84) >> 8) - 1;
201 * Newton-Raphson iteration
206 x = (2 * x + (u32)div64_u64(a, (u64)x * (u64)(x - 1)));
219 ca->ack_cnt += acked; /* count the number of ACKed packets */
221 if (ca->last_cwnd == cwnd &&
222 (s32)(tcp_jiffies32 - ca->last_time) <= HZ / 32)
225 /* The CUBIC function can update ca->cnt at most once per jiffy.
226 * On all cwnd reduction events, ca->epoch_start is set to 0,
227 * which will force a recalculation of ca->cnt.
229 if (ca->epoch_start && tcp_jiffies32 == ca->last_time)
232 ca->last_cwnd = cwnd;
233 ca->last_time = tcp_jiffies32;
235 if (ca->epoch_start == 0) {
236 ca->epoch_start = tcp_jiffies32; /* record beginning */
237 ca->ack_cnt = acked; /* start counting */
238 ca->tcp_cwnd = cwnd; /* syn with cubic */
240 if (ca->last_max_cwnd <= cwnd) {
241 ca->bic_K = 0;
242 ca->bic_origin_point = cwnd;
245 * (wmax-cwnd) * (srtt>>3 / HZ) / c * 2^(3*bictcp_HZ)
247 ca->bic_K = cubic_root(cube_factor
248 * (ca->last_max_cwnd - cwnd));
249 ca->bic_origin_point = ca->last_max_cwnd;
253 /* cubic function - calc*/
260 * time = (t - K) / 2^bictcp_HZ
262 * rtt = (srtt >> 3) / HZ
267 t = (s32)(tcp_jiffies32 - ca->epoch_start);
268 t += usecs_to_jiffies(ca->delay_min);
269 /* change the unit from HZ to bictcp_HZ */
271 do_div(t, HZ);
273 if (t < ca->bic_K) /* t - K */
274 offs = ca->bic_K - t;
276 offs = t - ca->bic_K;
278 /* c/rtt * (t-K)^3 */
280 if (t < ca->bic_K) /* below origin*/
281 bic_target = ca->bic_origin_point - delta;
283 bic_target = ca->bic_origin_point + delta;
285 /* cubic function - calc bictcp_cnt*/
287 ca->cnt = cwnd / (bic_target - cwnd);
289 ca->cnt = 100 * cwnd; /* very small increment*/
296 if (ca->last_max_cwnd == 0 && ca->cnt > 20)
297 ca->cnt = 20; /* increase cwnd 5% per RTT */
305 while (ca->ack_cnt > delta) { /* update tcp cwnd */
306 ca->ack_cnt -= delta;
307 ca->tcp_cwnd++;
310 if (ca->tcp_cwnd > cwnd) { /* if bic is slower than tcp */
311 delta = ca->tcp_cwnd - cwnd;
313 if (ca->cnt > max_cnt)
314 ca->cnt = max_cnt;
318 /* The maximum rate of cwnd increase CUBIC allows is 1 packet per
321 ca->cnt = max(ca->cnt, 2U);
338 tcp_cong_avoid_ai(tp, ca->cnt, acked);
346 ca->epoch_start = 0; /* end of epoch */
349 if (tcp_snd_cwnd(tp) < ca->last_max_cwnd && fast_convergence)
350 ca->last_max_cwnd = (tcp_snd_cwnd(tp) * (BICTCP_BETA_SCALE + beta))
353 ca->last_max_cwnd = tcp_snd_cwnd(tp);
368 * slow start we begin with small TSO packets and ca->delay_min would
372 * We apply another 100% factor because @rate is doubled at this point.
377 unsigned long rate;
379 rate = READ_ONCE(sk->sk_pacing_rate);
380 if (!rate)
383 div64_ul((u64)sk->sk_gso_max_size * 4 * USEC_PER_SEC, rate));
392 if (after(tp->snd_una, ca->end_seq))
402 /* first detection parameter - ack-train detection */
403 if ((s32)(now - ca->last_ack) <= hystart_ack_delta_us) {
404 ca->last_ack = now;
406 threshold = ca->delay_min + hystart_ack_delay(sk);
409 * ca->delay_min/2.
413 if (sk->sk_pacing_status == SK_PACING_NONE)
416 if ((s32)(now - ca->round_start) > threshold) {
417 ca->found = 1;
419 now - ca->round_start, threshold,
420 ca->delay_min, hystart_ack_delay(sk), tcp_snd_cwnd(tp));
426 tp->snd_ssthresh = tcp_snd_cwnd(tp);
433 if (ca->curr_rtt > delay)
434 ca->curr_rtt = delay;
435 if (ca->sample_cnt < HYSTART_MIN_SAMPLES) {
436 ca->sample_cnt++;
438 if (ca->curr_rtt > ca->delay_min +
439 HYSTART_DELAY_THRESH(ca->delay_min >> 3)) {
440 ca->found = 1;
446 tp->snd_ssthresh = tcp_snd_cwnd(tp);
452 __bpf_kfunc static void cubictcp_acked(struct sock *sk, const struct ack_sample *sample)
459 if (sample->rtt_us < 0)
463 if (ca->epoch_start && (s32)(tcp_jiffies32 - ca->epoch_start) < HZ)
466 delay = sample->rtt_us;
471 if (ca->delay_min == 0 || ca->delay_min > delay)
472 ca->delay_min = delay;
474 if (!ca->found && tcp_in_slow_start(tp) && hystart)
510 /* Precompute a bunch of the scaling factors that are used per-packet
515 / (BICTCP_BETA_SCALE - beta);
519 /* calculate the "K" for (wmax-cwnd) = c/rtt * K^3
520 * so K = cubic_root( (wmax-cwnd)*rtt/c )
521 * the unit of K is bictcp_HZ=2^10, not HZ
529 * HZ < 1,000,00 (corresponding to 10 nano-second)