Author: lstewart
Date: Sat May 28 05:17:52 2011
New Revision: 222403
URL: http://svn.freebsd.org/changeset/base/222403

Log:
  MFC r216114,217683:
  
  Import a clean-room implementation of the experimental CUBIC congestion 
control
  algorithm based on the Internet-Draft "draft-rhee-tcpm-cubic-02.txt". It is
  implemented as a kernel module compatible with the recently committed modular
  congestion control framework.
  
  CUBIC was designed for provide increased throughput in fast and long-distance
  networks. It attempts to maintain fairness when competing with legacy NewReno
  TCP in lower speed scenarios where NewReno is able to operate adequately.  The
  paper "CUBIC: A New TCP-Friendly High-Speed TCP Variant" provides additional
  detail.
  
  In collaboration with:        David Hayes <dahayes at swin edu au> and
                                Grenville Armitage <garmitage at swin edu au>
  Sponsored by: FreeBSD Foundation
  Reviewed by:  rpaulo

Added:
  stable/8/sys/modules/cc/cc_cubic/
     - copied from r216114, head/sys/modules/cc/cc_cubic/
  stable/8/sys/netinet/cc/cc_cubic.c
     - copied, changed from r216114, head/sys/netinet/cc/cc_cubic.c
  stable/8/sys/netinet/cc/cc_cubic.h
     - copied unchanged from r216114, head/sys/netinet/cc/cc_cubic.h
Modified:
  stable/8/sys/modules/cc/Makefile
Directory Properties:
  stable/8/sys/   (props changed)
  stable/8/sys/amd64/include/xen/   (props changed)
  stable/8/sys/cddl/contrib/opensolaris/   (props changed)
  stable/8/sys/contrib/dev/acpica/   (props changed)
  stable/8/sys/contrib/pf/   (props changed)

Modified: stable/8/sys/modules/cc/Makefile
==============================================================================
--- stable/8/sys/modules/cc/Makefile    Sat May 28 05:04:53 2011        
(r222402)
+++ stable/8/sys/modules/cc/Makefile    Sat May 28 05:17:52 2011        
(r222403)
@@ -1,5 +1,5 @@
 # $FreeBSD$
 
-SUBDIR=
+SUBDIR=        cc_cubic
 
 .include <bsd.subdir.mk>

Copied and modified: stable/8/sys/netinet/cc/cc_cubic.c (from r216114, 
head/sys/netinet/cc/cc_cubic.c)
==============================================================================
--- head/sys/netinet/cc/cc_cubic.c      Thu Dec  2 06:05:44 2010        
(r216114, copy source)
+++ stable/8/sys/netinet/cc/cc_cubic.c  Sat May 28 05:17:52 2011        
(r222403)
@@ -212,7 +212,7 @@ cubic_cb_init(struct cc_var *ccv)
        /* Init some key variables with sensible defaults. */
        cubic_data->t_last_cong = ticks;
        cubic_data->min_rtt_ticks = TCPTV_SRTTBASE;
-       cubic_data->mean_rtt_ticks = TCPTV_SRTTBASE;
+       cubic_data->mean_rtt_ticks = 1;
 
        ccv->cc_data = cubic_data;
 
@@ -328,12 +328,11 @@ cubic_post_recovery(struct cc_var *ccv)
        cubic_data->t_last_cong = ticks;
 
        /* Calculate the average RTT between congestion epochs. */
-       if (cubic_data->epoch_ack_count > 0 && cubic_data->sum_rtt_ticks > 0)
+       if (cubic_data->epoch_ack_count > 0 &&
+           cubic_data->sum_rtt_ticks >= cubic_data->epoch_ack_count) {
                cubic_data->mean_rtt_ticks = (int)(cubic_data->sum_rtt_ticks /
                    cubic_data->epoch_ack_count);
-       else
-               /* For safety. */
-               cubic_data->mean_rtt_ticks = cubic_data->min_rtt_ticks;
+       }
 
        cubic_data->epoch_ack_count = 0;
        cubic_data->sum_rtt_ticks = 0;
@@ -362,9 +361,21 @@ cubic_record_rtt(struct cc_var *ccv)
                 * XXXLAS: Should there be some hysteresis for minrtt?
                 */
                if ((t_srtt_ticks < cubic_data->min_rtt_ticks ||
-                   cubic_data->min_rtt_ticks == TCPTV_SRTTBASE))
+                   cubic_data->min_rtt_ticks == TCPTV_SRTTBASE)) {
                        cubic_data->min_rtt_ticks = max(1, t_srtt_ticks);
 
+                       /*
+                        * If the connection is within its first congestion
+                        * epoch, ensure we prime mean_rtt_ticks with a
+                        * reasonable value until the epoch average RTT is
+                        * calculated in cubic_post_recovery().
+                        */
+                       if (cubic_data->min_rtt_ticks >
+                           cubic_data->mean_rtt_ticks)
+                               cubic_data->mean_rtt_ticks =
+                                   cubic_data->min_rtt_ticks;
+               }
+
                /* Sum samples for epoch average RTT calculation. */
                cubic_data->sum_rtt_ticks += t_srtt_ticks;
                cubic_data->epoch_ack_count++;

