netfilter: xtables: move extension arguments into compound structure (5/6)
[safe/jmp/linux-2.6] / net / ipv4 / tcp_vegas.c
index 93c5f92..14504da 100644 (file)
@@ -31,7 +31,6 @@
  *     assumed senders never went idle.
  */
 
-#include <linux/config.h>
 #include <linux/mm.h>
 #include <linux/module.h>
 #include <linux/skbuff.h>
 
 #include <net/tcp.h>
 
+#include "tcp_vegas.h"
+
 /* Default values of the Vegas variables, in fixed-point representation
  * with V_PARAM_SHIFT bits to the right of the binary point.
  */
 #define V_PARAM_SHIFT 1
-static int alpha = 1<<V_PARAM_SHIFT;
-static int beta  = 3<<V_PARAM_SHIFT;
+static int alpha = 2<<V_PARAM_SHIFT;
+static int beta  = 4<<V_PARAM_SHIFT;
 static int gamma = 1<<V_PARAM_SHIFT;
 
 module_param(alpha, int, 0644);
@@ -55,17 +56,6 @@ module_param(gamma, int, 0644);
 MODULE_PARM_DESC(gamma, "limit on increase (scale by 2)");
 
 
-/* Vegas variables */
-struct vegas {
-       u32     beg_snd_nxt;    /* right edge during last RTT */
-       u32     beg_snd_una;    /* left edge  during last RTT */
-       u32     beg_snd_cwnd;   /* saves the size of the cwnd */
-       u8      doing_vegas_now;/* if true, do vegas for this RTT */
-       u16     cntRTT;         /* # of RTTs measured within last RTT */
-       u32     minRTT;         /* min of RTTs measured within last RTT (in usec) */
-       u32     baseRTT;        /* the min of all Vegas RTT measurements seen (in usec) */
-};
-
 /* There are several situations when we must "re-start" Vegas:
  *
  *  o when a connection is established
@@ -82,7 +72,7 @@ struct vegas {
  * Instead we must wait until the completion of an RTT during
  * which we actually receive ACKs.
  */
-static inline void vegas_enable(struct sock *sk)
+static void vegas_enable(struct sock *sk)
 {
        const struct tcp_sock *tp = tcp_sk(sk);
        struct vegas *vegas = inet_csk_ca(sk);
@@ -105,13 +95,14 @@ static inline void vegas_disable(struct sock *sk)
        vegas->doing_vegas_now = 0;
 }
 
-static void tcp_vegas_init(struct sock *sk)
+void tcp_vegas_init(struct sock *sk)
 {
        struct vegas *vegas = inet_csk_ca(sk);
 
        vegas->baseRTT = 0x7fffffff;
        vegas_enable(sk);
 }
+EXPORT_SYMBOL_GPL(tcp_vegas_init);
 
 /* Do RTT sampling needed for Vegas.
  * Basically we:
@@ -121,10 +112,16 @@ static void tcp_vegas_init(struct sock *sk)
  *   o min-filter RTT samples from a much longer window (forever for now)
  *     to find the propagation delay (baseRTT)
  */
-static void tcp_vegas_rtt_calc(struct sock *sk, u32 usrtt)
+void tcp_vegas_pkts_acked(struct sock *sk, u32 cnt, s32 rtt_us)
 {
        struct vegas *vegas = inet_csk_ca(sk);
-       u32 vrtt = usrtt + 1; /* Never allow zero rtt or baseRTT */
+       u32 vrtt;
+
+       if (rtt_us < 0)
+               return;
+
+       /* Never allow zero rtt or baseRTT */
+       vrtt = rtt_us + 1;
 
        /* Filter to find propagation delay: */
        if (vrtt < vegas->baseRTT)
@@ -136,8 +133,9 @@ static void tcp_vegas_rtt_calc(struct sock *sk, u32 usrtt)
        vegas->minRTT = min(vegas->minRTT, vrtt);
        vegas->cntRTT++;
 }
+EXPORT_SYMBOL_GPL(tcp_vegas_pkts_acked);
 
-static void tcp_vegas_state(struct sock *sk, u8 ca_state)
+void tcp_vegas_state(struct sock *sk, u8 ca_state)
 {
 
        if (ca_state == TCP_CA_Open)
@@ -145,6 +143,7 @@ static void tcp_vegas_state(struct sock *sk, u8 ca_state)
        else
                vegas_disable(sk);
 }
+EXPORT_SYMBOL_GPL(tcp_vegas_state);
 
 /*
  * If the connection is idle and we are restarting,
@@ -155,21 +154,23 @@ static void tcp_vegas_state(struct sock *sk, u8 ca_state)
  * packets, _then_ we can make Vegas calculations
  * again.
  */
