Stephen Hemminger | df3271f | 2005-12-13 23:13:28 -0800 | [diff] [blame] | 1 | /* |
Sangtae Ha | 6b3d626 | 2008-03-04 14:17:41 -0800 | [diff] [blame] | 2 | * TCP CUBIC: Binary Increase Congestion control for TCP v2.2 |
| 3 | * Home page: |
| 4 | * http://netsrv.csc.ncsu.edu/twiki/bin/view/Main/BIC |
Stephen Hemminger | df3271f | 2005-12-13 23:13:28 -0800 | [diff] [blame] | 5 | * This is from the implementation of CUBIC TCP in |
| 6 | * Injong Rhee, Lisong Xu. |
| 7 | * "CUBIC: A New TCP-Friendly High-Speed TCP Variant |
| 8 | * in PFLDnet 2005 |
| 9 | * Available from: |
Sangtae Ha | 6b3d626 | 2008-03-04 14:17:41 -0800 | [diff] [blame] | 10 | * http://netsrv.csc.ncsu.edu/export/cubic-paper.pdf |
Stephen Hemminger | df3271f | 2005-12-13 23:13:28 -0800 | [diff] [blame] | 11 | * |
| 12 | * Unless CUBIC is enabled and congestion window is large |
| 13 | * this behaves the same as the original Reno. |
| 14 | */ |
| 15 | |
Stephen Hemminger | df3271f | 2005-12-13 23:13:28 -0800 | [diff] [blame] | 16 | #include <linux/mm.h> |
| 17 | #include <linux/module.h> |
| 18 | #include <net/tcp.h> |
Stephen Hemminger | 89b3d9a | 2005-12-21 19:32:08 -0800 | [diff] [blame] | 19 | #include <asm/div64.h> |
Stephen Hemminger | df3271f | 2005-12-13 23:13:28 -0800 | [diff] [blame] | 20 | |
| 21 | #define BICTCP_BETA_SCALE 1024 /* Scale factor beta calculation |
| 22 | * max_cwnd = snd_cwnd * beta |
| 23 | */ |
Stephen Hemminger | df3271f | 2005-12-13 23:13:28 -0800 | [diff] [blame] | 24 | #define BICTCP_HZ 10 /* BIC HZ 2^10 = 1024 */ |
| 25 | |
Stephen Hemminger | 59758f4 | 2007-02-12 13:15:20 -0800 | [diff] [blame] | 26 | static int fast_convergence __read_mostly = 1; |
Sangtae Ha | 6b3d626 | 2008-03-04 14:17:41 -0800 | [diff] [blame] | 27 | static int beta __read_mostly = 717; /* = 717/1024 (BICTCP_BETA_SCALE) */ |
David S. Miller | 66e1e3b | 2007-06-13 01:03:53 -0700 | [diff] [blame] | 28 | static int initial_ssthresh __read_mostly; |
Stephen Hemminger | 59758f4 | 2007-02-12 13:15:20 -0800 | [diff] [blame] | 29 | static int bic_scale __read_mostly = 41; |
| 30 | static int tcp_friendliness __read_mostly = 1; |
Stephen Hemminger | df3271f | 2005-12-13 23:13:28 -0800 | [diff] [blame] | 31 | |
Stephen Hemminger | 59758f4 | 2007-02-12 13:15:20 -0800 | [diff] [blame] | 32 | static u32 cube_rtt_scale __read_mostly; |
| 33 | static u32 beta_scale __read_mostly; |
| 34 | static u64 cube_factor __read_mostly; |
Stephen Hemminger | 89b3d9a | 2005-12-21 19:32:08 -0800 | [diff] [blame] | 35 | |
| 36 | /* Note parameters that are used for precomputing scale factors are read-only */ |
Stephen Hemminger | df3271f | 2005-12-13 23:13:28 -0800 | [diff] [blame] | 37 | module_param(fast_convergence, int, 0644); |
| 38 | MODULE_PARM_DESC(fast_convergence, "turn on/off fast convergence"); |
Sangtae Ha | 6b3d626 | 2008-03-04 14:17:41 -0800 | [diff] [blame] | 39 | module_param(beta, int, 0644); |
Stephen Hemminger | df3271f | 2005-12-13 23:13:28 -0800 | [diff] [blame] | 40 | MODULE_PARM_DESC(beta, "beta for multiplicative increase"); |
| 41 | module_param(initial_ssthresh, int, 0644); |
| 42 | MODULE_PARM_DESC(initial_ssthresh, "initial value of slow start threshold"); |
Stephen Hemminger | 89b3d9a | 2005-12-21 19:32:08 -0800 | [diff] [blame] | 43 | module_param(bic_scale, int, 0444); |
Stephen Hemminger | df3271f | 2005-12-13 23:13:28 -0800 | [diff] [blame] | 44 | MODULE_PARM_DESC(bic_scale, "scale (scaled by 1024) value for bic function (bic_scale/1024)"); |
| 45 | module_param(tcp_friendliness, int, 0644); |
| 46 | MODULE_PARM_DESC(tcp_friendliness, "turn on/off tcp friendliness"); |
| 47 | |
Stephen Hemminger | df3271f | 2005-12-13 23:13:28 -0800 | [diff] [blame] | 48 | /* BIC TCP Parameters */ |
| 49 | struct bictcp { |
| 50 | u32 cnt; /* increase cwnd by 1 after ACKs */ |
| 51 | u32 last_max_cwnd; /* last maximum snd_cwnd */ |
| 52 | u32 loss_cwnd; /* congestion window at last loss */ |
| 53 | u32 last_cwnd; /* the last snd_cwnd */ |
| 54 | u32 last_time; /* time when updated last_cwnd */ |
| 55 | u32 bic_origin_point;/* origin point of bic function */ |
| 56 | u32 bic_K; /* time to origin point from the beginning of the current epoch */ |
| 57 | u32 delay_min; /* min delay */ |
| 58 | u32 epoch_start; /* beginning of an epoch */ |
| 59 | u32 ack_cnt; /* number of acks */ |
| 60 | u32 tcp_cwnd; /* estimated tcp cwnd */ |
| 61 | #define ACK_RATIO_SHIFT 4 |
| 62 | u32 delayed_ack; /* estimate the ratio of Packets/ACKs << 4 */ |
| 63 | }; |
| 64 | |
| 65 | static inline void bictcp_reset(struct bictcp *ca) |
| 66 | { |
| 67 | ca->cnt = 0; |
| 68 | ca->last_max_cwnd = 0; |
| 69 | ca->loss_cwnd = 0; |
| 70 | ca->last_cwnd = 0; |
| 71 | ca->last_time = 0; |
| 72 | ca->bic_origin_point = 0; |
| 73 | ca->bic_K = 0; |
| 74 | ca->delay_min = 0; |
| 75 | ca->epoch_start = 0; |
| 76 | ca->delayed_ack = 2 << ACK_RATIO_SHIFT; |
| 77 | ca->ack_cnt = 0; |
| 78 | ca->tcp_cwnd = 0; |
| 79 | } |
| 80 | |
| 81 | static void bictcp_init(struct sock *sk) |
| 82 | { |
| 83 | bictcp_reset(inet_csk_ca(sk)); |
| 84 | if (initial_ssthresh) |
| 85 | tcp_sk(sk)->snd_ssthresh = initial_ssthresh; |
| 86 | } |
| 87 | |
Stephen Hemminger | 7e58886 | 2007-03-22 12:10:58 -0700 | [diff] [blame] | 88 | /* calculate the cubic root of x using a table lookup followed by one |
| 89 | * Newton-Raphson iteration. |
| 90 | * Avg err ~= 0.195% |
Stephen Hemminger | df3271f | 2005-12-13 23:13:28 -0800 | [diff] [blame] | 91 | */ |
Stephen Hemminger | 9eb2d62 | 2005-12-21 19:32:36 -0800 | [diff] [blame] | 92 | static u32 cubic_root(u64 a) |
Stephen Hemminger | df3271f | 2005-12-13 23:13:28 -0800 | [diff] [blame] | 93 | { |
Stephen Hemminger | 7e58886 | 2007-03-22 12:10:58 -0700 | [diff] [blame] | 94 | u32 x, b, shift; |
| 95 | /* |
| 96 | * cbrt(x) MSB values for x MSB values in [0..63]. |
| 97 | * Precomputed then refined by hand - Willy Tarreau |
| 98 | * |
| 99 | * For x in [0..63], |
| 100 | * v = cbrt(x << 18) - 1 |
| 101 | * cbrt(x) = (v[x] + 10) >> 6 |
Stephen Hemminger | 9eb2d62 | 2005-12-21 19:32:36 -0800 | [diff] [blame] | 102 | */ |
Stephen Hemminger | 7e58886 | 2007-03-22 12:10:58 -0700 | [diff] [blame] | 103 | static const u8 v[] = { |
| 104 | /* 0x00 */ 0, 54, 54, 54, 118, 118, 118, 118, |
| 105 | /* 0x08 */ 123, 129, 134, 138, 143, 147, 151, 156, |
| 106 | /* 0x10 */ 157, 161, 164, 168, 170, 173, 176, 179, |
| 107 | /* 0x18 */ 181, 185, 187, 190, 192, 194, 197, 199, |
| 108 | /* 0x20 */ 200, 202, 204, 206, 209, 211, 213, 215, |
| 109 | /* 0x28 */ 217, 219, 221, 222, 224, 225, 227, 229, |
| 110 | /* 0x30 */ 231, 232, 234, 236, 237, 239, 240, 242, |
| 111 | /* 0x38 */ 244, 245, 246, 248, 250, 251, 252, 254, |
| 112 | }; |
Stephen Hemminger | df3271f | 2005-12-13 23:13:28 -0800 | [diff] [blame] | 113 | |
Stephen Hemminger | 7e58886 | 2007-03-22 12:10:58 -0700 | [diff] [blame] | 114 | b = fls64(a); |
| 115 | if (b < 7) { |
| 116 | /* a in [0..63] */ |
| 117 | return ((u32)v[(u32)a] + 35) >> 6; |
| 118 | } |
Stephen Hemminger | df3271f | 2005-12-13 23:13:28 -0800 | [diff] [blame] | 119 | |
Stephen Hemminger | 7e58886 | 2007-03-22 12:10:58 -0700 | [diff] [blame] | 120 | b = ((b * 84) >> 8) - 1; |
| 121 | shift = (a >> (b * 3)); |
| 122 | |
| 123 | x = ((u32)(((u32)v[shift] + 10) << b)) >> 6; |
| 124 | |
| 125 | /* |
| 126 | * Newton-Raphson iteration |
| 127 | * 2 |
| 128 | * x = ( 2 * x + a / x ) / 3 |
| 129 | * k+1 k k |
| 130 | */ |
| 131 | x = (2 * x + (u32)div64_64(a, (u64)x * (u64)(x - 1))); |
| 132 | x = ((x * 341) >> 10); |
Stephen Hemminger | 9eb2d62 | 2005-12-21 19:32:36 -0800 | [diff] [blame] | 133 | return x; |
Stephen Hemminger | df3271f | 2005-12-13 23:13:28 -0800 | [diff] [blame] | 134 | } |
| 135 | |
Stephen Hemminger | df3271f | 2005-12-13 23:13:28 -0800 | [diff] [blame] | 136 | /* |
| 137 | * Compute congestion window to use. |
| 138 | */ |
| 139 | static inline void bictcp_update(struct bictcp *ca, u32 cwnd) |
| 140 | { |
Stephen Hemminger | 89b3d9a | 2005-12-21 19:32:08 -0800 | [diff] [blame] | 141 | u64 offs; |
Sangtae Ha | 6b3d626 | 2008-03-04 14:17:41 -0800 | [diff] [blame] | 142 | u32 delta, t, bic_target, max_cnt; |
Stephen Hemminger | df3271f | 2005-12-13 23:13:28 -0800 | [diff] [blame] | 143 | |
| 144 | ca->ack_cnt++; /* count the number of ACKs */ |
| 145 | |
| 146 | if (ca->last_cwnd == cwnd && |
| 147 | (s32)(tcp_time_stamp - ca->last_time) <= HZ / 32) |
| 148 | return; |
| 149 | |
| 150 | ca->last_cwnd = cwnd; |
| 151 | ca->last_time = tcp_time_stamp; |
| 152 | |
Stephen Hemminger | df3271f | 2005-12-13 23:13:28 -0800 | [diff] [blame] | 153 | if (ca->epoch_start == 0) { |
| 154 | ca->epoch_start = tcp_time_stamp; /* record the beginning of an epoch */ |
| 155 | ca->ack_cnt = 1; /* start counting */ |
| 156 | ca->tcp_cwnd = cwnd; /* syn with cubic */ |
| 157 | |
| 158 | if (ca->last_max_cwnd <= cwnd) { |
| 159 | ca->bic_K = 0; |
| 160 | ca->bic_origin_point = cwnd; |
| 161 | } else { |
Stephen Hemminger | 89b3d9a | 2005-12-21 19:32:08 -0800 | [diff] [blame] | 162 | /* Compute new K based on |
| 163 | * (wmax-cwnd) * (srtt>>3 / HZ) / c * 2^(3*bictcp_HZ) |
| 164 | */ |
| 165 | ca->bic_K = cubic_root(cube_factor |
| 166 | * (ca->last_max_cwnd - cwnd)); |
Stephen Hemminger | df3271f | 2005-12-13 23:13:28 -0800 | [diff] [blame] | 167 | ca->bic_origin_point = ca->last_max_cwnd; |
| 168 | } |
| 169 | } |
| 170 | |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 171 | /* cubic function - calc*/ |
| 172 | /* calculate c * time^3 / rtt, |
| 173 | * while considering overflow in calculation of time^3 |
Stephen Hemminger | 89b3d9a | 2005-12-21 19:32:08 -0800 | [diff] [blame] | 174 | * (so time^3 is done by using 64 bit) |
Stephen Hemminger | df3271f | 2005-12-13 23:13:28 -0800 | [diff] [blame] | 175 | * and without the support of division of 64bit numbers |
Stephen Hemminger | 89b3d9a | 2005-12-21 19:32:08 -0800 | [diff] [blame] | 176 | * (so all divisions are done by using 32 bit) |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 177 | * also NOTE the unit of those veriables |
| 178 | * time = (t - K) / 2^bictcp_HZ |
| 179 | * c = bic_scale >> 10 |
Stephen Hemminger | df3271f | 2005-12-13 23:13:28 -0800 | [diff] [blame] | 180 | * rtt = (srtt >> 3) / HZ |
| 181 | * !!! The following code does not have overflow problems, |
| 182 | * if the cwnd < 1 million packets !!! |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 183 | */ |
Stephen Hemminger | df3271f | 2005-12-13 23:13:28 -0800 | [diff] [blame] | 184 | |
| 185 | /* change the unit from HZ to bictcp_HZ */ |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 186 | t = ((tcp_time_stamp + (ca->delay_min>>3) - ca->epoch_start) |
Stephen Hemminger | df3271f | 2005-12-13 23:13:28 -0800 | [diff] [blame] | 187 | << BICTCP_HZ) / HZ; |
| 188 | |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 189 | if (t < ca->bic_K) /* t - K */ |
Stephen Hemminger | 89b3d9a | 2005-12-21 19:32:08 -0800 | [diff] [blame] | 190 | offs = ca->bic_K - t; |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 191 | else |
| 192 | offs = t - ca->bic_K; |
Stephen Hemminger | df3271f | 2005-12-13 23:13:28 -0800 | [diff] [blame] | 193 | |
Stephen Hemminger | 89b3d9a | 2005-12-21 19:32:08 -0800 | [diff] [blame] | 194 | /* c/rtt * (t-K)^3 */ |
| 195 | delta = (cube_rtt_scale * offs * offs * offs) >> (10+3*BICTCP_HZ); |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 196 | if (t < ca->bic_K) /* below origin*/ |
| 197 | bic_target = ca->bic_origin_point - delta; |
| 198 | else /* above origin*/ |
| 199 | bic_target = ca->bic_origin_point + delta; |
Stephen Hemminger | df3271f | 2005-12-13 23:13:28 -0800 | [diff] [blame] | 200 | |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 201 | /* cubic function - calc bictcp_cnt*/ |
| 202 | if (bic_target > cwnd) { |
Stephen Hemminger | df3271f | 2005-12-13 23:13:28 -0800 | [diff] [blame] | 203 | ca->cnt = cwnd / (bic_target - cwnd); |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 204 | } else { |
| 205 | ca->cnt = 100 * cwnd; /* very small increment*/ |
| 206 | } |
Stephen Hemminger | df3271f | 2005-12-13 23:13:28 -0800 | [diff] [blame] | 207 | |
Stephen Hemminger | df3271f | 2005-12-13 23:13:28 -0800 | [diff] [blame] | 208 | /* TCP Friendly */ |
| 209 | if (tcp_friendliness) { |
Stephen Hemminger | 89b3d9a | 2005-12-21 19:32:08 -0800 | [diff] [blame] | 210 | u32 scale = beta_scale; |
| 211 | delta = (cwnd * scale) >> 3; |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 212 | while (ca->ack_cnt > delta) { /* update tcp cwnd */ |
| 213 | ca->ack_cnt -= delta; |
| 214 | ca->tcp_cwnd++; |
Stephen Hemminger | df3271f | 2005-12-13 23:13:28 -0800 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | if (ca->tcp_cwnd > cwnd){ /* if bic is slower than tcp */ |
Stephen Hemminger | 89b3d9a | 2005-12-21 19:32:08 -0800 | [diff] [blame] | 218 | delta = ca->tcp_cwnd - cwnd; |
| 219 | max_cnt = cwnd / delta; |
Stephen Hemminger | df3271f | 2005-12-13 23:13:28 -0800 | [diff] [blame] | 220 | if (ca->cnt > max_cnt) |
| 221 | ca->cnt = max_cnt; |
| 222 | } |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 223 | } |
Stephen Hemminger | df3271f | 2005-12-13 23:13:28 -0800 | [diff] [blame] | 224 | |
| 225 | ca->cnt = (ca->cnt << ACK_RATIO_SHIFT) / ca->delayed_ack; |
| 226 | if (ca->cnt == 0) /* cannot be zero */ |
| 227 | ca->cnt = 1; |
| 228 | } |
| 229 | |
Ilpo Järvinen | c3a05c6 | 2007-12-02 00:47:59 +0200 | [diff] [blame] | 230 | static void bictcp_cong_avoid(struct sock *sk, u32 ack, u32 in_flight) |
Stephen Hemminger | df3271f | 2005-12-13 23:13:28 -0800 | [diff] [blame] | 231 | { |
| 232 | struct tcp_sock *tp = tcp_sk(sk); |
| 233 | struct bictcp *ca = inet_csk_ca(sk); |
| 234 | |
Stephen Hemminger | df3271f | 2005-12-13 23:13:28 -0800 | [diff] [blame] | 235 | if (!tcp_is_cwnd_limited(sk, in_flight)) |
| 236 | return; |
| 237 | |
| 238 | if (tp->snd_cwnd <= tp->snd_ssthresh) |
| 239 | tcp_slow_start(tp); |
| 240 | else { |
| 241 | bictcp_update(ca, tp->snd_cwnd); |
| 242 | |
| 243 | /* In dangerous area, increase slowly. |
| 244 | * In theory this is tp->snd_cwnd += 1 / tp->snd_cwnd |
| 245 | */ |
| 246 | if (tp->snd_cwnd_cnt >= ca->cnt) { |
| 247 | if (tp->snd_cwnd < tp->snd_cwnd_clamp) |
| 248 | tp->snd_cwnd++; |
| 249 | tp->snd_cwnd_cnt = 0; |
| 250 | } else |
| 251 | tp->snd_cwnd_cnt++; |
| 252 | } |
| 253 | |
| 254 | } |
| 255 | |
| 256 | static u32 bictcp_recalc_ssthresh(struct sock *sk) |
| 257 | { |
| 258 | const struct tcp_sock *tp = tcp_sk(sk); |
| 259 | struct bictcp *ca = inet_csk_ca(sk); |
| 260 | |
| 261 | ca->epoch_start = 0; /* end of epoch */ |
| 262 | |
| 263 | /* Wmax and fast convergence */ |
| 264 | if (tp->snd_cwnd < ca->last_max_cwnd && fast_convergence) |
| 265 | ca->last_max_cwnd = (tp->snd_cwnd * (BICTCP_BETA_SCALE + beta)) |
| 266 | / (2 * BICTCP_BETA_SCALE); |
| 267 | else |
| 268 | ca->last_max_cwnd = tp->snd_cwnd; |
| 269 | |
| 270 | ca->loss_cwnd = tp->snd_cwnd; |
| 271 | |
| 272 | return max((tp->snd_cwnd * beta) / BICTCP_BETA_SCALE, 2U); |
| 273 | } |
| 274 | |
| 275 | static u32 bictcp_undo_cwnd(struct sock *sk) |
| 276 | { |
| 277 | struct bictcp *ca = inet_csk_ca(sk); |
| 278 | |
| 279 | return max(tcp_sk(sk)->snd_cwnd, ca->last_max_cwnd); |
| 280 | } |
| 281 | |
Stephen Hemminger | df3271f | 2005-12-13 23:13:28 -0800 | [diff] [blame] | 282 | static void bictcp_state(struct sock *sk, u8 new_state) |
| 283 | { |
| 284 | if (new_state == TCP_CA_Loss) |
| 285 | bictcp_reset(inet_csk_ca(sk)); |
| 286 | } |
| 287 | |
| 288 | /* Track delayed acknowledgment ratio using sliding window |
| 289 | * ratio = (15*ratio + sample) / 16 |
| 290 | */ |
Stephen Hemminger | 30cfd0b | 2007-07-25 23:49:34 -0700 | [diff] [blame] | 291 | static void bictcp_acked(struct sock *sk, u32 cnt, s32 rtt_us) |
Stephen Hemminger | df3271f | 2005-12-13 23:13:28 -0800 | [diff] [blame] | 292 | { |
| 293 | const struct inet_connection_sock *icsk = inet_csk(sk); |
Stephen Hemminger | e7d0c88 | 2007-07-25 23:50:06 -0700 | [diff] [blame] | 294 | struct bictcp *ca = inet_csk_ca(sk); |
| 295 | u32 delay; |
Stephen Hemminger | df3271f | 2005-12-13 23:13:28 -0800 | [diff] [blame] | 296 | |
Ilpo Järvinen | 35e8694 | 2007-05-31 10:16:47 +0300 | [diff] [blame] | 297 | if (icsk->icsk_ca_state == TCP_CA_Open) { |
Stephen Hemminger | df3271f | 2005-12-13 23:13:28 -0800 | [diff] [blame] | 298 | cnt -= ca->delayed_ack >> ACK_RATIO_SHIFT; |
| 299 | ca->delayed_ack += cnt; |
| 300 | } |
Stephen Hemminger | df3271f | 2005-12-13 23:13:28 -0800 | [diff] [blame] | 301 | |
Stephen Hemminger | e7d0c88 | 2007-07-25 23:50:06 -0700 | [diff] [blame] | 302 | /* Some calls are for duplicates without timetamps */ |
| 303 | if (rtt_us < 0) |
| 304 | return; |
| 305 | |
| 306 | /* Discard delay samples right after fast recovery */ |
| 307 | if ((s32)(tcp_time_stamp - ca->epoch_start) < HZ) |
| 308 | return; |
| 309 | |
| 310 | delay = usecs_to_jiffies(rtt_us) << 3; |
| 311 | if (delay == 0) |
| 312 | delay = 1; |
| 313 | |
| 314 | /* first time call or link delay decreases */ |
| 315 | if (ca->delay_min == 0 || ca->delay_min > delay) |
| 316 | ca->delay_min = delay; |
| 317 | } |
Stephen Hemminger | df3271f | 2005-12-13 23:13:28 -0800 | [diff] [blame] | 318 | |
| 319 | static struct tcp_congestion_ops cubictcp = { |
| 320 | .init = bictcp_init, |
| 321 | .ssthresh = bictcp_recalc_ssthresh, |
| 322 | .cong_avoid = bictcp_cong_avoid, |
| 323 | .set_state = bictcp_state, |
| 324 | .undo_cwnd = bictcp_undo_cwnd, |
Stephen Hemminger | df3271f | 2005-12-13 23:13:28 -0800 | [diff] [blame] | 325 | .pkts_acked = bictcp_acked, |
| 326 | .owner = THIS_MODULE, |
| 327 | .name = "cubic", |
| 328 | }; |
| 329 | |
| 330 | static int __init cubictcp_register(void) |
| 331 | { |
Alexey Dobriyan | 74975d4 | 2006-08-25 17:10:33 -0700 | [diff] [blame] | 332 | BUILD_BUG_ON(sizeof(struct bictcp) > ICSK_CA_PRIV_SIZE); |
Stephen Hemminger | 89b3d9a | 2005-12-21 19:32:08 -0800 | [diff] [blame] | 333 | |
| 334 | /* Precompute a bunch of the scaling factors that are used per-packet |
| 335 | * based on SRTT of 100ms |
| 336 | */ |
| 337 | |
| 338 | beta_scale = 8*(BICTCP_BETA_SCALE+beta)/ 3 / (BICTCP_BETA_SCALE - beta); |
| 339 | |
Stephen Hemminger | 2211924 | 2006-10-25 23:04:12 -0700 | [diff] [blame] | 340 | cube_rtt_scale = (bic_scale * 10); /* 1024*c/rtt */ |
Stephen Hemminger | 89b3d9a | 2005-12-21 19:32:08 -0800 | [diff] [blame] | 341 | |
| 342 | /* calculate the "K" for (wmax-cwnd) = c/rtt * K^3 |
| 343 | * so K = cubic_root( (wmax-cwnd)*rtt/c ) |
| 344 | * the unit of K is bictcp_HZ=2^10, not HZ |
| 345 | * |
| 346 | * c = bic_scale >> 10 |
| 347 | * rtt = 100ms |
| 348 | * |
| 349 | * the following code has been designed and tested for |
| 350 | * cwnd < 1 million packets |
| 351 | * RTT < 100 seconds |
| 352 | * HZ < 1,000,00 (corresponding to 10 nano-second) |
| 353 | */ |
| 354 | |
| 355 | /* 1/c * 2^2*bictcp_HZ * srtt */ |
| 356 | cube_factor = 1ull << (10+3*BICTCP_HZ); /* 2^40 */ |
| 357 | |
| 358 | /* divide by bic_scale and by constant Srtt (100ms) */ |
| 359 | do_div(cube_factor, bic_scale * 10); |
| 360 | |
Stephen Hemminger | df3271f | 2005-12-13 23:13:28 -0800 | [diff] [blame] | 361 | return tcp_register_congestion_control(&cubictcp); |
| 362 | } |
| 363 | |
| 364 | static void __exit cubictcp_unregister(void) |
| 365 | { |
| 366 | tcp_unregister_congestion_control(&cubictcp); |
| 367 | } |
| 368 | |
| 369 | module_init(cubictcp_register); |
| 370 | module_exit(cubictcp_unregister); |
| 371 | |
| 372 | MODULE_AUTHOR("Sangtae Ha, Stephen Hemminger"); |
| 373 | MODULE_LICENSE("GPL"); |
| 374 | MODULE_DESCRIPTION("CUBIC TCP"); |
Sangtae Ha | 6b3d626 | 2008-03-04 14:17:41 -0800 | [diff] [blame] | 375 | MODULE_VERSION("2.2"); |