1*b87d8561SStephen Hemminger /* 2*b87d8561SStephen Hemminger * TCP Vegas congestion control 3*b87d8561SStephen Hemminger * 4*b87d8561SStephen Hemminger * This is based on the congestion detection/avoidance scheme described in 5*b87d8561SStephen Hemminger * Lawrence S. Brakmo and Larry L. Peterson. 6*b87d8561SStephen Hemminger * "TCP Vegas: End to end congestion avoidance on a global internet." 7*b87d8561SStephen Hemminger * IEEE Journal on Selected Areas in Communication, 13(8):1465--1480, 8*b87d8561SStephen Hemminger * October 1995. Available from: 9*b87d8561SStephen Hemminger * ftp://ftp.cs.arizona.edu/xkernel/Papers/jsac.ps 10*b87d8561SStephen Hemminger * 11*b87d8561SStephen Hemminger * See http://www.cs.arizona.edu/xkernel/ for their implementation. 12*b87d8561SStephen Hemminger * The main aspects that distinguish this implementation from the 13*b87d8561SStephen Hemminger * Arizona Vegas implementation are: 14*b87d8561SStephen Hemminger * o We do not change the loss detection or recovery mechanisms of 15*b87d8561SStephen Hemminger * Linux in any way. Linux already recovers from losses quite well, 16*b87d8561SStephen Hemminger * using fine-grained timers, NewReno, and FACK. 17*b87d8561SStephen Hemminger * o To avoid the performance penalty imposed by increasing cwnd 18*b87d8561SStephen Hemminger * only every-other RTT during slow start, we increase during 19*b87d8561SStephen Hemminger * every RTT during slow start, just like Reno. 20*b87d8561SStephen Hemminger * o Largely to allow continuous cwnd growth during slow start, 21*b87d8561SStephen Hemminger * we use the rate at which ACKs come back as the "actual" 22*b87d8561SStephen Hemminger * rate, rather than the rate at which data is sent. 23*b87d8561SStephen Hemminger * o To speed convergence to the right rate, we set the cwnd 24*b87d8561SStephen Hemminger * to achieve the right ("actual") rate when we exit slow start. 25*b87d8561SStephen Hemminger * o To filter out the noise caused by delayed ACKs, we use the 26*b87d8561SStephen Hemminger * minimum RTT sample observed during the last RTT to calculate 27*b87d8561SStephen Hemminger * the actual rate. 28*b87d8561SStephen Hemminger * o When the sender re-starts from idle, it waits until it has 29*b87d8561SStephen Hemminger * received ACKs for an entire flight of new data before making 30*b87d8561SStephen Hemminger * a cwnd adjustment decision. The original Vegas implementation 31*b87d8561SStephen Hemminger * assumed senders never went idle. 32*b87d8561SStephen Hemminger */ 33*b87d8561SStephen Hemminger 34*b87d8561SStephen Hemminger #include <linux/config.h> 35*b87d8561SStephen Hemminger #include <linux/mm.h> 36*b87d8561SStephen Hemminger #include <linux/module.h> 37*b87d8561SStephen Hemminger #include <linux/skbuff.h> 38*b87d8561SStephen Hemminger #include <linux/tcp_diag.h> 39*b87d8561SStephen Hemminger 40*b87d8561SStephen Hemminger #include <net/tcp.h> 41*b87d8561SStephen Hemminger 42*b87d8561SStephen Hemminger /* Default values of the Vegas variables, in fixed-point representation 43*b87d8561SStephen Hemminger * with V_PARAM_SHIFT bits to the right of the binary point. 44*b87d8561SStephen Hemminger */ 45*b87d8561SStephen Hemminger #define V_PARAM_SHIFT 1 46*b87d8561SStephen Hemminger static int alpha = 1<<V_PARAM_SHIFT; 47*b87d8561SStephen Hemminger static int beta = 3<<V_PARAM_SHIFT; 48*b87d8561SStephen Hemminger static int gamma = 1<<V_PARAM_SHIFT; 49*b87d8561SStephen Hemminger 50*b87d8561SStephen Hemminger module_param(alpha, int, 0644); 51*b87d8561SStephen Hemminger MODULE_PARM_DESC(alpha, "lower bound of packets in network (scale by 2)"); 52*b87d8561SStephen Hemminger module_param(beta, int, 0644); 53*b87d8561SStephen Hemminger MODULE_PARM_DESC(beta, "upper bound of packets in network (scale by 2)"); 54*b87d8561SStephen Hemminger module_param(gamma, int, 0644); 55*b87d8561SStephen Hemminger MODULE_PARM_DESC(gamma, "limit on increase (scale by 2)"); 56*b87d8561SStephen Hemminger 57*b87d8561SStephen Hemminger 58*b87d8561SStephen Hemminger /* Vegas variables */ 59*b87d8561SStephen Hemminger struct vegas { 60*b87d8561SStephen Hemminger u32 beg_snd_nxt; /* right edge during last RTT */ 61*b87d8561SStephen Hemminger u32 beg_snd_una; /* left edge during last RTT */ 62*b87d8561SStephen Hemminger u32 beg_snd_cwnd; /* saves the size of the cwnd */ 63*b87d8561SStephen Hemminger u8 doing_vegas_now;/* if true, do vegas for this RTT */ 64*b87d8561SStephen Hemminger u16 cntRTT; /* # of RTTs measured within last RTT */ 65*b87d8561SStephen Hemminger u32 minRTT; /* min of RTTs measured within last RTT (in usec) */ 66*b87d8561SStephen Hemminger u32 baseRTT; /* the min of all Vegas RTT measurements seen (in usec) */ 67*b87d8561SStephen Hemminger }; 68*b87d8561SStephen Hemminger 69*b87d8561SStephen Hemminger /* There are several situations when we must "re-start" Vegas: 70*b87d8561SStephen Hemminger * 71*b87d8561SStephen Hemminger * o when a connection is established 72*b87d8561SStephen Hemminger * o after an RTO 73*b87d8561SStephen Hemminger * o after fast recovery 74*b87d8561SStephen Hemminger * o when we send a packet and there is no outstanding 75*b87d8561SStephen Hemminger * unacknowledged data (restarting an idle connection) 76*b87d8561SStephen Hemminger * 77*b87d8561SStephen Hemminger * In these circumstances we cannot do a Vegas calculation at the 78*b87d8561SStephen Hemminger * end of the first RTT, because any calculation we do is using 79*b87d8561SStephen Hemminger * stale info -- both the saved cwnd and congestion feedback are 80*b87d8561SStephen Hemminger * stale. 81*b87d8561SStephen Hemminger * 82*b87d8561SStephen Hemminger * Instead we must wait until the completion of an RTT during 83*b87d8561SStephen Hemminger * which we actually receive ACKs. 84*b87d8561SStephen Hemminger */ 85*b87d8561SStephen Hemminger static inline void vegas_enable(struct tcp_sock *tp) 86*b87d8561SStephen Hemminger { 87*b87d8561SStephen Hemminger struct vegas *vegas = tcp_ca(tp); 88*b87d8561SStephen Hemminger 89*b87d8561SStephen Hemminger /* Begin taking Vegas samples next time we send something. */ 90*b87d8561SStephen Hemminger vegas->doing_vegas_now = 1; 91*b87d8561SStephen Hemminger 92*b87d8561SStephen Hemminger /* Set the beginning of the next send window. */ 93*b87d8561SStephen Hemminger vegas->beg_snd_nxt = tp->snd_nxt; 94*b87d8561SStephen Hemminger 95*b87d8561SStephen Hemminger vegas->cntRTT = 0; 96*b87d8561SStephen Hemminger vegas->minRTT = 0x7fffffff; 97*b87d8561SStephen Hemminger } 98*b87d8561SStephen Hemminger 99*b87d8561SStephen Hemminger /* Stop taking Vegas samples for now. */ 100*b87d8561SStephen Hemminger static inline void vegas_disable(struct tcp_sock *tp) 101*b87d8561SStephen Hemminger { 102*b87d8561SStephen Hemminger struct vegas *vegas = tcp_ca(tp); 103*b87d8561SStephen Hemminger 104*b87d8561SStephen Hemminger vegas->doing_vegas_now = 0; 105*b87d8561SStephen Hemminger } 106*b87d8561SStephen Hemminger 107*b87d8561SStephen Hemminger static void tcp_vegas_init(struct tcp_sock *tp) 108*b87d8561SStephen Hemminger { 109*b87d8561SStephen Hemminger struct vegas *vegas = tcp_ca(tp); 110*b87d8561SStephen Hemminger 111*b87d8561SStephen Hemminger vegas->baseRTT = 0x7fffffff; 112*b87d8561SStephen Hemminger vegas_enable(tp); 113*b87d8561SStephen Hemminger } 114*b87d8561SStephen Hemminger 115*b87d8561SStephen Hemminger /* Do RTT sampling needed for Vegas. 116*b87d8561SStephen Hemminger * Basically we: 117*b87d8561SStephen Hemminger * o min-filter RTT samples from within an RTT to get the current 118*b87d8561SStephen Hemminger * propagation delay + queuing delay (we are min-filtering to try to 119*b87d8561SStephen Hemminger * avoid the effects of delayed ACKs) 120*b87d8561SStephen Hemminger * o min-filter RTT samples from a much longer window (forever for now) 121*b87d8561SStephen Hemminger * to find the propagation delay (baseRTT) 122*b87d8561SStephen Hemminger */ 123*b87d8561SStephen Hemminger static void tcp_vegas_rtt_calc(struct tcp_sock *tp, u32 usrtt) 124*b87d8561SStephen Hemminger { 125*b87d8561SStephen Hemminger struct vegas *vegas = tcp_ca(tp); 126*b87d8561SStephen Hemminger u32 vrtt = usrtt + 1; /* Never allow zero rtt or baseRTT */ 127*b87d8561SStephen Hemminger 128*b87d8561SStephen Hemminger /* Filter to find propagation delay: */ 129*b87d8561SStephen Hemminger if (vrtt < vegas->baseRTT) 130*b87d8561SStephen Hemminger vegas->baseRTT = vrtt; 131*b87d8561SStephen Hemminger 132*b87d8561SStephen Hemminger /* Find the min RTT during the last RTT to find 133*b87d8561SStephen Hemminger * the current prop. delay + queuing delay: 134*b87d8561SStephen Hemminger */ 135*b87d8561SStephen Hemminger vegas->minRTT = min(vegas->minRTT, vrtt); 136*b87d8561SStephen Hemminger vegas->cntRTT++; 137*b87d8561SStephen Hemminger } 138*b87d8561SStephen Hemminger 139*b87d8561SStephen Hemminger static void tcp_vegas_state(struct tcp_sock *tp, u8 ca_state) 140*b87d8561SStephen Hemminger { 141*b87d8561SStephen Hemminger 142*b87d8561SStephen Hemminger if (ca_state == TCP_CA_Open) 143*b87d8561SStephen Hemminger vegas_enable(tp); 144*b87d8561SStephen Hemminger else 145*b87d8561SStephen Hemminger vegas_disable(tp); 146*b87d8561SStephen Hemminger } 147*b87d8561SStephen Hemminger 148*b87d8561SStephen Hemminger /* 149*b87d8561SStephen Hemminger * If the connection is idle and we are restarting, 150*b87d8561SStephen Hemminger * then we don't want to do any Vegas calculations 151*b87d8561SStephen Hemminger * until we get fresh RTT samples. So when we 152*b87d8561SStephen Hemminger * restart, we reset our Vegas state to a clean 153*b87d8561SStephen Hemminger * slate. After we get acks for this flight of 154*b87d8561SStephen Hemminger * packets, _then_ we can make Vegas calculations 155*b87d8561SStephen Hemminger * again. 156*b87d8561SStephen Hemminger */ 157*b87d8561SStephen Hemminger static void tcp_vegas_cwnd_event(struct tcp_sock *tp, enum tcp_ca_event event) 158*b87d8561SStephen Hemminger { 159*b87d8561SStephen Hemminger if (event == CA_EVENT_CWND_RESTART || 160*b87d8561SStephen Hemminger event == CA_EVENT_TX_START) 161*b87d8561SStephen Hemminger tcp_vegas_init(tp); 162*b87d8561SStephen Hemminger } 163*b87d8561SStephen Hemminger 164*b87d8561SStephen Hemminger static void tcp_vegas_cong_avoid(struct tcp_sock *tp, u32 ack, 165*b87d8561SStephen Hemminger u32 seq_rtt, u32 in_flight, int flag) 166*b87d8561SStephen Hemminger { 167*b87d8561SStephen Hemminger struct vegas *vegas = tcp_ca(tp); 168*b87d8561SStephen Hemminger 169*b87d8561SStephen Hemminger if (!vegas->doing_vegas_now) 170*b87d8561SStephen Hemminger return tcp_reno_cong_avoid(tp, ack, seq_rtt, in_flight, flag); 171*b87d8561SStephen Hemminger 172*b87d8561SStephen Hemminger /* The key players are v_beg_snd_una and v_beg_snd_nxt. 173*b87d8561SStephen Hemminger * 174*b87d8561SStephen Hemminger * These are so named because they represent the approximate values 175*b87d8561SStephen Hemminger * of snd_una and snd_nxt at the beginning of the current RTT. More 176*b87d8561SStephen Hemminger * precisely, they represent the amount of data sent during the RTT. 177*b87d8561SStephen Hemminger * At the end of the RTT, when we receive an ACK for v_beg_snd_nxt, 178*b87d8561SStephen Hemminger * we will calculate that (v_beg_snd_nxt - v_beg_snd_una) outstanding 179*b87d8561SStephen Hemminger * bytes of data have been ACKed during the course of the RTT, giving 180*b87d8561SStephen Hemminger * an "actual" rate of: 181*b87d8561SStephen Hemminger * 182*b87d8561SStephen Hemminger * (v_beg_snd_nxt - v_beg_snd_una) / (rtt duration) 183*b87d8561SStephen Hemminger * 184*b87d8561SStephen Hemminger * Unfortunately, v_beg_snd_una is not exactly equal to snd_una, 185*b87d8561SStephen Hemminger * because delayed ACKs can cover more than one segment, so they 186*b87d8561SStephen Hemminger * don't line up nicely with the boundaries of RTTs. 187*b87d8561SStephen Hemminger * 188*b87d8561SStephen Hemminger * Another unfortunate fact of life is that delayed ACKs delay the 189*b87d8561SStephen Hemminger * advance of the left edge of our send window, so that the number 190*b87d8561SStephen Hemminger * of bytes we send in an RTT is often less than our cwnd will allow. 191*b87d8561SStephen Hemminger * So we keep track of our cwnd separately, in v_beg_snd_cwnd. 192*b87d8561SStephen Hemminger */ 193*b87d8561SStephen Hemminger 194*b87d8561SStephen Hemminger if (after(ack, vegas->beg_snd_nxt)) { 195*b87d8561SStephen Hemminger /* Do the Vegas once-per-RTT cwnd adjustment. */ 196*b87d8561SStephen Hemminger u32 old_wnd, old_snd_cwnd; 197*b87d8561SStephen Hemminger 198*b87d8561SStephen Hemminger 199*b87d8561SStephen Hemminger /* Here old_wnd is essentially the window of data that was 200*b87d8561SStephen Hemminger * sent during the previous RTT, and has all 201*b87d8561SStephen Hemminger * been acknowledged in the course of the RTT that ended 202*b87d8561SStephen Hemminger * with the ACK we just received. Likewise, old_snd_cwnd 203*b87d8561SStephen Hemminger * is the cwnd during the previous RTT. 204*b87d8561SStephen Hemminger */ 205*b87d8561SStephen Hemminger old_wnd = (vegas->beg_snd_nxt - vegas->beg_snd_una) / 206*b87d8561SStephen Hemminger tp->mss_cache; 207*b87d8561SStephen Hemminger old_snd_cwnd = vegas->beg_snd_cwnd; 208*b87d8561SStephen Hemminger 209*b87d8561SStephen Hemminger /* Save the extent of the current window so we can use this 210*b87d8561SStephen Hemminger * at the end of the next RTT. 211*b87d8561SStephen Hemminger */ 212*b87d8561SStephen Hemminger vegas->beg_snd_una = vegas->beg_snd_nxt; 213*b87d8561SStephen Hemminger vegas->beg_snd_nxt = tp->snd_nxt; 214*b87d8561SStephen Hemminger vegas->beg_snd_cwnd = tp->snd_cwnd; 215*b87d8561SStephen Hemminger 216*b87d8561SStephen Hemminger /* Take into account the current RTT sample too, to 217*b87d8561SStephen Hemminger * decrease the impact of delayed acks. This double counts 218*b87d8561SStephen Hemminger * this sample since we count it for the next window as well, 219*b87d8561SStephen Hemminger * but that's not too awful, since we're taking the min, 220*b87d8561SStephen Hemminger * rather than averaging. 221*b87d8561SStephen Hemminger */ 222*b87d8561SStephen Hemminger tcp_vegas_rtt_calc(tp, seq_rtt*1000); 223*b87d8561SStephen Hemminger 224*b87d8561SStephen Hemminger /* We do the Vegas calculations only if we got enough RTT 225*b87d8561SStephen Hemminger * samples that we can be reasonably sure that we got 226*b87d8561SStephen Hemminger * at least one RTT sample that wasn't from a delayed ACK. 227*b87d8561SStephen Hemminger * If we only had 2 samples total, 228*b87d8561SStephen Hemminger * then that means we're getting only 1 ACK per RTT, which 229*b87d8561SStephen Hemminger * means they're almost certainly delayed ACKs. 230*b87d8561SStephen Hemminger * If we have 3 samples, we should be OK. 231*b87d8561SStephen Hemminger */ 232*b87d8561SStephen Hemminger 233*b87d8561SStephen Hemminger if (vegas->cntRTT <= 2) { 234*b87d8561SStephen Hemminger /* We don't have enough RTT samples to do the Vegas 235*b87d8561SStephen Hemminger * calculation, so we'll behave like Reno. 236*b87d8561SStephen Hemminger */ 237*b87d8561SStephen Hemminger if (tp->snd_cwnd > tp->snd_ssthresh) 238*b87d8561SStephen Hemminger tp->snd_cwnd++; 239*b87d8561SStephen Hemminger } else { 240*b87d8561SStephen Hemminger u32 rtt, target_cwnd, diff; 241*b87d8561SStephen Hemminger 242*b87d8561SStephen Hemminger /* We have enough RTT samples, so, using the Vegas 243*b87d8561SStephen Hemminger * algorithm, we determine if we should increase or 244*b87d8561SStephen Hemminger * decrease cwnd, and by how much. 245*b87d8561SStephen Hemminger */ 246*b87d8561SStephen Hemminger 247*b87d8561SStephen Hemminger /* Pluck out the RTT we are using for the Vegas 248*b87d8561SStephen Hemminger * calculations. This is the min RTT seen during the 249*b87d8561SStephen Hemminger * last RTT. Taking the min filters out the effects 250*b87d8561SStephen Hemminger * of delayed ACKs, at the cost of noticing congestion 251*b87d8561SStephen Hemminger * a bit later. 252*b87d8561SStephen Hemminger */ 253*b87d8561SStephen Hemminger rtt = vegas->minRTT; 254*b87d8561SStephen Hemminger 255*b87d8561SStephen Hemminger /* Calculate the cwnd we should have, if we weren't 256*b87d8561SStephen Hemminger * going too fast. 257*b87d8561SStephen Hemminger * 258*b87d8561SStephen Hemminger * This is: 259*b87d8561SStephen Hemminger * (actual rate in segments) * baseRTT 260*b87d8561SStephen Hemminger * We keep it as a fixed point number with 261*b87d8561SStephen Hemminger * V_PARAM_SHIFT bits to the right of the binary point. 262*b87d8561SStephen Hemminger */ 263*b87d8561SStephen Hemminger target_cwnd = ((old_wnd * vegas->baseRTT) 264*b87d8561SStephen Hemminger << V_PARAM_SHIFT) / rtt; 265*b87d8561SStephen Hemminger 266*b87d8561SStephen Hemminger /* Calculate the difference between the window we had, 267*b87d8561SStephen Hemminger * and the window we would like to have. This quantity 268*b87d8561SStephen Hemminger * is the "Diff" from the Arizona Vegas papers. 269*b87d8561SStephen Hemminger * 270*b87d8561SStephen Hemminger * Again, this is a fixed point number with 271*b87d8561SStephen Hemminger * V_PARAM_SHIFT bits to the right of the binary 272*b87d8561SStephen Hemminger * point. 273*b87d8561SStephen Hemminger */ 274*b87d8561SStephen Hemminger diff = (old_wnd << V_PARAM_SHIFT) - target_cwnd; 275*b87d8561SStephen Hemminger 276*b87d8561SStephen Hemminger if (tp->snd_cwnd < tp->snd_ssthresh) { 277*b87d8561SStephen Hemminger /* Slow start. */ 278*b87d8561SStephen Hemminger if (diff > gamma) { 279*b87d8561SStephen Hemminger /* Going too fast. Time to slow down 280*b87d8561SStephen Hemminger * and switch to congestion avoidance. 281*b87d8561SStephen Hemminger */ 282*b87d8561SStephen Hemminger tp->snd_ssthresh = 2; 283*b87d8561SStephen Hemminger 284*b87d8561SStephen Hemminger /* Set cwnd to match the actual rate 285*b87d8561SStephen Hemminger * exactly: 286*b87d8561SStephen Hemminger * cwnd = (actual rate) * baseRTT 287*b87d8561SStephen Hemminger * Then we add 1 because the integer 288*b87d8561SStephen Hemminger * truncation robs us of full link 289*b87d8561SStephen Hemminger * utilization. 290*b87d8561SStephen Hemminger */ 291*b87d8561SStephen Hemminger tp->snd_cwnd = min(tp->snd_cwnd, 292*b87d8561SStephen Hemminger (target_cwnd >> 293*b87d8561SStephen Hemminger V_PARAM_SHIFT)+1); 294*b87d8561SStephen Hemminger 295*b87d8561SStephen Hemminger } 296*b87d8561SStephen Hemminger } else { 297*b87d8561SStephen Hemminger /* Congestion avoidance. */ 298*b87d8561SStephen Hemminger u32 next_snd_cwnd; 299*b87d8561SStephen Hemminger 300*b87d8561SStephen Hemminger /* Figure out where we would like cwnd 301*b87d8561SStephen Hemminger * to be. 302*b87d8561SStephen Hemminger */ 303*b87d8561SStephen Hemminger if (diff > beta) { 304*b87d8561SStephen Hemminger /* The old window was too fast, so 305*b87d8561SStephen Hemminger * we slow down. 306*b87d8561SStephen Hemminger */ 307*b87d8561SStephen Hemminger next_snd_cwnd = old_snd_cwnd - 1; 308*b87d8561SStephen Hemminger } else if (diff < alpha) { 309*b87d8561SStephen Hemminger /* We don't have enough extra packets 310*b87d8561SStephen Hemminger * in the network, so speed up. 311*b87d8561SStephen Hemminger */ 312*b87d8561SStephen Hemminger next_snd_cwnd = old_snd_cwnd + 1; 313*b87d8561SStephen Hemminger } else { 314*b87d8561SStephen Hemminger /* Sending just as fast as we 315*b87d8561SStephen Hemminger * should be. 316*b87d8561SStephen Hemminger */ 317*b87d8561SStephen Hemminger next_snd_cwnd = old_snd_cwnd; 318*b87d8561SStephen Hemminger } 319*b87d8561SStephen Hemminger 320*b87d8561SStephen Hemminger /* Adjust cwnd upward or downward, toward the 321*b87d8561SStephen Hemminger * desired value. 322*b87d8561SStephen Hemminger */ 323*b87d8561SStephen Hemminger if (next_snd_cwnd > tp->snd_cwnd) 324*b87d8561SStephen Hemminger tp->snd_cwnd++; 325*b87d8561SStephen Hemminger else if (next_snd_cwnd < tp->snd_cwnd) 326*b87d8561SStephen Hemminger tp->snd_cwnd--; 327*b87d8561SStephen Hemminger } 328*b87d8561SStephen Hemminger } 329*b87d8561SStephen Hemminger 330*b87d8561SStephen Hemminger /* Wipe the slate clean for the next RTT. */ 331*b87d8561SStephen Hemminger vegas->cntRTT = 0; 332*b87d8561SStephen Hemminger vegas->minRTT = 0x7fffffff; 333*b87d8561SStephen Hemminger } 334*b87d8561SStephen Hemminger 335*b87d8561SStephen Hemminger /* The following code is executed for every ack we receive, 336*b87d8561SStephen Hemminger * except for conditions checked in should_advance_cwnd() 337*b87d8561SStephen Hemminger * before the call to tcp_cong_avoid(). Mainly this means that 338*b87d8561SStephen Hemminger * we only execute this code if the ack actually acked some 339*b87d8561SStephen Hemminger * data. 340*b87d8561SStephen Hemminger */ 341*b87d8561SStephen Hemminger 342*b87d8561SStephen Hemminger /* If we are in slow start, increase our cwnd in response to this ACK. 343*b87d8561SStephen Hemminger * (If we are not in slow start then we are in congestion avoidance, 344*b87d8561SStephen Hemminger * and adjust our congestion window only once per RTT. See the code 345*b87d8561SStephen Hemminger * above.) 346*b87d8561SStephen Hemminger */ 347*b87d8561SStephen Hemminger if (tp->snd_cwnd <= tp->snd_ssthresh) 348*b87d8561SStephen Hemminger tp->snd_cwnd++; 349*b87d8561SStephen Hemminger 350*b87d8561SStephen Hemminger /* to keep cwnd from growing without bound */ 351*b87d8561SStephen Hemminger tp->snd_cwnd = min_t(u32, tp->snd_cwnd, tp->snd_cwnd_clamp); 352*b87d8561SStephen Hemminger 353*b87d8561SStephen Hemminger /* Make sure that we are never so timid as to reduce our cwnd below 354*b87d8561SStephen Hemminger * 2 MSS. 355*b87d8561SStephen Hemminger * 356*b87d8561SStephen Hemminger * Going below 2 MSS would risk huge delayed ACKs from our receiver. 357*b87d8561SStephen Hemminger */ 358*b87d8561SStephen Hemminger tp->snd_cwnd = max(tp->snd_cwnd, 2U); 359*b87d8561SStephen Hemminger } 360*b87d8561SStephen Hemminger 361*b87d8561SStephen Hemminger /* Extract info for Tcp socket info provided via netlink. */ 362*b87d8561SStephen Hemminger static void tcp_vegas_get_info(struct tcp_sock *tp, u32 ext, 363*b87d8561SStephen Hemminger struct sk_buff *skb) 364*b87d8561SStephen Hemminger { 365*b87d8561SStephen Hemminger const struct vegas *ca = tcp_ca(tp); 366*b87d8561SStephen Hemminger if (ext & (1<<(TCPDIAG_VEGASINFO-1))) { 367*b87d8561SStephen Hemminger struct tcpvegas_info *info; 368*b87d8561SStephen Hemminger 369*b87d8561SStephen Hemminger info = RTA_DATA(__RTA_PUT(skb, TCPDIAG_VEGASINFO, 370*b87d8561SStephen Hemminger sizeof(*info))); 371*b87d8561SStephen Hemminger 372*b87d8561SStephen Hemminger info->tcpv_enabled = ca->doing_vegas_now; 373*b87d8561SStephen Hemminger info->tcpv_rttcnt = ca->cntRTT; 374*b87d8561SStephen Hemminger info->tcpv_rtt = ca->baseRTT; 375*b87d8561SStephen Hemminger info->tcpv_minrtt = ca->minRTT; 376*b87d8561SStephen Hemminger rtattr_failure: ; 377*b87d8561SStephen Hemminger } 378*b87d8561SStephen Hemminger } 379*b87d8561SStephen Hemminger 380*b87d8561SStephen Hemminger static struct tcp_congestion_ops tcp_vegas = { 381*b87d8561SStephen Hemminger .init = tcp_vegas_init, 382*b87d8561SStephen Hemminger .ssthresh = tcp_reno_ssthresh, 383*b87d8561SStephen Hemminger .cong_avoid = tcp_vegas_cong_avoid, 384*b87d8561SStephen Hemminger .min_cwnd = tcp_reno_min_cwnd, 385*b87d8561SStephen Hemminger .rtt_sample = tcp_vegas_rtt_calc, 386*b87d8561SStephen Hemminger .set_state = tcp_vegas_state, 387*b87d8561SStephen Hemminger .cwnd_event = tcp_vegas_cwnd_event, 388*b87d8561SStephen Hemminger .get_info = tcp_vegas_get_info, 389*b87d8561SStephen Hemminger 390*b87d8561SStephen Hemminger .owner = THIS_MODULE, 391*b87d8561SStephen Hemminger .name = "vegas", 392*b87d8561SStephen Hemminger }; 393*b87d8561SStephen Hemminger 394*b87d8561SStephen Hemminger static int __init tcp_vegas_register(void) 395*b87d8561SStephen Hemminger { 396*b87d8561SStephen Hemminger BUG_ON(sizeof(struct vegas) > TCP_CA_PRIV_SIZE); 397*b87d8561SStephen Hemminger tcp_register_congestion_control(&tcp_vegas); 398*b87d8561SStephen Hemminger return 0; 399*b87d8561SStephen Hemminger } 400*b87d8561SStephen Hemminger 401*b87d8561SStephen Hemminger static void __exit tcp_vegas_unregister(void) 402*b87d8561SStephen Hemminger { 403*b87d8561SStephen Hemminger tcp_unregister_congestion_control(&tcp_vegas); 404*b87d8561SStephen Hemminger } 405*b87d8561SStephen Hemminger 406*b87d8561SStephen Hemminger module_init(tcp_vegas_register); 407*b87d8561SStephen Hemminger module_exit(tcp_vegas_unregister); 408*b87d8561SStephen Hemminger 409*b87d8561SStephen Hemminger MODULE_AUTHOR("Stephen Hemminger"); 410*b87d8561SStephen Hemminger MODULE_LICENSE("GPL"); 411*b87d8561SStephen Hemminger MODULE_DESCRIPTION("TCP Vegas"); 412