mylinuxer

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
  1 /*
  2  * TCP CUBIC: Binary Increase Congestion control for TCP v2.3
  3  * Home page:
  4  *      http://netsrv.csc.ncsu.edu/twiki/bin/view/Main/BIC
  5  * This is from the implementation of CUBIC TCP in
  6  * Sangtae Ha, Injong Rhee and Lisong Xu,
  7  *  "CUBIC: A New TCP-Friendly High-Speed TCP Variant"
  8  *  in ACM SIGOPS Operating System Review, July 2008.
  9  * Available from:
 10  *  http://netsrv.csc.ncsu.edu/export/cubic_a_new_tcp_2008.pdf
 11  *
 12  * CUBIC integrates a new slow start algorithm, called HyStart.
 13  * The details of HyStart are presented in
 14  *  Sangtae Ha and Injong Rhee,
 15  *  "Taming the Elephants: New TCP Slow Start", NCSU TechReport 2008.
 16  * Available from:
 17  *  http://netsrv.csc.ncsu.edu/export/hystart_techreport_2008.pdf
 18  *
 19  * All testing results are available from:
 20  * http://netsrv.csc.ncsu.edu/wiki/index.php/TCP_Testing
 21  *
 22  * Unless CUBIC is enabled and congestion window is large
 23  * this behaves the same as the original Reno.
 24  */
 25 
 26 #include <linux/mm.h>
 27 #include <linux/module.h>
 28 #include <linux/math64.h>
 29 #include <net/tcp.h>
 30 
 31 #define BICTCP_BETA_SCALE    1024    /* Scale factor beta calculation
 32                      * max_cwnd = snd_cwnd * beta
 33                      */
 34 #define    BICTCP_HZ        10    /* BIC HZ 2^10 = 1024 */
 35 
 36 /* Two methods of hybrid slow start */
 37 //Both run independently at the same time and slow start exits when any of them detects an exit point.
 38 //1. ACK train length
 39 //2. Delay increase
 40 
 41 #define HYSTART_ACK_TRAIN    0x1
 42 #define HYSTART_DELAY        0x2
 43 /* 注意:这里的delay_min没有放大8倍!
 44  * 此宏用来计算Delay increase threshold
 45  * delay_min <= 32ms,则threshold = 2ms
 46  * 32ms < delay_min < 256ms,则threshold = delay_min / 16 ms
 47  * delay_min >= 256ms,则threshold = 16ms
 48  */
 49 /* Number of delay samples for detecting the increase of delay */
 50 #define HYSTART_MIN_SAMPLES    8
 51 #define HYSTART_DELAY_MIN    (2U<<3)
 52 #define HYSTART_DELAY_MAX    (16U<<3)
 53 #define HYSTART_DELAY_THRESH(x)    clamp(x, HYSTART_DELAY_MIN, HYSTART_DELAY_MAX)
 54 
 55 static int fast_convergence __read_mostly = 1;
 56 static int beta __read_mostly = 717;    /* = 717/1024 (BICTCP_BETA_SCALE) */
 57 //beta在BIC中为819,而CUBIC中为717,
 58 //会导致在bictcp_recalc_ssthresh中,并且启用了fast convergence,
 59 //cubic: last_max_cwnd = 0.85*snd_cwnd ,而慢启动阈值=0.7*snd_cwnd 。
 60 //bic:   last_max_cwnd = 0.95*snd_cwnd ,而慢启动阈值=0.8*snd_cwnd 。
 61 //这样会导致更早的到达平衡值,对snd_cwnd有很大的影响。
 62 
 63 
 64 
 65 static int initial_ssthresh __read_mostly;
 66 static int bic_scale __read_mostly = 41;
 67 static int tcp_friendliness __read_mostly = 1;
 68 
 69 
 70 
 71 //hybrid slow start的开关
 72 static int hystart __read_mostly = 1;
 73 //HyStart状态描述
 74 //1:packet-train  2: delay   3:both packet-train and delay
 75 //默认2种方法都使用,故设为3
 76 static int hystart_detect __read_mostly = HYSTART_ACK_TRAIN | HYSTART_DELAY;
 77 //设置snd_ssthresh的最小拥塞窗口值,除非cwnd超过了这个值,才能使用HyStart 
 78 static int hystart_low_window __read_mostly = 16;
 79 
 80 static u32 cube_rtt_scale __read_mostly;
 81 static u32 beta_scale __read_mostly;
 82 static u64 cube_factor __read_mostly;
 83 
 84 /* Note parameters that are used for precomputing scale factors are read-only */
 85 module_param(fast_convergence, int, 0644);
 86 MODULE_PARM_DESC(fast_convergence, "turn on/off fast convergence");
 87 module_param(beta, int, 0644);
 88 MODULE_PARM_DESC(beta, "beta for multiplicative increase");
 89 module_param(initial_ssthresh, int, 0644);
 90 MODULE_PARM_DESC(initial_ssthresh, "initial value of slow start threshold");
 91 module_param(bic_scale, int, 0444);
 92 MODULE_PARM_DESC(bic_scale, "scale (scaled by 1024) value for bic function (bic_scale/1024)");
 93 module_param(tcp_friendliness, int, 0644);
 94 MODULE_PARM_DESC(tcp_friendliness, "turn on/off tcp friendliness");
 95 module_param(hystart, int, 0644);
 96 MODULE_PARM_DESC(hystart, "turn on/off hybrid slow start algorithm");
 97 module_param(hystart_detect, int, 0644);
 98 MODULE_PARM_DESC(hystart_detect, "hyrbrid slow start detection mechanisms"
 99          " 1: packet-train 2: delay 3: both packet-train and delay");