-static void tcp_vegas_cwnd_event(struct sock *sk, enum tcp_ca_event event)
+void tcp_vegas_cwnd_event(struct sock *sk, enum tcp_ca_event event)
 {
        if (event == CA_EVENT_CWND_RESTART ||
            event == CA_EVENT_TX_START)
                tcp_vegas_init(sk);
 }
+EXPORT_SYMBOL_GPL(tcp_vegas_cwnd_event);
 
-static void tcp_vegas_cong_avoid(struct sock *sk, u32 ack,
-                                u32 seq_rtt, u32 in_flight, int flag)
+static void tcp_vegas_cong_avoid(struct sock *sk, u32 ack, u32 in_flight)
 {
        struct tcp_sock *tp = tcp_sk(sk);
        struct vegas *vegas = inet_csk_ca(sk);
 
-       if (!vegas->doing_vegas_now)
-               return tcp_reno_cong_avoid(sk, ack, seq_rtt, in_flight, flag);
+       if (!vegas->doing_vegas_now) {
+               tcp_reno_cong_avoid(sk, ack, in_flight);
+               return;
+       }
 
        /* The key players are v_beg_snd_una and v_beg_snd_nxt.
         *
@@ -215,14 +216,6 @@ static void tcp_vegas_cong_avoid(struct sock *sk, u32 ack,
                vegas->beg_snd_nxt  = tp->snd_nxt;
                vegas->beg_snd_cwnd = tp->snd_cwnd;
 
-               /* Take into account the current RTT sample too, to
-                * decrease the impact of delayed acks. This double counts
-                * this sample since we count it for the next window as well,
-                * but that's not too awful, since we're taking the min,
-                * rather than averaging.
-                */
-               tcp_vegas_rtt_calc(sk, seq_rtt * 1000);
-
                /* We do the Vegas calculations only if we got enough RTT
                 * samples that we can be reasonably sure that we got
                 * at least one RTT sample that wasn't from a delayed ACK.
@@ -236,10 +229,10 @@ static void tcp_vegas_cong_avoid(struct sock *sk, u32 ack,
                        /* We don't have enough RTT samples to do the Vegas
                         * calculation, so we'll behave like Reno.
                         */
-                       if (tp->snd_cwnd > tp->snd_ssthresh)
-                               tp->snd_cwnd++;
+                       tcp_reno_cong_avoid(sk, ack, in_flight);
                } else {
-                       u32 rtt, target_cwnd, diff;
+                       u32 rtt, diff;
+                       u64 target_cwnd;
 
                        /* We have enough RTT samples, so, using the Vegas
                         * algorithm, we determine if we should increase or
@@ -262,8 +255,9 @@ static void tcp_vegas_cong_avoid(struct sock *sk, u32 ack,
                         * We keep it as a fixed point number with
                         * V_PARAM_SHIFT bits to the right of the binary point.
                         */
-                       target_cwnd = ((old_wnd * vegas->baseRTT)
-                                      << V_PARAM_SHIFT) / rtt;
+                       target_cwnd = ((u64)old_wnd * vegas->baseRTT);
+                       target_cwnd <<= V_PARAM_SHIFT;
+                       do_div(target_cwnd, rtt);
 
                        /* Calculate the difference between the window we had,
                         * and the window we would like to have. This quantity
@@ -275,26 +269,26 @@ static void tcp_vegas_cong_avoid(struct sock *sk, u32 ack,
                         */
                        diff = (old_wnd << V_PARAM_SHIFT) - target_cwnd;
 
-                       if (tp->snd_cwnd < tp->snd_ssthresh) {
-                               /* Slow start.  */
-                               if (diff > gamma) {
-                                       /* Going too fast. Time to slow down
-                                        * and switch to congestion avoidance.
-                                        */
-                                       tp->snd_ssthresh = 2;
-
-                                       /* Set cwnd to match the actual rate
-                                        * exactly:
-                                        *   cwnd = (actual rate) * baseRTT
-                                        * Then we add 1 because the integer
-                                        * truncation robs us of full link
-                                        * utilization.
-                                        */
-                                       tp->snd_cwnd = min(tp->snd_cwnd,
-                                                          (target_cwnd >>
-                                                           V_PARAM_SHIFT)+1);
+                       if (diff > gamma && tp->snd_ssthresh > 2 ) {
+                               /* Going too fast. Time to slow down
+                                * and switch to congestion avoidance.
+                                */
+                               tp->snd_ssthresh = 2;
+
+                               /* Set cwnd to match the actual rate
+                                * exactly:
+                                *   cwnd = (actual rate) * baseRTT
+                                * Then we add 1 because the integer
+                                * truncation robs us of full link
+                                * utilization.
+                                */
+                               tp->snd_cwnd = min(tp->snd_cwnd,
+                                                  ((u32)target_cwnd >>
+                                                   V_PARAM_SHIFT)+1);
 
-                               }
+                       } else if (tp->snd_cwnd <= tp->snd_ssthresh) {
+                               /* Slow start.  */
+                               tcp_slow_start(tp);
                        } else {
                                /* Congestion avoidance. */
                                u32 next_snd_cwnd;
@@ -327,64 +321,47 @@ static void tcp_vegas_cong_avoid(struct sock *sk, u32 ack,
                                else if (next_snd_cwnd < tp->snd_cwnd)
                                        tp->snd_cwnd--;
                        }
+
+                       if (tp->snd_cwnd < 2)
+                               tp->snd_cwnd = 2;
+                       else if (tp->snd_cwnd > tp->snd_cwnd_clamp)
+                               tp->snd_cwnd = tp->snd_cwnd_clamp;
                }
 
                /* Wipe the slate clean for the next RTT. */
                vegas->cntRTT = 0;
                vegas->minRTT = 0x7fffffff;
        }
+       /* Use normal slow start */
+       else if (tp->snd_cwnd <= tp->snd_ssthresh)
+               tcp_slow_start(tp);
 
-       /* The following code is executed for every ack we receive,
-        * except for conditions checked in should_advance_cwnd()
-        * before the call to tcp_cong_avoid(). Mainly this means that
-        * we only execute this code if the ack actually acked some
-        * data.
-        */
-
-       /* If we are in slow start, increase our cwnd in response to this ACK.
-        * (If we are not in slow start then we are in congestion avoidance,
-        * and adjust our congestion window only once per RTT. See the code
-        * above.)
-        */
-       if (tp->snd_cwnd <= tp->snd_ssthresh)
-               tp->snd_cwnd++;
-
-       /* to keep cwnd from growing without bound */
-       tp->snd_cwnd = min_t(u32, tp->snd_cwnd, tp->snd_cwnd_clamp);
-
-       /* Make sure that we are never so timid as to reduce our cwnd below
-        * 2 MSS.
-        *
-        * Going below 2 MSS would risk huge delayed ACKs from our receiver.
-        */
-       tp->snd_cwnd = max(tp->snd_cwnd, 2U);
 }
 
 /* Extract info for Tcp socket info provided via netlink. */
