xref: /freebsd/sys/netinet/tcp_stacks/tcp_rack.h (revision 5956d97f4b3204318ceb6aa9c77bd0bc6ea87a41)
1 /*-
2  * Copyright (c) 2016-2020 Netflix, Inc.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
14  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
17  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23  * SUCH DAMAGE.
24  *
25  * $FreeBSD$
26  */
27 
28 #ifndef _NETINET_TCP_RACK_H_
29 #define _NETINET_TCP_RACK_H_
30 
31 #define RACK_ACKED	    0x000001/* The remote endpoint acked this */
32 #define RACK_TO_REXT	    0x000002/* A timeout occured on this sendmap entry */
33 #define RACK_DEFERRED	    0x000004/* We can't use this for RTT calc - not used */
34 #define RACK_OVERMAX	    0x000008/* We have more retran's then we can fit */
35 #define RACK_SACK_PASSED    0x000010/* A sack was done above this block */
36 #define RACK_WAS_SACKPASS   0x000020/* We retransmitted due to SACK pass */
37 #define RACK_HAS_FIN	    0x000040/* segment is sent with fin */
38 #define RACK_TLP	    0x000080/* segment sent as tail-loss-probe */
39 #define RACK_RWND_COLLAPSED 0x000100/* The peer collapsed the rwnd on the segment */
40 #define RACK_APP_LIMITED    0x000200/* We went app limited after this send */
41 #define RACK_WAS_ACKED	    0x000400/* a RTO undid the ack, but it already had a rtt calc done */
42 #define RACK_HAS_SYN	    0x000800/* SYN is on this guy */
43 #define RACK_SENT_W_DSACK   0x001000/* Sent with a dsack */
44 #define RACK_SENT_SP	    0x002000/* sent in slow path */
45 #define RACK_SENT_FP        0x004000/* sent in fast path */
46 #define RACK_HAD_PUSH	    0x008000/* Push was sent on original send */
47 #define RACK_MUST_RXT	    0x010000/* We must retransmit this rsm (non-sack/mtu chg)*/
48 #define RACK_NUM_OF_RETRANS 3
49 
50 #define RACK_INITIAL_RTO 1000000 /* 1 second in microseconds */
51 
52 #define RACK_REQ_AVG 3 	/* Must be less than 256 */
53 
54 struct rack_sendmap {
55 	TAILQ_ENTRY(rack_sendmap) r_tnext;	/* Time of transmit based next */
56 	uint32_t r_start;	/* Sequence number of the segment */
57 	uint32_t r_end;		/* End seq, this is 1 beyond actually */
58 	uint32_t r_rtr_bytes;	/* How many bytes have been retransmitted */
59 	uint32_t r_flags : 24,	/* Flags as defined above */
60 		 r_rtr_cnt : 8;	/* Retran count, index this -1 to get time */
61 	struct mbuf *m;
62 	uint32_t soff;
63 	uint32_t orig_m_len;
64 	uint32_t r_nseq_appl;	/* If this one is app limited, this is the nxt seq limited */
65 	uint8_t r_dupack;	/* Dup ack count */
66 	uint8_t r_in_tmap;	/* Flag to see if its in the r_tnext array */
67 	uint8_t r_limit_type;	/* is this entry counted against a limit? */
68 	uint8_t r_just_ret : 1, /* After sending, the next pkt was just returned, i.e. limited  */
69 		r_one_out_nr : 1,	/* Special case 1 outstanding and not in recovery */
70 		r_no_rtt_allowed : 1, /* No rtt measurement allowed */
71 		r_hw_tls : 1,
72 		r_avail : 4;
73 	uint64_t r_tim_lastsent[RACK_NUM_OF_RETRANS];
74 	uint64_t r_ack_arrival;	/* This is the time of ack-arrival (if SACK'd) */
75 	RB_ENTRY(rack_sendmap) r_next;		/* RB Tree next */
76 	uint32_t r_fas;		/* Flight at send */
77 };
78 
79 struct deferred_opt_list {
80 	TAILQ_ENTRY(deferred_opt_list) next;
81 	int optname;
82 	uint64_t optval;
83 };
84 
85 /*
86  * Timestamps in the rack sendmap are now moving to be
87  * uint64_t's. This means that if you want a uint32_t
88  * usec timestamp (the old usecond timestamp) you simply have
89  * to cast it to uint32_t. The reason we do this is not for
90  * wrap, but we need to get back, at times, to the millisecond
91  * timestamp that is used in the TSTMP option. To do this we
92  * can use the rack_ts_to_msec() inline below which can take
93  * the 64bit ts and make into the correct timestamp millisecond
94  * wise. Thats not possible with the 32bit usecond timestamp since
95  * the seconds wrap too quickly to cover all bases.
96  *
97  * There are quite a few places in rack where I simply cast
98  * back to uint32_t and then end up using the TSTMP_XX()
99  * macros. This is ok, but we could do simple compares if
100  * we ever decided to move all of those variables to 64 bits
101  * as well.
102  */
103 
104 inline uint64_t
105 rack_to_usec_ts(struct timeval *tv)
106 {
107 	return ((tv->tv_sec * HPTS_USEC_IN_SEC) + tv->tv_usec);
108 }
109 
110 inline uint32_t
111 rack_ts_to_msec(uint64_t ts)
112 {
113 	return((uint32_t)(ts / HPTS_MSEC_IN_SEC));
114 }
115 
116 
117 RB_HEAD(rack_rb_tree_head, rack_sendmap);
118 TAILQ_HEAD(rack_head, rack_sendmap);
119 TAILQ_HEAD(def_opt_head, deferred_opt_list);
120 
121 /* Map change logging */
122 #define MAP_MERGE	0x01
123 #define MAP_SPLIT	0x02
124 #define MAP_NEW		0x03
125 #define MAP_SACK_M1	0x04
126 #define MAP_SACK_M2	0x05
127 #define MAP_SACK_M3	0x06
128 #define MAP_SACK_M4	0x07
129 #define MAP_SACK_M5	0x08
130 #define MAP_FREE	0x09
131 #define MAP_TRIM_HEAD	0x0a
132 
133 #define RACK_LIMIT_TYPE_SPLIT	1
134 
135 /*
136  * We use the rate sample structure to
137  * assist in single sack/ack rate and rtt
138  * calculation. In the future we will expand
139  * this in BBR to do forward rate sample
140  * b/w estimation.
141  */
142 #define RACK_RTT_EMPTY 0x00000001	/* Nothing yet stored in RTT's */
143 #define RACK_RTT_VALID 0x00000002	/* We have at least one valid RTT */
144 struct rack_rtt_sample {
145 	uint32_t rs_flags;
146 	uint32_t rs_rtt_lowest;
147 	uint32_t rs_rtt_highest;
148 	uint32_t rs_rtt_cnt;
149 	uint32_t rs_us_rtt;
150 	int32_t  confidence;
151 	uint64_t rs_rtt_tot;
152 	uint16_t rs_us_rtrcnt;
153 };
154 
155 #define RACK_LOG_TYPE_ACK	0x01
156 #define RACK_LOG_TYPE_OUT	0x02
157 #define RACK_LOG_TYPE_TO	0x03
158 #define RACK_LOG_TYPE_ALLOC     0x04
159 #define RACK_LOG_TYPE_FREE      0x05
160 
161 /*
162  * Magic numbers for logging timeout events if the
163  * logging is enabled.
164  */
165 #define RACK_TO_FRM_TMR  1
166 #define RACK_TO_FRM_TLP  2
167 #define RACK_TO_FRM_RACK 3
168 #define RACK_TO_FRM_KEEP 4
169 #define RACK_TO_FRM_PERSIST 5
170 #define RACK_TO_FRM_DELACK 6
171 
172 struct rack_opts_stats {
173 	uint64_t tcp_rack_tlp_reduce;
174 	uint64_t tcp_rack_pace_always;
175 	uint64_t tcp_rack_pace_reduce;
176 	uint64_t tcp_rack_max_seg;
177 	uint64_t tcp_rack_prr_sendalot;
178 	uint64_t tcp_rack_min_to;
179 	uint64_t tcp_rack_early_seg;
180 	uint64_t tcp_rack_reord_thresh;
181 	uint64_t tcp_rack_reord_fade;
182 	uint64_t tcp_rack_tlp_thresh;
183 	uint64_t tcp_rack_pkt_delay;
184 	uint64_t tcp_rack_tlp_inc_var;
185 	uint64_t tcp_tlp_use;
186 	uint64_t tcp_rack_idle_reduce;
187 	uint64_t tcp_rack_idle_reduce_high;
188 	uint64_t rack_no_timer_in_hpts;
189 	uint64_t tcp_rack_min_pace_seg;
190 	uint64_t tcp_rack_pace_rate_ca;
191 	uint64_t tcp_rack_rr;
192 	uint64_t tcp_rack_do_detection;
193 	uint64_t tcp_rack_rrr_no_conf_rate;
194 	uint64_t tcp_initial_rate;
195 	uint64_t tcp_initial_win;
196 	uint64_t tcp_hdwr_pacing;
197 	uint64_t tcp_gp_inc_ss;
198 	uint64_t tcp_gp_inc_ca;
199 	uint64_t tcp_gp_inc_rec;
200 	uint64_t tcp_rack_force_max_seg;
201 	uint64_t tcp_rack_pace_rate_ss;
202 	uint64_t tcp_rack_pace_rate_rec;
203 	/* Temp counters for dsack */
204 	uint64_t tcp_sack_path_1;
205 	uint64_t tcp_sack_path_2a;
206 	uint64_t tcp_sack_path_2b;
207 	uint64_t tcp_sack_path_3;
208 	uint64_t tcp_sack_path_4;
209 	/* non temp counters */
210 	uint64_t tcp_rack_scwnd;
211 	uint64_t tcp_rack_noprr;
212 	uint64_t tcp_rack_cfg_rate;
213 	uint64_t tcp_timely_dyn;
214 	uint64_t tcp_rack_mbufq;
215 	uint64_t tcp_fillcw;
216 	uint64_t tcp_npush;
217 	uint64_t tcp_lscwnd;
218 	uint64_t tcp_profile;
219 	uint64_t tcp_hdwr_rate_cap;
220 	uint64_t tcp_pacing_rate_cap;
221 	uint64_t tcp_pacing_up_only;
222 	uint64_t tcp_use_cmp_acks;
223 	uint64_t tcp_rack_abc_val;
224 	uint64_t tcp_rec_abc_val;
225 	uint64_t tcp_rack_measure_cnt;
226 	uint64_t tcp_rack_delayed_ack;
227 	uint64_t tcp_rack_rtt_use;
228 	uint64_t tcp_data_after_close;
229 	uint64_t tcp_defer_opt;
230 	uint64_t tcp_rack_fastrsm_hack;
231 	uint64_t tcp_rack_beta;
232 	uint64_t tcp_rack_beta_ecn;
233 	uint64_t tcp_rack_timer_slop;
234 	uint64_t tcp_rack_dsack_opt;
235 };
236 
237 /* RTT shrink reasons */
238 #define RACK_RTTS_INIT     0
239 #define RACK_RTTS_NEWRTT   1
240 #define RACK_RTTS_EXITPROBE 2
241 #define RACK_RTTS_ENTERPROBE 3
242 #define RACK_RTTS_REACHTARGET 4
243 #define RACK_RTTS_SEEHBP 5
244 #define RACK_RTTS_NOBACKOFF 6
245 #define RACK_RTTS_SAFETY 7
246 
247 #define RACK_USE_BEG 1
248 #define RACK_USE_END 2
249 #define RACK_USE_END_OR_THACK 3
250 
251 #define TLP_USE_ID	1	/* Internet draft behavior */
252 #define TLP_USE_TWO_ONE 2	/* Use 2.1 behavior */
253 #define TLP_USE_TWO_TWO 3	/* Use 2.2 behavior */
254 #define RACK_MIN_BW 8000	/* 64kbps in Bps */
255 
256 /* Rack quality indicators for GPUT measurements */
257 #define RACK_QUALITY_NONE	0	/* No quality stated */
258 #define RACK_QUALITY_HIGH 	1	/* A normal measurement of a GP RTT */
259 #define RACK_QUALITY_APPLIMITED	2 	/* An app limited case that may be of lower quality */
260 #define RACK_QUALITY_PERSIST	3	/* A measurement where we went into persists */
261 #define RACK_QUALITY_PROBERTT	4	/* A measurement where we went into or exited probe RTT */
262 #define RACK_QUALITY_ALLACKED	5	/* All data is now acknowledged */
263 
264 /*********************/
265 /* Rack Trace points */
266 /*********************/
267 /*
268  * Rack trace points are interesting points within
269  * the rack code that the author/debugger may want
270  * to have BB logging enabled if we hit that point.
271  * In order to enable a trace point you set the
272  * sysctl var net.inet.tcp.<stack>.tp.number to
273  * one of the numbers listed below. You also
274  * must make sure net.inet.tcp.<stack>.tp.bbmode is
275  * non-zero, the default is 4 for continuous tracing.
276  * You also set in the number of connections you want
277  * have get BB logs in net.inet.tcp.<stack>.tp.count.
278  *
279  * Count will decrement every time BB logging is assigned
280  * to a connection that hit your tracepoint.
281  *
282  * You can enable all trace points by setting the number
283  * to 0xffffffff. You can disable all trace points by
284  * setting number to zero (or count to 0).
285  *
286  * Below are the enumerated list of tracepoints that
287  * have currently been defined in the code. Add more
288  * as you add a call to rack_trace_point(rack, <name>);
289  * where <name> is defined below.
290  */
291 #define RACK_TP_HWENOBUF	0x00000001	/* When we are doing hardware pacing and hit enobufs */
292 #define RACK_TP_ENOBUF		0x00000002	/* When we hit enobufs with software pacing */
293 #define RACK_TP_COLLAPSED_WND	0x00000003	/* When a peer to collapses its rwnd on us */
294 
295 #define MIN_GP_WIN 6	/* We need at least 6 MSS in a GP measurement */
296 #ifdef _KERNEL
297 #define RACK_OPTS_SIZE (sizeof(struct rack_opts_stats)/sizeof(uint64_t))
298 extern counter_u64_t rack_opts_arry[RACK_OPTS_SIZE];
299 #define RACK_OPTS_ADD(name, amm) counter_u64_add(rack_opts_arry[(offsetof(struct rack_opts_stats, name)/sizeof(uint64_t))], (amm))
300 #define RACK_OPTS_INC(name) RACK_OPTS_ADD(name, 1)
301 #endif
302 /*
303  * As we get each SACK we wade through the
304  * rc_map and mark off what is acked.
305  * We also increment rc_sacked as well.
306  *
307  * We also pay attention to missing entries
308  * based on the time and possibly mark them
309  * for retransmit. If we do and we are not already
310  * in recovery we enter recovery. In doing
311  * so we claer prr_delivered/holes_rxt and prr_sent_dur_rec.
312  * We also setup rc_next/rc_snd_nxt/rc_send_end so
313  * we will know where to send from. When not in
314  * recovery rc_next will be NULL and rc_snd_nxt should
315  * equal snd_max.
316  *
317  * Whenever we retransmit from recovery we increment
318  * rc_holes_rxt as we retran a block and mark it as retransmitted
319  * with the time it was sent. During non-recovery sending we
320  * add to our map and note the time down of any send expanding
321  * the rc_map at the tail and moving rc_snd_nxt up with snd_max.
322  *
323  * In recovery during SACK/ACK processing if a chunk has
324  * been retransmitted and it is now acked, we decrement rc_holes_rxt.
325  * When we retransmit from the scoreboard we use
326  * rc_next and rc_snd_nxt/rc_send_end to help us
327  * find what needs to be retran.
328  *
329  * To calculate pipe we simply take (snd_max - snd_una) + rc_holes_rxt
330  * This gets us the effect of RFC6675 pipe, counting twice for
331  * bytes retransmitted.
332  */
333 
334 #define TT_RACK_FR_TMR	0x2000
335 
336 /*
337  * Locking for the rack control block.
338  * a) Locked by INP_WLOCK
339  * b) Locked by the hpts-mutex
340  *
341  */
342 #define RACK_GP_HIST 4	/* How much goodput history do we maintain? */
343 
344 #define RACK_NUM_FSB_DEBUG 16
345 #ifdef _KERNEL
346 struct rack_fast_send_blk {
347 	uint32_t left_to_send;
348 	uint16_t tcp_ip_hdr_len;
349 	uint8_t tcp_flags;
350 	uint8_t hoplimit;
351 	uint8_t *tcp_ip_hdr;
352 	uint32_t recwin;
353 	uint32_t off;
354 	struct tcphdr *th;
355 	struct udphdr *udp;
356 	struct mbuf *m;
357 	uint32_t o_m_len;
358 	uint32_t rfo_apply_push : 1,
359 		hw_tls : 1,
360 		unused : 30;
361 };
362 
363 struct rack_control {
364 	/* Second cache line 0x40 from tcp_rack */
365 	struct rack_rb_tree_head rc_mtree; /* Tree of all segments Lock(a) */
366 	struct rack_head rc_tmap;	/* List in transmit order Lock(a) */
367 	struct rack_sendmap *rc_tlpsend;	/* Remembered place for
368 						 * tlp_sending Lock(a) */
369 	struct rack_sendmap *rc_resend;	/* something we have been asked to
370 					 * resend */
371 	struct rack_fast_send_blk fsb;	/* The fast-send block */
372 	uint32_t timer_slop;
373 	uint32_t input_pkt;
374 	uint32_t saved_input_pkt;
375 	uint32_t rc_hpts_flags;
376 	uint32_t rc_fixed_pacing_rate_ca;
377 	uint32_t rc_fixed_pacing_rate_rec;
378 	uint32_t rc_fixed_pacing_rate_ss;
379 	uint32_t cwnd_to_use;	/* The cwnd in use */
380 	uint32_t rc_timer_exp;	/* If a timer ticks of expiry */
381 	uint32_t rc_rack_min_rtt;	/* lowest RTT seen Lock(a) */
382 	uint32_t rc_rack_largest_cwnd;	/* Largest CWND we have seen Lock(a) */
383 
384 	/* Third Cache line 0x80 */
385 	struct rack_head rc_free;	/* Allocation array */
386 	uint64_t last_hw_bw_req;
387 	uint64_t crte_prev_rate;
388 	uint64_t bw_rate_cap;
389 	uint32_t rc_reorder_ts;	/* Last time we saw reordering Lock(a) */
390 
391 	uint32_t rc_tlp_new_data;	/* we need to send new-data on a TLP
392 					 * Lock(a) */
393 	uint32_t rc_prr_out;	/* bytes sent during recovery Lock(a) */
394 
395 	uint32_t rc_prr_recovery_fs;	/* recovery fs point Lock(a) */
396 
397 	uint32_t rc_prr_sndcnt;	/* Prr sndcnt Lock(a) */
398 
399 	uint32_t rc_sacked;	/* Tot sacked on scoreboard Lock(a) */
400 	uint32_t last_sent_tlp_seq;	/* Last tlp sequence that was retransmitted Lock(a) */
401 
402 	uint32_t rc_prr_delivered;	/* during recovery prr var Lock(a) */
403 	uint16_t rc_tlp_cnt_out;	/* count of times we have sent a TLP without new data */
404 	uint16_t last_sent_tlp_len;	/* Number of bytes in the last sent tlp */
405 
406 	uint32_t rc_loss_count;	/* How many bytes have been retransmitted
407 				 * Lock(a) */
408 	uint32_t rc_reorder_fade;	/* Socket option value Lock(a) */
409 
410 	/* Forth cache line 0xc0  */
411 	/* Times */
412 
413 	uint32_t rc_rack_tmit_time;	/* Rack transmit time Lock(a) */
414 	uint32_t rc_holes_rxt;	/* Tot retraned from scoreboard Lock(a) */
415 
416 	uint32_t rc_num_maps_alloced;	/* Number of map blocks (sacks) we
417 					 * have allocated */
418 	uint32_t rc_rcvtime;	/* When we last received data */
419 	uint32_t rc_num_split_allocs;	/* num split map entries allocated */
420 
421 	uint32_t rc_last_output_to;
422 	uint32_t rc_went_idle_time;
423 
424 	struct rack_sendmap *rc_sacklast;	/* sack remembered place
425 						 * Lock(a) */
426 
427 	struct rack_sendmap *rc_first_appl;	/* Pointer to first app limited */
428 	struct rack_sendmap *rc_end_appl;	/* Pointer to last app limited */
429 	/* Cache line split 0x100 */
430 	struct sack_filter rack_sf;
431 	/* Cache line split 0x140 */
432 	/* Flags for various things */
433 	uint32_t rc_pace_max_segs;
434 	uint32_t rc_pace_min_segs;
435 	uint32_t rc_app_limited_cnt;
436 	uint16_t rack_per_of_gp_ss; /* 100 = 100%, so from 65536 = 655 x bw  */
437 	uint16_t rack_per_of_gp_ca; /* 100 = 100%, so from 65536 = 655 x bw  */
438 	uint16_t rack_per_of_gp_rec; /* 100 = 100%, so from 65536 = 655 x bw, 0=off */
439 	uint16_t rack_per_of_gp_probertt; /* 100 = 100%, so from 65536 = 655 x bw, 0=off */
440 	uint32_t rc_high_rwnd;
441 	uint32_t ack_count;
442 	uint32_t sack_count;
443 	uint32_t sack_noextra_move;
444 	uint32_t sack_moved_extra;
445 	struct rack_rtt_sample rack_rs;
446 	const struct tcp_hwrate_limit_table *crte;
447 	uint32_t rc_agg_early;
448 	uint32_t rc_agg_delayed;
449 	uint32_t rc_tlp_rxt_last_time;
450 	uint32_t rc_saved_cwnd;
451 	uint64_t rc_gp_output_ts; /* chg*/
452 	uint64_t rc_gp_cumack_ts; /* chg*/
453 	struct timeval act_rcv_time;
454 	struct timeval rc_last_time_decay;	/* SAD time decay happened here */
455 	uint64_t gp_bw;
456 	uint64_t init_rate;
457 #ifdef NETFLIX_SHARED_CWND
458 	struct shared_cwnd *rc_scw;
459 #endif
460 	uint64_t last_gp_comp_bw;
461 	uint64_t last_max_bw;	/* Our calculated max b/w last */
462 	struct time_filter_small rc_gp_min_rtt;
463 	struct def_opt_head opt_list;
464 	int32_t rc_rtt_diff;		/* Timely style rtt diff of our gp_srtt */
465 	uint32_t rc_gp_srtt;		/* Current GP srtt */
466 	uint32_t rc_prev_gp_srtt;	/* Previous RTT */
467 	uint32_t rc_entry_gp_rtt;	/* Entry to PRTT gp-rtt */
468 	uint32_t rc_loss_at_start;	/* At measurement window where was our lost value */
469 
470 	uint32_t dsack_round_end;	/* In a round of seeing a DSACK */
471 	uint32_t current_round;		/* Starting at zero */
472 	uint32_t roundends;		/* acked value above which round ends */
473 	uint32_t num_dsack;		/* Count of dsack's seen  (1 per window)*/
474 	uint32_t forced_ack_ts;
475 	uint32_t rc_lower_rtt_us_cts;	/* Time our GP rtt was last lowered */
476 	uint32_t rc_time_probertt_entered;
477 	uint32_t rc_time_probertt_starts;
478 	uint32_t rc_lowest_us_rtt;
479 	uint32_t rc_highest_us_rtt;
480 	uint32_t rc_last_us_rtt;
481 	uint32_t rc_time_of_last_probertt;
482 	uint32_t rc_target_probertt_flight;
483 	uint32_t rc_probertt_sndmax_atexit;	/* Highest sent to in probe-rtt */
484 	uint32_t rc_cwnd_at_erec;
485 	uint32_t rc_ssthresh_at_erec;
486 	uint32_t dsack_byte_cnt;
487 	uint32_t retran_during_recovery;
488 	uint32_t rc_gp_lowrtt;			/* Lowest rtt seen during GPUT measurement */
489 	uint32_t rc_gp_high_rwnd;		/* Highest rwnd seen during GPUT measurement */
490 	uint32_t rc_snd_max_at_rto;	/* For non-sack when the RTO occured what was snd-max */
491 	uint32_t rc_out_at_rto;
492 	int32_t rc_scw_index;
493 	uint32_t rc_tlp_threshold;	/* Socket option value Lock(a) */
494 	uint32_t rc_last_timeout_snduna;
495 	uint32_t last_tlp_acked_start;
496 	uint32_t last_tlp_acked_end;
497 	uint32_t challenge_ack_ts;
498 	uint32_t challenge_ack_cnt;
499 	uint32_t rc_min_to;	/* Socket option value Lock(a) */
500 	uint32_t rc_pkt_delay;	/* Socket option value Lock(a) */
501 	uint32_t persist_lost_ends;
502 	struct newreno rc_saved_beta;	/*
503 					 * For newreno cc:
504 					 * rc_saved_cc are the values we have had
505 					 * set by the user, if pacing is not happening
506 					 * (i.e. its early and we have not turned on yet
507 					 *  or it was turned off). The minute pacing
508 					 * is turned on we pull out the values currently
509 					 * being used by newreno and replace them with
510 					 * these values, then save off the old values here,
511 					 * we also set the flag (if ecn_beta is set) to make
512 					 * new_reno do less of a backoff for ecn (think abe).
513 					 */
514 	uint16_t rc_early_recovery_segs;	/* Socket option value Lock(a) */
515 	uint16_t rc_reorder_shift;	/* Socket option value Lock(a) */
516 	uint8_t dsack_persist;
517 	uint8_t rc_no_push_at_mrtt;	/* No push when we exceed max rtt */
518 	uint8_t num_measurements;	/* Number of measurements (up to 0xff, we freeze at 0xff)  */
519 	uint8_t req_measurements;	/* How many measurements are required? */
520 	uint8_t rc_tlp_cwnd_reduce;	/* Socket option value Lock(a) */
521 	uint8_t rc_prr_sendalot;/* Socket option value Lock(a) */
522 	uint8_t rc_rate_sample_method;
523 };
524 #endif
525 
526 #define RACK_TIMELY_CNT_BOOST 5	/* At 5th increase boost */
527 #define RACK_MINRTT_FILTER_TIM 10 /* Seconds */
528 
529 #define RACK_HYSTART_OFF	0
530 #define RACK_HYSTART_ON		1	/* hystart++ on */
531 #define RACK_HYSTART_ON_W_SC	2	/* hystart++ on +Slam Cwnd */
532 #define RACK_HYSTART_ON_W_SC_C	3	/* hystart++ on,
533 					 * Conservative ssthresh and
534 					 * +Slam cwnd
535 					 */
536 
537 #ifdef _KERNEL
538 
539 struct tcp_rack {
540 	/* First cache line 0x00 */
541 	TAILQ_ENTRY(tcp_rack) r_hpts;	/* hptsi queue next Lock(b) */
542 	int32_t(*r_substate) (struct mbuf *, struct tcphdr *,
543 	    struct socket *, struct tcpcb *, struct tcpopt *,
544 	    int32_t, int32_t, uint32_t, int, int, uint8_t);	/* Lock(a) */
545 	struct tcpcb *rc_tp;	/* The tcpcb Lock(a) */
546 	struct inpcb *rc_inp;	/* The inpcb Lock(a) */
547 	uint8_t rc_free_cnt;	/* Number of free entries on the rc_free list
548 				 * Lock(a) */
549 	uint8_t client_bufferlvl;	/* 0 - 5 normaly, less than or at 2 means its real low */
550 	uint8_t no_prr_addback : 1,
551 		gp_ready : 1,
552 		defer_options: 1,
553 		fast_rsm_hack: 1,
554 		rc_ack_can_sendout_data: 1, /*
555 					     * If set it will override pacing restrictions on not sending
556 					     * data when the pacing timer is running. I.e. you set this
557 					     * and an ACK will send data. Default is off and its only used
558 					     * without pacing when we are doing 5G speed up for there
559 					     * ack filtering.
560 					     */
561 		rc_pacing_cc_set: 1,	     /*
562 					      * If we are pacing (pace_always=1) and we have reached the
563 					      * point where we start pacing (fixed or gp has reached its
564 					      * magic gp_ready state) this flag indicates we have set in
565 					      * values to effect CC's backoff's. If pacing is turned off
566 					      * then we must restore the values saved in rc_saved_beta,
567 					      * if its going to gp_ready we need to copy the values into
568 					      * the CC module and set our flags.
569 					      *
570 					      * Note this only happens if the cc name is newreno (CCALGONAME_NEWRENO).
571 					      */
572 
573 		rc_rack_tmr_std_based :1,
574 		rc_rack_use_dsack: 1;
575 	uint8_t rc_dsack_round_seen: 1,
576 		rc_last_tlp_acked_set: 1,
577 		rc_last_tlp_past_cumack: 1,
578 		rc_last_sent_tlp_seq_valid: 1,
579 		rc_last_sent_tlp_past_cumack: 1,
580 		probe_not_answered: 1,
581 		avail_bytes : 2;
582 	uint32_t rc_rack_rtt;	/* RACK-RTT Lock(a) */
583 	uint16_t r_mbuf_queue : 1,	/* Do we do mbuf queue for non-paced */
584 		 rtt_limit_mul : 4,	/* muliply this by low rtt */
585 		 r_limit_scw : 1,
586 		 r_must_retran : 1,	/* For non-sack customers we hit an RTO and new data should be resends */
587 		 r_use_cmp_ack: 1,	/* Do we use compressed acks */
588 		 r_ent_rec_ns: 1,	/* We entered recovery and have not sent */
589 		 r_might_revert: 1,	/* Flag to find out if we might need to revert */
590 		 r_fast_output: 1, 	/* Fast output is in progress we can skip the bulk of rack_output */
591 		 r_fsb_inited: 1,
592 		 r_rack_hw_rate_caps: 1,
593 		 r_up_only: 1,
594 		 r_via_fill_cw : 1,
595 		 r_fill_less_agg : 1;
596 
597 	uint8_t rc_user_set_max_segs;	/* Socket option value Lock(a) */
598 	uint8_t rc_labc;		/* Appropriate Byte Counting Value */
599 	uint16_t forced_ack : 1,
600 		rc_gp_incr : 1,
601 		rc_gp_bwred : 1,
602 		rc_gp_timely_inc_cnt : 3,
603 		rc_gp_timely_dec_cnt : 3,
604 		r_use_labc_for_rec: 1,
605 		rc_highly_buffered: 1,		/* The path is highly buffered */
606 		rc_dragged_bottom: 1,
607 		rc_dack_mode : 1,		/* Mac O/S emulation of d-ack */
608 		rc_dack_toggle : 1,		/* For Mac O/S emulation of d-ack */
609 		rc_gp_filled : 1,
610 		rc_is_spare : 1;
611 	uint8_t r_state;	/* Current rack state Lock(a) */
612 	uint8_t rc_tmr_stopped : 7,
613 		t_timers_stopped : 1;
614 	uint8_t rc_enobuf : 7,	/* count of enobufs on connection provides */
615 		rc_on_min_to : 1;
616 	uint8_t r_timer_override : 1,	/* hpts override Lock(a) */
617 		r_is_v6 : 1,	/* V6 pcb Lock(a)  */
618 		rc_in_persist : 1,
619 		rc_tlp_in_progress : 1,
620 		rc_always_pace : 1,	/* Socket option value Lock(a) */
621 		rc_pace_to_cwnd : 1,
622 		rc_pace_fill_if_rttin_range : 1,
623 		rc_srtt_measure_made : 1;
624 	uint8_t app_limited_needs_set : 1,
625 		use_fixed_rate : 1,
626 		rc_has_collapsed : 1,
627 		r_rep_attack : 1,
628 		r_rep_reverse : 1,
629 		rack_hdrw_pacing : 1,  /* We are doing Hardware pacing */
630 		rack_hdw_pace_ena : 1, /* Is hardware pacing enabled? */
631 		rack_attempt_hdwr_pace : 1; /* Did we attempt hdwr pacing (if allowed) */
632 	uint8_t rack_tlp_threshold_use : 3,	/* only 1, 2 and 3 used so far */
633 		rack_rec_nonrxt_use_cr : 1,
634 		rack_enable_scwnd : 1,
635 		rack_attempted_scwnd : 1,
636 		rack_no_prr : 1,
637 		rack_scwnd_is_idle : 1;
638 	uint8_t rc_allow_data_af_clo: 1,
639 		delayed_ack : 1,
640 		set_pacing_done_a_iw : 1,
641 		use_rack_rr : 1,
642 		alloc_limit_reported : 1,
643 		sack_attack_disable : 1,
644 		do_detection : 1,
645 		rc_force_max_seg : 1;
646 	uint8_t r_early : 1,
647 		r_late : 1,
648 		r_wanted_output: 1,
649 		r_rr_config : 2,
650 		rc_avail_bit : 3;
651 	uint16_t rc_init_win : 8,
652 		rc_gp_rtt_set : 1,
653 		rc_gp_dyn_mul : 1,
654 		rc_gp_saw_rec : 1,
655 		rc_gp_saw_ca : 1,
656 		rc_gp_saw_ss : 1,
657 		rc_gp_no_rec_chg : 1,
658 		in_probe_rtt : 1,
659 		measure_saw_probe_rtt : 1;
660 	/* Cache line 2 0x40 */
661 	struct rack_control r_ctl;
662 }        __aligned(CACHE_LINE_SIZE);
663 
664 #endif
665 #endif
666