• Home
  • Raw
  • Download

Lines Matching +full:delta +full:- +full:x +full:- +full:threshold

1 // SPDX-License-Identifier: GPL-2.0-only
8 * "CUBIC: A New TCP-Friendly High-Speed TCP Variant"
45 #define HYSTART_DELAY_THRESH(x) clamp(x, HYSTART_DELAY_MIN, HYSTART_DELAY_MAX) argument
62 /* Note parameters that are used for precomputing scale factors are read-only */
68 MODULE_PARM_DESC(initial_ssthresh, "initial value of slow start threshold");
77 " 1: packet-train 2: delay 3: both packet-train and delay");
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()
154 s32 delta; in bictcp_cwnd_event() local
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()
170 /* calculate the cubic root of x using a table lookup followed by one
171 * Newton-Raphson iteration.
176 u32 x, b, shift; in cubic_root() local
178 * cbrt(x) MSB values for x MSB values in [0..63]. in cubic_root()
179 * Precomputed then refined by hand - Willy Tarreau in cubic_root()
181 * For x in [0..63], in cubic_root()
182 * v = cbrt(x << 18) - 1 in cubic_root()
183 * cbrt(x) = (v[x] + 10) >> 6 in cubic_root()
202 b = ((b * 84) >> 8) - 1; in cubic_root()
205 x = ((u32)(((u32)v[shift] + 10) << b)) >> 6; in cubic_root()
208 * Newton-Raphson iteration in cubic_root()
210 * x = ( 2 * x + a / x ) / 3 in cubic_root()
213 x = (2 * x + (u32)div64_u64(a, (u64)x * (u64)(x - 1))); in cubic_root()
214 x = ((x * 341) >> 10); in cubic_root()
215 return x; in cubic_root()
223 u32 delta, bic_target, max_cnt; in bictcp_update() local
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()
286 delta = (cube_rtt_scale * offs * offs * offs) >> (10+3*BICTCP_HZ); 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()
311 delta = (cwnd * scale) >> 3; 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()
319 max_cnt = cwnd / delta; in bictcp_update()
320 if (ca->cnt > max_cnt) in bictcp_update()
321 ca->cnt = max_cnt; in bictcp_update()
326 * 2 packets ACKed, meaning cwnd grows at 1.5x per RTT. in bictcp_update()
328 ca->cnt = max(ca->cnt, 2U); in bictcp_update()
344 bictcp_update(ca, tp->snd_cwnd, acked); in bictcp_cong_avoid()
345 tcp_cong_avoid_ai(tp, ca->cnt, acked); in bictcp_cong_avoid()
353 ca->epoch_start = 0; /* end of epoch */ in bictcp_recalc_ssthresh()
356 if (tp->snd_cwnd < ca->last_max_cwnd && fast_convergence) in bictcp_recalc_ssthresh()
357 ca->last_max_cwnd = (tp->snd_cwnd * (BICTCP_BETA_SCALE + beta)) in bictcp_recalc_ssthresh()
360 ca->last_max_cwnd = tp->snd_cwnd; in bictcp_recalc_ssthresh()
362 return max((tp->snd_cwnd * beta) / BICTCP_BETA_SCALE, 2U); in bictcp_recalc_ssthresh()
375 * slow start we begin with small TSO packets and ca->delay_min would
386 rate = READ_ONCE(sk->sk_pacing_rate); in hystart_ack_delay()
397 u32 threshold; in hystart_update() local
399 if (after(tp->snd_una, ca->end_seq)) in hystart_update()
405 /* first detection parameter - ack-train detection */ in hystart_update()
406 if ((s32)(now - ca->last_ack) <= hystart_ack_delta_us) { in hystart_update()
407 ca->last_ack = now; in hystart_update()
409 threshold = ca->delay_min + hystart_ack_delay(sk); in hystart_update()
412 * ca->delay_min/2. in hystart_update()
416 if (sk->sk_pacing_status == SK_PACING_NONE) in hystart_update()
417 threshold >>= 1; in hystart_update()
419 if ((s32)(now - ca->round_start) > threshold) { in hystart_update()
420 ca->found = 1; in hystart_update()
422 now - ca->round_start, threshold, in hystart_update()
423 ca->delay_min, hystart_ack_delay(sk), tp->snd_cwnd); in hystart_update()
428 tp->snd_cwnd); in hystart_update()
429 tp->snd_ssthresh = tp->snd_cwnd; in hystart_update()
436 if (ca->curr_rtt > delay) in hystart_update()
437 ca->curr_rtt = delay; in hystart_update()
438 if (ca->sample_cnt < HYSTART_MIN_SAMPLES) { in hystart_update()
439 ca->sample_cnt++; in hystart_update()
441 if (ca->curr_rtt > ca->delay_min + in hystart_update()
442 HYSTART_DELAY_THRESH(ca->delay_min >> 3)) { in hystart_update()
443 ca->found = 1; in hystart_update()
448 tp->snd_cwnd); in hystart_update()
449 tp->snd_ssthresh = tp->snd_cwnd; in hystart_update()
462 if (sample->rtt_us < 0) in bictcp_acked()
466 if (ca->epoch_start && (s32)(tcp_jiffies32 - ca->epoch_start) < HZ) in bictcp_acked()
469 delay = sample->rtt_us; in bictcp_acked()
474 if (ca->delay_min == 0 || ca->delay_min > delay) in bictcp_acked()
475 ca->delay_min = delay; in bictcp_acked()
477 /* hystart triggers when cwnd is larger than some threshold */ in bictcp_acked()
478 if (!ca->found && tcp_in_slow_start(tp) && hystart && in bictcp_acked()
479 tp->snd_cwnd >= hystart_low_window) in bictcp_acked()
499 /* Precompute a bunch of the scaling factors that are used per-packet in cubictcp_register()
504 / (BICTCP_BETA_SCALE - beta); in cubictcp_register()
508 /* calculate the "K" for (wmax-cwnd) = c/rtt * K^3 in cubictcp_register()
509 * so K = cubic_root( (wmax-cwnd)*rtt/c ) in cubictcp_register()
518 * HZ < 1,000,00 (corresponding to 10 nano-second) in cubictcp_register()