xref: /freebsd/sys/netinet/cc/cc_newreno.c (revision 783d3ff6d7fae619db8a7990b8a6387de0c677b5)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 1982, 1986, 1988, 1990, 1993, 1994, 1995
5  *	The Regents of the University of California.
6  * Copyright (c) 2007-2008,2010,2014
7  *	Swinburne University of Technology, Melbourne, Australia.
8  * Copyright (c) 2009-2010 Lawrence Stewart <lstewart@freebsd.org>
9  * Copyright (c) 2010 The FreeBSD Foundation
10  * All rights reserved.
11  *
12  * This software was developed at the Centre for Advanced Internet
13  * Architectures, Swinburne University of Technology, by Lawrence Stewart, James
14  * Healy and David Hayes, made possible in part by a grant from the Cisco
15  * University Research Program Fund at Community Foundation Silicon Valley.
16  *
17  * Portions of this software were developed at the Centre for Advanced
18  * Internet Architectures, Swinburne University of Technology, Melbourne,
19  * Australia by David Hayes under sponsorship from the FreeBSD Foundation.
20  *
21  * Redistribution and use in source and binary forms, with or without
22  * modification, are permitted provided that the following conditions
23  * are met:
24  * 1. Redistributions of source code must retain the above copyright
25  *    notice, this list of conditions and the following disclaimer.
26  * 2. Redistributions in binary form must reproduce the above copyright
27  *    notice, this list of conditions and the following disclaimer in the
28  *    documentation and/or other materials provided with the distribution.
29  *
30  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
31  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
32  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
34  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
35  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
36  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
37  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
38  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
39  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40  * SUCH DAMAGE.
41  */
42 
43 /*
44  * This software was first released in 2007 by James Healy and Lawrence Stewart
45  * whilst working on the NewTCP research project at Swinburne University of
46  * Technology's Centre for Advanced Internet Architectures, Melbourne,
47  * Australia, which was made possible in part by a grant from the Cisco
48  * University Research Program Fund at Community Foundation Silicon Valley.
49  * More details are available at:
50  *   http://caia.swin.edu.au/urp/newtcp/
51  *
52  * Dec 2014 garmitage@swin.edu.au
53  * Borrowed code fragments from cc_cdg.c to add modifiable beta
54  * via sysctls.
55  *
56  */
57 
58 #include <sys/param.h>
59 #include <sys/kernel.h>
60 #include <sys/malloc.h>
61 #include <sys/module.h>
62 #include <sys/socket.h>
63 #include <sys/lock.h>
64 #include <sys/mutex.h>
65 #include <sys/socketvar.h>
66 #include <sys/sysctl.h>
67 #include <sys/systm.h>
68 
69 #include <net/vnet.h>
70 
71 #include <net/route.h>
72 #include <net/route/nhop.h>
73 
74 #include <netinet/in_pcb.h>
75 #include <netinet/in.h>
76 #include <netinet/in_pcb.h>
77 #include <netinet/tcp.h>
78 #include <netinet/tcp_seq.h>
79 #include <netinet/tcp_var.h>
80 #include <netinet/tcp_log_buf.h>
81 #include <netinet/tcp_hpts.h>
82 #include <netinet/cc/cc.h>
83 #include <netinet/cc/cc_module.h>
84 #include <netinet/cc/cc_newreno.h>
85 
86 static void	newreno_cb_destroy(struct cc_var *ccv);
87 static void	newreno_ack_received(struct cc_var *ccv, ccsignal_t type);
88 static void	newreno_after_idle(struct cc_var *ccv);
89 static void	newreno_cong_signal(struct cc_var *ccv, ccsignal_t type);
90 static int newreno_ctl_output(struct cc_var *ccv, struct sockopt *sopt, void *buf);
91 static void	newreno_newround(struct cc_var *ccv, uint32_t round_cnt);
92 static void	newreno_rttsample(struct cc_var *ccv, uint32_t usec_rtt, uint32_t rxtcnt, uint32_t fas);
93 static 	int	newreno_cb_init(struct cc_var *ccv, void *);
94 static size_t	newreno_data_sz(void);
95 
96 
97 VNET_DECLARE(uint32_t, newreno_beta);
98 #define V_newreno_beta VNET(newreno_beta)
99 VNET_DECLARE(uint32_t, newreno_beta_ecn);
100 #define V_newreno_beta_ecn VNET(newreno_beta_ecn)
101 
102 struct cc_algo newreno_cc_algo = {
103 	.name = "newreno",
104 	.cb_destroy = newreno_cb_destroy,
105 	.ack_received = newreno_ack_received,
106 	.after_idle = newreno_after_idle,
107 	.cong_signal = newreno_cong_signal,
108 	.post_recovery = newreno_cc_post_recovery,
109 	.ctl_output = newreno_ctl_output,
110 	.newround = newreno_newround,
111 	.rttsample = newreno_rttsample,
112 	.cb_init = newreno_cb_init,
113 	.cc_data_sz = newreno_data_sz,
114 };
115 
116 static void
117 newreno_log_hystart_event(struct cc_var *ccv, struct newreno *nreno, uint8_t mod, uint32_t flex1)
118 {
119 	/*
120 	 * Types of logs (mod value)
121 	 * 1 - rtt_thresh in flex1, checking to see if RTT is to great.
122 	 * 2 - rtt is too great, rtt_thresh in flex1.
123 	 * 3 - CSS is active incr in flex1
124 	 * 4 - A new round is beginning flex1 is round count
125 	 * 5 - A new RTT measurement flex1 is the new measurement.
126 	 * 6 - We enter CA ssthresh is also in flex1.
127 	 * 7 - Socket option to change hystart executed opt.val in flex1.
128 	 * 8 - Back out of CSS into SS, flex1 is the css_baseline_minrtt
129 	 * 9 - We enter CA, via an ECN mark.
130 	 * 10 - We enter CA, via a loss.
131 	 * 11 - We have slipped out of SS into CA via cwnd growth.
132 	 * 12 - After idle has re-enabled hystart++
133 	 */
134 	struct tcpcb *tp;
135 
136 	if (hystart_bblogs == 0)
137 		return;
138 	tp = ccv->ccvc.tcp;
139 	if (tcp_bblogging_on(tp)) {
140 		union tcp_log_stackspecific log;
141 		struct timeval tv;
142 
143 		memset(&log, 0, sizeof(log));
144 		log.u_bbr.flex1 = flex1;
145 		log.u_bbr.flex2 = nreno->css_current_round_minrtt;
146 		log.u_bbr.flex3 = nreno->css_lastround_minrtt;
147 		log.u_bbr.flex4 = nreno->css_rttsample_count;
148 		log.u_bbr.flex5 = nreno->css_entered_at_round;
149 		log.u_bbr.flex6 = nreno->css_baseline_minrtt;
150 		/* We only need bottom 16 bits of flags */
151 		log.u_bbr.flex7 = nreno->newreno_flags & 0x0000ffff;
152 		log.u_bbr.flex8 = mod;
153 		log.u_bbr.epoch = nreno->css_current_round;
154 		log.u_bbr.timeStamp = tcp_get_usecs(&tv);
155 		log.u_bbr.lt_epoch = nreno->css_fas_at_css_entry;
156 		log.u_bbr.pkts_out = nreno->css_last_fas;
157 		log.u_bbr.delivered = nreno->css_lowrtt_fas;
158 		log.u_bbr.pkt_epoch = ccv->flags;
159 		TCP_LOG_EVENTP(tp, NULL,
160 		    &tptosocket(tp)->so_rcv,
161 		    &tptosocket(tp)->so_snd,
162 		    TCP_HYSTART, 0,
163 		    0, &log, false, &tv);
164 	}
165 }
166 
167 static size_t
168 newreno_data_sz(void)
169 {
170 	return (sizeof(struct newreno));
171 }
172 
173 static int
174 newreno_cb_init(struct cc_var *ccv, void *ptr)
175 {
176 	struct newreno *nreno;
177 
178 	INP_WLOCK_ASSERT(tptoinpcb(ccv->ccvc.tcp));
179 	if (ptr == NULL) {
180 		ccv->cc_data = malloc(sizeof(struct newreno), M_CC_MEM, M_NOWAIT);
181 		if (ccv->cc_data == NULL)
182 			return (ENOMEM);
183 	} else
184 		ccv->cc_data = ptr;
185 	nreno = (struct newreno *)ccv->cc_data;
186 	/* NB: nreno is not zeroed, so initialise all fields. */
187 	nreno->beta = V_newreno_beta;
188 	nreno->beta_ecn = V_newreno_beta_ecn;
189 	/*
190 	 * We set the enabled flag so that if
191 	 * the socket option gets strobed and
192 	 * we have not hit a loss
193 	 */
194 	nreno->newreno_flags = CC_NEWRENO_HYSTART_ENABLED;
195 	/* At init set both to infinity */
196 	nreno->css_lastround_minrtt = 0xffffffff;
197 	nreno->css_current_round_minrtt = 0xffffffff;
198 	nreno->css_current_round = 0;
199 	nreno->css_baseline_minrtt = 0xffffffff;
200 	nreno->css_rttsample_count = 0;
201 	nreno->css_entered_at_round = 0;
202 	nreno->css_fas_at_css_entry = 0;
203 	nreno->css_lowrtt_fas = 0;
204 	nreno->css_last_fas = 0;
205 	return (0);
206 }
207 
208 static void
209 newreno_cb_destroy(struct cc_var *ccv)
210 {
211 	free(ccv->cc_data, M_CC_MEM);
212 }
213 
214 static void
215 newreno_ack_received(struct cc_var *ccv, ccsignal_t type)
216 {
217 	struct newreno *nreno;
218 
219 	nreno = ccv->cc_data;
220 	if (type == CC_ACK && !IN_RECOVERY(CCV(ccv, t_flags)) &&
221 	    (ccv->flags & CCF_CWND_LIMITED)) {
222 		u_int cw = CCV(ccv, snd_cwnd);
223 		u_int incr = CCV(ccv, t_maxseg);
224 
225 		/*
226 		 * Regular in-order ACK, open the congestion window.
227 		 * Method depends on which congestion control state we're
228 		 * in (slow start or cong avoid) and if ABC (RFC 3465) is
229 		 * enabled.
230 		 *
231 		 * slow start: cwnd <= ssthresh
232 		 * cong avoid: cwnd > ssthresh
233 		 *
234 		 * slow start and ABC (RFC 3465):
235 		 *   Grow cwnd exponentially by the amount of data
236 		 *   ACKed capping the max increment per ACK to
237 		 *   (abc_l_var * maxseg) bytes.
238 		 *
239 		 * slow start without ABC (RFC 5681):
240 		 *   Grow cwnd exponentially by maxseg per ACK.
241 		 *
242 		 * cong avoid and ABC (RFC 3465):
243 		 *   Grow cwnd linearly by maxseg per RTT for each
244 		 *   cwnd worth of ACKed data.
245 		 *
246 		 * cong avoid without ABC (RFC 5681):
247 		 *   Grow cwnd linearly by approximately maxseg per RTT using
248 		 *   maxseg^2 / cwnd per ACK as the increment.
249 		 *   If cwnd > maxseg^2, fix the cwnd increment at 1 byte to
250 		 *   avoid capping cwnd.
251 		 */
252 		if (cw > CCV(ccv, snd_ssthresh)) {
253 			if (nreno->newreno_flags & CC_NEWRENO_HYSTART_IN_CSS) {
254 				/*
255 				 * We have slipped into CA with
256 				 * CSS active. Deactivate all.
257 				 */
258 				/* Turn off the CSS flag */
259 				nreno->newreno_flags &= ~CC_NEWRENO_HYSTART_IN_CSS;
260 				/* Disable use of CSS in the future except long idle  */
261 				nreno->newreno_flags &= ~CC_NEWRENO_HYSTART_ENABLED;
262 				newreno_log_hystart_event(ccv, nreno, 11, CCV(ccv, snd_ssthresh));
263 			}
264 			if (V_tcp_do_rfc3465) {
265 				if (ccv->flags & CCF_ABC_SENTAWND)
266 					ccv->flags &= ~CCF_ABC_SENTAWND;
267 				else
268 					incr = 0;
269 			} else
270 				incr = max((incr * incr / cw), 1);
271 		} else if (V_tcp_do_rfc3465) {
272 			/*
273 			 * In slow-start with ABC enabled and no RTO in sight?
274 			 * (Must not use abc_l_var > 1 if slow starting after
275 			 * an RTO. On RTO, snd_nxt = snd_una, so the
276 			 * snd_nxt == snd_max check is sufficient to
277 			 * handle this).
278 			 *
279 			 * XXXLAS: Find a way to signal SS after RTO that
280 			 * doesn't rely on tcpcb vars.
281 			 */
282 			uint16_t abc_val;
283 
284 			if (ccv->flags & CCF_USE_LOCAL_ABC)
285 				abc_val = ccv->labc;
286 			else
287 				abc_val = V_tcp_abc_l_var;
288 			if ((ccv->flags & CCF_HYSTART_ALLOWED) &&
289 			    (nreno->newreno_flags & CC_NEWRENO_HYSTART_ENABLED) &&
290 			    ((nreno->newreno_flags & CC_NEWRENO_HYSTART_IN_CSS) == 0)) {
291 				/*
292 				 * Hystart is allowed and still enabled and we are not yet
293 				 * in CSS. Lets check to see if we can make a decision on
294 				 * if we need to go into CSS.
295 				 */
296 				if ((nreno->css_rttsample_count >= hystart_n_rttsamples) &&
297 				    (nreno->css_current_round_minrtt != 0xffffffff) &&
298 				    (nreno->css_lastround_minrtt != 0xffffffff)) {
299 					uint32_t rtt_thresh;
300 
301 					/* Clamp (minrtt_thresh, lastround/8, maxrtt_thresh) */
302 					rtt_thresh = (nreno->css_lastround_minrtt >> 3);
303 					if (rtt_thresh < hystart_minrtt_thresh)
304 						rtt_thresh = hystart_minrtt_thresh;
305 					if (rtt_thresh > hystart_maxrtt_thresh)
306 						rtt_thresh = hystart_maxrtt_thresh;
307 					newreno_log_hystart_event(ccv, nreno, 1, rtt_thresh);
308 					if (nreno->css_current_round_minrtt >= (nreno->css_lastround_minrtt + rtt_thresh)) {
309 						/* Enter CSS */
310 						nreno->newreno_flags |= CC_NEWRENO_HYSTART_IN_CSS;
311 						nreno->css_fas_at_css_entry = nreno->css_lowrtt_fas;
312 						/*
313 						 * The draft (v4) calls for us to set baseline to css_current_round_min
314 						 * but that can cause an oscillation. We probably shoudl be using
315 						 * css_lastround_minrtt, but the authors insist that will cause
316 						 * issues on exiting early. We will leave the draft version for now
317 						 * but I suspect this is incorrect.
318 						 */
319 						nreno->css_baseline_minrtt = nreno->css_current_round_minrtt;
320 						nreno->css_entered_at_round = nreno->css_current_round;
321 						newreno_log_hystart_event(ccv, nreno, 2, rtt_thresh);
322 					}
323 				}
324 			}
325 			if (CCV(ccv, snd_nxt) == CCV(ccv, snd_max))
326 				incr = min(ccv->bytes_this_ack,
327 				    ccv->nsegs * abc_val *
328 				    CCV(ccv, t_maxseg));
329 			else
330 				incr = min(ccv->bytes_this_ack, CCV(ccv, t_maxseg));
331 
332 			/* Only if Hystart is enabled will the flag get set */
333 			if (nreno->newreno_flags & CC_NEWRENO_HYSTART_IN_CSS) {
334 				incr /= hystart_css_growth_div;
335 				newreno_log_hystart_event(ccv, nreno, 3, incr);
336 			}
337 		}
338 		/* ABC is on by default, so incr equals 0 frequently. */
339 		if (incr > 0)
340 			CCV(ccv, snd_cwnd) = min(cw + incr,
341 			    TCP_MAXWIN << CCV(ccv, snd_scale));
342 	}
343 }
344 
345 static void
346 newreno_after_idle(struct cc_var *ccv)
347 {
348 	struct newreno *nreno;
349 
350 	nreno = ccv->cc_data;
351 	newreno_cc_after_idle(ccv);
352 	if ((nreno->newreno_flags & CC_NEWRENO_HYSTART_ENABLED) == 0) {
353 		/*
354 		 * Re-enable hystart if we have been idle.
355 		 */
356 		nreno->newreno_flags &= ~CC_NEWRENO_HYSTART_IN_CSS;
357 		nreno->newreno_flags |= CC_NEWRENO_HYSTART_ENABLED;
358 		newreno_log_hystart_event(ccv, nreno, 12, CCV(ccv, snd_ssthresh));
359 	}
360 }
361 
362 /*
363  * Perform any necessary tasks before we enter congestion recovery.
364  */
365 static void
366 newreno_cong_signal(struct cc_var *ccv, ccsignal_t type)
367 {
368 	struct newreno *nreno;
369 	uint32_t beta, beta_ecn, cwin, factor, mss, pipe;
370 
371 	cwin = CCV(ccv, snd_cwnd);
372 	mss = tcp_fixed_maxseg(ccv->ccvc.tcp);
373 	nreno = ccv->cc_data;
374 	beta = (nreno == NULL) ? V_newreno_beta : nreno->beta;;
375 	beta_ecn = (nreno == NULL) ? V_newreno_beta_ecn : nreno->beta_ecn;
376 	/*
377 	 * Note that we only change the backoff for ECN if the
378 	 * global sysctl V_cc_do_abe is set <or> the stack itself
379 	 * has set a flag in our newreno_flags (due to pacing) telling
380 	 * us to use the lower valued back-off.
381 	 */
382 	if ((type == CC_ECN) &&
383 	    (V_cc_do_abe ||
384 	    ((nreno != NULL) && (nreno->newreno_flags & CC_NEWRENO_BETA_ECN_ENABLED))))
385 		factor = beta_ecn;
386 	else
387 		factor = beta;
388 
389 	/* Catch algos which mistakenly leak private signal types. */
390 	KASSERT((type & CC_SIGPRIVMASK) == 0,
391 	    ("%s: congestion signal type 0x%08x is private\n", __func__, type));
392 
393 	cwin = max(((uint64_t)cwin * (uint64_t)factor) / (100ULL * (uint64_t)mss),
394 	    2) * mss;
395 
396 	switch (type) {
397 	case CC_NDUPACK:
398 		if (nreno->newreno_flags & CC_NEWRENO_HYSTART_ENABLED) {
399 			/* Make sure the flags are all off we had a loss */
400 			nreno->newreno_flags &= ~CC_NEWRENO_HYSTART_ENABLED;
401 			nreno->newreno_flags &= ~CC_NEWRENO_HYSTART_IN_CSS;
402 			newreno_log_hystart_event(ccv, nreno, 10, CCV(ccv, snd_ssthresh));
403 		}
404 		if (!IN_FASTRECOVERY(CCV(ccv, t_flags))) {
405 			if (IN_CONGRECOVERY(CCV(ccv, t_flags) &&
406 			    V_cc_do_abe && V_cc_abe_frlossreduce)) {
407 				CCV(ccv, snd_ssthresh) =
408 				    ((uint64_t)CCV(ccv, snd_ssthresh) *
409 				     (uint64_t)beta) / (uint64_t)beta_ecn;
410 			}
411 			if (!IN_CONGRECOVERY(CCV(ccv, t_flags)))
412 				CCV(ccv, snd_ssthresh) = cwin;
413 			ENTER_RECOVERY(CCV(ccv, t_flags));
414 		}
415 		break;
416 	case CC_ECN:
417 		if (nreno->newreno_flags & CC_NEWRENO_HYSTART_ENABLED) {
418 			/* Make sure the flags are all off we had a loss */
419 			nreno->newreno_flags &= ~CC_NEWRENO_HYSTART_ENABLED;
420 			nreno->newreno_flags &= ~CC_NEWRENO_HYSTART_IN_CSS;
421 			newreno_log_hystart_event(ccv, nreno, 9, CCV(ccv, snd_ssthresh));
422 		}
423 		if (!IN_CONGRECOVERY(CCV(ccv, t_flags))) {
424 			CCV(ccv, snd_ssthresh) = cwin;
425 			CCV(ccv, snd_cwnd) = cwin;
426 			ENTER_CONGRECOVERY(CCV(ccv, t_flags));
427 		}
428 		break;
429 	case CC_RTO:
430 		if (CCV(ccv, t_rxtshift) == 1) {
431 			if (V_tcp_do_newsack) {
432 				pipe = tcp_compute_pipe(ccv->ccvc.tcp);
433 			} else {
434 				pipe = CCV(ccv, snd_max) -
435 					CCV(ccv, snd_fack) +
436 					CCV(ccv, sackhint.sack_bytes_rexmit);
437 			}
438 			CCV(ccv, snd_ssthresh) = max(2,
439 				((uint64_t)min(CCV(ccv, snd_wnd), pipe) *
440 				    (uint64_t)factor) /
441 				    (100ULL * (uint64_t)mss)) * mss;
442 		}
443 		CCV(ccv, snd_cwnd) = mss;
444 		break;
445 	default:
446 		break;
447 	}
448 }
449 
450 static int
451 newreno_ctl_output(struct cc_var *ccv, struct sockopt *sopt, void *buf)
452 {
453 	struct newreno *nreno;
454 	struct cc_newreno_opts *opt;
455 
456 	if (sopt->sopt_valsize != sizeof(struct cc_newreno_opts))
457 		return (EMSGSIZE);
458 
459 	if (CC_ALGO(ccv->ccvc.tcp) != &newreno_cc_algo)
460 		return (ENOPROTOOPT);
461 
462 	nreno = (struct newreno *)ccv->cc_data;
463 	opt = buf;
464 	switch (sopt->sopt_dir) {
465 	case SOPT_SET:
466 		switch (opt->name) {
467 		case CC_NEWRENO_BETA:
468 			nreno->beta = opt->val;
469 			break;
470 		case CC_NEWRENO_BETA_ECN:
471 			nreno->beta_ecn = opt->val;
472 			nreno->newreno_flags |= CC_NEWRENO_BETA_ECN_ENABLED;
473 			break;
474 		default:
475 			return (ENOPROTOOPT);
476 		}
477 		break;
478 	case SOPT_GET:
479 		switch (opt->name) {
480 		case CC_NEWRENO_BETA:
481 			opt->val =  nreno->beta;
482 			break;
483 		case CC_NEWRENO_BETA_ECN:
484 			opt->val = nreno->beta_ecn;
485 			break;
486 		default:
487 			return (ENOPROTOOPT);
488 		}
489 		break;
490 	default:
491 		return (EINVAL);
492 	}
493 
494 	return (0);
495 }
496 
497 static int
498 newreno_beta_handler(SYSCTL_HANDLER_ARGS)
499 {
500 	int error;
501 	uint32_t new;
502 
503 	new = *(uint32_t *)arg1;
504 	error = sysctl_handle_int(oidp, &new, 0, req);
505 	if (error == 0 && req->newptr != NULL ) {
506 		if (arg1 == &VNET_NAME(newreno_beta_ecn) && !V_cc_do_abe)
507 			error = EACCES;
508 		else if (new == 0 || new > 100)
509 			error = EINVAL;
510 		else
511 			*(uint32_t *)arg1 = new;
512 	}
513 
514 	return (error);
515 }
516 
517 static void
518 newreno_newround(struct cc_var *ccv, uint32_t round_cnt)
519 {
520 	struct newreno *nreno;
521 
522 	nreno = (struct newreno *)ccv->cc_data;
523 	/* We have entered a new round */
524 	nreno->css_lastround_minrtt = nreno->css_current_round_minrtt;
525 	nreno->css_current_round_minrtt = 0xffffffff;
526 	nreno->css_rttsample_count = 0;
527 	nreno->css_current_round = round_cnt;
528 	if ((nreno->newreno_flags & CC_NEWRENO_HYSTART_IN_CSS) &&
529 	    ((round_cnt - nreno->css_entered_at_round) >= hystart_css_rounds)) {
530 		/* Enter CA */
531 		if (ccv->flags & CCF_HYSTART_CAN_SH_CWND) {
532 			/*
533 			 * We engage more than snd_ssthresh, engage
534 			 * the brakes!! Though we will stay in SS to
535 			 * creep back up again, so lets leave CSS active
536 			 * and give us hystart_css_rounds more rounds.
537 			 */
538 			if (ccv->flags & CCF_HYSTART_CONS_SSTH) {
539 				CCV(ccv, snd_ssthresh) = ((nreno->css_lowrtt_fas + nreno->css_fas_at_css_entry) / 2);
540 			} else {
541 				CCV(ccv, snd_ssthresh) = nreno->css_lowrtt_fas;
542 			}
543 			CCV(ccv, snd_cwnd) = nreno->css_fas_at_css_entry;
544 			nreno->css_entered_at_round = round_cnt;
545 		} else {
546 			CCV(ccv, snd_ssthresh) = CCV(ccv, snd_cwnd);
547 			/* Turn off the CSS flag */
548 			nreno->newreno_flags &= ~CC_NEWRENO_HYSTART_IN_CSS;
549 			/* Disable use of CSS in the future except long idle  */
550 			nreno->newreno_flags &= ~CC_NEWRENO_HYSTART_ENABLED;
551 		}
552 		newreno_log_hystart_event(ccv, nreno, 6, CCV(ccv, snd_ssthresh));
553 	}
554 	if (nreno->newreno_flags & CC_NEWRENO_HYSTART_ENABLED)
555 		newreno_log_hystart_event(ccv, nreno, 4, round_cnt);
556 }
557 
558 static void
559 newreno_rttsample(struct cc_var *ccv, uint32_t usec_rtt, uint32_t rxtcnt, uint32_t fas)
560 {
561 	struct newreno *nreno;
562 
563 	nreno = (struct newreno *)ccv->cc_data;
564 	if (rxtcnt > 1) {
565 		/*
566 		 * Only look at RTT's that are non-ambiguous.
567 		 */
568 		return;
569 	}
570 	nreno->css_rttsample_count++;
571 	nreno->css_last_fas = fas;
572 	if (nreno->css_current_round_minrtt > usec_rtt) {
573 		nreno->css_current_round_minrtt = usec_rtt;
574 		nreno->css_lowrtt_fas = nreno->css_last_fas;
575 	}
576 	if ((nreno->css_rttsample_count >= hystart_n_rttsamples) &&
577 	    (nreno->css_current_round_minrtt != 0xffffffff) &&
578 	    (nreno->css_current_round_minrtt < nreno->css_baseline_minrtt) &&
579 	    (nreno->css_lastround_minrtt != 0xffffffff)) {
580 		/*
581 		 * We were in CSS and the RTT is now less, we
582 		 * entered CSS erroneously.
583 		 */
584 		nreno->newreno_flags &= ~CC_NEWRENO_HYSTART_IN_CSS;
585 		newreno_log_hystart_event(ccv, nreno, 8, nreno->css_baseline_minrtt);
586 		nreno->css_baseline_minrtt = 0xffffffff;
587 	}
588 	if (nreno->newreno_flags & CC_NEWRENO_HYSTART_ENABLED)
589 		newreno_log_hystart_event(ccv, nreno, 5, usec_rtt);
590 }
591 
592 SYSCTL_DECL(_net_inet_tcp_cc_newreno);
593 SYSCTL_NODE(_net_inet_tcp_cc, OID_AUTO, newreno,
594     CTLFLAG_RW | CTLFLAG_MPSAFE, NULL,
595     "New Reno related settings");
596 
597 SYSCTL_PROC(_net_inet_tcp_cc_newreno, OID_AUTO, beta,
598     CTLFLAG_VNET | CTLTYPE_UINT | CTLFLAG_RW | CTLFLAG_NEEDGIANT,
599     &VNET_NAME(newreno_beta), 3, &newreno_beta_handler, "IU",
600     "New Reno beta, specified as number between 1 and 100");
601 
602 SYSCTL_PROC(_net_inet_tcp_cc_newreno, OID_AUTO, beta_ecn,
603     CTLFLAG_VNET | CTLTYPE_UINT | CTLFLAG_RW | CTLFLAG_NEEDGIANT,
604     &VNET_NAME(newreno_beta_ecn), 3, &newreno_beta_handler, "IU",
605     "New Reno beta ecn, specified as number between 1 and 100");
606 
607 DECLARE_CC_MODULE(newreno, &newreno_cc_algo);
608 MODULE_VERSION(newreno, 2);
609