]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/netinet/tcp_stacks/tcp_rack.h
Merge libc++ trunk r366426, resolve conflicts, and add FREEBSD-Xlist.
[FreeBSD/FreeBSD.git] / sys / netinet / tcp_stacks / tcp_rack.h
1 /*-
2  * Copyright (c) 2016 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        0x0001/* The remote endpoint acked this */
32 #define RACK_TO_MIXED     0x0002/* A timeout occured that mixed the send order */
33 #define RACK_DEFERRED     0x0004/* We can't use this for RTT calc */
34 #define RACK_OVERMAX      0x0008/* We have more retran's then we can fit */
35 #define RACK_SACK_PASSED  0x0010/* A sack was done above this block */
36 #define RACK_WAS_SACKPASS 0x0020/* We retransmitted due to SACK pass */
37 #define RACK_HAS_FIN      0x0040/* segment is sent with fin */
38 #define RACK_TLP          0x0080/* segment sent as tail-loss-probe */
39
40 #define RACK_NUM_OF_RETRANS 3
41
42 #define RACK_INITIAL_RTO 1000 /* 1 second in milli seconds */
43
44 struct rack_sendmap {
45         TAILQ_ENTRY(rack_sendmap) r_next;       /* seq number arrayed next */
46         TAILQ_ENTRY(rack_sendmap) r_tnext;      /* Time of transmit based next */
47         uint32_t r_tim_lastsent[RACK_NUM_OF_RETRANS];
48         uint32_t r_start;       /* Sequence number of the segment */
49         uint32_t r_end;         /* End seq, this is 1 beyond actually */
50         uint32_t r_rtr_bytes;   /* How many bytes have been retransmitted */
51         uint16_t r_rtr_cnt;     /* Retran count, index this -1 to get time
52                                  * sent */
53         uint8_t r_flags;        /* Flags as defined above */
54         uint8_t r_sndcnt;       /* Retran count, not limited by
55                                  * RACK_NUM_OF_RETRANS */
56         uint8_t r_in_tmap;      /* Flag to see if its in the r_tnext array */
57         uint8_t r_limit_type;   /* is this entry counted against a limit? */
58         uint8_t r_resv[2];
59 };
60 #define RACK_LIMIT_TYPE_SPLIT   1
61
62 TAILQ_HEAD(rack_head, rack_sendmap);
63
64
65 /*
66  * We use the rate sample structure to
67  * assist in single sack/ack rate and rtt
68  * calculation. In the future we will expand
69  * this in BBR to do forward rate sample
70  * b/w estimation.
71  */
72 #define RACK_RTT_EMPTY 0x00000001       /* Nothing yet stored in RTT's */
73 #define RACK_RTT_VALID 0x00000002       /* We have at least one valid RTT */
74 struct rack_rtt_sample {
75         uint32_t rs_flags;
76         uint32_t rs_rtt_lowest;
77         uint32_t rs_rtt_highest;
78         uint32_t rs_rtt_cnt;
79         uint64_t rs_rtt_tot;
80 };
81
82 #define RACK_LOG_TYPE_ACK       0x01
83 #define RACK_LOG_TYPE_OUT       0x02
84 #define RACK_LOG_TYPE_TO        0x03
85 #define RACK_LOG_TYPE_ALLOC     0x04
86 #define RACK_LOG_TYPE_FREE      0x05
87
88
89 struct rack_log {
90         union {
91                 struct rack_sendmap *rsm;       /* For alloc/free */
92                 uint64_t sb_acc;/* For out/ack or t-o */
93         };
94         uint32_t th_seq;
95         uint32_t th_ack;
96         uint32_t snd_una;
97         uint32_t snd_nxt;       /* th_win for TYPE_ACK */
98         uint32_t snd_max;
99         uint32_t blk_start[4];
100         uint32_t blk_end[4];
101         uint8_t type;
102         uint8_t n_sackblks;
103         uint16_t len;           /* Timeout T3=1, TLP=2, RACK=3 */
104 };
105
106 /*
107  * Magic numbers for logging timeout events if the
108  * logging is enabled.
109  */
110 #define RACK_TO_FRM_TMR  1
111 #define RACK_TO_FRM_TLP  2
112 #define RACK_TO_FRM_RACK 3
113 #define RACK_TO_FRM_KEEP 4
114 #define RACK_TO_FRM_PERSIST 5
115 #define RACK_TO_FRM_DELACK 6
116
117 struct rack_opts_stats {
118         uint64_t tcp_rack_prop_rate;
119         uint64_t tcp_rack_prop;
120         uint64_t tcp_rack_tlp_reduce;
121         uint64_t tcp_rack_early_recov;
122         uint64_t tcp_rack_pace_always;
123         uint64_t tcp_rack_pace_reduce;
124         uint64_t tcp_rack_max_seg;
125         uint64_t tcp_rack_prr_sendalot;
126         uint64_t tcp_rack_min_to;
127         uint64_t tcp_rack_early_seg;
128         uint64_t tcp_rack_reord_thresh;
129         uint64_t tcp_rack_reord_fade;
130         uint64_t tcp_rack_tlp_thresh;
131         uint64_t tcp_rack_pkt_delay;
132         uint64_t tcp_rack_tlp_inc_var;
133         uint64_t tcp_tlp_use;
134         uint64_t tcp_rack_idle_reduce;
135         uint64_t tcp_rack_idle_reduce_high;
136         uint64_t rack_no_timer_in_hpts;
137         uint64_t tcp_rack_min_pace_seg;
138         uint64_t tcp_rack_min_pace;
139 };
140
141 #define TLP_USE_ID      1       /* Internet draft behavior */
142 #define TLP_USE_TWO_ONE 2       /* Use 2.1 behavior */
143 #define TLP_USE_TWO_TWO 3       /* Use 2.2 behavior */
144
145 #ifdef _KERNEL
146 #define RACK_OPTS_SIZE (sizeof(struct rack_opts_stats)/sizeof(uint64_t))
147 extern counter_u64_t rack_opts_arry[RACK_OPTS_SIZE];
148 #define RACK_OPTS_ADD(name, amm) counter_u64_add(rack_opts_arry[(offsetof(struct rack_opts_stats, name)/sizeof(uint64_t))], (amm))
149 #define RACK_OPTS_INC(name) RACK_OPTS_ADD(name, 1)
150 #endif
151 /*
152  * As we get each SACK we wade through the
153  * rc_map and mark off what is acked.
154  * We also increment rc_sacked as well.
155  *
156  * We also pay attention to missing entries
157  * based on the time and possibly mark them
158  * for retransmit. If we do and we are not already
159  * in recovery we enter recovery. In doing
160  * so we claer prr_delivered/holes_rxt and prr_sent_dur_rec.
161  * We also setup rc_next/rc_snd_nxt/rc_send_end so
162  * we will know where to send from. When not in
163  * recovery rc_next will be NULL and rc_snd_nxt should
164  * equal snd_max.
165  *
166  * Whenever we retransmit from recovery we increment
167  * rc_holes_rxt as we retran a block and mark it as retransmitted
168  * with the time it was sent. During non-recovery sending we
169  * add to our map and note the time down of any send expanding
170  * the rc_map at the tail and moving rc_snd_nxt up with snd_max.
171  *
172  * In recovery during SACK/ACK processing if a chunk has
173  * been retransmitted and it is now acked, we decrement rc_holes_rxt.
174  * When we retransmit from the scoreboard we use
175  * rc_next and rc_snd_nxt/rc_send_end to help us
176  * find what needs to be retran.
177  *
178  * To calculate pipe we simply take (snd_max - snd_una) + rc_holes_rxt
179  * This gets us the effect of RFC6675 pipe, counting twice for
180  * bytes retransmitted.
181  */
182
183 #define TT_RACK_FR_TMR  0x2000
184
185 /*
186  * Locking for the rack control block.
187  * a) Locked by INP_WLOCK
188  * b) Locked by the hpts-mutex
189  *
190  */
191
192 struct rack_control {
193         /* Second cache line 0x40 from tcp_rack */
194         struct rack_head rc_map;/* List of all segments Lock(a) */
195         struct rack_head rc_tmap;       /* List in transmit order Lock(a) */
196         struct rack_sendmap *rc_tlpsend;        /* Remembered place for
197                                                  * tlp_sending Lock(a) */
198         struct rack_sendmap *rc_resend; /* something we have been asked to
199                                          * resend */
200         uint32_t rc_hpts_flags;
201         uint32_t rc_timer_exp;  /* If a timer ticks of expiry */
202         uint32_t rc_rack_min_rtt;       /* lowest RTT seen Lock(a) */
203         uint32_t rc_rack_largest_cwnd;  /* Largest CWND we have seen Lock(a) */
204
205         /* Third Cache line 0x80 */
206         struct rack_head rc_free;       /* Allocation array */
207         uint32_t rc_time_last_sent;     /* Time we last sent some data and
208                                          * logged it Lock(a). */
209         uint32_t rc_reorder_ts; /* Last time we saw reordering Lock(a) */
210
211         uint32_t rc_tlp_new_data;       /* we need to send new-data on a TLP
212                                          * Lock(a) */
213         uint32_t rc_prr_out;    /* bytes sent during recovery Lock(a) */
214
215         uint32_t rc_prr_recovery_fs;    /* recovery fs point Lock(a) */
216
217         uint32_t rc_prr_sndcnt; /* Prr sndcnt Lock(a) */
218
219         uint32_t rc_sacked;     /* Tot sacked on scoreboard Lock(a) */
220         uint32_t rc_last_tlp_seq;       /* Last tlp sequence Lock(a) */
221
222         uint32_t rc_prr_delivered;      /* during recovery prr var Lock(a) */
223         uint16_t rc_tlp_send_cnt;       /* Number of TLP sends we have done
224                                          * since peer spoke to us Lock(a) */
225         uint16_t rc_tlp_seg_send_cnt;   /* Number of times we have TLP sent
226                                          * rc_last_tlp_seq Lock(a) */
227
228         uint32_t rc_loss_count; /* During recovery how many segments were lost
229                                  * Lock(a) */
230         uint32_t rc_reorder_fade;       /* Socket option value Lock(a) */
231
232         /* Forth cache line 0xc0  */
233         /* Times */
234
235         uint32_t rc_rack_tmit_time;     /* Rack transmit time Lock(a) */
236         uint32_t rc_holes_rxt;  /* Tot retraned from scoreboard Lock(a) */
237
238         /* Variables to track bad retransmits and recover */
239         uint32_t rc_rsm_start;  /* RSM seq number we retransmitted Lock(a) */
240         uint32_t rc_cwnd_at;    /* cwnd at the retransmit Lock(a) */
241
242         uint32_t rc_ssthresh_at;/* ssthresh at the retransmit Lock(a) */
243         uint32_t rc_num_maps_alloced;   /* Number of map blocks (sacks) we
244                                          * have allocated */
245         uint32_t rc_rcvtime;    /* When we last received data */
246         uint32_t rc_num_split_allocs;   /* num split map entries allocated */
247         uint32_t rc_last_output_to; 
248         uint32_t rc_went_idle_time;
249
250         struct rack_sendmap *rc_sacklast;       /* sack remembered place
251                                                  * Lock(a) */
252
253         struct rack_sendmap *rc_next;   /* remembered place where we next
254                                          * retransmit at Lock(a) */
255         struct rack_sendmap *rc_rsm_at_retran;  /* Debug variable kept for
256                                                  * cache line alignment
257                                                  * Lock(a) */
258         /* Cache line split 0x100 */
259         struct sack_filter rack_sf;
260         /* Cache line split 0x140 */
261         /* Flags for various things */
262         struct rack_rtt_sample rack_rs;
263         uint32_t rc_tlp_threshold;      /* Socket option value Lock(a) */
264         uint16_t rc_early_recovery_segs;        /* Socket option value Lock(a) */
265         uint16_t rc_reorder_shift;      /* Socket option value Lock(a) */
266         uint16_t rc_pkt_delay;  /* Socket option value Lock(a) */
267         uint8_t rc_prop_rate;   /* Socket option value Lock(a) */
268         uint8_t rc_prop_reduce; /* Socket option value Lock(a) */
269         uint8_t rc_tlp_cwnd_reduce;     /* Socket option value Lock(a) */
270         uint8_t rc_early_recovery;      /* Socket option value Lock(a) */
271         uint8_t rc_prr_sendalot;/* Socket option value Lock(a) */
272         uint8_t rc_min_to;      /* Socket option value Lock(a) */
273         uint8_t rc_prr_inc_var; /* Socket option value Lock(a) */
274         uint8_t rc_tlp_rtx_out; /* This is TLPRtxOut in the draft */
275         uint8_t rc_rate_sample_method;
276 };
277
278 #ifdef _KERNEL
279
280 struct tcp_rack {
281         /* First cache line 0x00 */
282         TAILQ_ENTRY(tcp_rack) r_hpts;   /* hptsi queue next Lock(b) */
283         int32_t(*r_substate) (struct mbuf *, struct tcphdr *,
284             struct socket *, struct tcpcb *, struct tcpopt *,
285             int32_t, int32_t, uint32_t, int, int);      /* Lock(a) */
286         struct tcpcb *rc_tp;    /* The tcpcb Lock(a) */
287         struct inpcb *rc_inp;   /* The inpcb Lock(a) */
288         uint32_t rc_free_cnt;   /* Number of free entries on the rc_free list
289                                  * Lock(a) */
290         uint32_t rc_rack_rtt;   /* RACK-RTT Lock(a) */
291         uint16_t r_wanted_output;       /* Output routine wanted to be called */
292         uint16_t r_cpu;         /* CPU that the INP is running on Lock(a) */
293         uint16_t rc_pace_max_segs;      /* Socket option value Lock(a) */
294         uint16_t rc_pace_reduce;/* Socket option value Lock(a) */
295
296         uint8_t r_state;        /* Current rack state Lock(a) */
297         uint8_t rc_tmr_stopped : 7,
298                 t_timers_stopped : 1;
299         uint8_t rc_enobuf;      /* count of enobufs on connection provides
300                                  * backoff Lock(a) */
301         uint8_t r_timer_override : 1,   /* hpts override Lock(a) */
302                 r_tlp_running : 1,      /* Running from a TLP timeout Lock(a) */
303                 r_is_v6 : 1,    /* V6 pcb Lock(a)  */
304                 rc_in_persist : 1,
305                 rc_last_pto_set : 1, /* XXX not used */
306                 rc_tlp_in_progress : 1,
307                 rc_always_pace : 1,     /* Socket option value Lock(a) */
308                 rc_timer_up : 1;        /* The rack timer is up flag  Lock(a) */
309         uint8_t r_idle_reduce_largest : 1,
310                 r_enforce_min_pace : 2,
311                 r_min_pace_seg_thresh : 5;
312         uint8_t rack_tlp_threshold_use;
313         uint8_t rc_allow_data_af_clo: 1,
314                 delayed_ack : 1,
315                 alloc_limit_reported : 1,
316                 rc_avail : 5;
317         uint8_t r_resv[2];      /* Fill to cache line boundary */
318         /* Cache line 2 0x40 */
319         struct rack_control r_ctl;
320 }        __aligned(CACHE_LINE_SIZE);
321
322 #endif
323 #endif