-static void tcp_vegas_get_info(struct sock *sk, u32 ext,
-                              struct sk_buff *skb)
+void tcp_vegas_get_info(struct sock *sk, u32 ext, struct sk_buff *skb)
 {
        const struct vegas *ca = inet_csk_ca(sk);
        if (ext & (1 << (INET_DIAG_VEGASINFO - 1))) {
-               struct tcpvegas_info *info;
-
-               info = RTA_DATA(__RTA_PUT(skb, INET_DIAG_VEGASINFO,
-                                         sizeof(*info)));
-
-               info->tcpv_enabled = ca->doing_vegas_now;
-               info->tcpv_rttcnt = ca->cntRTT;
-               info->tcpv_rtt = ca->baseRTT;
-               info->tcpv_minrtt = ca->minRTT;
-       rtattr_failure: ;
+               struct tcpvegas_info info = {
+                       .tcpv_enabled = ca->doing_vegas_now,
+                       .tcpv_rttcnt = ca->cntRTT,
+                       .tcpv_rtt = ca->baseRTT,
+                       .tcpv_minrtt = ca->minRTT,
+               };
+
+               nla_put(skb, INET_DIAG_VEGASINFO, sizeof(info), &info);
        }
 }
+EXPORT_SYMBOL_GPL(tcp_vegas_get_info);
 
 static struct tcp_congestion_ops tcp_vegas = {
+       .flags          = TCP_CONG_RTT_STAMP,
        .init           = tcp_vegas_init,
        .ssthresh       = tcp_reno_ssthresh,
        .cong_avoid     = tcp_vegas_cong_avoid,
        .min_cwnd       = tcp_reno_min_cwnd,
-       .rtt_sample     = tcp_vegas_rtt_calc,
+       .pkts_acked     = tcp_vegas_pkts_acked,
        .set_state      = tcp_vegas_state,
        .cwnd_event     = tcp_vegas_cwnd_event,
        .get_info       = tcp_vegas_get_info,
@@ -395,7 +372,7 @@ static struct tcp_congestion_ops tcp_vegas = {
 
 static int __init tcp_vegas_register(void)
 {
-       BUG_ON(sizeof(struct vegas) > ICSK_CA_PRIV_SIZE);
+       BUILD_BUG_ON(sizeof(struct vegas) > ICSK_CA_PRIV_SIZE);
        tcp_register_congestion_control(&tcp_vegas);
        return 0;
 }