Lines Matching +full:min +full:- +full:sample +full:- +full:rate +full:- +full:hz

1 // SPDX-License-Identifier: GPL-2.0-or-later
4 * Copyright (c) 2005-7 The University of Waikato, Hamilton, New Zealand.
5 * Copyright (c) 2005-7 Ian McDonald <ian.mcdonald@jandi.co.nz>
14 * Copyright (c) 2003 Nils-Erik Mattsson, Joacim Haggmark, Magnus Erixzon
35 * Transmitter Half-Connection Routines
54 enum ccid3_hc_tx_states oldstate = hc->tx_state; in ccid3_hc_tx_set_state()
56 ccid3_pr_debug("%s(%p) %-8.8s -> %s\n", in ccid3_hc_tx_set_state()
60 hc->tx_state = state; in ccid3_hc_tx_set_state()
64 * Compute the initial sending rate X_init in the manner of RFC 3390:
66 * X_init = min(4 * s, max(2 * s, 4380 bytes)) / RTT
69 * (rev-02) clarifies the use of RFC 3390 with regard to the above formula.
75 const __u32 w_init = clamp_t(__u32, 4380U, 2 * hc->tx_s, 4 * hc->tx_s); in rfc3390_initial_rate()
77 return scaled_div(w_init << 6, hc->tx_rtt); in rfc3390_initial_rate()
81 * ccid3_update_send_interval - Calculate new t_ipi = s / X_inst
88 hc->tx_t_ipi = scaled_div32(((u64)hc->tx_s) << 6, hc->tx_x); in ccid3_update_send_interval()
90 DCCP_BUG_ON(hc->tx_t_ipi == 0); in ccid3_update_send_interval()
91 ccid3_pr_debug("t_ipi=%u, s=%u, X=%u\n", hc->tx_t_ipi, in ccid3_update_send_interval()
92 hc->tx_s, (unsigned int)(hc->tx_x >> 6)); in ccid3_update_send_interval()
97 u32 delta = ktime_us_delta(now, hc->tx_t_last_win_count); in ccid3_hc_tx_idle_rtt()
99 return delta / hc->tx_rtt; in ccid3_hc_tx_idle_rtt()
103 * ccid3_hc_tx_update_x - Update allowed sending rate X
105 * @stamp: most recent time if available - can be left NULL.
110 * fine-grained resolution of sending rates. This requires scaling by 2^6
117 __u64 min_rate = 2 * hc->tx_x_recv; in ccid3_hc_tx_update_x()
118 const __u64 old_x = hc->tx_x; in ccid3_hc_tx_update_x()
122 * Handle IDLE periods: do not reduce below RFC3390 initial sending rate in ccid3_hc_tx_update_x()
124 * a sender is idle if it has not sent anything over a 2-RTT-period. in ccid3_hc_tx_update_x()
129 min_rate = max(min_rate, 2 * hc->tx_x_recv); in ccid3_hc_tx_update_x()
132 if (hc->tx_p > 0) { in ccid3_hc_tx_update_x()
134 hc->tx_x = min(((__u64)hc->tx_x_calc) << 6, min_rate); in ccid3_hc_tx_update_x()
135 hc->tx_x = max(hc->tx_x, (((__u64)hc->tx_s) << 6) / TFRC_T_MBI); in ccid3_hc_tx_update_x()
137 } else if (ktime_us_delta(now, hc->tx_t_ld) - (s64)hc->tx_rtt >= 0) { in ccid3_hc_tx_update_x()
139 hc->tx_x = min(2 * hc->tx_x, min_rate); in ccid3_hc_tx_update_x()
140 hc->tx_x = max(hc->tx_x, in ccid3_hc_tx_update_x()
141 scaled_div(((__u64)hc->tx_s) << 6, hc->tx_rtt)); in ccid3_hc_tx_update_x()
142 hc->tx_t_ld = now; in ccid3_hc_tx_update_x()
145 if (hc->tx_x != old_x) { in ccid3_hc_tx_update_x()
148 (unsigned int)(hc->tx_x >> 6), hc->tx_x_calc, in ccid3_hc_tx_update_x()
149 (unsigned int)(hc->tx_x_recv >> 6)); in ccid3_hc_tx_update_x()
156 * ccid3_hc_tx_update_s - Track the mean packet size `s'
164 const u16 old_s = hc->tx_s; in ccid3_hc_tx_update_s()
166 hc->tx_s = tfrc_ewma(hc->tx_s, len, 9); in ccid3_hc_tx_update_s()
168 if (hc->tx_s != old_s) in ccid3_hc_tx_update_s()
179 u32 delta = ktime_us_delta(now, hc->tx_t_last_win_count), in ccid3_hc_tx_update_win_count()
180 quarter_rtts = (4 * delta) / hc->tx_rtt; in ccid3_hc_tx_update_win_count()
183 hc->tx_t_last_win_count = now; in ccid3_hc_tx_update_win_count()
184 hc->tx_last_win_count += min(quarter_rtts, 5U); in ccid3_hc_tx_update_win_count()
185 hc->tx_last_win_count &= 0xF; /* mod 16 */ in ccid3_hc_tx_update_win_count()
192 struct sock *sk = hc->sk; in ccid3_hc_tx_no_feedback_timer()
202 ccid3_pr_debug("%s(%p, state=%s) - entry\n", dccp_role(sk), sk, in ccid3_hc_tx_no_feedback_timer()
203 ccid3_tx_state_name(hc->tx_state)); in ccid3_hc_tx_no_feedback_timer()
206 if ((1 << sk->sk_state) & ~(DCCPF_OPEN | DCCPF_PARTOPEN)) in ccid3_hc_tx_no_feedback_timer()
210 if (hc->tx_state == TFRC_SSTATE_FBACK) in ccid3_hc_tx_no_feedback_timer()
214 * Determine new allowed sending rate X as per draft rfc3448bis-00, 4.4 in ccid3_hc_tx_no_feedback_timer()
217 if (hc->tx_t_rto == 0 || hc->tx_p == 0) { in ccid3_hc_tx_no_feedback_timer()
219 /* halve send rate directly */ in ccid3_hc_tx_no_feedback_timer()
220 hc->tx_x = max(hc->tx_x / 2, in ccid3_hc_tx_no_feedback_timer()
221 (((__u64)hc->tx_s) << 6) / TFRC_T_MBI); in ccid3_hc_tx_no_feedback_timer()
234 if (hc->tx_x_calc > (hc->tx_x_recv >> 5)) in ccid3_hc_tx_no_feedback_timer()
235 hc->tx_x_recv = in ccid3_hc_tx_no_feedback_timer()
236 max(hc->tx_x_recv / 2, in ccid3_hc_tx_no_feedback_timer()
237 (((__u64)hc->tx_s) << 6) / (2*TFRC_T_MBI)); in ccid3_hc_tx_no_feedback_timer()
239 hc->tx_x_recv = hc->tx_x_calc; in ccid3_hc_tx_no_feedback_timer()
240 hc->tx_x_recv <<= 4; in ccid3_hc_tx_no_feedback_timer()
245 (unsigned long long)hc->tx_x); in ccid3_hc_tx_no_feedback_timer()
251 if (unlikely(hc->tx_t_rto == 0)) /* no feedback received yet */ in ccid3_hc_tx_no_feedback_timer()
254 t_nfb = max(hc->tx_t_rto, 2 * hc->tx_t_ipi); in ccid3_hc_tx_no_feedback_timer()
257 sk_reset_timer(sk, &hc->tx_no_feedback_timer, in ccid3_hc_tx_no_feedback_timer()
265 * ccid3_hc_tx_send_packet - Delay-based dequeueing of TX packets
270 * returns a millisecond-delay value between 0 and t_mbi = 64000 msec.
281 * zero-sized Data(Ack)s is theoretically possible, but for congestion in ccid3_hc_tx_send_packet()
282 * control this case is pathological - ignore it. in ccid3_hc_tx_send_packet()
284 if (unlikely(skb->len == 0)) in ccid3_hc_tx_send_packet()
285 return -EBADMSG; in ccid3_hc_tx_send_packet()
287 if (hc->tx_state == TFRC_SSTATE_NO_SENT) { in ccid3_hc_tx_send_packet()
288 sk_reset_timer(sk, &hc->tx_no_feedback_timer, (jiffies + in ccid3_hc_tx_send_packet()
290 hc->tx_last_win_count = 0; in ccid3_hc_tx_send_packet()
291 hc->tx_t_last_win_count = now; in ccid3_hc_tx_send_packet()
294 hc->tx_t_nom = now; in ccid3_hc_tx_send_packet()
296 hc->tx_s = skb->len; in ccid3_hc_tx_send_packet()
299 * Use initial RTT sample when available: recommended by erratum in ccid3_hc_tx_send_packet()
303 if (dp->dccps_syn_rtt) { in ccid3_hc_tx_send_packet()
304 ccid3_pr_debug("SYN RTT = %uus\n", dp->dccps_syn_rtt); in ccid3_hc_tx_send_packet()
305 hc->tx_rtt = dp->dccps_syn_rtt; in ccid3_hc_tx_send_packet()
306 hc->tx_x = rfc3390_initial_rate(sk); in ccid3_hc_tx_send_packet()
307 hc->tx_t_ld = now; in ccid3_hc_tx_send_packet()
310 * Sender does not have RTT sample: in ccid3_hc_tx_send_packet()
311 * - set fallback RTT (RFC 4340, 3.4) since a RTT value in ccid3_hc_tx_send_packet()
313 * - set sending rate X_pps = 1pps as per RFC 3448, 4.2. in ccid3_hc_tx_send_packet()
315 hc->tx_rtt = DCCP_FALLBACK_RTT; in ccid3_hc_tx_send_packet()
316 hc->tx_x = hc->tx_s; in ccid3_hc_tx_send_packet()
317 hc->tx_x <<= 6; in ccid3_hc_tx_send_packet()
324 delay = ktime_us_delta(hc->tx_t_nom, now); in ccid3_hc_tx_send_packet()
329 * if (t_now > t_nom - delta) in ccid3_hc_tx_send_packet()
332 * // send the packet in (t_nom - t_now) milliseconds. in ccid3_hc_tx_send_packet()
341 dp->dccps_hc_tx_insert_options = 1; in ccid3_hc_tx_send_packet()
342 DCCP_SKB_CB(skb)->dccpd_ccval = hc->tx_last_win_count; in ccid3_hc_tx_send_packet()
345 hc->tx_t_nom = ktime_add_us(hc->tx_t_nom, hc->tx_t_ipi); in ccid3_hc_tx_send_packet()
355 if (tfrc_tx_hist_add(&hc->tx_hist, dccp_sk(sk)->dccps_gss)) in ccid3_hc_tx_packet_sent()
356 DCCP_CRIT("packet history - out of memory!"); in ccid3_hc_tx_packet_sent()
368 if (!(DCCP_SKB_CB(skb)->dccpd_type == DCCP_PKT_ACK || in ccid3_hc_tx_packet_recv()
369 DCCP_SKB_CB(skb)->dccpd_type == DCCP_PKT_DATAACK)) in ccid3_hc_tx_packet_recv()
375 * - the host has not sent out anything (e.g. a passive server), in ccid3_hc_tx_packet_recv()
376 * - the Ack is outdated (packet with higher Ack number was received), in ccid3_hc_tx_packet_recv()
377 * - it is a bogus Ack (for a packet not sent on this connection). in ccid3_hc_tx_packet_recv()
379 acked = tfrc_tx_hist_find_entry(hc->tx_hist, dccp_hdr_ack_seq(skb)); in ccid3_hc_tx_packet_recv()
383 tfrc_tx_hist_purge(&acked->next); in ccid3_hc_tx_packet_recv()
387 r_sample = dccp_sample_rtt(sk, ktime_us_delta(now, acked->stamp)); in ccid3_hc_tx_packet_recv()
388 hc->tx_rtt = tfrc_ewma(hc->tx_rtt, r_sample, 9); in ccid3_hc_tx_packet_recv()
391 * Update allowed sending rate X as per draft rfc3448bis-00, 4.2/3 in ccid3_hc_tx_packet_recv()
393 if (hc->tx_state == TFRC_SSTATE_NO_FBACK) { in ccid3_hc_tx_packet_recv()
396 if (hc->tx_t_rto == 0) { in ccid3_hc_tx_packet_recv()
400 hc->tx_x = rfc3390_initial_rate(sk); in ccid3_hc_tx_packet_recv()
401 hc->tx_t_ld = now; in ccid3_hc_tx_packet_recv()
406 } else if (hc->tx_p == 0) { in ccid3_hc_tx_packet_recv()
414 /* Update sending rate (step 4 of [RFC 3448, 4.3]) */ in ccid3_hc_tx_packet_recv()
415 if (hc->tx_p > 0) in ccid3_hc_tx_packet_recv()
416 hc->tx_x_calc = tfrc_calc_x(hc->tx_s, hc->tx_rtt, hc->tx_p); in ccid3_hc_tx_packet_recv()
420 ccid3_pr_debug("%s(%p), RTT=%uus (sample=%uus), s=%u, " in ccid3_hc_tx_packet_recv()
422 dccp_role(sk), sk, hc->tx_rtt, r_sample, in ccid3_hc_tx_packet_recv()
423 hc->tx_s, hc->tx_p, hc->tx_x_calc, in ccid3_hc_tx_packet_recv()
424 (unsigned int)(hc->tx_x_recv >> 6), in ccid3_hc_tx_packet_recv()
425 (unsigned int)(hc->tx_x >> 6)); in ccid3_hc_tx_packet_recv()
428 sk_stop_timer(sk, &hc->tx_no_feedback_timer); in ccid3_hc_tx_packet_recv()
434 sk->sk_write_space(sk); in ccid3_hc_tx_packet_recv()
438 * rate halving on networks with very low RTTs (<= 1 ms), use per-route in ccid3_hc_tx_packet_recv()
441 hc->tx_t_rto = max_t(u32, 4 * hc->tx_rtt, in ccid3_hc_tx_packet_recv()
442 USEC_PER_SEC/HZ * tcp_rto_min(sk)); in ccid3_hc_tx_packet_recv()
447 t_nfb = max(hc->tx_t_rto, 2 * hc->tx_t_ipi); in ccid3_hc_tx_packet_recv()
453 sk_reset_timer(sk, &hc->tx_no_feedback_timer, in ccid3_hc_tx_packet_recv()
472 return -EINVAL; in ccid3_hc_tx_parse_options()
477 /* Receive Rate is kept in units of 64 bytes/second */ in ccid3_hc_tx_parse_options()
478 hc->tx_x_recv = opt_val; in ccid3_hc_tx_parse_options()
479 hc->tx_x_recv <<= 6; in ccid3_hc_tx_parse_options()
484 /* Update the fixpoint Loss Event Rate fraction */ in ccid3_hc_tx_parse_options()
485 hc->tx_p = tfrc_invert_loss_event_rate(opt_val); in ccid3_hc_tx_parse_options()
498 hc->tx_state = TFRC_SSTATE_NO_SENT; in ccid3_hc_tx_init()
499 hc->tx_hist = NULL; in ccid3_hc_tx_init()
500 hc->sk = sk; in ccid3_hc_tx_init()
501 timer_setup(&hc->tx_no_feedback_timer, in ccid3_hc_tx_init()
510 sk_stop_timer(sk, &hc->tx_no_feedback_timer); in ccid3_hc_tx_exit()
511 tfrc_tx_hist_purge(&hc->tx_hist); in ccid3_hc_tx_exit()
516 info->tcpi_rto = ccid3_hc_tx_sk(sk)->tx_t_rto; in ccid3_hc_tx_get_info()
517 info->tcpi_rtt = ccid3_hc_tx_sk(sk)->tx_rtt; in ccid3_hc_tx_get_info()
530 return -EINVAL; in ccid3_hc_tx_getsockopt()
532 tfrc.tfrctx_x = hc->tx_x; in ccid3_hc_tx_getsockopt()
533 tfrc.tfrctx_x_recv = hc->tx_x_recv; in ccid3_hc_tx_getsockopt()
534 tfrc.tfrctx_x_calc = hc->tx_x_calc; in ccid3_hc_tx_getsockopt()
535 tfrc.tfrctx_rtt = hc->tx_rtt; in ccid3_hc_tx_getsockopt()
536 tfrc.tfrctx_p = hc->tx_p; in ccid3_hc_tx_getsockopt()
537 tfrc.tfrctx_rto = hc->tx_t_rto; in ccid3_hc_tx_getsockopt()
538 tfrc.tfrctx_ipi = hc->tx_t_ipi; in ccid3_hc_tx_getsockopt()
543 return -ENOPROTOOPT; in ccid3_hc_tx_getsockopt()
547 return -EFAULT; in ccid3_hc_tx_getsockopt()
553 * Receiver Half-Connection Routines
580 enum ccid3_hc_rx_states oldstate = hc->rx_state; in ccid3_hc_rx_set_state()
582 ccid3_pr_debug("%s(%p) %-8.8s -> %s\n", in ccid3_hc_rx_set_state()
586 hc->rx_state = state; in ccid3_hc_rx_set_state()
600 hc->rx_x_recv = 0; in ccid3_hc_rx_send_feedback()
601 hc->rx_pinv = ~0U; /* see RFC 4342, 8.5 */ in ccid3_hc_rx_send_feedback()
614 if (hc->rx_x_recv > 0) in ccid3_hc_rx_send_feedback()
618 delta = ktime_us_delta(now, hc->rx_tstamp_last_feedback); in ccid3_hc_rx_send_feedback()
621 hc->rx_x_recv = scaled_div32(hc->rx_bytes_recv, delta); in ccid3_hc_rx_send_feedback()
628 hc->rx_x_recv, hc->rx_pinv); in ccid3_hc_rx_send_feedback()
630 hc->rx_tstamp_last_feedback = now; in ccid3_hc_rx_send_feedback()
631 hc->rx_last_counter = dccp_hdr(skb)->dccph_ccval; in ccid3_hc_rx_send_feedback()
632 hc->rx_bytes_recv = 0; in ccid3_hc_rx_send_feedback()
634 dp->dccps_hc_rx_insert_options = 1; in ccid3_hc_rx_send_feedback()
643 if (!(sk->sk_state == DCCP_OPEN || sk->sk_state == DCCP_PARTOPEN)) in ccid3_hc_rx_insert_options()
649 x_recv = htonl(hc->rx_x_recv); in ccid3_hc_rx_insert_options()
650 pinv = htonl(hc->rx_pinv); in ccid3_hc_rx_insert_options()
656 return -1; in ccid3_hc_rx_insert_options()
662 * ccid3_first_li - Implements [RFC 5348, 6.3.1]
668 * X_recv = --------
679 if (hc->rx_rtt == 0) { in ccid3_first_li()
681 hc->rx_rtt = DCCP_FALLBACK_RTT; in ccid3_first_li()
684 delta = ktime_us_delta(ktime_get(), hc->rx_tstamp_last_feedback); in ccid3_first_li()
687 x_recv = scaled_div32(hc->rx_bytes_recv, delta); in ccid3_first_li()
688 if (x_recv == 0) { /* would also trigger divide-by-zero */ in ccid3_first_li()
690 if (hc->rx_x_recv == 0) { in ccid3_first_li()
694 x_recv = hc->rx_x_recv; in ccid3_first_li()
697 fval = scaled_div(hc->rx_s, hc->rx_rtt); in ccid3_first_li()
701 ccid3_pr_debug("%s(%p), receive rate=%u bytes/s, implied " in ccid3_first_li()
702 "loss rate=%u\n", dccp_role(sk), sk, x_recv, p); in ccid3_first_li()
711 const u64 ndp = dccp_sk(sk)->dccps_options_received.dccpor_ndp; in ccid3_hc_rx_packet_recv()
714 if (unlikely(hc->rx_state == TFRC_RSTATE_NO_DATA)) { in ccid3_hc_rx_packet_recv()
716 const u32 payload = skb->len - dccp_hdr(skb)->dccph_doff * 4; in ccid3_hc_rx_packet_recv()
719 hc->rx_s = payload; in ccid3_hc_rx_packet_recv()
723 * RFC 3448, 6.3) -- gerrit in ccid3_hc_rx_packet_recv()
729 if (tfrc_rx_hist_duplicate(&hc->rx_hist, skb)) in ccid3_hc_rx_packet_recv()
733 const u32 payload = skb->len - dccp_hdr(skb)->dccph_doff * 4; in ccid3_hc_rx_packet_recv()
735 * Update moving-average of s and the sum of received payload bytes in ccid3_hc_rx_packet_recv()
737 hc->rx_s = tfrc_ewma(hc->rx_s, payload, 9); in ccid3_hc_rx_packet_recv()
738 hc->rx_bytes_recv += payload; in ccid3_hc_rx_packet_recv()
744 if (tfrc_rx_handle_loss(&hc->rx_hist, &hc->rx_li_hist, in ccid3_hc_rx_packet_recv()
750 if (tfrc_rx_hist_loss_pending(&hc->rx_hist)) in ccid3_hc_rx_packet_recv()
759 if (!tfrc_lh_is_initialised(&hc->rx_li_hist)) { in ccid3_hc_rx_packet_recv()
760 const u32 sample = tfrc_rx_hist_sample_rtt(&hc->rx_hist, skb); in ccid3_hc_rx_packet_recv() local
763 * Sample RTT values, since an RTT estimate is required for the in ccid3_hc_rx_packet_recv()
766 if (sample != 0) in ccid3_hc_rx_packet_recv()
767 hc->rx_rtt = tfrc_ewma(hc->rx_rtt, sample, 9); in ccid3_hc_rx_packet_recv()
769 } else if (tfrc_lh_update_i_mean(&hc->rx_li_hist, skb)) { in ccid3_hc_rx_packet_recv()
778 * Check if the periodic once-per-RTT feedback is due; RFC 4342, 10.3 in ccid3_hc_rx_packet_recv()
780 if (SUB16(dccp_hdr(skb)->dccph_ccval, hc->rx_last_counter) > 3) in ccid3_hc_rx_packet_recv()
784 tfrc_rx_hist_add_packet(&hc->rx_hist, skb, ndp); in ccid3_hc_rx_packet_recv()
795 hc->rx_state = TFRC_RSTATE_NO_DATA; in ccid3_hc_rx_init()
796 tfrc_lh_init(&hc->rx_li_hist); in ccid3_hc_rx_init()
797 return tfrc_rx_hist_alloc(&hc->rx_hist); in ccid3_hc_rx_init()
804 tfrc_rx_hist_purge(&hc->rx_hist); in ccid3_hc_rx_exit()
805 tfrc_lh_cleanup(&hc->rx_li_hist); in ccid3_hc_rx_exit()
810 info->tcpi_ca_state = ccid3_hc_rx_sk(sk)->rx_state; in ccid3_hc_rx_get_info()
811 info->tcpi_options |= TCPI_OPT_TIMESTAMPS; in ccid3_hc_rx_get_info()
812 info->tcpi_rcv_rtt = ccid3_hc_rx_sk(sk)->rx_rtt; in ccid3_hc_rx_get_info()
825 return -EINVAL; in ccid3_hc_rx_getsockopt()
826 rx_info.tfrcrx_x_recv = hc->rx_x_recv; in ccid3_hc_rx_getsockopt()
827 rx_info.tfrcrx_rtt = hc->rx_rtt; in ccid3_hc_rx_getsockopt()
828 rx_info.tfrcrx_p = tfrc_invert_loss_event_rate(hc->rx_pinv); in ccid3_hc_rx_getsockopt()
833 return -ENOPROTOOPT; in ccid3_hc_rx_getsockopt()
837 return -EFAULT; in ccid3_hc_rx_getsockopt()
844 .ccid_name = "TCP-Friendly Rate Control",
865 MODULE_PARM_DESC(ccid3_debug, "Enable CCID-3 debug messages");