xref: /freebsd/sys/netinet/tcp_stacks/tcp_rack.h (revision 1d386b48a555f61cb7325543adbbb5c3f3407a66)
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 
26 #ifndef _NETINET_TCP_RACK_H_
27 #define _NETINET_TCP_RACK_H_
28 
29 #define RACK_ACKED	    0x000001/* The remote endpoint acked this */
30 #define RACK_TO_REXT	    0x000002/* A timeout occurred on this sendmap entry */
31 #define RACK_DEFERRED	    0x000004/* We can't use this for RTT calc - not used */
32 #define RACK_OVERMAX	    0x000008/* We have more retran's then we can fit */
33 #define RACK_SACK_PASSED    0x000010/* A sack was done above this block */
34 #define RACK_WAS_SACKPASS   0x000020/* We retransmitted due to SACK pass */
35 #define RACK_HAS_FIN	    0x000040/* segment is sent with fin */
36 #define RACK_TLP	    0x000080/* segment sent as tail-loss-probe */
37 #define RACK_RWND_COLLAPSED 0x000100/* The peer collapsed the rwnd on the segment */
38 #define RACK_APP_LIMITED    0x000200/* We went app limited after this send */
39 #define RACK_WAS_ACKED	    0x000400/* a RTO undid the ack, but it already had a rtt calc done */
40 #define RACK_HAS_SYN	    0x000800/* SYN is on this guy */
41 #define RACK_SENT_W_DSACK   0x001000/* Sent with a dsack */
42 #define RACK_SENT_SP	    0x002000/* sent in slow path */
43 #define RACK_SENT_FP        0x004000/* sent in fast path */
44 #define RACK_HAD_PUSH	    0x008000/* Push was sent on original send */
45 #define RACK_MUST_RXT	    0x010000/* We must retransmit this rsm (non-sack/mtu chg)*/
46 #define RACK_IN_GP_WIN	    0x020000/* Send was in GP window when sent */
47 #define RACK_SHUFFLED	    0x040000/* The RSM was shuffled some data from one to another */
48 #define RACK_MERGED	    0x080000/* The RSM was merged */
49 #define RACK_PMTU_CHG	    0x100000/* The path mtu changed on this guy */
50 #define RACK_STRADDLE	    0x200000/* The seq straddles the bucket line */
51 #define RACK_NUM_OF_RETRANS 3
52 
53 #define RACK_INITIAL_RTO 1000000 /* 1 second in microseconds */
54 
55 #define RACK_REQ_AVG 3 	/* Must be less than 256 */
56 
57 struct rack_sendmap {
58 	TAILQ_ENTRY(rack_sendmap) next;
59 	TAILQ_ENTRY(rack_sendmap) r_tnext;	/* Time of transmit based next */
60 	uint32_t bindex;
61 	uint32_t r_start;	/* Sequence number of the segment */
62 	uint32_t r_end;		/* End seq, this is 1 beyond actually */
63 	uint32_t r_rtr_bytes;	/* How many bytes have been retransmitted */
64 	uint32_t r_flags : 24,	/* Flags as defined above */
65 		 r_rtr_cnt : 8;	/* Retran count, index this -1 to get time */
66 	struct mbuf *m;
67 	uint32_t soff;
68 	uint32_t orig_m_len;	/* The original mbuf len when we sent (can update) */
69 	uint32_t orig_t_space;	/* The original trailing space when we sent (can update) */
70 	uint32_t r_nseq_appl;	/* If this one is app limited, this is the nxt seq limited */
71 	uint8_t r_dupack;	/* Dup ack count */
72 	uint8_t r_in_tmap;	/* Flag to see if its in the r_tnext array */
73 	uint8_t r_limit_type;	/* is this entry counted against a limit? */
74 	uint8_t r_just_ret : 1, /* After sending, the next pkt was just returned, i.e. limited  */
75 		r_one_out_nr : 1,	/* Special case 1 outstanding and not in recovery */
76 		r_no_rtt_allowed : 1, /* No rtt measurement allowed */
77 		r_hw_tls : 1,
78 		r_avail : 4;
79 	uint64_t r_tim_lastsent[RACK_NUM_OF_RETRANS];
80 	uint64_t r_ack_arrival;	/* This is the time of ack-arrival (if SACK'd) */
81 	uint32_t r_fas;		/* Flight at send */
82 	uint8_t r_bas;		/* The burst size (burst at send = bas)  */
83 };
84 
85 struct deferred_opt_list {
86 	TAILQ_ENTRY(deferred_opt_list) next;
87 	int optname;
88 	uint64_t optval;
89 };
90 
91 /*
92  * Timestamps in the rack sendmap are now moving to be
93  * uint64_t's. This means that if you want a uint32_t
94  * usec timestamp (the old usecond timestamp) you simply have
95  * to cast it to uint32_t. The reason we do this is not for
96  * wrap, but we need to get back, at times, to the millisecond
97  * timestamp that is used in the TSTMP option. To do this we
98  * can use the rack_ts_to_msec() inline below which can take
99  * the 64bit ts and make into the correct timestamp millisecond
100  * wise. Thats not possible with the 32bit usecond timestamp since
101  * the seconds wrap too quickly to cover all bases.
102  *
103  * There are quite a few places in rack where I simply cast
104  * back to uint32_t and then end up using the TSTMP_XX()
105  * macros. This is ok, but we could do simple compares if
106  * we ever decided to move all of those variables to 64 bits
107  * as well.
108  */
109 
110 static inline uint64_t
111 rack_to_usec_ts(struct timeval *tv)
112 {
113 	return ((tv->tv_sec * HPTS_USEC_IN_SEC) + tv->tv_usec);
114 }
115 
116 static inline uint32_t
117 rack_ts_to_msec(uint64_t ts)
118 {
119 	return((uint32_t)(ts / HPTS_MSEC_IN_SEC));
120 }
121 
122 
123 RB_HEAD(rack_rb_tree_head, rack_sendmap);
124 TAILQ_HEAD(rack_head, rack_sendmap);
125 TAILQ_HEAD(def_opt_head, deferred_opt_list);
126 
127 /* Map change logging */
128 #define MAP_MERGE	0x01
129 #define MAP_SPLIT	0x02
130 #define MAP_NEW		0x03
131 #define MAP_SACK_M1	0x04
132 #define MAP_SACK_M2	0x05
133 #define MAP_SACK_M3	0x06
134 #define MAP_SACK_M4	0x07
135 #define MAP_SACK_M5	0x08
136 #define MAP_FREE	0x09
137 #define MAP_TRIM_HEAD	0x0a
138 
139 #define RACK_LIMIT_TYPE_SPLIT	1
140 
141 /*
142  * We use the rate sample structure to
143  * assist in single sack/ack rate and rtt
144  * calculation. In the future we will expand
145  * this in BBR to do forward rate sample
146  * b/w estimation.
147  */
148 #define RACK_RTT_EMPTY 0x00000001	/* Nothing yet stored in RTT's */
149 #define RACK_RTT_VALID 0x00000002	/* We have at least one valid RTT */
150 struct rack_rtt_sample {
151 	uint32_t rs_flags;
152 	uint32_t rs_rtt_lowest;
153 	uint32_t rs_rtt_highest;
154 	uint32_t rs_rtt_cnt;
155 	uint32_t rs_us_rtt;
156 	int32_t  confidence;
157 	uint64_t rs_rtt_tot;
158 	uint16_t rs_us_rtrcnt;
159 };
160 
161 #define RACK_LOG_TYPE_ACK	0x01
162 #define RACK_LOG_TYPE_OUT	0x02
163 #define RACK_LOG_TYPE_TO	0x03
164 #define RACK_LOG_TYPE_ALLOC     0x04
165 #define RACK_LOG_TYPE_FREE      0x05
166 
167 /*
168  * Magic numbers for logging timeout events if the
169  * logging is enabled.
170  */
171 #define RACK_TO_FRM_TMR  1
172 #define RACK_TO_FRM_TLP  2
173 #define RACK_TO_FRM_RACK 3
174 #define RACK_TO_FRM_KEEP 4
175 #define RACK_TO_FRM_PERSIST 5
176 #define RACK_TO_FRM_DELACK 6
177 
178 struct rack_opts_stats {
179 	uint64_t tcp_rack_tlp_reduce;
180 	uint64_t tcp_rack_pace_always;
181 	uint64_t tcp_rack_pace_reduce;
182 	uint64_t tcp_rack_max_seg;
183 	uint64_t tcp_rack_prr_sendalot;
184 	uint64_t tcp_rack_min_to;
185 	uint64_t tcp_rack_early_seg;
186 	uint64_t tcp_rack_reord_thresh;
187 	uint64_t tcp_rack_reord_fade;
188 	uint64_t tcp_rack_tlp_thresh;
189 	uint64_t tcp_rack_pkt_delay;
190 	uint64_t tcp_rack_tlp_inc_var;
191 	uint64_t tcp_tlp_use;
192 	uint64_t tcp_rack_idle_reduce;
193 	uint64_t tcp_rack_idle_reduce_high;
194 	uint64_t rack_no_timer_in_hpts;
195 	uint64_t tcp_rack_min_pace_seg;
196 	uint64_t tcp_rack_pace_rate_ca;
197 	uint64_t tcp_rack_rr;
198 	uint64_t tcp_rack_do_detection;
199 	uint64_t tcp_rack_rrr_no_conf_rate;
200 	uint64_t tcp_initial_rate;
201 	uint64_t tcp_initial_win;
202 	uint64_t tcp_hdwr_pacing;
203 	uint64_t tcp_gp_inc_ss;
204 	uint64_t tcp_gp_inc_ca;
205 	uint64_t tcp_gp_inc_rec;
206 	uint64_t tcp_rack_force_max_seg;
207 	uint64_t tcp_rack_pace_rate_ss;
208 	uint64_t tcp_rack_pace_rate_rec;
209 	/* Temp counters for dsack */
210 	uint64_t tcp_sack_path_1; /* not used */
211 	uint64_t tcp_sack_path_2a; /* not used */
212 	uint64_t tcp_sack_path_2b; /* not used */
213 	uint64_t tcp_sack_path_3; /* not used */
214 	uint64_t tcp_sack_path_4; /* not used */
215 	/* non temp counters */
216 	uint64_t tcp_rack_scwnd;
217 	uint64_t tcp_rack_noprr;
218 	uint64_t tcp_rack_cfg_rate;
219 	uint64_t tcp_timely_dyn;
220 	uint64_t tcp_rack_mbufq;
221 	uint64_t tcp_fillcw;
222 	uint64_t tcp_npush;
223 	uint64_t tcp_lscwnd;
224 	uint64_t tcp_profile;
225 	uint64_t tcp_hdwr_rate_cap;
226 	uint64_t tcp_pacing_rate_cap;
227 	uint64_t tcp_pacing_up_only;
228 	uint64_t tcp_use_cmp_acks;
229 	uint64_t tcp_rack_abc_val;
230 	uint64_t tcp_rec_abc_val;
231 	uint64_t tcp_rack_measure_cnt;
232 	uint64_t tcp_rack_delayed_ack;
233 	uint64_t tcp_rack_rtt_use;
234 	uint64_t tcp_data_after_close;
235 	uint64_t tcp_defer_opt;
236 	uint64_t tcp_rxt_clamp;
237 	uint64_t tcp_rack_beta;
238 	uint64_t tcp_rack_beta_ecn;
239 	uint64_t tcp_rack_timer_slop;
240 	uint64_t tcp_rack_dsack_opt;
241 	uint64_t tcp_rack_hi_beta;
242 	uint64_t tcp_split_limit;
243 	uint64_t tcp_rack_pacing_divisor;
244 	uint64_t tcp_rack_min_seg;
245 	uint64_t tcp_dgp_in_rec;
246 };
247 
248 /* RTT shrink reasons */
249 #define RACK_RTTS_INIT     0
250 #define RACK_RTTS_NEWRTT   1
251 #define RACK_RTTS_EXITPROBE 2
252 #define RACK_RTTS_ENTERPROBE 3
253 #define RACK_RTTS_REACHTARGET 4
254 #define RACK_RTTS_SEEHBP 5
255 #define RACK_RTTS_NOBACKOFF 6
256 #define RACK_RTTS_SAFETY 7
257 
258 #define RACK_USE_BEG 1
259 #define RACK_USE_END 2
260 #define RACK_USE_END_OR_THACK 3
261 
262 #define TLP_USE_ID	1	/* Internet draft behavior */
263 #define TLP_USE_TWO_ONE 2	/* Use 2.1 behavior */
264 #define TLP_USE_TWO_TWO 3	/* Use 2.2 behavior */
265 #define RACK_MIN_BW 8000	/* 64kbps in Bps */
266 
267 /* Rack quality indicators for GPUT measurements */
268 #define RACK_QUALITY_NONE	0	/* No quality stated */
269 #define RACK_QUALITY_HIGH 	1	/* A normal measurement of a GP RTT */
270 #define RACK_QUALITY_APPLIMITED	2 	/* An app limited case that may be of lower quality */
271 #define RACK_QUALITY_PERSIST	3	/* A measurement where we went into persists */
272 #define RACK_QUALITY_PROBERTT	4	/* A measurement where we went into or exited probe RTT */
273 #define RACK_QUALITY_ALLACKED	5	/* All data is now acknowledged */
274 
275 #define MIN_GP_WIN 6	/* We need at least 6 MSS in a GP measurement */
276 #ifdef _KERNEL
277 #define RACK_OPTS_SIZE (sizeof(struct rack_opts_stats)/sizeof(uint64_t))
278 extern counter_u64_t rack_opts_arry[RACK_OPTS_SIZE];
279 #define RACK_OPTS_ADD(name, amm) counter_u64_add(rack_opts_arry[(offsetof(struct rack_opts_stats, name)/sizeof(uint64_t))], (amm))
280 #define RACK_OPTS_INC(name) RACK_OPTS_ADD(name, 1)
281 #endif
282 /*
283  * As we get each SACK we wade through the
284  * rc_map and mark off what is acked.
285  * We also increment rc_sacked as well.
286  *
287  * We also pay attention to missing entries
288  * based on the time and possibly mark them
289  * for retransmit. If we do and we are not already
290  * in recovery we enter recovery. In doing
291  * so we claer prr_delivered/holes_rxt and prr_sent_dur_rec.
292  * We also setup rc_next/rc_snd_nxt/rc_send_end so
293  * we will know where to send from. When not in
294  * recovery rc_next will be NULL and rc_snd_nxt should
295  * equal snd_max.
296  *
297  * Whenever we retransmit from recovery we increment
298  * rc_holes_rxt as we retran a block and mark it as retransmitted
299  * with the time it was sent. During non-recovery sending we
300  * add to our map and note the time down of any send expanding
301  * the rc_map at the tail and moving rc_snd_nxt up with snd_max.
302  *
303  * In recovery during SACK/ACK processing if a chunk has
304  * been retransmitted and it is now acked, we decrement rc_holes_rxt.
305  * When we retransmit from the scoreboard we use
306  * rc_next and rc_snd_nxt/rc_send_end to help us
307  * find what needs to be retran.
308  *
309  * To calculate pipe we simply take (snd_max - snd_una) + rc_holes_rxt
310  * This gets us the effect of RFC6675 pipe, counting twice for
311  * bytes retransmitted.
312  */
313 
314 #define TT_RACK_FR_TMR	0x2000
315 
316 /*
317  * Locking for the rack control block.
318  * a) Locked by INP_WLOCK
319  * b) Locked by the hpts-mutex
320  *
321  */
322 #define RACK_GP_HIST 4	/* How much goodput history do we maintain? */
323 
324 #define RACK_NUM_FSB_DEBUG 16
325 #ifdef _KERNEL
326 struct rack_fast_send_blk {
327 	uint32_t left_to_send;
328 	uint16_t tcp_ip_hdr_len;
329 	uint8_t tcp_flags;
330 	uint8_t hoplimit;
331 	uint8_t *tcp_ip_hdr;
332 	uint32_t recwin;
333 	uint32_t off;
334 	struct tcphdr *th;
335 	struct udphdr *udp;
336 	struct mbuf *m;
337 	uint32_t o_m_len;
338 	uint32_t o_t_len;
339 	uint32_t rfo_apply_push : 1,
340 		hw_tls : 1,
341 		unused : 30;
342 };
343 
344 struct tailq_hash;
345 
346 struct rack_control {
347 	/* Second cache line 0x40 from tcp_rack */
348 	struct tailq_hash *tqh; /* Tree of all segments Lock(a) */
349 	struct rack_head rc_tmap;	/* List in transmit order Lock(a) */
350 	struct rack_sendmap *rc_tlpsend;	/* Remembered place for
351 						 * tlp_sending Lock(a) */
352 	struct rack_sendmap *rc_resend;	/* something we have been asked to
353 					 * resend */
354 	struct rack_fast_send_blk fsb;	/* The fast-send block */
355 	uint32_t timer_slop;
356 	uint16_t pace_len_divisor;
357 	uint16_t rc_user_set_min_segs;
358 	uint32_t rc_hpts_flags;
359 	uint32_t rc_fixed_pacing_rate_ca;
360 	uint32_t rc_fixed_pacing_rate_rec;
361 	uint32_t rc_fixed_pacing_rate_ss;
362 	uint32_t cwnd_to_use;	/* The cwnd in use */
363 	uint32_t rc_timer_exp;	/* If a timer ticks of expiry */
364 	uint32_t rc_rack_min_rtt;	/* lowest RTT seen Lock(a) */
365 	uint32_t rc_rack_largest_cwnd;	/* Largest CWND we have seen Lock(a) */
366 
367 	/* Third Cache line 0x80 */
368 	struct rack_head rc_free;	/* Allocation array */
369 	uint64_t last_hw_bw_req;
370 	uint64_t crte_prev_rate;
371 	uint64_t bw_rate_cap;
372 	uint64_t last_cumack_advance; /* Last time cumack moved forward */
373 	uint32_t rc_reorder_ts;	/* Last time we saw reordering Lock(a) */
374 
375 	uint32_t rc_tlp_new_data;	/* we need to send new-data on a TLP
376 					 * Lock(a) */
377 	uint32_t rc_prr_out;	/* bytes sent during recovery Lock(a) */
378 
379 	uint32_t rc_prr_recovery_fs;	/* recovery fs point Lock(a) */
380 
381 	uint32_t rc_prr_sndcnt;	/* Prr sndcnt Lock(a) */
382 
383 	uint32_t rc_sacked;	/* Tot sacked on scoreboard Lock(a) */
384 	uint32_t last_sent_tlp_seq;	/* Last tlp sequence that was retransmitted Lock(a) */
385 
386 	uint32_t rc_prr_delivered;	/* during recovery prr var Lock(a) */
387 
388 	uint16_t rc_tlp_cnt_out;	/* count of times we have sent a TLP without new data */
389 	uint16_t last_sent_tlp_len;	/* Number of bytes in the last sent tlp */
390 
391 	uint32_t rc_loss_count;	/* How many bytes have been retransmitted
392 				 * Lock(a) */
393 	uint32_t rc_reorder_fade;	/* Socket option value Lock(a) */
394 
395 	/* Forth cache line 0xc0  */
396 	/* Times */
397 
398 	uint32_t rc_rack_tmit_time;	/* Rack transmit time Lock(a) */
399 	uint32_t rc_holes_rxt;	/* Tot retraned from scoreboard Lock(a) */
400 
401 	uint32_t rc_num_maps_alloced;	/* Number of map blocks (sacks) we
402 					 * have allocated */
403 	uint32_t rc_rcvtime;	/* When we last received data */
404 	uint32_t rc_num_split_allocs;	/* num split map entries allocated */
405 	uint32_t rc_split_limit;	/* Limit from control var can be set by socket opt */
406 
407 	uint32_t rc_last_output_to;
408 	uint32_t rc_went_idle_time;
409 
410 	struct rack_sendmap *rc_sacklast;	/* sack remembered place
411 						 * Lock(a) */
412 
413 	struct rack_sendmap *rc_first_appl;	/* Pointer to first app limited */
414 	struct rack_sendmap *rc_end_appl;	/* Pointer to last app limited */
415 	/* Cache line split 0x100 */
416 	struct sack_filter rack_sf;
417 	/* Cache line split 0x140 */
418 	/* Flags for various things */
419 	uint32_t rc_pace_max_segs;
420 	uint32_t rc_pace_min_segs;
421 	uint32_t rc_app_limited_cnt;
422 	uint16_t rack_per_of_gp_ss; /* 100 = 100%, so from 65536 = 655 x bw  */
423 	uint16_t rack_per_of_gp_ca; /* 100 = 100%, so from 65536 = 655 x bw  */
424 	uint16_t rack_per_of_gp_rec; /* 100 = 100%, so from 65536 = 655 x bw, 0=off */
425 	uint16_t rack_per_of_gp_probertt; /* 100 = 100%, so from 65536 = 655 x bw, 0=off */
426 	uint32_t rc_high_rwnd;
427 	uint32_t ack_count;
428 	uint32_t sack_count;
429 	uint32_t sack_noextra_move;
430 	uint32_t sack_moved_extra;
431 	struct rack_rtt_sample rack_rs;
432 	const struct tcp_hwrate_limit_table *crte;
433 	uint32_t rc_agg_early;
434 	uint32_t rc_agg_delayed;
435 	uint32_t rc_tlp_rxt_last_time;
436 	uint32_t rc_saved_cwnd;
437 	uint64_t rc_gp_output_ts; /* chg*/
438 	uint64_t rc_gp_cumack_ts; /* chg*/
439 	struct timeval act_rcv_time;
440 	struct timeval rc_last_time_decay;	/* SAD time decay happened here */
441 	uint64_t gp_bw;
442 	uint64_t init_rate;
443 #ifdef NETFLIX_SHARED_CWND
444 	struct shared_cwnd *rc_scw;
445 #endif
446 	uint64_t last_gp_comp_bw;
447 	uint64_t last_max_bw;	/* Our calculated max b/w last */
448 	struct time_filter_small rc_gp_min_rtt;
449 	struct def_opt_head opt_list;
450 	uint64_t lt_bw_time;	/* Total time with data outstanding (lt_bw = long term bandwidth)  */
451 	uint64_t lt_bw_bytes;	/* Total bytes acked */
452 	uint64_t lt_timemark;	/* 64 bit timestamp when we started sending */
453 	struct tcp_sendfile_track *rc_last_sft;
454 	uint32_t lt_seq;	/* Seq at start of lt_bw gauge */
455 	int32_t rc_rtt_diff;		/* Timely style rtt diff of our gp_srtt */
456 	uint64_t last_sndbytes;
457 	uint64_t last_snd_rxt_bytes;
458 	uint64_t rxt_threshold;
459 	uint64_t last_tmit_time_acked;	/* Holds the last cumack point's last send time */
460 	uint32_t last_rnd_rxt_clamped;
461 	uint32_t num_of_clamps_applied;
462 	uint32_t clamp_options;
463 	uint32_t max_clamps;
464 
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 last_collapse_point;	/* Last point peer collapsed too */
476 	uint32_t high_collapse_point;
477 	uint32_t rc_lower_rtt_us_cts;	/* Time our GP rtt was last lowered */
478 	uint32_t rc_time_probertt_entered;
479 	uint32_t rc_time_probertt_starts;
480 	uint32_t rc_lowest_us_rtt;
481 	uint32_t rc_highest_us_rtt;
482 	uint32_t rc_last_us_rtt;
483 	uint32_t rc_time_of_last_probertt;
484 	uint32_t rc_target_probertt_flight;
485 	uint32_t rc_probertt_sndmax_atexit;	/* Highest sent to in probe-rtt */
486 	uint32_t rc_cwnd_at_erec;
487 	uint32_t rc_ssthresh_at_erec;
488 	uint32_t dsack_byte_cnt;
489 	uint32_t retran_during_recovery;
490 	uint32_t rc_gp_lowrtt;			/* Lowest rtt seen during GPUT measurement */
491 	uint32_t rc_gp_high_rwnd;		/* Highest rwnd seen during GPUT measurement */
492 	uint32_t rc_snd_max_at_rto;	/* For non-sack when the RTO occurred what was snd-max */
493 	uint32_t rc_out_at_rto;
494 	int32_t rc_scw_index;
495 	uint32_t rc_tlp_threshold;	/* Socket option value Lock(a) */
496 	uint32_t rc_last_timeout_snduna;
497 	uint32_t last_tlp_acked_start;
498 	uint32_t last_tlp_acked_end;
499 	uint32_t challenge_ack_ts;
500 	uint32_t challenge_ack_cnt;
501 	uint32_t rc_min_to;	/* Socket option value Lock(a) */
502 	uint32_t rc_pkt_delay;	/* Socket option value Lock(a) */
503 	uint32_t persist_lost_ends;
504 	uint32_t ack_during_sd;
505 	uint32_t input_pkt;
506 	uint32_t saved_input_pkt;
507 	uint32_t saved_rxt_clamp_val; 	/* The encoded value we used to setup clamping */
508 	struct newreno rc_saved_beta;	/*
509 					 * For newreno cc:
510 					 * rc_saved_cc are the values we have had
511 					 * set by the user, if pacing is not happening
512 					 * (i.e. its early and we have not turned on yet
513 					 *  or it was turned off). The minute pacing
514 					 * is turned on we pull out the values currently
515 					 * being used by newreno and replace them with
516 					 * these values, then save off the old values here,
517 					 * we also set the flag (if ecn_beta is set) to make
518 					 * new_reno do less of a backoff for ecn (think abe).
519 					 */
520 	uint16_t rc_early_recovery_segs;	/* Socket option value Lock(a) */
521 	uint16_t rc_reorder_shift;	/* Socket option value Lock(a) */
522 	uint8_t rack_per_upper_bound_ss;
523 	uint8_t rack_per_upper_bound_ca;
524 	uint8_t dsack_persist;
525 	uint8_t rc_no_push_at_mrtt;	/* No push when we exceed max rtt */
526 	uint8_t num_measurements;	/* Number of measurements (up to 0xff, we freeze at 0xff)  */
527 	uint8_t req_measurements;	/* How many measurements are required? */
528 	uint8_t saved_hibeta;
529 	uint8_t rc_tlp_cwnd_reduce;	/* Socket option value Lock(a) */
530 	uint8_t rc_prr_sendalot;/* Socket option value Lock(a) */
531 	uint8_t rc_rate_sample_method;
532 	uint8_t rc_dgp_bl_agg;		/* Buffer Level aggression during DGP */
533 	uint8_t full_dgp_in_rec;	/* Flag to say if we do full DGP in recovery */
534 	uint8_t client_suggested_maxseg;	/* Not sure what to do with this yet */
535 	uint8_t pacing_discount_amm;	/*
536 					 * This is a multipler to the base discount that
537 					 * can be used to increase the discount.
538 					 */
539 	uint8_t already_had_a_excess;
540 };
541 #endif
542 
543 /* DGP with no buffer level mitigations */
544 #define DGP_LEVEL0	0
545 
546 /*
547  * DGP with buffer level mitigation where BL:4 caps fillcw and BL:5
548  * turns off fillcw.
549  */
550 #define DGP_LEVEL1	1
551 
552 /*
553  * DGP with buffer level mitigation where BL:3 caps fillcw and BL:4 turns off fillcw
554  * and BL:5 reduces by 10%
555  */
556 #define DGP_LEVEL2	2
557 
558 /*
559  * DGP with buffer level mitigation where BL:2 caps fillcw and BL:3 turns off
560  * fillcw  BL:4 reduces by 10% and BL:5 reduces by 20%
561  */
562 #define DGP_LEVEL3	3
563 
564 /* Hybrid pacing log defines */
565 #define HYBRID_LOG_NO_ROOM	0	/* No room for the clients request */
566 #define HYBRID_LOG_TURNED_OFF	1	/* Turned off hybrid pacing */
567 #define HYBRID_LOG_NO_PACING	2	/* Failed to set pacing on */
568 #define HYBRID_LOG_RULES_SET	3	/* Hybrid pacing for this chunk is set */
569 #define HYBRID_LOG_NO_RANGE	4	/* In DGP mode, no range found */
570 #define HYBRID_LOG_RULES_APP	5	/* The specified rules were applied */
571 #define HYBRID_LOG_REQ_COMP	6	/* The request completed */
572 #define HYBRID_LOG_BW_MEASURE	7	/* Follow up b/w measurements to the previous completed log */
573 #define HYBRID_LOG_RATE_CAP	8	/* We had a rate cap apply */
574 #define HYBRID_LOG_CAP_CALC	9	/* How we calculate the cap */
575 #define HYBRID_LOG_ISSAME	10	/* Same as before  -- temp */
576 #define HYBRID_LOG_ALLSENT	11	/* We sent it all no more rate-cap */
577 #define HYBRID_LOG_OUTOFTIME	12	/* We are past the deadline DGP */
578 #define HYBRID_LOG_CAPERROR	13	/* Hit one of the TSNH cases */
579 #define HYBRID_LOG_EXTEND	14	/* We extended the end */
580 #define HYBRID_LOG_SENT_LOST	15	/* A closing sent/lost report */
581 
582 #define RACK_TIMELY_CNT_BOOST 5	/* At 5th increase boost */
583 #define RACK_MINRTT_FILTER_TIM 10 /* Seconds */
584 
585 #define RACK_HYSTART_OFF	0
586 #define RACK_HYSTART_ON		1	/* hystart++ on */
587 #define RACK_HYSTART_ON_W_SC	2	/* hystart++ on +Slam Cwnd */
588 #define RACK_HYSTART_ON_W_SC_C	3	/* hystart++ on,
589 					 * Conservative ssthresh and
590 					 * +Slam cwnd
591 					 */
592 
593 #define MAX_USER_SET_SEG 0x3f	/* The max we can set is 63 which is probably too many */
594 
595 #ifdef _KERNEL
596 
597 struct tcp_rack {
598 	/* First cache line 0x00 */
599 	TAILQ_ENTRY(tcp_rack) r_hpts;	/* hptsi queue next Lock(b) */
600 	int32_t(*r_substate) (struct mbuf *, struct tcphdr *,
601 	    struct socket *, struct tcpcb *, struct tcpopt *,
602 	    int32_t, int32_t, uint32_t, int, int, uint8_t);	/* Lock(a) */
603 	struct tcpcb *rc_tp;	/* The tcpcb Lock(a) */
604 	struct inpcb *rc_inp;	/* The inpcb Lock(a) */
605 	uint8_t rc_free_cnt;	/* Number of free entries on the rc_free list
606 				 * Lock(a) */
607 	uint8_t client_bufferlvl : 3, /* Expected range [0,5]: 0=unset, 1=low/empty */
608 		rack_deferred_inited : 1,
609 	        /* ******************************************************************** */
610 	        /* Note for details of next two fields see rack_init_retransmit_rate()  */
611 	        /* ******************************************************************** */
612 		full_size_rxt: 1,
613 		shape_rxt_to_pacing_min : 1,
614 	        /* ******************************************************************** */
615 		rc_ack_required: 1,
616 		r_pacing_discount : 1;
617 	uint8_t no_prr_addback : 1,
618 		gp_ready : 1,
619 		defer_options: 1,
620 		excess_rxt_on: 1,	/* Are actions on for excess retransmissions? */
621 		rc_ack_can_sendout_data: 1, /*
622 					     * If set it will override pacing restrictions on not sending
623 					     * data when the pacing timer is running. I.e. you set this
624 					     * and an ACK will send data. Default is off and its only used
625 					     * without pacing when we are doing 5G speed up for there
626 					     * ack filtering.
627 					     */
628 		rc_pacing_cc_set: 1,	     /*
629 					      * If we are pacing (pace_always=1) and we have reached the
630 					      * point where we start pacing (fixed or gp has reached its
631 					      * magic gp_ready state) this flag indicates we have set in
632 					      * values to effect CC's backoff's. If pacing is turned off
633 					      * then we must restore the values saved in rc_saved_beta,
634 					      * if its going to gp_ready we need to copy the values into
635 					      * the CC module and set our flags.
636 					      *
637 					      * Note this only happens if the cc name is newreno (CCALGONAME_NEWRENO).
638 					      */
639 
640 		rc_rack_tmr_std_based :1,
641 		rc_rack_use_dsack: 1;
642 	uint8_t rc_dsack_round_seen: 1,
643 		rc_last_tlp_acked_set: 1,
644 		rc_last_tlp_past_cumack: 1,
645 		rc_last_sent_tlp_seq_valid: 1,
646 		rc_last_sent_tlp_past_cumack: 1,
647 		probe_not_answered: 1,
648 		rack_hibeta : 1,
649 		lt_bw_up : 1;
650 	uint32_t rc_rack_rtt;	/* RACK-RTT Lock(a) */
651 	uint16_t r_mbuf_queue : 1,	/* Do we do mbuf queue for non-paced */
652 		 rtt_limit_mul : 4,	/* muliply this by low rtt */
653 		 r_limit_scw : 1,
654 		 r_must_retran : 1,	/* For non-sack customers we hit an RTO and new data should be resends */
655 		 r_use_cmp_ack: 1,	/* Do we use compressed acks */
656 		 r_ent_rec_ns: 1,	/* We entered recovery and have not sent */
657 		 r_might_revert: 1,	/* Flag to find out if we might need to revert */
658 		 r_fast_output: 1, 	/* Fast output is in progress we can skip the bulk of rack_output */
659 		 r_fsb_inited: 1,
660 		 r_rack_hw_rate_caps: 1,
661 		 r_up_only: 1,
662 		 r_via_fill_cw : 1,
663 		 r_fill_less_agg : 1;
664 
665 	uint8_t rc_user_set_max_segs : 7,	/* Socket option value Lock(a) */
666 		rc_fillcw_apply_discount;
667 	uint8_t rc_labc;		/* Appropriate Byte Counting Value */
668 	uint16_t forced_ack : 1,
669 		rc_gp_incr : 1,
670 		rc_gp_bwred : 1,
671 		rc_gp_timely_inc_cnt : 3,
672 		rc_gp_timely_dec_cnt : 3,
673 		r_use_labc_for_rec: 1,
674 		rc_highly_buffered: 1,		/* The path is highly buffered */
675 		rc_dragged_bottom: 1,
676 		rc_pace_dnd : 1,		/* The pace do not disturb bit */
677 		rc_avali2 : 1,
678 		rc_gp_filled : 1,
679 		rc_hw_nobuf : 1;
680 	uint8_t r_state : 4, 	/* Current rack state Lock(a) */
681 		rc_catch_up : 1,	/* catch up mode in dgp */
682 		rc_hybrid_mode : 1,	/* We are in hybrid mode */
683 		rc_suspicious : 1,	/* Suspect sacks have been given */
684 		rc_new_rnd_needed: 1;
685 	uint8_t rc_tmr_stopped : 7,
686 		t_timers_stopped : 1;
687 	uint8_t rc_enobuf : 7,	/* count of enobufs on connection provides */
688 		rc_on_min_to : 1;
689 	uint8_t r_timer_override : 1,	/* hpts override Lock(a) */
690 		r_is_v6 : 1,	/* V6 pcb Lock(a)  */
691 		rc_in_persist : 1,
692 		rc_tlp_in_progress : 1,
693 		rc_always_pace : 1,	/* Socket option value Lock(a) */
694 		rc_pace_to_cwnd : 1,
695 		rc_pace_fill_if_rttin_range : 1,
696 		rc_srtt_measure_made : 1;
697 	uint8_t app_limited_needs_set : 1,
698 		use_fixed_rate : 1,
699 		rc_has_collapsed : 1,
700 		r_cwnd_was_clamped : 1,
701 		r_clamped_gets_lower : 1,
702 		rack_hdrw_pacing : 1,  /* We are doing Hardware pacing */
703 		rack_hdw_pace_ena : 1, /* Is hardware pacing enabled? */
704 		rack_attempt_hdwr_pace : 1; /* Did we attempt hdwr pacing (if allowed) */
705 	uint8_t rack_tlp_threshold_use : 3,	/* only 1, 2 and 3 used so far */
706 		rack_rec_nonrxt_use_cr : 1,
707 		rack_enable_scwnd : 1,
708 		rack_attempted_scwnd : 1,
709 		rack_no_prr : 1,
710 		rack_scwnd_is_idle : 1;
711 	uint8_t rc_allow_data_af_clo: 1,
712 		delayed_ack : 1,
713 		set_pacing_done_a_iw : 1,
714 		use_rack_rr : 1,
715 		alloc_limit_reported : 1,
716 		sack_attack_disable : 1,
717 		do_detection : 1,
718 		rc_force_max_seg : 1;
719 	uint8_t r_early : 1,
720 		r_late : 1,
721 		r_wanted_output: 1,
722 		r_rr_config : 2,
723 		r_persist_lt_bw_off : 1,
724 		r_collapse_point_valid : 1,
725 		dgp_on : 1;
726 	uint16_t rc_init_win : 8,
727 		rc_gp_rtt_set : 1,
728 		rc_gp_dyn_mul : 1,
729 		rc_gp_saw_rec : 1,
730 		rc_gp_saw_ca : 1,
731 		rc_gp_saw_ss : 1,
732 		rc_gp_no_rec_chg : 1,
733 		in_probe_rtt : 1,
734 		measure_saw_probe_rtt : 1;
735 	/* Cache line 2 0x40 */
736 	struct rack_control r_ctl;
737 }        __aligned(CACHE_LINE_SIZE);
738 
739 #endif
740 #endif
741