167fef78bSLawrence Stewart /*- 2fe267a55SPedro F. Giffuni * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3fe267a55SPedro F. Giffuni * 467fef78bSLawrence Stewart * Copyright (c) 2008-2010 Lawrence Stewart <lstewart@freebsd.org> 567fef78bSLawrence Stewart * Copyright (c) 2010 The FreeBSD Foundation 667fef78bSLawrence Stewart * All rights reserved. 767fef78bSLawrence Stewart * 867fef78bSLawrence Stewart * This software was developed by Lawrence Stewart while studying at the Centre 9891b8ed4SLawrence Stewart * for Advanced Internet Architectures, Swinburne University of Technology, made 10891b8ed4SLawrence Stewart * possible in part by a grant from the Cisco University Research Program Fund 11891b8ed4SLawrence Stewart * at Community Foundation Silicon Valley. 1267fef78bSLawrence Stewart * 1367fef78bSLawrence Stewart * Portions of this software were developed at the Centre for Advanced 1467fef78bSLawrence Stewart * Internet Architectures, Swinburne University of Technology, Melbourne, 1567fef78bSLawrence Stewart * Australia by David Hayes under sponsorship from the FreeBSD Foundation. 1667fef78bSLawrence Stewart * 1767fef78bSLawrence Stewart * Redistribution and use in source and binary forms, with or without 1867fef78bSLawrence Stewart * modification, are permitted provided that the following conditions 1967fef78bSLawrence Stewart * are met: 2067fef78bSLawrence Stewart * 1. Redistributions of source code must retain the above copyright 2167fef78bSLawrence Stewart * notice, this list of conditions and the following disclaimer. 2267fef78bSLawrence Stewart * 2. Redistributions in binary form must reproduce the above copyright 2367fef78bSLawrence Stewart * notice, this list of conditions and the following disclaimer in the 2467fef78bSLawrence Stewart * documentation and/or other materials provided with the distribution. 2567fef78bSLawrence Stewart * 2667fef78bSLawrence Stewart * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 2767fef78bSLawrence Stewart * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2867fef78bSLawrence Stewart * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2967fef78bSLawrence Stewart * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 3067fef78bSLawrence Stewart * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 3167fef78bSLawrence Stewart * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 3267fef78bSLawrence Stewart * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 3367fef78bSLawrence Stewart * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3467fef78bSLawrence Stewart * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3567fef78bSLawrence Stewart * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3667fef78bSLawrence Stewart * SUCH DAMAGE. 3767fef78bSLawrence Stewart */ 3867fef78bSLawrence Stewart 3967fef78bSLawrence Stewart /* 4067fef78bSLawrence Stewart * An implementation of the CUBIC congestion control algorithm for FreeBSD, 4167fef78bSLawrence Stewart * based on the Internet Draft "draft-rhee-tcpm-cubic-02" by Rhee, Xu and Ha. 4267fef78bSLawrence Stewart * Originally released as part of the NewTCP research project at Swinburne 43891b8ed4SLawrence Stewart * University of Technology's Centre for Advanced Internet Architectures, 44891b8ed4SLawrence Stewart * Melbourne, Australia, which was made possible in part by a grant from the 45891b8ed4SLawrence Stewart * Cisco University Research Program Fund at Community Foundation Silicon 46891b8ed4SLawrence Stewart * Valley. More details are available at: 4767fef78bSLawrence Stewart * http://caia.swin.edu.au/urp/newtcp/ 4867fef78bSLawrence Stewart */ 4967fef78bSLawrence Stewart 5067fef78bSLawrence Stewart #include <sys/cdefs.h> 5167fef78bSLawrence Stewart __FBSDID("$FreeBSD$"); 5267fef78bSLawrence Stewart 5367fef78bSLawrence Stewart #include <sys/param.h> 5467fef78bSLawrence Stewart #include <sys/kernel.h> 55c968c769SMichael Tuexen #include <sys/limits.h> 5667fef78bSLawrence Stewart #include <sys/malloc.h> 5767fef78bSLawrence Stewart #include <sys/module.h> 5867fef78bSLawrence Stewart #include <sys/socket.h> 5967fef78bSLawrence Stewart #include <sys/socketvar.h> 6067fef78bSLawrence Stewart #include <sys/sysctl.h> 6167fef78bSLawrence Stewart #include <sys/systm.h> 6267fef78bSLawrence Stewart 6367fef78bSLawrence Stewart #include <net/vnet.h> 6467fef78bSLawrence Stewart 65b8d60729SRandall Stewart #include <net/route.h> 66b8d60729SRandall Stewart #include <net/route/nhop.h> 67b8d60729SRandall Stewart 68b8d60729SRandall Stewart #include <netinet/in_pcb.h> 692de3e790SGleb Smirnoff #include <netinet/tcp.h> 7067fef78bSLawrence Stewart #include <netinet/tcp_seq.h> 7167fef78bSLawrence Stewart #include <netinet/tcp_timer.h> 7267fef78bSLawrence Stewart #include <netinet/tcp_var.h> 73a9696510SRandall Stewart #include <netinet/tcp_log_buf.h> 74a9696510SRandall Stewart #include <netinet/tcp_hpts.h> 754644fda3SGleb Smirnoff #include <netinet/cc/cc.h> 7667fef78bSLawrence Stewart #include <netinet/cc/cc_cubic.h> 7767fef78bSLawrence Stewart #include <netinet/cc/cc_module.h> 7867fef78bSLawrence Stewart 7967fef78bSLawrence Stewart static void cubic_ack_received(struct cc_var *ccv, uint16_t type); 8067fef78bSLawrence Stewart static void cubic_cb_destroy(struct cc_var *ccv); 81b8d60729SRandall Stewart static int cubic_cb_init(struct cc_var *ccv, void *ptr); 8267fef78bSLawrence Stewart static void cubic_cong_signal(struct cc_var *ccv, uint32_t type); 8367fef78bSLawrence Stewart static void cubic_conn_init(struct cc_var *ccv); 8467fef78bSLawrence Stewart static int cubic_mod_init(void); 8567fef78bSLawrence Stewart static void cubic_post_recovery(struct cc_var *ccv); 8667fef78bSLawrence Stewart static void cubic_record_rtt(struct cc_var *ccv); 8737674273SRichard Scheffenegger static void cubic_ssthresh_update(struct cc_var *ccv, uint32_t maxseg); 8835cd141bSMichael Tuexen static void cubic_after_idle(struct cc_var *ccv); 89b8d60729SRandall Stewart static size_t cubic_data_sz(void); 90a9696510SRandall Stewart static void cubic_newround(struct cc_var *ccv, uint32_t round_cnt); 91a9696510SRandall Stewart static void cubic_rttsample(struct cc_var *ccv, uint32_t usec_rtt, 92a9696510SRandall Stewart uint32_t rxtcnt, uint32_t fas); 9367fef78bSLawrence Stewart 9467fef78bSLawrence Stewart struct cc_algo cubic_cc_algo = { 9567fef78bSLawrence Stewart .name = "cubic", 9667fef78bSLawrence Stewart .ack_received = cubic_ack_received, 9767fef78bSLawrence Stewart .cb_destroy = cubic_cb_destroy, 9867fef78bSLawrence Stewart .cb_init = cubic_cb_init, 9967fef78bSLawrence Stewart .cong_signal = cubic_cong_signal, 10067fef78bSLawrence Stewart .conn_init = cubic_conn_init, 10167fef78bSLawrence Stewart .mod_init = cubic_mod_init, 10267fef78bSLawrence Stewart .post_recovery = cubic_post_recovery, 10335cd141bSMichael Tuexen .after_idle = cubic_after_idle, 104a9696510SRandall Stewart .cc_data_sz = cubic_data_sz, 105a9696510SRandall Stewart .rttsample = cubic_rttsample, 106a9696510SRandall Stewart .newround = cubic_newround 10767fef78bSLawrence Stewart }; 10867fef78bSLawrence Stewart 10967fef78bSLawrence Stewart static void 110a9696510SRandall Stewart cubic_log_hystart_event(struct cc_var *ccv, struct cubic *cubicd, uint8_t mod, uint32_t flex1) 111a9696510SRandall Stewart { 112a9696510SRandall Stewart /* 113a9696510SRandall Stewart * Types of logs (mod value) 114a9696510SRandall Stewart * 1 - rtt_thresh in flex1, checking to see if RTT is to great. 115a9696510SRandall Stewart * 2 - rtt is too great, rtt_thresh in flex1. 116a9696510SRandall Stewart * 3 - CSS is active incr in flex1 117a9696510SRandall Stewart * 4 - A new round is beginning flex1 is round count 118a9696510SRandall Stewart * 5 - A new RTT measurement flex1 is the new measurement. 119a9696510SRandall Stewart * 6 - We enter CA ssthresh is also in flex1. 120a9696510SRandall Stewart * 7 - Socket option to change hystart executed opt.val in flex1. 121a9696510SRandall Stewart * 8 - Back out of CSS into SS, flex1 is the css_baseline_minrtt 122a9696510SRandall Stewart * 9 - We enter CA, via an ECN mark. 123a9696510SRandall Stewart * 10 - We enter CA, via a loss. 124a9696510SRandall Stewart * 11 - We have slipped out of SS into CA via cwnd growth. 125a9696510SRandall Stewart * 12 - After idle has re-enabled hystart++ 126a9696510SRandall Stewart */ 127a9696510SRandall Stewart struct tcpcb *tp; 128a9696510SRandall Stewart 129a9696510SRandall Stewart if (hystart_bblogs == 0) 130a9696510SRandall Stewart return; 131a9696510SRandall Stewart tp = ccv->ccvc.tcp; 132a9696510SRandall Stewart if (tp->t_logstate != TCP_LOG_STATE_OFF) { 133a9696510SRandall Stewart union tcp_log_stackspecific log; 134a9696510SRandall Stewart struct timeval tv; 135a9696510SRandall Stewart 136a9696510SRandall Stewart memset(&log, 0, sizeof(log)); 137a9696510SRandall Stewart log.u_bbr.flex1 = flex1; 138a9696510SRandall Stewart log.u_bbr.flex2 = cubicd->css_current_round_minrtt; 139a9696510SRandall Stewart log.u_bbr.flex3 = cubicd->css_lastround_minrtt; 140a9696510SRandall Stewart log.u_bbr.flex4 = cubicd->css_rttsample_count; 141a9696510SRandall Stewart log.u_bbr.flex5 = cubicd->css_entered_at_round; 142a9696510SRandall Stewart log.u_bbr.flex6 = cubicd->css_baseline_minrtt; 143a9696510SRandall Stewart /* We only need bottom 16 bits of flags */ 144a9696510SRandall Stewart log.u_bbr.flex7 = cubicd->flags & 0x0000ffff; 145a9696510SRandall Stewart log.u_bbr.flex8 = mod; 146a9696510SRandall Stewart log.u_bbr.epoch = cubicd->css_current_round; 147a9696510SRandall Stewart log.u_bbr.timeStamp = tcp_get_usecs(&tv); 148a9696510SRandall Stewart log.u_bbr.lt_epoch = cubicd->css_fas_at_css_entry; 149a9696510SRandall Stewart log.u_bbr.pkts_out = cubicd->css_last_fas; 150a9696510SRandall Stewart log.u_bbr.delivered = cubicd->css_lowrtt_fas; 151a9696510SRandall Stewart log.u_bbr.pkt_epoch = ccv->flags; 152a9696510SRandall Stewart TCP_LOG_EVENTP(tp, NULL, 153a9696510SRandall Stewart &tp->t_inpcb->inp_socket->so_rcv, 154a9696510SRandall Stewart &tp->t_inpcb->inp_socket->so_snd, 155a9696510SRandall Stewart TCP_HYSTART, 0, 156a9696510SRandall Stewart 0, &log, false, &tv); 157a9696510SRandall Stewart } 158a9696510SRandall Stewart } 159a9696510SRandall Stewart 160a9696510SRandall Stewart static void 161a9696510SRandall Stewart cubic_does_slow_start(struct cc_var *ccv, struct cubic *cubicd) 162a9696510SRandall Stewart { 163a9696510SRandall Stewart /* 164a9696510SRandall Stewart * In slow-start with ABC enabled and no RTO in sight? 165a9696510SRandall Stewart * (Must not use abc_l_var > 1 if slow starting after 166a9696510SRandall Stewart * an RTO. On RTO, snd_nxt = snd_una, so the 167a9696510SRandall Stewart * snd_nxt == snd_max check is sufficient to 168a9696510SRandall Stewart * handle this). 169a9696510SRandall Stewart * 170a9696510SRandall Stewart * XXXLAS: Find a way to signal SS after RTO that 171a9696510SRandall Stewart * doesn't rely on tcpcb vars. 172a9696510SRandall Stewart */ 173a9696510SRandall Stewart u_int cw = CCV(ccv, snd_cwnd); 174a9696510SRandall Stewart u_int incr = CCV(ccv, t_maxseg); 175a9696510SRandall Stewart uint16_t abc_val; 176a9696510SRandall Stewart 177a9696510SRandall Stewart cubicd->flags |= CUBICFLAG_IN_SLOWSTART; 178a9696510SRandall Stewart if (ccv->flags & CCF_USE_LOCAL_ABC) 179a9696510SRandall Stewart abc_val = ccv->labc; 180a9696510SRandall Stewart else 181a9696510SRandall Stewart abc_val = V_tcp_abc_l_var; 182a9696510SRandall Stewart if ((ccv->flags & CCF_HYSTART_ALLOWED) && 183a9696510SRandall Stewart (cubicd->flags & CUBICFLAG_HYSTART_ENABLED) && 184a9696510SRandall Stewart ((cubicd->flags & CUBICFLAG_HYSTART_IN_CSS) == 0)) { 185a9696510SRandall Stewart /* 186a9696510SRandall Stewart * Hystart is allowed and still enabled and we are not yet 187a9696510SRandall Stewart * in CSS. Lets check to see if we can make a decision on 188a9696510SRandall Stewart * if we need to go into CSS. 189a9696510SRandall Stewart */ 190a9696510SRandall Stewart if ((cubicd->css_rttsample_count >= hystart_n_rttsamples) && 191a9696510SRandall Stewart (cubicd->css_current_round_minrtt != 0xffffffff) && 192a9696510SRandall Stewart (cubicd->css_lastround_minrtt != 0xffffffff)) { 193a9696510SRandall Stewart uint32_t rtt_thresh; 194a9696510SRandall Stewart 195a9696510SRandall Stewart /* Clamp (minrtt_thresh, lastround/8, maxrtt_thresh) */ 196a9696510SRandall Stewart rtt_thresh = (cubicd->css_lastround_minrtt >> 3); 197a9696510SRandall Stewart if (rtt_thresh < hystart_minrtt_thresh) 198a9696510SRandall Stewart rtt_thresh = hystart_minrtt_thresh; 199a9696510SRandall Stewart if (rtt_thresh > hystart_maxrtt_thresh) 200a9696510SRandall Stewart rtt_thresh = hystart_maxrtt_thresh; 201a9696510SRandall Stewart cubic_log_hystart_event(ccv, cubicd, 1, rtt_thresh); 202a9696510SRandall Stewart 203a9696510SRandall Stewart if (cubicd->css_current_round_minrtt >= (cubicd->css_lastround_minrtt + rtt_thresh)) { 204a9696510SRandall Stewart /* Enter CSS */ 205a9696510SRandall Stewart cubicd->flags |= CUBICFLAG_HYSTART_IN_CSS; 206a9696510SRandall Stewart cubicd->css_fas_at_css_entry = cubicd->css_lowrtt_fas; 207a9696510SRandall Stewart /* 208a9696510SRandall Stewart * The draft (v4) calls for us to set baseline to css_current_round_min 209a9696510SRandall Stewart * but that can cause an oscillation. We probably shoudl be using 210a9696510SRandall Stewart * css_lastround_minrtt, but the authors insist that will cause 211a9696510SRandall Stewart * issues on exiting early. We will leave the draft version for now 212a9696510SRandall Stewart * but I suspect this is incorrect. 213a9696510SRandall Stewart */ 214a9696510SRandall Stewart cubicd->css_baseline_minrtt = cubicd->css_current_round_minrtt; 215a9696510SRandall Stewart cubicd->css_entered_at_round = cubicd->css_current_round; 216a9696510SRandall Stewart cubic_log_hystart_event(ccv, cubicd, 2, rtt_thresh); 217a9696510SRandall Stewart } 218a9696510SRandall Stewart } 219a9696510SRandall Stewart } 220a9696510SRandall Stewart if (CCV(ccv, snd_nxt) == CCV(ccv, snd_max)) 221a9696510SRandall Stewart incr = min(ccv->bytes_this_ack, 222a9696510SRandall Stewart ccv->nsegs * abc_val * 223a9696510SRandall Stewart CCV(ccv, t_maxseg)); 224a9696510SRandall Stewart else 225a9696510SRandall Stewart incr = min(ccv->bytes_this_ack, CCV(ccv, t_maxseg)); 226a9696510SRandall Stewart 227a9696510SRandall Stewart /* Only if Hystart is enabled will the flag get set */ 228a9696510SRandall Stewart if (cubicd->flags & CUBICFLAG_HYSTART_IN_CSS) { 229a9696510SRandall Stewart incr /= hystart_css_growth_div; 230a9696510SRandall Stewart cubic_log_hystart_event(ccv, cubicd, 3, incr); 231a9696510SRandall Stewart } 232a9696510SRandall Stewart /* ABC is on by default, so incr equals 0 frequently. */ 233a9696510SRandall Stewart if (incr > 0) 234a9696510SRandall Stewart CCV(ccv, snd_cwnd) = min((cw + incr), 235a9696510SRandall Stewart TCP_MAXWIN << CCV(ccv, snd_scale)); 236a9696510SRandall Stewart } 237a9696510SRandall Stewart 238a9696510SRandall Stewart static void 23967fef78bSLawrence Stewart cubic_ack_received(struct cc_var *ccv, uint16_t type) 24067fef78bSLawrence Stewart { 24167fef78bSLawrence Stewart struct cubic *cubic_data; 24267fef78bSLawrence Stewart unsigned long w_tf, w_cubic_next; 24367fef78bSLawrence Stewart int ticks_since_cong; 24467fef78bSLawrence Stewart 24567fef78bSLawrence Stewart cubic_data = ccv->cc_data; 24667fef78bSLawrence Stewart cubic_record_rtt(ccv); 24767fef78bSLawrence Stewart 24867fef78bSLawrence Stewart /* 249ad7a0eb1SRichard Scheffenegger * For a regular ACK and we're not in cong/fast recovery and 250ad7a0eb1SRichard Scheffenegger * we're cwnd limited, always recalculate cwnd. 25167fef78bSLawrence Stewart */ 25267fef78bSLawrence Stewart if (type == CC_ACK && !IN_RECOVERY(CCV(ccv, t_flags)) && 253ad7a0eb1SRichard Scheffenegger (ccv->flags & CCF_CWND_LIMITED)) { 25467fef78bSLawrence Stewart /* Use the logic in NewReno ack_received() for slow start. */ 25567fef78bSLawrence Stewart if (CCV(ccv, snd_cwnd) <= CCV(ccv, snd_ssthresh) || 2566907bbaeSRichard Scheffenegger cubic_data->min_rtt_ticks == TCPTV_SRTTBASE) { 257a9696510SRandall Stewart cubic_does_slow_start(ccv, cubic_data); 2586907bbaeSRichard Scheffenegger } else { 259a9696510SRandall Stewart if (cubic_data->flags & CUBICFLAG_HYSTART_IN_CSS) { 260a9696510SRandall Stewart /* 261a9696510SRandall Stewart * We have slipped into CA with 262a9696510SRandall Stewart * CSS active. Deactivate all. 263a9696510SRandall Stewart */ 264a9696510SRandall Stewart /* Turn off the CSS flag */ 265a9696510SRandall Stewart cubic_data->flags &= ~CUBICFLAG_HYSTART_IN_CSS; 266a9696510SRandall Stewart /* Disable use of CSS in the future except long idle */ 267a9696510SRandall Stewart cubic_data->flags &= ~CUBICFLAG_HYSTART_ENABLED; 268a9696510SRandall Stewart cubic_log_hystart_event(ccv, cubic_data, 11, CCV(ccv, snd_ssthresh)); 269a9696510SRandall Stewart } 27037674273SRichard Scheffenegger if ((cubic_data->flags & CUBICFLAG_RTO_EVENT) && 27137674273SRichard Scheffenegger (cubic_data->flags & CUBICFLAG_IN_SLOWSTART)) { 27237674273SRichard Scheffenegger /* RFC8312 Section 4.7 */ 27337674273SRichard Scheffenegger cubic_data->flags &= ~(CUBICFLAG_RTO_EVENT | 27437674273SRichard Scheffenegger CUBICFLAG_IN_SLOWSTART); 27537674273SRichard Scheffenegger cubic_data->max_cwnd = CCV(ccv, snd_cwnd); 27637674273SRichard Scheffenegger cubic_data->K = 0; 27737674273SRichard Scheffenegger } else if (cubic_data->flags & (CUBICFLAG_IN_SLOWSTART | 2782bb6dfabSRichard Scheffenegger CUBICFLAG_IN_APPLIMIT)) { 2792bb6dfabSRichard Scheffenegger cubic_data->flags &= ~(CUBICFLAG_IN_SLOWSTART | 2802bb6dfabSRichard Scheffenegger CUBICFLAG_IN_APPLIMIT); 2812bb6dfabSRichard Scheffenegger cubic_data->t_last_cong = ticks; 2822bb6dfabSRichard Scheffenegger cubic_data->K = cubic_k(cubic_data->max_cwnd / 2832bb6dfabSRichard Scheffenegger CCV(ccv, t_maxseg)); 2842bb6dfabSRichard Scheffenegger } 285c968c769SMichael Tuexen if ((ticks_since_cong = 286c968c769SMichael Tuexen ticks - cubic_data->t_last_cong) < 0) { 287c968c769SMichael Tuexen /* 288c968c769SMichael Tuexen * dragging t_last_cong along 289c968c769SMichael Tuexen */ 290c968c769SMichael Tuexen ticks_since_cong = INT_MAX; 291c968c769SMichael Tuexen cubic_data->t_last_cong = ticks - INT_MAX; 292c968c769SMichael Tuexen } 29367fef78bSLawrence Stewart /* 29467fef78bSLawrence Stewart * The mean RTT is used to best reflect the equations in 29567fef78bSLawrence Stewart * the I-D. Using min_rtt in the tf_cwnd calculation 29667fef78bSLawrence Stewart * causes w_tf to grow much faster than it should if the 29767fef78bSLawrence Stewart * RTT is dominated by network buffering rather than 298a4641f4eSPedro F. Giffuni * propagation delay. 29967fef78bSLawrence Stewart */ 30067fef78bSLawrence Stewart w_tf = tf_cwnd(ticks_since_cong, 30167fef78bSLawrence Stewart cubic_data->mean_rtt_ticks, cubic_data->max_cwnd, 30267fef78bSLawrence Stewart CCV(ccv, t_maxseg)); 30367fef78bSLawrence Stewart 30467fef78bSLawrence Stewart w_cubic_next = cubic_cwnd(ticks_since_cong + 30567fef78bSLawrence Stewart cubic_data->mean_rtt_ticks, cubic_data->max_cwnd, 30667fef78bSLawrence Stewart CCV(ccv, t_maxseg), cubic_data->K); 30767fef78bSLawrence Stewart 30867fef78bSLawrence Stewart ccv->flags &= ~CCF_ABC_SENTAWND; 30967fef78bSLawrence Stewart 310c968c769SMichael Tuexen if (w_cubic_next < w_tf) { 31167fef78bSLawrence Stewart /* 31267fef78bSLawrence Stewart * TCP-friendly region, follow tf 31367fef78bSLawrence Stewart * cwnd growth. 31467fef78bSLawrence Stewart */ 315c968c769SMichael Tuexen if (CCV(ccv, snd_cwnd) < w_tf) 316c968c769SMichael Tuexen CCV(ccv, snd_cwnd) = ulmin(w_tf, INT_MAX); 317cce999b3SRichard Scheffenegger } else if (CCV(ccv, snd_cwnd) < w_cubic_next) { 31867fef78bSLawrence Stewart /* 31967fef78bSLawrence Stewart * Concave or convex region, follow CUBIC 32067fef78bSLawrence Stewart * cwnd growth. 321cce999b3SRichard Scheffenegger * Only update snd_cwnd, if it doesn't shrink. 32267fef78bSLawrence Stewart */ 323c968c769SMichael Tuexen CCV(ccv, snd_cwnd) = ulmin(w_cubic_next, 324c968c769SMichael Tuexen INT_MAX); 32567fef78bSLawrence Stewart } 32667fef78bSLawrence Stewart 32767fef78bSLawrence Stewart /* 32867fef78bSLawrence Stewart * If we're not in slow start and we're probing for a 32967fef78bSLawrence Stewart * new cwnd limit at the start of a connection 33067fef78bSLawrence Stewart * (happens when hostcache has a relevant entry), 33167fef78bSLawrence Stewart * keep updating our current estimate of the 33267fef78bSLawrence Stewart * max_cwnd. 33367fef78bSLawrence Stewart */ 3346907bbaeSRichard Scheffenegger if (((cubic_data->flags & CUBICFLAG_CONG_EVENT) == 0) && 3357d87664aSMichael Tuexen cubic_data->max_cwnd < CCV(ccv, snd_cwnd)) { 33667fef78bSLawrence Stewart cubic_data->max_cwnd = CCV(ccv, snd_cwnd); 337b0c1a13eSMichael Tuexen cubic_data->K = cubic_k(cubic_data->max_cwnd / 338b0c1a13eSMichael Tuexen CCV(ccv, t_maxseg)); 33967fef78bSLawrence Stewart } 34067fef78bSLawrence Stewart } 3412fda0a6fSRichard Scheffenegger } else if (type == CC_ACK && !IN_RECOVERY(CCV(ccv, t_flags)) && 3422fda0a6fSRichard Scheffenegger !(ccv->flags & CCF_CWND_LIMITED)) { 3432fda0a6fSRichard Scheffenegger cubic_data->flags |= CUBICFLAG_IN_APPLIMIT; 34467fef78bSLawrence Stewart } 3457d87664aSMichael Tuexen } 34667fef78bSLawrence Stewart 34735cd141bSMichael Tuexen /* 348*ea6d0de2SRichard Scheffenegger * This is a CUBIC specific implementation of after_idle. 34935cd141bSMichael Tuexen * - Reset cwnd by calling New Reno implementation of after_idle. 35035cd141bSMichael Tuexen * - Reset t_last_cong. 35135cd141bSMichael Tuexen */ 35235cd141bSMichael Tuexen static void 35335cd141bSMichael Tuexen cubic_after_idle(struct cc_var *ccv) 35435cd141bSMichael Tuexen { 35535cd141bSMichael Tuexen struct cubic *cubic_data; 35635cd141bSMichael Tuexen 35735cd141bSMichael Tuexen cubic_data = ccv->cc_data; 35835cd141bSMichael Tuexen 359b0c1a13eSMichael Tuexen cubic_data->max_cwnd = ulmax(cubic_data->max_cwnd, CCV(ccv, snd_cwnd)); 360b0c1a13eSMichael Tuexen cubic_data->K = cubic_k(cubic_data->max_cwnd / CCV(ccv, t_maxseg)); 361a9696510SRandall Stewart if ((cubic_data->flags & CUBICFLAG_HYSTART_ENABLED) == 0) { 362a9696510SRandall Stewart /* 363a9696510SRandall Stewart * Re-enable hystart if we have been idle. 364a9696510SRandall Stewart */ 365a9696510SRandall Stewart cubic_data->flags &= ~CUBICFLAG_HYSTART_IN_CSS; 366a9696510SRandall Stewart cubic_data->flags |= CUBICFLAG_HYSTART_ENABLED; 367a9696510SRandall Stewart cubic_log_hystart_event(ccv, cubic_data, 12, CCV(ccv, snd_ssthresh)); 368a9696510SRandall Stewart } 369b8d60729SRandall Stewart newreno_cc_after_idle(ccv); 37035cd141bSMichael Tuexen cubic_data->t_last_cong = ticks; 37135cd141bSMichael Tuexen } 37235cd141bSMichael Tuexen 37367fef78bSLawrence Stewart static void 37467fef78bSLawrence Stewart cubic_cb_destroy(struct cc_var *ccv) 37567fef78bSLawrence Stewart { 376b8d60729SRandall Stewart free(ccv->cc_data, M_CC_MEM); 377b8d60729SRandall Stewart } 378b8d60729SRandall Stewart 379b8d60729SRandall Stewart static size_t 380b8d60729SRandall Stewart cubic_data_sz(void) 381b8d60729SRandall Stewart { 382b8d60729SRandall Stewart return (sizeof(struct cubic)); 38367fef78bSLawrence Stewart } 38467fef78bSLawrence Stewart 38567fef78bSLawrence Stewart static int 386b8d60729SRandall Stewart cubic_cb_init(struct cc_var *ccv, void *ptr) 38767fef78bSLawrence Stewart { 38867fef78bSLawrence Stewart struct cubic *cubic_data; 38967fef78bSLawrence Stewart 390b8d60729SRandall Stewart INP_WLOCK_ASSERT(ccv->ccvc.tcp->t_inpcb); 391b8d60729SRandall Stewart if (ptr == NULL) { 392b8d60729SRandall Stewart cubic_data = malloc(sizeof(struct cubic), M_CC_MEM, M_NOWAIT|M_ZERO); 39367fef78bSLawrence Stewart if (cubic_data == NULL) 39467fef78bSLawrence Stewart return (ENOMEM); 395b8d60729SRandall Stewart } else 396b8d60729SRandall Stewart cubic_data = ptr; 39767fef78bSLawrence Stewart 39867fef78bSLawrence Stewart /* Init some key variables with sensible defaults. */ 39967fef78bSLawrence Stewart cubic_data->t_last_cong = ticks; 40067fef78bSLawrence Stewart cubic_data->min_rtt_ticks = TCPTV_SRTTBASE; 40147f44cddSLawrence Stewart cubic_data->mean_rtt_ticks = 1; 40267fef78bSLawrence Stewart 40367fef78bSLawrence Stewart ccv->cc_data = cubic_data; 404a9696510SRandall Stewart cubic_data->flags = CUBICFLAG_HYSTART_ENABLED; 405a9696510SRandall Stewart /* At init set both to infinity */ 406a9696510SRandall Stewart cubic_data->css_lastround_minrtt = 0xffffffff; 407a9696510SRandall Stewart cubic_data->css_current_round_minrtt = 0xffffffff; 408a9696510SRandall Stewart cubic_data->css_current_round = 0; 409a9696510SRandall Stewart cubic_data->css_baseline_minrtt = 0xffffffff; 410a9696510SRandall Stewart cubic_data->css_rttsample_count = 0; 411a9696510SRandall Stewart cubic_data->css_entered_at_round = 0; 412a9696510SRandall Stewart cubic_data->css_fas_at_css_entry = 0; 413a9696510SRandall Stewart cubic_data->css_lowrtt_fas = 0; 414a9696510SRandall Stewart cubic_data->css_last_fas = 0; 41567fef78bSLawrence Stewart 41667fef78bSLawrence Stewart return (0); 41767fef78bSLawrence Stewart } 41867fef78bSLawrence Stewart 41967fef78bSLawrence Stewart /* 42067fef78bSLawrence Stewart * Perform any necessary tasks before we enter congestion recovery. 42167fef78bSLawrence Stewart */ 42267fef78bSLawrence Stewart static void 42367fef78bSLawrence Stewart cubic_cong_signal(struct cc_var *ccv, uint32_t type) 42467fef78bSLawrence Stewart { 42567fef78bSLawrence Stewart struct cubic *cubic_data; 42639a12f01SRichard Scheffenegger u_int mss; 42767fef78bSLawrence Stewart 42867fef78bSLawrence Stewart cubic_data = ccv->cc_data; 42939a12f01SRichard Scheffenegger mss = tcp_maxseg(ccv->ccvc.tcp); 43067fef78bSLawrence Stewart 43167fef78bSLawrence Stewart switch (type) { 43267fef78bSLawrence Stewart case CC_NDUPACK: 433a9696510SRandall Stewart if (cubic_data->flags & CUBICFLAG_HYSTART_ENABLED) { 434a9696510SRandall Stewart /* Make sure the flags are all off we had a loss */ 435a9696510SRandall Stewart cubic_data->flags &= ~CUBICFLAG_HYSTART_ENABLED; 436a9696510SRandall Stewart cubic_data->flags &= ~CUBICFLAG_HYSTART_IN_CSS; 437a9696510SRandall Stewart cubic_log_hystart_event(ccv, cubic_data, 10, CCV(ccv, snd_ssthresh)); 438a9696510SRandall Stewart } 43967fef78bSLawrence Stewart if (!IN_FASTRECOVERY(CCV(ccv, t_flags))) { 44067fef78bSLawrence Stewart if (!IN_CONGRECOVERY(CCV(ccv, t_flags))) { 44137674273SRichard Scheffenegger cubic_ssthresh_update(ccv, mss); 4426907bbaeSRichard Scheffenegger cubic_data->flags |= CUBICFLAG_CONG_EVENT; 443a459638fSRichard Scheffenegger cubic_data->t_last_cong = ticks; 44437674273SRichard Scheffenegger cubic_data->K = cubic_k(cubic_data->max_cwnd / mss); 44567fef78bSLawrence Stewart } 44667fef78bSLawrence Stewart ENTER_RECOVERY(CCV(ccv, t_flags)); 44767fef78bSLawrence Stewart } 44867fef78bSLawrence Stewart break; 44967fef78bSLawrence Stewart 45067fef78bSLawrence Stewart case CC_ECN: 451a9696510SRandall Stewart if (cubic_data->flags & CUBICFLAG_HYSTART_ENABLED) { 452a9696510SRandall Stewart /* Make sure the flags are all off we had a loss */ 453a9696510SRandall Stewart cubic_data->flags &= ~CUBICFLAG_HYSTART_ENABLED; 454a9696510SRandall Stewart cubic_data->flags &= ~CUBICFLAG_HYSTART_IN_CSS; 455a9696510SRandall Stewart cubic_log_hystart_event(ccv, cubic_data, 9, CCV(ccv, snd_ssthresh)); 456a9696510SRandall Stewart } 45767fef78bSLawrence Stewart if (!IN_CONGRECOVERY(CCV(ccv, t_flags))) { 45837674273SRichard Scheffenegger cubic_ssthresh_update(ccv, mss); 4596907bbaeSRichard Scheffenegger cubic_data->flags |= CUBICFLAG_CONG_EVENT; 46067fef78bSLawrence Stewart cubic_data->t_last_cong = ticks; 46137674273SRichard Scheffenegger cubic_data->K = cubic_k(cubic_data->max_cwnd / mss); 46267fef78bSLawrence Stewart CCV(ccv, snd_cwnd) = CCV(ccv, snd_ssthresh); 46367fef78bSLawrence Stewart ENTER_CONGRECOVERY(CCV(ccv, t_flags)); 46467fef78bSLawrence Stewart } 46567fef78bSLawrence Stewart break; 46667fef78bSLawrence Stewart 46767fef78bSLawrence Stewart case CC_RTO: 46837674273SRichard Scheffenegger /* RFC8312 Section 4.7 */ 46937674273SRichard Scheffenegger if (CCV(ccv, t_rxtshift) == 1) { 47037674273SRichard Scheffenegger cubic_data->t_last_cong_prev = cubic_data->t_last_cong; 47137674273SRichard Scheffenegger cubic_data->prev_max_cwnd_cp = cubic_data->prev_max_cwnd; 4721edbb54fSEd Maste } 47337674273SRichard Scheffenegger cubic_data->flags |= CUBICFLAG_CONG_EVENT | CUBICFLAG_RTO_EVENT; 47437674273SRichard Scheffenegger cubic_data->prev_max_cwnd = cubic_data->max_cwnd; 47537674273SRichard Scheffenegger CCV(ccv, snd_ssthresh) = ((uint64_t)CCV(ccv, snd_cwnd) * 47637674273SRichard Scheffenegger CUBIC_BETA) >> CUBIC_SHIFT; 47737674273SRichard Scheffenegger CCV(ccv, snd_cwnd) = mss; 47837674273SRichard Scheffenegger break; 47937674273SRichard Scheffenegger 48037674273SRichard Scheffenegger case CC_RTO_ERR: 48137674273SRichard Scheffenegger cubic_data->flags &= ~(CUBICFLAG_CONG_EVENT | CUBICFLAG_RTO_EVENT); 48237674273SRichard Scheffenegger cubic_data->max_cwnd = cubic_data->prev_max_cwnd; 48337674273SRichard Scheffenegger cubic_data->prev_max_cwnd = cubic_data->prev_max_cwnd_cp; 48437674273SRichard Scheffenegger cubic_data->t_last_cong = cubic_data->t_last_cong_prev; 48537674273SRichard Scheffenegger cubic_data->K = cubic_k(cubic_data->max_cwnd / mss); 48667fef78bSLawrence Stewart break; 48767fef78bSLawrence Stewart } 48867fef78bSLawrence Stewart } 48967fef78bSLawrence Stewart 49067fef78bSLawrence Stewart static void 49167fef78bSLawrence Stewart cubic_conn_init(struct cc_var *ccv) 49267fef78bSLawrence Stewart { 49367fef78bSLawrence Stewart struct cubic *cubic_data; 49467fef78bSLawrence Stewart 49567fef78bSLawrence Stewart cubic_data = ccv->cc_data; 49667fef78bSLawrence Stewart 49767fef78bSLawrence Stewart /* 49867fef78bSLawrence Stewart * Ensure we have a sane initial value for max_cwnd recorded. Without 49967fef78bSLawrence Stewart * this here bad things happen when entries from the TCP hostcache 50067fef78bSLawrence Stewart * get used. 50167fef78bSLawrence Stewart */ 50267fef78bSLawrence Stewart cubic_data->max_cwnd = CCV(ccv, snd_cwnd); 50367fef78bSLawrence Stewart } 50467fef78bSLawrence Stewart 50567fef78bSLawrence Stewart static int 50667fef78bSLawrence Stewart cubic_mod_init(void) 50767fef78bSLawrence Stewart { 50867fef78bSLawrence Stewart return (0); 50967fef78bSLawrence Stewart } 51067fef78bSLawrence Stewart 51167fef78bSLawrence Stewart /* 51267fef78bSLawrence Stewart * Perform any necessary tasks before we exit congestion recovery. 51367fef78bSLawrence Stewart */ 51467fef78bSLawrence Stewart static void 51567fef78bSLawrence Stewart cubic_post_recovery(struct cc_var *ccv) 51667fef78bSLawrence Stewart { 51767fef78bSLawrence Stewart struct cubic *cubic_data; 518f81bc34eSHiren Panchasara int pipe; 51967fef78bSLawrence Stewart 52067fef78bSLawrence Stewart cubic_data = ccv->cc_data; 521f81bc34eSHiren Panchasara pipe = 0; 52267fef78bSLawrence Stewart 52367fef78bSLawrence Stewart if (IN_FASTRECOVERY(CCV(ccv, t_flags))) { 52467fef78bSLawrence Stewart /* 52567fef78bSLawrence Stewart * If inflight data is less than ssthresh, set cwnd 52667fef78bSLawrence Stewart * conservatively to avoid a burst of data, as suggested in 52767fef78bSLawrence Stewart * the NewReno RFC. Otherwise, use the CUBIC method. 52867fef78bSLawrence Stewart * 52967fef78bSLawrence Stewart * XXXLAS: Find a way to do this without needing curack 53067fef78bSLawrence Stewart */ 531d1de2b05SRichard Scheffenegger if (V_tcp_do_newsack) 532f81bc34eSHiren Panchasara pipe = tcp_compute_pipe(ccv->ccvc.tcp); 533f81bc34eSHiren Panchasara else 534f81bc34eSHiren Panchasara pipe = CCV(ccv, snd_max) - ccv->curack; 535f81bc34eSHiren Panchasara 536f81bc34eSHiren Panchasara if (pipe < CCV(ccv, snd_ssthresh)) 5375cc11a89SMichael Tuexen /* 5385cc11a89SMichael Tuexen * Ensure that cwnd does not collapse to 1 MSS under 5395cc11a89SMichael Tuexen * adverse conditions. Implements RFC6582 5405cc11a89SMichael Tuexen */ 5415cc11a89SMichael Tuexen CCV(ccv, snd_cwnd) = max(pipe, CCV(ccv, t_maxseg)) + 5425cc11a89SMichael Tuexen CCV(ccv, t_maxseg); 54367fef78bSLawrence Stewart else 54467fef78bSLawrence Stewart /* Update cwnd based on beta and adjusted max_cwnd. */ 54514558b99SRichard Scheffenegger CCV(ccv, snd_cwnd) = max(((uint64_t)cubic_data->max_cwnd * 54614558b99SRichard Scheffenegger CUBIC_BETA) >> CUBIC_SHIFT, 54714558b99SRichard Scheffenegger 2 * CCV(ccv, t_maxseg)); 54867fef78bSLawrence Stewart } 54967fef78bSLawrence Stewart 55067fef78bSLawrence Stewart /* Calculate the average RTT between congestion epochs. */ 55147f44cddSLawrence Stewart if (cubic_data->epoch_ack_count > 0 && 55247f44cddSLawrence Stewart cubic_data->sum_rtt_ticks >= cubic_data->epoch_ack_count) { 55367fef78bSLawrence Stewart cubic_data->mean_rtt_ticks = (int)(cubic_data->sum_rtt_ticks / 55467fef78bSLawrence Stewart cubic_data->epoch_ack_count); 55547f44cddSLawrence Stewart } 55667fef78bSLawrence Stewart 55767fef78bSLawrence Stewart cubic_data->epoch_ack_count = 0; 55867fef78bSLawrence Stewart cubic_data->sum_rtt_ticks = 0; 55967fef78bSLawrence Stewart } 56067fef78bSLawrence Stewart 56167fef78bSLawrence Stewart /* 56267fef78bSLawrence Stewart * Record the min RTT and sum samples for the epoch average RTT calculation. 56367fef78bSLawrence Stewart */ 56467fef78bSLawrence Stewart static void 56567fef78bSLawrence Stewart cubic_record_rtt(struct cc_var *ccv) 56667fef78bSLawrence Stewart { 56767fef78bSLawrence Stewart struct cubic *cubic_data; 56867fef78bSLawrence Stewart int t_srtt_ticks; 56967fef78bSLawrence Stewart 57067fef78bSLawrence Stewart /* Ignore srtt until a min number of samples have been taken. */ 57167fef78bSLawrence Stewart if (CCV(ccv, t_rttupdated) >= CUBIC_MIN_RTT_SAMPLES) { 57267fef78bSLawrence Stewart cubic_data = ccv->cc_data; 57367fef78bSLawrence Stewart t_srtt_ticks = CCV(ccv, t_srtt) / TCP_RTT_SCALE; 57467fef78bSLawrence Stewart 57567fef78bSLawrence Stewart /* 57667fef78bSLawrence Stewart * Record the current SRTT as our minrtt if it's the smallest 57767fef78bSLawrence Stewart * we've seen or minrtt is currently equal to its initialised 57867fef78bSLawrence Stewart * value. 57967fef78bSLawrence Stewart * 58067fef78bSLawrence Stewart * XXXLAS: Should there be some hysteresis for minrtt? 58167fef78bSLawrence Stewart */ 58267fef78bSLawrence Stewart if ((t_srtt_ticks < cubic_data->min_rtt_ticks || 58347f44cddSLawrence Stewart cubic_data->min_rtt_ticks == TCPTV_SRTTBASE)) { 58467fef78bSLawrence Stewart cubic_data->min_rtt_ticks = max(1, t_srtt_ticks); 58567fef78bSLawrence Stewart 58647f44cddSLawrence Stewart /* 58747f44cddSLawrence Stewart * If the connection is within its first congestion 58847f44cddSLawrence Stewart * epoch, ensure we prime mean_rtt_ticks with a 58947f44cddSLawrence Stewart * reasonable value until the epoch average RTT is 59047f44cddSLawrence Stewart * calculated in cubic_post_recovery(). 59147f44cddSLawrence Stewart */ 59247f44cddSLawrence Stewart if (cubic_data->min_rtt_ticks > 59347f44cddSLawrence Stewart cubic_data->mean_rtt_ticks) 59447f44cddSLawrence Stewart cubic_data->mean_rtt_ticks = 59547f44cddSLawrence Stewart cubic_data->min_rtt_ticks; 59647f44cddSLawrence Stewart } 59747f44cddSLawrence Stewart 59867fef78bSLawrence Stewart /* Sum samples for epoch average RTT calculation. */ 59967fef78bSLawrence Stewart cubic_data->sum_rtt_ticks += t_srtt_ticks; 60067fef78bSLawrence Stewart cubic_data->epoch_ack_count++; 60167fef78bSLawrence Stewart } 60267fef78bSLawrence Stewart } 60367fef78bSLawrence Stewart 60467fef78bSLawrence Stewart /* 60567fef78bSLawrence Stewart * Update the ssthresh in the event of congestion. 60667fef78bSLawrence Stewart */ 60767fef78bSLawrence Stewart static void 60837674273SRichard Scheffenegger cubic_ssthresh_update(struct cc_var *ccv, uint32_t maxseg) 60967fef78bSLawrence Stewart { 61067fef78bSLawrence Stewart struct cubic *cubic_data; 61114558b99SRichard Scheffenegger uint32_t ssthresh; 612a459638fSRichard Scheffenegger uint32_t cwnd; 61367fef78bSLawrence Stewart 61467fef78bSLawrence Stewart cubic_data = ccv->cc_data; 615a459638fSRichard Scheffenegger cwnd = CCV(ccv, snd_cwnd); 616a459638fSRichard Scheffenegger 617a459638fSRichard Scheffenegger /* Fast convergence heuristic. */ 618a459638fSRichard Scheffenegger if (cwnd < cubic_data->max_cwnd) { 619a459638fSRichard Scheffenegger cwnd = ((uint64_t)cwnd * CUBIC_FC_FACTOR) >> CUBIC_SHIFT; 620a459638fSRichard Scheffenegger } 621a459638fSRichard Scheffenegger cubic_data->prev_max_cwnd = cubic_data->max_cwnd; 622a459638fSRichard Scheffenegger cubic_data->max_cwnd = cwnd; 62367fef78bSLawrence Stewart 62467fef78bSLawrence Stewart /* 625a459638fSRichard Scheffenegger * On the first congestion event, set ssthresh to cwnd * 0.5 626a459638fSRichard Scheffenegger * and reduce max_cwnd to cwnd * beta. This aligns the cubic concave 627a459638fSRichard Scheffenegger * region appropriately. On subsequent congestion events, set 628a459638fSRichard Scheffenegger * ssthresh to cwnd * beta. 62967fef78bSLawrence Stewart */ 630a459638fSRichard Scheffenegger if ((cubic_data->flags & CUBICFLAG_CONG_EVENT) == 0) { 631a459638fSRichard Scheffenegger ssthresh = cwnd >> 1; 632a459638fSRichard Scheffenegger cubic_data->max_cwnd = ((uint64_t)cwnd * 6333ac12506SJonathan T. Looney CUBIC_BETA) >> CUBIC_SHIFT; 634a459638fSRichard Scheffenegger } else { 635a459638fSRichard Scheffenegger ssthresh = ((uint64_t)cwnd * 636a459638fSRichard Scheffenegger CUBIC_BETA) >> CUBIC_SHIFT; 637a459638fSRichard Scheffenegger } 63837674273SRichard Scheffenegger CCV(ccv, snd_ssthresh) = max(ssthresh, 2 * maxseg); 63967fef78bSLawrence Stewart } 64067fef78bSLawrence Stewart 641a9696510SRandall Stewart static void 642a9696510SRandall Stewart cubic_rttsample(struct cc_var *ccv, uint32_t usec_rtt, uint32_t rxtcnt, uint32_t fas) 643a9696510SRandall Stewart { 644a9696510SRandall Stewart struct cubic *cubicd; 645a9696510SRandall Stewart 646a9696510SRandall Stewart cubicd = ccv->cc_data; 647a9696510SRandall Stewart if (rxtcnt > 1) { 648a9696510SRandall Stewart /* 649a9696510SRandall Stewart * Only look at RTT's that are non-ambiguous. 650a9696510SRandall Stewart */ 651a9696510SRandall Stewart return; 652a9696510SRandall Stewart } 653a9696510SRandall Stewart cubicd->css_rttsample_count++; 654a9696510SRandall Stewart cubicd->css_last_fas = fas; 655a9696510SRandall Stewart if (cubicd->css_current_round_minrtt > usec_rtt) { 656a9696510SRandall Stewart cubicd->css_current_round_minrtt = usec_rtt; 657a9696510SRandall Stewart cubicd->css_lowrtt_fas = cubicd->css_last_fas; 658a9696510SRandall Stewart } 659a9696510SRandall Stewart if ((cubicd->css_rttsample_count >= hystart_n_rttsamples) && 660a9696510SRandall Stewart (cubicd->css_current_round_minrtt != 0xffffffff) && 661e88412d8SRandall Stewart (cubicd->css_current_round_minrtt < cubicd->css_baseline_minrtt) && 662a9696510SRandall Stewart (cubicd->css_lastround_minrtt != 0xffffffff)) { 663a9696510SRandall Stewart /* 664a9696510SRandall Stewart * We were in CSS and the RTT is now less, we 665a9696510SRandall Stewart * entered CSS erroneously. 666a9696510SRandall Stewart */ 667a9696510SRandall Stewart cubicd->flags &= ~CUBICFLAG_HYSTART_IN_CSS; 668a9696510SRandall Stewart cubic_log_hystart_event(ccv, cubicd, 8, cubicd->css_baseline_minrtt); 669a9696510SRandall Stewart cubicd->css_baseline_minrtt = 0xffffffff; 670a9696510SRandall Stewart } 671a9696510SRandall Stewart if (cubicd->flags & CUBICFLAG_HYSTART_ENABLED) 672a9696510SRandall Stewart cubic_log_hystart_event(ccv, cubicd, 5, usec_rtt); 673a9696510SRandall Stewart } 674a9696510SRandall Stewart 675a9696510SRandall Stewart static void 676a9696510SRandall Stewart cubic_newround(struct cc_var *ccv, uint32_t round_cnt) 677a9696510SRandall Stewart { 678a9696510SRandall Stewart struct cubic *cubicd; 679a9696510SRandall Stewart 680a9696510SRandall Stewart cubicd = ccv->cc_data; 681a9696510SRandall Stewart /* We have entered a new round */ 682a9696510SRandall Stewart cubicd->css_lastround_minrtt = cubicd->css_current_round_minrtt; 683a9696510SRandall Stewart cubicd->css_current_round_minrtt = 0xffffffff; 684a9696510SRandall Stewart cubicd->css_rttsample_count = 0; 685a9696510SRandall Stewart cubicd->css_current_round = round_cnt; 686a9696510SRandall Stewart if ((cubicd->flags & CUBICFLAG_HYSTART_IN_CSS) && 687a9696510SRandall Stewart ((round_cnt - cubicd->css_entered_at_round) >= hystart_css_rounds)) { 688a9696510SRandall Stewart /* Enter CA */ 689a9696510SRandall Stewart if (ccv->flags & CCF_HYSTART_CAN_SH_CWND) { 690a9696510SRandall Stewart /* 691a9696510SRandall Stewart * We engage more than snd_ssthresh, engage 692a9696510SRandall Stewart * the brakes!! Though we will stay in SS to 693a9696510SRandall Stewart * creep back up again, so lets leave CSS active 694a9696510SRandall Stewart * and give us hystart_css_rounds more rounds. 695a9696510SRandall Stewart */ 696a9696510SRandall Stewart if (ccv->flags & CCF_HYSTART_CONS_SSTH) { 697a9696510SRandall Stewart CCV(ccv, snd_ssthresh) = ((cubicd->css_lowrtt_fas + cubicd->css_fas_at_css_entry) / 2); 698a9696510SRandall Stewart } else { 699a9696510SRandall Stewart CCV(ccv, snd_ssthresh) = cubicd->css_lowrtt_fas; 700a9696510SRandall Stewart } 701a9696510SRandall Stewart CCV(ccv, snd_cwnd) = cubicd->css_fas_at_css_entry; 702a9696510SRandall Stewart cubicd->css_entered_at_round = round_cnt; 703a9696510SRandall Stewart } else { 704a9696510SRandall Stewart CCV(ccv, snd_ssthresh) = CCV(ccv, snd_cwnd); 705a9696510SRandall Stewart /* Turn off the CSS flag */ 706a9696510SRandall Stewart cubicd->flags &= ~CUBICFLAG_HYSTART_IN_CSS; 707a9696510SRandall Stewart /* Disable use of CSS in the future except long idle */ 708a9696510SRandall Stewart cubicd->flags &= ~CUBICFLAG_HYSTART_ENABLED; 709a9696510SRandall Stewart } 710a9696510SRandall Stewart cubic_log_hystart_event(ccv, cubicd, 6, CCV(ccv, snd_ssthresh)); 711a9696510SRandall Stewart } 712a9696510SRandall Stewart if (cubicd->flags & CUBICFLAG_HYSTART_ENABLED) 713a9696510SRandall Stewart cubic_log_hystart_event(ccv, cubicd, 4, round_cnt); 714a9696510SRandall Stewart } 715a9696510SRandall Stewart 71667fef78bSLawrence Stewart DECLARE_CC_MODULE(cubic, &cubic_cc_algo); 717b8d60729SRandall Stewart MODULE_VERSION(cubic, 2); 718