Copied: stable/8/sys/netinet/cc/cc_cubic.h (from r216114, 
head/sys/netinet/cc/cc_cubic.h)
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ stable/8/sys/netinet/cc/cc_cubic.h  Sat May 28 05:17:52 2011        
(r222403, copy of r216114, head/sys/netinet/cc/cc_cubic.h)
@@ -0,0 +1,229 @@
+/*-
+ * Copyright (c) 2008-2010 Lawrence Stewart <[email protected]>
+ * Copyright (c) 2010 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Lawrence Stewart while studying at the Centre
+ * for Advanced Internet Architectures, Swinburne University, made possible in
+ * part by a grant from the Cisco University Research Program Fund at Community
+ * Foundation Silicon Valley.
+ *
+ * Portions of this software were developed at the Centre for Advanced
+ * Internet Architectures, Swinburne University of Technology, Melbourne,
+ * Australia by David Hayes under sponsorship from the FreeBSD Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _NETINET_CC_CUBIC_H_
+#define _NETINET_CC_CUBIC_H_
+
+/* Number of bits of precision for fixed point math calcs. */
+#define        CUBIC_SHIFT             8
+
+#define        CUBIC_SHIFT_4           32
+
+/* 0.5 << CUBIC_SHIFT. */
+#define        RENO_BETA               128
+
+/* ~0.8 << CUBIC_SHIFT. */
+#define        CUBIC_BETA              204
+
+/* ~0.2 << CUBIC_SHIFT. */
+#define        ONE_SUB_CUBIC_BETA      51
+
+/* 3 * ONE_SUB_CUBIC_BETA. */
+#define        THREE_X_PT2             153
+
+/* (2 << CUBIC_SHIFT) - ONE_SUB_CUBIC_BETA. */
+#define        TWO_SUB_PT2             461
+
+/* ~0.4 << CUBIC_SHIFT. */
+#define        CUBIC_C_FACTOR          102
+
+/* CUBIC fast convergence factor: ~0.9 << CUBIC_SHIFT. */
+#define        CUBIC_FC_FACTOR         230
+
+/* Don't trust s_rtt until this many rtt samples have been taken. */
+#define        CUBIC_MIN_RTT_SAMPLES   8
+
+/* Userland only bits. */
+#ifndef _KERNEL
+
+extern int hz;
+
+/*
+ * Implementation based on the formulae found in the CUBIC Internet Draft
+ * "draft-rhee-tcpm-cubic-02".
+ *
+ * Note BETA used in cc_cubic is equal to (1-beta) in the I-D
+ */
+
+static __inline float
+theoretical_cubic_k(double wmax_pkts)
+{
+       double C;
+
+       C = 0.4;
+
+       return (pow((wmax_pkts * 0.2) / C, (1.0 / 3.0)) * pow(2, CUBIC_SHIFT));
+}
+
+static __inline unsigned long
+theoretical_cubic_cwnd(int ticks_since_cong, unsigned long wmax, uint32_t smss)
+{
+       double C, wmax_pkts;
+
+       C = 0.4;
+       wmax_pkts = wmax / (double)smss;
+
+       return (smss * (wmax_pkts +
+           (C * pow(ticks_since_cong / (double)hz -
+           theoretical_cubic_k(wmax_pkts) / pow(2, CUBIC_SHIFT), 3.0))));
+}
+
+static __inline unsigned long
+theoretical_reno_cwnd(int ticks_since_cong, int rtt_ticks, unsigned long wmax,
+    uint32_t smss)
+{
+
+       return ((wmax * 0.5) + ((ticks_since_cong / (float)rtt_ticks) * smss));
+}
+
+static __inline unsigned long
+theoretical_tf_cwnd(int ticks_since_cong, int rtt_ticks, unsigned long wmax,
+    uint32_t smss)
+{
+
+       return ((wmax * 0.8) + ((3 * 0.2) / (2 - 0.2) *
+           (ticks_since_cong / (float)rtt_ticks) * smss));
+}
+
+#endif /* !_KERNEL */
+
+/*
+ * Compute the CUBIC K value used in the cwnd calculation, using an
+ * implementation of eqn 2 in the I-D. The method used
+ * here is adapted from Apple Computer Technical Report #KT-32.
+ */
+static __inline int64_t
+cubic_k(unsigned long wmax_pkts)
+{
+       int64_t s, K;
+       uint16_t p;
+
+       K = s = 0;
+       p = 0;
+
+       /* (wmax * beta)/C with CUBIC_SHIFT worth of precision. */
+       s = ((wmax_pkts * ONE_SUB_CUBIC_BETA) << CUBIC_SHIFT) / CUBIC_C_FACTOR;
+
+       /* Rebase s to be between 1 and 1/8 with a shift of CUBIC_SHIFT. */
+       while (s >= 256) {
+               s >>= 3;
+               p++;
+       }
+
+       /*
+        * Some magic constants taken from the Apple TR with appropriate
+        * shifts: 275 == 1.072302 << CUBIC_SHIFT, 98 == 0.3812513 <<
+        * CUBIC_SHIFT, 120 == 0.46946116 << CUBIC_SHIFT.
+        */
+       K = (((s * 275) >> CUBIC_SHIFT) + 98) -
+           (((s * s * 120) >> CUBIC_SHIFT) >> CUBIC_SHIFT);
+
+       /* Multiply by 2^p to undo the rebasing of s from above. */
+       return (K <<= p);
+}
+
+/*
+ * Compute the new cwnd value using an implementation of eqn 1 from the I-D.
+ * Thanks to Kip Macy for help debugging this function.
+ *
+ * XXXLAS: Characterise bounds for overflow.
+ */
+static __inline unsigned long
+cubic_cwnd(int ticks_since_cong, unsigned long wmax, uint32_t smss, int64_t K)
+{
+       int64_t cwnd;
+
+       /* K is in fixed point form with CUBIC_SHIFT worth of precision. */
+
+       /* t - K, with CUBIC_SHIFT worth of precision. */
+       cwnd = ((int64_t)(ticks_since_cong << CUBIC_SHIFT) - (K * hz)) / hz;
+
+       /* (t - K)^3, with CUBIC_SHIFT^3 worth of precision. */
+       cwnd *= (cwnd * cwnd);
+
+       /*
+        * C(t - K)^3 + wmax
+        * The down shift by CUBIC_SHIFT_4 is because cwnd has 4 lots of
+        * CUBIC_SHIFT included in the value. 3 from the cubing of cwnd above,
+        * and an extra from multiplying through by CUBIC_C_FACTOR.
+        */
+       cwnd = ((cwnd * CUBIC_C_FACTOR * smss) >> CUBIC_SHIFT_4) + wmax;
+
+       return ((unsigned long)cwnd);
+}
+
+/*
+ * Compute an approximation of the NewReno cwnd some number of ticks after a
+ * congestion event. RTT should be the average RTT estimate for the path
+ * measured over the previous congestion epoch and wmax is the value of cwnd at
+ * the last congestion event. The "TCP friendly" concept in the CUBIC I-D is
+ * rather tricky to understand and it turns out this function is not required.
+ * It is left here for reference.
+ */
+static __inline unsigned long
+reno_cwnd(int ticks_since_cong, int rtt_ticks, unsigned long wmax,
+    uint32_t smss)
+{
+
+       /*
+        * For NewReno, beta = 0.5, therefore: W_tcp(t) = wmax*0.5 + t/RTT
+        * W_tcp(t) deals with cwnd/wmax in pkts, so because our cwnd is in
+        * bytes, we have to multiply by smss.
+        */
+       return (((wmax * RENO_BETA) + (((ticks_since_cong * smss)
+           << CUBIC_SHIFT) / rtt_ticks)) >> CUBIC_SHIFT);
+}
+
+/*
+ * Compute an approximation of the "TCP friendly" cwnd some number of ticks
+ * after a congestion event that is designed to yield the same average cwnd as
+ * NewReno while using CUBIC's beta of 0.8. RTT should be the average RTT
+ * estimate for the path measured over the previous congestion epoch and wmax 
is
+ * the value of cwnd at the last congestion event.
+ */
+static __inline unsigned long
+tf_cwnd(int ticks_since_cong, int rtt_ticks, unsigned long wmax,
+    uint32_t smss)
+{
+
+       /* Equation 4 of I-D. */
+       return (((wmax * CUBIC_BETA) + (((THREE_X_PT2 * ticks_since_cong *
+           smss) << CUBIC_SHIFT) / TWO_SUB_PT2 / rtt_ticks)) >> CUBIC_SHIFT);
+}
+
+#endif /* _NETINET_CC_CUBIC_H_ */
_______________________________________________
[email protected] mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "[email protected]"

Reply via email to