1 /*
2 * TCP CUBIC: Binary Increase Congestion control for TCP v2.33 * Home page:4 *http://netsrv.csc.ncsu.edu/twiki/bin/view/Main/BIC
5 * This is from the implementation of CUBIC TCP in6 * 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 in14 * 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 large23 * this behaves the same as the original Reno.24 */
25
26 #include
27 #include
28 #include
29 #include
30
31 #define BICTCP_BETA_SCALE 1024 /* Scale factor beta calculation
32 * max_cwnd = snd_cwnd *beta33 */
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 length39 //2. Delay increase
40
41 #define HYSTART_ACK_TRAIN 0x1
42 #define HYSTART_DELAY 0x2
43 /*注意:这里的delay_min没有放大8倍!44 * 此宏用来计算Delay increase threshold45 * delay_min <= 32ms,则threshold = 2ms46 * 32ms < delay_min < 256ms,则threshold = delay_min / 16 ms47 * delay_min >= 256ms,则threshold = 16ms48 */
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 intinitial_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 delay75 //默认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 staticu32 cube_rtt_scale __read_mostly;81 staticu32 beta_scale __read_mostly;82 staticu64 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 al