xref: /freebsd/sys/netinet/cc/cc_newreno.c (revision 2e3f49888ec8851bafb22011533217487764fdb0)
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, uint16_t type);
88 static void	newreno_after_idle(struct cc_var *ccv);
89 static void	newreno_cong_signal(struct cc_var *ccv, uint32_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, uint16_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, uint32_t type)
367 {
368 	struct newreno *nreno;
369 	uint32_t beta, beta_ecn, cwin, factor;
370 	u_int mss;
371 
372 	cwin = CCV(ccv, snd_cwnd);
373 	mss = tcp_fixed_maxseg(ccv->ccvc.tcp);
374 	nreno = ccv->cc_data;
375 	beta = (nreno == NULL) ? V_newreno_beta : nreno->beta;;
376 	beta_ecn = (nreno == NULL) ? V_newreno_beta_ecn : nreno->beta_ecn;
377 	/*
378 	 * Note that we only change the backoff for ECN if the
379 	 * global sysctl V_cc_do_abe is set <or> the stack itself
380 	 * has set a flag in our newreno_flags (due to pacing) telling
381 	 * us to use the lower valued back-off.
382 	 */
383 	if ((type == CC_ECN) &&
384 	    (V_cc_do_abe ||
385 	    ((nreno != NULL) && (nreno->newreno_flags & CC_NEWRENO_BETA_ECN_ENABLED))))
386 		factor = beta_ecn;
387 	else
388 		factor = beta;
389 
390 	/* Catch algos which mistakenly leak private signal types. */
391 	KASSERT((type & CC_SIGPRIVMASK) == 0,
392 	    ("%s: congestion signal type 0x%08x is private\n", __func__, type));
393 
394 	cwin = max(((uint64_t)cwin * (uint64_t)factor) / (100ULL * (uint64_t)mss),
395 	    2) * mss;
396 
397 	switch (type) {
398 	case CC_NDUPACK:
399 		if (nreno->newreno_flags & CC_NEWRENO_HYSTART_ENABLED) {
400 			/* Make sure the flags are all off we had a loss */
401 			nreno->newreno_flags &= ~CC_NEWRENO_HYSTART_ENABLED;
402 			nreno->newreno_flags &= ~CC_NEWRENO_HYSTART_IN_CSS;
403 			newreno_log_hystart_event(ccv, nreno, 10, CCV(ccv, snd_ssthresh));
404 		}
405 		if (!IN_FASTRECOVERY(CCV(ccv, t_flags))) {
406 			if (IN_CONGRECOVERY(CCV(ccv, t_flags) &&
407 			    V_cc_do_abe && V_cc_abe_frlossreduce)) {
408 				CCV(ccv, snd_ssthresh) =
409 				    ((uint64_t)CCV(ccv, snd_ssthresh) *
410 				     (uint64_t)beta) / (uint64_t)beta_ecn;
411 			}
412 			if (!IN_CONGRECOVERY(CCV(ccv, t_flags)))
413 				CCV(ccv, snd_ssthresh) = cwin;
414 			ENTER_RECOVERY(CCV(ccv, t_flags));
415 		}
416 		break;
417 	case CC_ECN:
418 		if (nreno->newreno_flags & CC_NEWRENO_HYSTART_ENABLED) {
419 			/* Make sure the flags are all off we had a loss */
420 			nreno->newreno_flags &= ~CC_NEWRENO_HYSTART_ENABLED;
421 			nreno->newreno_flags &= ~CC_NEWRENO_HYSTART_IN_CSS;
422 			newreno_log_hystart_event(ccv, nreno, 9, CCV(ccv, snd_ssthresh));
423 		}
424 		if (!IN_CONGRECOVERY(CCV(ccv, t_flags))) {
425 			CCV(ccv, snd_ssthresh) = cwin;
426 			CCV(ccv, snd_cwnd) = cwin;
427 			ENTER_CONGRECOVERY(CCV(ccv, t_flags));
428 		}
429 		break;
430 	case CC_RTO:
431 		CCV(ccv, snd_ssthresh) = max(min(CCV(ccv, snd_wnd),
432 						 CCV(ccv, snd_cwnd)) / 2 / mss,
433 					     2) * mss;
434 		CCV(ccv, snd_cwnd) = mss;
435 		break;
436 	}
437 }
438 
439 static int
440 newreno_ctl_output(struct cc_var *ccv, struct sockopt *sopt, void *buf)
441 {
442 	struct newreno *nreno;
443 	struct cc_newreno_opts *opt;
444 
445 	if (sopt->sopt_valsize != sizeof(struct cc_newreno_opts))
446 		return (EMSGSIZE);
447 
448 	if (CC_ALGO(ccv->ccvc.tcp) != &newreno_cc_algo)
449 		return (ENOPROTOOPT);
450 
451 	nreno = (struct newreno *)ccv->cc_data;
452 	opt = buf;
453 	switch (sopt->sopt_dir) {
454 	case SOPT_SET:
455 		switch (opt->name) {
456 		case CC_NEWRENO_BETA:
457 			nreno->beta = opt->val;
458 			break;
459 		case CC_NEWRENO_BETA_ECN:
460 			nreno->beta_ecn = opt->val;
461 			nreno->newreno_flags |= CC_NEWRENO_BETA_ECN_ENABLED;
462 			break;
463 		default:
464 			return (ENOPROTOOPT);
465 		}
466 		break;
467 	case SOPT_GET:
468 		switch (opt->name) {
469 		case CC_NEWRENO_BETA:
470 			opt->val =  nreno->beta;
471 			break;
472 		case CC_NEWRENO_BETA_ECN:
473 			opt->val = nreno->beta_ecn;
474 			break;
475 		default:
476 			return (ENOPROTOOPT);
477 		}
478 		break;
479 	default:
480 		return (EINVAL);
481 	}
482 
483 	return (0);
484 }
485 
486 static int
487 newreno_beta_handler(SYSCTL_HANDLER_ARGS)
488 {
489 	int error;
490 	uint32_t new;
491 
492 	new = *(uint32_t *)arg1;
493 	error = sysctl_handle_int(oidp, &new, 0, req);
494 	if (error == 0 && req->newptr != NULL ) {
495 		if (arg1 == &VNET_NAME(newreno_beta_ecn) && !V_cc_do_abe)
496 			error = EACCES;
497 		else if (new == 0 || new > 100)
498 			error = EINVAL;
499 		else
500 			*(uint32_t *)arg1 = new;
501 	}
502 
503 	return (error);
504 }
505 
506 static void
507 newreno_newround(struct cc_var *ccv, uint32_t round_cnt)
508 {
509 	struct newreno *nreno;
510 
511 	nreno = (struct newreno *)ccv->cc_data;
512 	/* We have entered a new round */
513 	nreno->css_lastround_minrtt = nreno->css_current_round_minrtt;
514 	nreno->css_current_round_minrtt = 0xffffffff;
515 	nreno->css_rttsample_count = 0;
516 	nreno->css_current_round = round_cnt;
517 	if ((nreno->newreno_flags & CC_NEWRENO_HYSTART_IN_CSS) &&
518 	    ((round_cnt - nreno->css_entered_at_round) >= hystart_css_rounds)) {
519 		/* Enter CA */
520 		if (ccv->flags & CCF_HYSTART_CAN_SH_CWND) {
521 			/*
522 			 * We engage more than snd_ssthresh, engage
523 			 * the brakes!! Though we will stay in SS to
524 			 * creep back up again, so lets leave CSS active
525 			 * and give us hystart_css_rounds more rounds.
526 			 */
527 			if (ccv->flags & CCF_HYSTART_CONS_SSTH) {
528 				CCV(ccv, snd_ssthresh) = ((nreno->css_lowrtt_fas + nreno->css_fas_at_css_entry) / 2);
529 			} else {
530 				CCV(ccv, snd_ssthresh) = nreno->css_lowrtt_fas;
531 			}
532 			CCV(ccv, snd_cwnd) = nreno->css_fas_at_css_entry;
533 			nreno->css_entered_at_round = round_cnt;
534 		} else {
535 			CCV(ccv, snd_ssthresh) = CCV(ccv, snd_cwnd);
536 			/* Turn off the CSS flag */
537 			nreno->newreno_flags &= ~CC_NEWRENO_HYSTART_IN_CSS;
538 			/* Disable use of CSS in the future except long idle  */
539 			nreno->newreno_flags &= ~CC_NEWRENO_HYSTART_ENABLED;
540 		}
541 		newreno_log_hystart_event(ccv, nreno, 6, CCV(ccv, snd_ssthresh));
542 	}
543 	if (nreno->newreno_flags & CC_NEWRENO_HYSTART_ENABLED)
544 		newreno_log_hystart_event(ccv, nreno, 4, round_cnt);
545 }
546 
547 static void
548 newreno_rttsample(struct cc_var *ccv, uint32_t usec_rtt, uint32_t rxtcnt, uint32_t fas)
549 {
550 	struct newreno *nreno;
551 
552 	nreno = (struct newreno *)ccv->cc_data;
553 	if (rxtcnt > 1) {
554 		/*
555 		 * Only look at RTT's that are non-ambiguous.
556 		 */
557 		return;
558 	}
559 	nreno->css_rttsample_count++;
560 	nreno->css_last_fas = fas;
561 	if (nreno->css_current_round_minrtt > usec_rtt) {
562 		nreno->css_current_round_minrtt = usec_rtt;
563 		nreno->css_lowrtt_fas = nreno->css_last_fas;
564 	}
565 	if ((nreno->css_rttsample_count >= hystart_n_rttsamples) &&
566 	    (nreno->css_current_round_minrtt != 0xffffffff) &&
567 	    (nreno->css_current_round_minrtt < nreno->css_baseline_minrtt) &&
568 	    (nreno->css_lastround_minrtt != 0xffffffff)) {
569 		/*
570 		 * We were in CSS and the RTT is now less, we
571 		 * entered CSS erroneously.
572 		 */
573 		nreno->newreno_flags &= ~CC_NEWRENO_HYSTART_IN_CSS;
574 		newreno_log_hystart_event(ccv, nreno, 8, nreno->css_baseline_minrtt);
575 		nreno->css_baseline_minrtt = 0xffffffff;
576 	}
577 	if (nreno->newreno_flags & CC_NEWRENO_HYSTART_ENABLED)
578 		newreno_log_hystart_event(ccv, nreno, 5, usec_rtt);
579 }
580 
581 SYSCTL_DECL(_net_inet_tcp_cc_newreno);
582 SYSCTL_NODE(_net_inet_tcp_cc, OID_AUTO, newreno,
583     CTLFLAG_RW | CTLFLAG_MPSAFE, NULL,
584     "New Reno related settings");
585 
586 SYSCTL_PROC(_net_inet_tcp_cc_newreno, OID_AUTO, beta,
587     CTLFLAG_VNET | CTLTYPE_UINT | CTLFLAG_RW | CTLFLAG_NEEDGIANT,
588     &VNET_NAME(newreno_beta), 3, &newreno_beta_handler, "IU",
589     "New Reno beta, specified as number between 1 and 100");
590 
591 SYSCTL_PROC(_net_inet_tcp_cc_newreno, OID_AUTO, beta_ecn,
592     CTLFLAG_VNET | CTLTYPE_UINT | CTLFLAG_RW | CTLFLAG_NEEDGIANT,
593     &VNET_NAME(newreno_beta_ecn), 3, &newreno_beta_handler, "IU",
594     "New Reno beta ecn, specified as number between 1 and 100");
595 
596 DECLARE_CC_MODULE(newreno, &newreno_cc_algo);
597 MODULE_VERSION(newreno, 2);
598