Lines Matching +full:avg +full:- +full:samples

1 // SPDX-License-Identifier: GPL-2.0-only
13 * "while (ca->ack_cnt > delta)" loop is changed to the equivalent
14 * "ca->ack_cnt / delta" operation.
35 /* Number of delay samples for detecting the increase of delay */
54 / (BICTCP_BETA_SCALE - beta);
55 /* calculate the "K" for (wmax-cwnd) = c/rtt * K^3
56 * so K = cubic_root( (wmax-cwnd)*rtt/c )
65 * HZ < 1,000,00 (corresponding to 10 nano-second)
86 __u8 sample_cnt; /* number of samples to decide curr_rtt */
96 ca->cnt = 0; in bictcp_reset()
97 ca->last_max_cwnd = 0; in bictcp_reset()
98 ca->last_cwnd = 0; in bictcp_reset()
99 ca->last_time = 0; in bictcp_reset()
100 ca->bic_origin_point = 0; in bictcp_reset()
101 ca->bic_K = 0; in bictcp_reset()
102 ca->delay_min = 0; in bictcp_reset()
103 ca->epoch_start = 0; in bictcp_reset()
104 ca->ack_cnt = 0; in bictcp_reset()
105 ca->tcp_cwnd = 0; in bictcp_reset()
106 ca->found = 0; in bictcp_reset()
125 int num = BITS_PER_U64 - 1; in fls64()
130 if (!(x & (~0ull << (BITS_PER_U64-32)))) { in fls64()
131 num -= 32; in fls64()
134 if (!(x & (~0ull << (BITS_PER_U64-16)))) { in fls64()
135 num -= 16; in fls64()
138 if (!(x & (~0ull << (BITS_PER_U64-8)))) { in fls64()
139 num -= 8; in fls64()
142 if (!(x & (~0ull << (BITS_PER_U64-4)))) { in fls64()
143 num -= 4; in fls64()
146 if (!(x & (~0ull << (BITS_PER_U64-2)))) { in fls64()
147 num -= 2; in fls64()
150 if (!(x & (~0ull << (BITS_PER_U64-1)))) in fls64()
151 num -= 1; in fls64()
158 return tcp_sk(sk)->tcp_mstamp; in bictcp_clock_us()
166 ca->round_start = ca->last_ack = bictcp_clock_us(sk); in bictcp_hystart_reset()
167 ca->end_seq = tp->snd_nxt; in bictcp_hystart_reset()
168 ca->curr_rtt = ~0U; in bictcp_hystart_reset()
169 ca->sample_cnt = 0; in bictcp_hystart_reset()
188 tcp_sk(sk)->snd_ssthresh = initial_ssthresh; in BPF_PROG()
192 * The remaining tcp-cubic functions have an easier way.
194 SEC("no-sec-prefix-bictcp_cwnd_event")
202 delta = now - tcp_sk(sk)->lsndtime; in BPF_PROG()
207 if (ca->epoch_start && delta > 0) { in BPF_PROG()
208 ca->epoch_start += delta; in BPF_PROG()
209 if (after(ca->epoch_start, now)) in BPF_PROG()
210 ca->epoch_start = now; in BPF_PROG()
218 * Precomputed then refined by hand - Willy Tarreau
221 * v = cbrt(x << 18) - 1
236 * Newton-Raphson iteration.
237 * Avg err ~= 0.195%
249 b = ((b * 84) >> 8) - 1; in cubic_root()
259 * Newton-Raphson iteration in cubic_root()
264 x = (2 * x + (__u32)div64_u64(a, (__u64)x * (__u64)(x - 1))); in cubic_root()
278 ca->ack_cnt += acked; /* count the number of ACKed packets */ in bictcp_update()
280 if (ca->last_cwnd == cwnd && in bictcp_update()
281 (__s32)(tcp_jiffies32 - ca->last_time) <= HZ / 32) in bictcp_update()
284 /* The CUBIC function can update ca->cnt at most once per jiffy. in bictcp_update()
285 * On all cwnd reduction events, ca->epoch_start is set to 0, in bictcp_update()
286 * which will force a recalculation of ca->cnt. in bictcp_update()
288 if (ca->epoch_start && tcp_jiffies32 == ca->last_time) in bictcp_update()
291 ca->last_cwnd = cwnd; in bictcp_update()
292 ca->last_time = tcp_jiffies32; in bictcp_update()
294 if (ca->epoch_start == 0) { in bictcp_update()
295 ca->epoch_start = tcp_jiffies32; /* record beginning */ in bictcp_update()
296 ca->ack_cnt = acked; /* start counting */ in bictcp_update()
297 ca->tcp_cwnd = cwnd; /* syn with cubic */ in bictcp_update()
299 if (ca->last_max_cwnd <= cwnd) { in bictcp_update()
300 ca->bic_K = 0; in bictcp_update()
301 ca->bic_origin_point = cwnd; in bictcp_update()
304 * (wmax-cwnd) * (srtt>>3 / HZ) / c * 2^(3*bictcp_HZ) in bictcp_update()
306 ca->bic_K = cubic_root(cube_factor in bictcp_update()
307 * (ca->last_max_cwnd - cwnd)); in bictcp_update()
308 ca->bic_origin_point = ca->last_max_cwnd; in bictcp_update()
312 /* cubic function - calc*/ in bictcp_update()
319 * time = (t - K) / 2^bictcp_HZ in bictcp_update()
326 t = (__s32)(tcp_jiffies32 - ca->epoch_start) * USEC_PER_JIFFY; in bictcp_update()
327 t += ca->delay_min; in bictcp_update()
332 if (t < ca->bic_K) /* t - K */ in bictcp_update()
333 offs = ca->bic_K - t; in bictcp_update()
335 offs = t - ca->bic_K; in bictcp_update()
337 /* c/rtt * (t-K)^3 */ in bictcp_update()
339 if (t < ca->bic_K) /* below origin*/ in bictcp_update()
340 bic_target = ca->bic_origin_point - delta; in bictcp_update()
342 bic_target = ca->bic_origin_point + delta; in bictcp_update()
344 /* cubic function - calc bictcp_cnt*/ in bictcp_update()
346 ca->cnt = cwnd / (bic_target - cwnd); in bictcp_update()
348 ca->cnt = 100 * cwnd; /* very small increment*/ in bictcp_update()
355 if (ca->last_max_cwnd == 0 && ca->cnt > 20) in bictcp_update()
356 ca->cnt = 20; /* increase cwnd 5% per RTT */ in bictcp_update()
366 if (ca->ack_cnt > delta && delta) { in bictcp_update()
367 n = ca->ack_cnt / delta; in bictcp_update()
368 ca->ack_cnt -= n * delta; in bictcp_update()
369 ca->tcp_cwnd += n; in bictcp_update()
372 if (ca->tcp_cwnd > cwnd) { /* if bic is slower than tcp */ in bictcp_update()
373 delta = ca->tcp_cwnd - cwnd; in bictcp_update()
375 if (ca->cnt > max_cnt) in bictcp_update()
376 ca->cnt = max_cnt; in bictcp_update()
383 ca->cnt = max(ca->cnt, 2U); in bictcp_update()
396 if (hystart && after(ack, ca->end_seq)) in BPF_STRUCT_OPS()
402 bictcp_update(ca, tp->snd_cwnd, acked); in BPF_STRUCT_OPS()
403 tcp_cong_avoid_ai(tp, ca->cnt, acked); in BPF_STRUCT_OPS()
411 ca->epoch_start = 0; /* end of epoch */ in BPF_STRUCT_OPS()
414 if (tp->snd_cwnd < ca->last_max_cwnd && fast_convergence) in BPF_STRUCT_OPS()
415 ca->last_max_cwnd = (tp->snd_cwnd * (BICTCP_BETA_SCALE + beta)) in BPF_STRUCT_OPS()
418 ca->last_max_cwnd = tp->snd_cwnd; in BPF_STRUCT_OPS()
420 return max((tp->snd_cwnd * beta) / BICTCP_BETA_SCALE, 2U); in BPF_STRUCT_OPS()
435 * slow start we begin with small TSO packets and ca->delay_min would
446 rate = sk->sk_pacing_rate; in hystart_ack_delay()
462 /* first detection parameter - ack-train detection */ in hystart_update()
463 if ((__s32)(now - ca->last_ack) <= hystart_ack_delta_us) { in hystart_update()
464 ca->last_ack = now; in hystart_update()
466 threshold = ca->delay_min + hystart_ack_delay(sk); in hystart_update()
469 * ca->delay_min/2. in hystart_update()
473 if (sk->sk_pacing_status == SK_PACING_NONE) in hystart_update()
476 if ((__s32)(now - ca->round_start) > threshold) { in hystart_update()
477 ca->found = 1; in hystart_update()
478 tp->snd_ssthresh = tp->snd_cwnd; in hystart_update()
485 if (ca->curr_rtt > delay) in hystart_update()
486 ca->curr_rtt = delay; in hystart_update()
487 if (ca->sample_cnt < HYSTART_MIN_SAMPLES) { in hystart_update()
488 ca->sample_cnt++; in hystart_update()
490 if (ca->curr_rtt > ca->delay_min + in hystart_update()
491 HYSTART_DELAY_THRESH(ca->delay_min >> 3)) { in hystart_update()
492 ca->found = 1; in hystart_update()
493 tp->snd_ssthresh = tp->snd_cwnd; in hystart_update()
507 if (sample->rtt_us < 0) in BPF_STRUCT_OPS()
510 /* Discard delay samples right after fast recovery */ in BPF_STRUCT_OPS()
511 if (ca->epoch_start && (__s32)(tcp_jiffies32 - ca->epoch_start) < HZ) in BPF_STRUCT_OPS()
514 delay = sample->rtt_us; in BPF_STRUCT_OPS()
519 if (ca->delay_min == 0 || ca->delay_min > delay) in BPF_STRUCT_OPS()
520 ca->delay_min = delay; in BPF_STRUCT_OPS()
523 if (!ca->found && tcp_in_slow_start(tp) && hystart && in BPF_STRUCT_OPS()
524 tp->snd_cwnd >= hystart_low_window) in BPF_STRUCT_OPS()
532 return max(tp->snd_cwnd, tp->prior_cwnd); in BPF_STRUCT_OPS()