100 module_param(hystart_low_window, int, 0644);
101 MODULE_PARM_DESC(hystart_low_window, "lower bound cwnd for hybrid slow start");
102 
103 /* BIC TCP Parameters */
104 struct bictcp {
105     u32    cnt;        /*用来控制snd_cwnd的增长 increase cwnd by 1 after ACKs */
106 //两个重要的count值:
107 //第一个是tcp_sock->snd_cwnd_cnt,表示在当前的拥塞窗口中已经
108     //发送(经过对方ack包确认)的数据段的个数,
109 //而第二个是bictcp->cnt,它是cubic拥塞算法的核心,
110 //主要用来控制在拥塞避免状态的时候,什么时候才能增大拥塞窗口,
111 //具体实现是通过比较cnt和snd_cwnd_cnt,来决定是否增大拥塞窗口,
112     
113     u32 last_max_cwnd;    /*上一次的最大拥塞窗口值 last maximum snd_cwnd */
114     u32    loss_cwnd;    /* 拥塞状态切换时的拥塞窗口值congestion window at last loss */
115     u32    last_cwnd;    /* 上一次的拥塞窗口值 the last snd_cwnd */
116     u32    last_time;    /* time when updated last_cwnd */
117     u32    bic_origin_point;/*即新的Wmax饱和点,取Wlast_max_cwnd和snd_cwnd较大者 origin point of bic function */
118     u32    bic_K;        /*即新Wmax所对应的时间点t,W(bic_K) = Wmax    time to origin point from the beginning of the current epoch */
119     u32    delay_min;    /*应该是最小RTT    min delay */
120     u32    epoch_start;    /*拥塞状态切换开始的时刻  beginning of an epoch */
121     u32    ack_cnt;    /*在一个epoch中的ack包的数量   number of acks */
122     u32    tcp_cwnd;    /*按照Reno算法计算得的cwnd    estimated tcp cwnd */
123 #define ACK_RATIO_SHIFT    4
124     u16    delayed_ack;    /* estimate the ratio of Packets/ACKs << 4 */
125     u8    sample_cnt;    /*第几个sample    number of samples to decide curr_rtt */
126     u8    found;        /* the exit point is found? */
127     u32    round_start;    /*针对每个RTT     beginning of each round */
128     u32    end_seq;    /*用来标识每个RTT    end_seq of the round */
129     u32    last_jiffies;    /*超过2ms则不认为是连续的   last time when the ACK spacing is close */
130     u32    curr_rtt;    /*由sampe中最小的决定    the minimum rtt of current round */
131 };
132 
133 static inline void bictcp_reset(struct bictcp *ca)
134 {//论文说Time out时调用
135     ca->cnt = 0;
136     ca->last_max_cwnd = 0;
137     ca->loss_cwnd = 0;
138     ca->last_cwnd = 0;
139     ca->last_time = 0;
140     ca->bic_origin_point = 0;
141     ca->bic_K = 0;
142     ca->delay_min = 0;
143     ca->epoch_start = 0;
144     ca->delayed_ack = 2 << ACK_RATIO_SHIFT;
145     ca->ack_cnt = 0;
146     ca->tcp_cwnd = 0;
147     ca->found = 0;
148 }
149 
150 static inline void bictcp_hystart_reset(struct sock *sk)
151 {
152     struct tcp_sock *tp = tcp_sk(sk);
153     struct bictcp *ca = inet_csk_ca(sk);
154 
155     ca->round_start = ca->last_jiffies = jiffies;//记录时间戳
156     ca->end_seq = tp->snd_nxt;//记录待发送的下一个序列号
157     ca->curr_rtt = 0;
158     ca->sample_cnt = 0;
159 
160     //bictcp_hystart_reset中并没有对ca->found置0。
161     //也就是说,只有在初始化时、LOSS状态时、开启hystart的慢启动时。
162     //HyStart才会派上用场,其它时间并不使用.
163 }
164 
165 static void bictcp_init(struct sock *sk)
166 {
167     bictcp_reset(inet_csk_ca(sk));
168 
169     if (hystart)//如果指定hystart
170         bictcp_hystart_reset(sk);
171 
172     if (!hystart && initial_ssthresh)
173         tcp_sk(sk)->snd_ssthresh = initial_ssthresh;
174 }
175 
176 /* calculate the cubic root of x using a table lookup followed by one
177  * Newton-Raphson iteration.
178  * Avg err ~= 0.195%
179  */
180 static u32 cubic_root(u64 a) //用来计算立方根
181 {
182     u32 x, b, shift;
183     /*
184      * cbrt(x) MSB values for x MSB values in [0..63].
185      * Precomputed then refined by hand - Willy Tarreau
186      *
187      * For x in [0..63],
188      *   v = cbrt(x << 18) - 1
189      *   cbrt(x) = (v[x] + 10) >> 6
190      */
191     static const u8 v[] = {
192         /* 0x00 */    0,   54,   54,   54,  118,  118,  118,  118,
193         /* 0x08 */  123,  129,  134,  138,  143,  147,  151,  156,
194         /* 0x10 */  157,  161,  164,  168,  170,  173,  176,  179,
195         /* 0x18 */  181,  185,  187,  190,  192,  194,  197,  199,
196         /* 0x20 */  200,  202,  204,  206,  209,  211,  213,  215,
197         /* 0x28 */  217,  219,  221,  222,  224,  225,  227,  229,
198         /* 0x30 */  231,  232,  234,  236,  237,  239,  240,  242,
199         /* 0x38 */  244,  245,  246,  248,  250,  251,  252,  254,
200     };
201 
202     b = fls64(a);
203     if (b < 7) {
204         /* a in [0..63] */
205         return ((u32)v[(u32)a] + 35) >> 6;
206     }
207 
208     b = ((b * 84) >> 8) - 1;
209     shift = (a >> (b * 3));
210 
211     x = ((u32)(((u32)v[shift] + 10) << b)) >> 6;
212 
213     /*
214      * Newton-Raphson iteration
215      *                         2
216      * x    = ( 2 * x  +  a / x  ) / 3
217      *  k+1          k         k
218      */
219     x = (2 * x + (u32)div64_u64(a, (u64)x * (u64)(x - 1)));
220     x = ((x * 341) >> 10);
221     return x;
222 }
223 
224 /*
225  * Compute congestion window to use.
226  */  //从快速恢复退出并进入拥塞避免状态之后,更新cnt
227 static inline void bictcp_update(struct bictcp *ca, u32 cwnd)
228 {
229     u64 offs;//时间差|t - K|
230     //delta是cwnd差,bic_target是预测值,t为预测时间
231     u32 delta, t, bic_target, max_cnt;
232 
233     ca->ack_cnt++;    /*ack包计数器加1   count the number of ACKs */
234 
235     if (ca->last_cwnd == cwnd && //当前窗口与历史窗口相同
236         (s32)(tcp_time_stamp - ca->last_time) <= HZ / 32)//时间差小于1000/32ms
237         return; //直接结束
238 
239     ca->last_cwnd = cwnd;//记录进入拥塞避免时的窗口值
240     ca->last_time = tcp_time_stamp;//记录进入拥塞避免时的时刻
241 
242     if (ca->epoch_start == 0) {//丢包后,开启一个新的时段
243         ca->epoch_start = tcp_time_stamp;    /*新时段的开始 record the beginning of an epoch */
244         ca->ack_cnt = 1;            /*ack包计数器初始化  start counting */
245         ca->tcp_cwnd = cwnd;            /*同步更新 syn with cubic */
246 
247         //取max(last_max_cwnd , cwnd)作为当前Wmax饱和点
248         if (ca->last_max_cwnd <= cwnd) {
249             ca->bic_K = 0;
250             ca->bic_origin_point = cwnd;
251         } else {
252             /* Compute new K based on
253              * (wmax-cwnd) * (srtt>>3 / HZ) / c * 2^(3*bictcp_HZ)
254              */
255             ca->bic_K = cubic_root(cube_factor
256                            * (ca->last_max_cwnd - cwnd));
257             ca->bic_origin_point = ca->last_max_cwnd;
258         }
259     }
260 
261     /* cubic function - calc*/
262     /* calculate c * time^3 / rtt,
263      *  while considering overflow in calculation of time^3
264      * (so time^3 is done by using 64 bit)
265      * and without the support of division of 64bit numbers
266      * (so all divisions are done by using 32 bit)
267      *  also NOTE the unit of those veriables
268      *      time  = (t - K) / 2^bictcp_HZ
269      *      c = bic_scale >> 10 == 0.04
270      * rtt  = (srtt >> 3) / HZ
271      * !!! The following code does not have overflow problems,
272      * if the cwnd < 1 million packets !!!
273      */
274 
275     /* change the unit from HZ to bictcp_HZ */
276     t = ((tcp_time_stamp + (ca->delay_min>>3) - ca->epoch_start)
277          << BICTCP_HZ) / HZ;
278 
279      //求| t - bic_K | 
280     if (t < ca->bic_K)        // 还未达到Wmax 
281         offs = ca->bic_K - t;
282     else
283         offs = t - ca->bic_K;//已经超过Wmax 
284 
285     /* c/rtt * (t-K)^3 */     //计算立方,delta =| W(t) - W(bic_K) | 
286     delta = (cube_rtt_scale * offs * offs * offs) >> (10+3*BICTCP_HZ);
287 
288 
289      
290      //t为预测时间,bic_K为新Wmax所对应的时间,
291      //bic_target为cwnd预测值,bic_origin_point为当前Wmax饱和点
292     if (t < ca->bic_K)                                    /* below origin*/
293         bic_target = ca->bic_origin_point - delta;
294     else                                                    /* above origin*/
295         bic_target = ca->bic_origin_point + delta;
296 
297     /* cubic function - calc bictcp_cnt*/
298     if (bic_target > cwnd) {// 相差越多,增长越快,这就是函数形状由来
299         ca->cnt = cwnd / (bic_target - cwnd);//
300     } else {//目前cwnd已经超出预期了,应该降速
301         ca->cnt = 100 * cwnd;              /* very small increment*/
302     }
303 
304 
305 
306     /* TCP Friendly —如果bic比RENO慢,则提升cwnd增长速度,即减小cnt 
307      * 以上次丢包以后的时间t算起,每次RTT增长 3B / ( 2 - B),那么可以得到 
308       * 采用RENO算法的cwnd。 
309       * cwnd (RENO) = cwnd + 3B / (2 - B) * ack_cnt / cwnd 
310      * B为乘性减少因子,在此算法中为0.3 
311      */
312     if (tcp_friendliness) {
313         u32 scale = beta_scale;
314         delta = (cwnd * scale) >> 3; //delta代表多少ACK可使tcp_cwnd++
315         while (ca->ack_cnt > delta) {        /* update tcp cwnd */
316             ca->ack_cnt -= delta;
317             ca->tcp_cwnd++;
318         }
319 
320         if (ca->tcp_cwnd > cwnd){    /* if bic is slower than tcp */
321             delta = ca->tcp_cwnd - cwnd;
322             max_cnt = cwnd / delta;
323             if (ca->cnt > max_cnt)
324                 ca->cnt = max_cnt;
325         }
326     }
327 
328     ca->cnt = (ca->cnt << ACK_RATIO_SHIFT) / ca->delayed_ack;
329     if (ca->cnt == 0)            /* cannot be zero */
330         ca->cnt = 1; //此时代表cwnd远小于bic_target,增长速度最大
331 }
332 
333 static void bictcp_cong_avoid(struct sock *sk, u32 ack, u32 in_flight)
334 {
335     struct tcp_sock *tp = tcp_sk(sk);
336     struct bictcp *ca = inet_csk_ca(sk);
337 
338     //判断发送拥塞窗口是否到达限制,如果到达限制则直接返回。
339     if (!tcp_is_cwnd_limited(sk, in_flight))
340         return;
341 
342     if (tp->snd_cwnd <= tp->snd_ssthresh) {
343         //当snd_cwnd<=ssthresh的时候,进入慢启动状态
344         if (hystart && after(ack, ca->end_seq))//是否需要reset对应的bictcp的值
345             bictcp_hystart_reset(sk);
346         tcp_slow_start(tp);//进入slow start状态
347     } else {
348         //当snd_cwnd>ssthresh的时候,进入拥塞避免状态
349         bictcp_update(ca, tp->snd_cwnd);//首先会更新bictcp->cnt
350         tcp_cong_avoid_ai(tp, ca->cnt);//然后进入拥塞避免,更新tcp_sock->snd_cwnd_cnt
351     }
352 
353 }
354 
355 
356 //每次发生拥塞状态切换时,就会重新计算慢启动阈值
357 //做了两件事:重赋值last_max_cwnd、返回新的慢启动阈值
358 static u32 bictcp_recalc_ssthresh(struct sock *sk)
359 {//论文说这个函数在Packet loss时调用
360     const struct tcp_sock *tp = tcp_sk(sk);
361     struct bictcp *ca = inet_csk_ca(sk);
362 
363     ca->epoch_start = 0;    /* 发生拥塞状态切换,标志一个epoch结束   end of epoch */
364 
365     /* Wmax and fast convergence */
366     //当一个新的TCP流加入到网络,
367     //网络中已有TCP流需要放弃自己带宽,
368     //给新的TCP流提供一定的上升空间。
369     //为提高已有TCP流所释放的带宽而引入快速收敛机制。
370     if (tp->snd_cwnd < ca->last_max_cwnd && fast_convergence)  
371         //snd_cwnd<last_max_cwnd
372         //表示已有TCP流所经历的饱和点因为可用带宽改变而正在降低。
373         //然后,通过进一步降低Wmax让已有流释放更多带宽。
374         //这种行为有效地延长已有流增大其窗口的时间,
375         //因为降低后的Wmax强制已有流更早进入平稳状态。
376         //这允许新流有更多的时间来赶上其窗口尺寸。
377         ca->last_max_cwnd = (tp->snd_cwnd * (BICTCP_BETA_SCALE + beta))
378             / (2 * BICTCP_BETA_SCALE); //last_max_cwnd = 0.9 * snd_cwnd 
379     else
380         ca->last_max_cwnd = tp->snd_cwnd;
381 
382     ca->loss_cwnd = tp->snd_cwnd;
383 
384     //修改snd_ssthresh,即max(0.7*snd_cwnd,2)
385     return max((tp->snd_cwnd * beta) / BICTCP_BETA_SCALE, 2U);
386     
387 }
388 
389 static u32 bictcp_undo_cwnd(struct sock *sk)
390 {
391     struct bictcp *ca = inet_csk_ca(sk);
392 
393     return max(tcp_sk(sk)->snd_cwnd, ca->last_max_cwnd);
394 }
395 
396 static void bictcp_state(struct sock *sk, u8 new_state)
397 {
398     if (new_state == TCP_CA_Loss) {//如果处于LOSS状态,丢包处理
399         bictcp_reset(inet_csk_ca(sk));
400         bictcp_hystart_reset(sk);
401     }
402 }
403 
404 static void hystart_update(struct sock *sk, u32 delay)
405 {//会修改snd_ssthresh
406     struct tcp_sock *tp = tcp_sk(sk);
407     struct bictcp *ca = inet_csk_ca(sk);
408 
409     if (!(ca->found & hystart_detect)) {
410         u32 curr_jiffies = jiffies;
411 
412         /* first detection parameter - ack-train detection */
413         if (curr_jiffies - ca->last_jiffies <= msecs_to_jiffies(2)) {
414             ca->last_jiffies = curr_jiffies;
415             if (curr_jiffies - ca->round_start >= ca->delay_min>>4)
416                 ca->found |= HYSTART_ACK_TRAIN;
417         }
418 
419         /* obtain the minimum delay of more than sampling packets */
420         if (ca->sample_cnt < HYSTART_MIN_SAMPLES) {
421             if (ca->curr_rtt == 0 || ca->curr_rtt > delay)
422                 ca->curr_rtt = delay;
423 
424             ca->sample_cnt++;
425         } else {
426             if (ca->curr_rtt > ca->delay_min +
427                 HYSTART_DELAY_THRESH(ca->delay_min>>4))
428                 ca->found |= HYSTART_DELAY;
429         }
430         /*
431          * Either one of two conditions are met,
432          * we exit from slow start immediately.
433          */
434         if (ca->found & hystart_detect)//found是一个是否退出slow start的标记
435             tp->snd_ssthresh = tp->snd_cwnd;//修改snd_ssthresh
436     }
437 }
438 
439 /* Track delayed acknowledgment ratio using sliding window
440  * ratio = (15*ratio + sample) / 16
441  */  //基本每次收到ack都会调用这个函数,更新snd_ssthresh和delayed_ack
442 static void bictcp_acked(struct sock *sk, u32 cnt, s32 rtt_us)
443 {//论文说这个函数在On each ACK时调用
444     const struct inet_connection_sock *icsk = inet_csk(sk);
445     const struct tcp_sock *tp = tcp_sk(sk);
446     struct bictcp *ca = inet_csk_ca(sk);
447     u32 delay;
448 
449     if (icsk->icsk_ca_state == TCP_CA_Open) {
450         cnt -= ca->delayed_ack >> ACK_RATIO_SHIFT;
451         ca->delayed_ack += cnt;
452     }
453 
454     /* Some calls are for duplicates without timetamps */
455     if (rtt_us < 0)
456         return;
457 
458     /* Discard delay samples right after fast recovery */
459     if ((s32)(tcp_time_stamp - ca->epoch_start) < HZ)
460         return;
461 
462     delay = usecs_to_jiffies(rtt_us) << 3;
463     if (delay == 0)
464         delay = 1;
465 
466     /* first time call or link delay decreases */
467     if (ca->delay_min == 0 || ca->delay_min > delay)
468         ca->delay_min = delay;
469 
470     /* hystart triggers when cwnd is larger than some threshold */
471     //tp->snd_ssthresh初始值是一个很大的值0x7fffffff
472     
473     //当拥塞窗口增大到16的时候,
474     //调用hystart_update来修改更新snd_ssthresh
475     //hystart_update主要用于是否退出slow start
476     if (hystart && tp->snd_cwnd <= tp->snd_ssthresh &&
477         tp->snd_cwnd >= hystart_low_window)
478         hystart_update(sk, delay);
479 }
480 
481 static struct tcp_congestion_ops cubictcp = {
482     
483     .init        = bictcp_init,
484 
485     
486     //调用ssthresh函数的地方有:tcp_fastretrans_alert(), tcp_enter_cwr(),tcp_enter_frto(), tcp_enter_loss() 
487     //看起来每次发生拥塞状态切换的时候,都会调整ssthresh。   
488   //修改snd_ssthresh值的地方有bictcp_init,hystart_update以及上面列出的调用ssthresh函数处。
489     .ssthresh    = bictcp_recalc_ssthresh,
490 
491     //发送方发出一个data包之后,接收方回复一个ack包,发送方收到这个ack包之后,
492   //调用tcp_ack()->tcp_cong_avoid()->bictcp_cong_avoid()来更改拥塞窗口snd_cwnd大小.
493     .cong_avoid    = bictcp_cong_avoid,
494     
495     .set_state    = bictcp_state,
496 
497     //调用undo_cwnd函数的地方有:tcp_undo_cwr()用来撤销之前误判导致的"缩小拥塞窗口"
498     .undo_cwnd    = bictcp_undo_cwnd,
499     
500     //调用ptts_acked函数的路径为:tcp_ack() -->tcp_clean_rtx_queue()
501     .pkts_acked     = bictcp_acked,
502     
503     .owner        = THIS_MODULE,
504     .name        = "cubic",
505 };
506 
507 static int __init cubictcp_register(void)
508 {
509      //bictcp参数的个数不能过多
510     BUILD_BUG_ON(sizeof(struct bictcp) > ICSK_CA_PRIV_SIZE);
511 
512     /* Precompute a bunch of the scaling factors that are used per-packet
513      * based on SRTT of 100ms
514      */
515      //beta_scale == 8*(1024 + 717) / 3 / (1024 -717 ),大约为15 
516     beta_scale = 8*(BICTCP_BETA_SCALE+beta)/ 3 / (BICTCP_BETA_SCALE - beta);
517 
518     //cube_rtt_scale == 41*10 = 410 
519     cube_rtt_scale = (bic_scale * 10);    /* 1024*c/rtt */
520 
521     /* calculate the "K" for (wmax-cwnd) = c/rtt * K^3
522      *  so K = cubic_root( (wmax-cwnd)*rtt/c )
523      * the unit of K is bictcp_HZ=2^10, not HZ
524      *
525      *  c = bic_scale >> 10
526      *  rtt = 100ms
527      *
528      * the following code has been designed and tested for
529      * cwnd < 1 million packets
530      * RTT < 100 seconds
531      * HZ < 1,000,00  (corresponding to 10 nano-second)
532      */
533 
534     /* 1/c * 2^2*bictcp_HZ * srtt */
535     cube_factor = 1ull << (10+3*BICTCP_HZ); /* cube_factor == 2^40 */
536 
537     /* divide by bic_scale and by constant Srtt (100ms) */
538     do_div(cube_factor, bic_scale * 10);//cube_factor == 2^40 / 410
539 
540     return tcp_register_congestion_control(&cubictcp);
541 }
542 
543 static void __exit cubictcp_unregister(void)
544 {
545     tcp_unregister_congestion_control(&cubictcp);
546 }
547 
548 module_init(cubictcp_register);
549 module_exit(cubictcp_unregister);
550 
551 MODULE_AUTHOR("Sangtae Ha, Stephen Hemminger");
552 MODULE_LICENSE("GPL");
553 MODULE_DESCRIPTION("CUBIC TCP");
554 MODULE_VERSION("2.3");

 

posted on 2016-01-20 18:13  mylinuxer  阅读(3420)  评论(0编辑  收藏  举报