blob: c4fc811bf377f6f65f86b21eb51e659555f1c2e6 [file] [log] [blame]
John Heffnera628d292005-06-23 12:24:58 -07001/*
2 * Sally Floyd's High Speed TCP (RFC 3649) congestion control
3 *
4 * See http://www.icir.org/floyd/hstcp.html
5 *
6 * John Heffner <jheffner@psc.edu>
7 */
8
John Heffnera628d292005-06-23 12:24:58 -07009#include <linux/module.h>
10#include <net/tcp.h>
11
12
13/* From AIMD tables from RFC 3649 appendix B,
14 * with fixed-point MD scaled <<8.
15 */
16static const struct hstcp_aimd_val {
17 unsigned int cwnd;
18 unsigned int md;
19} hstcp_aimd_vals[] = {
20 { 38, 128, /* 0.50 */ },
21 { 118, 112, /* 0.44 */ },
22 { 221, 104, /* 0.41 */ },
23 { 347, 98, /* 0.38 */ },
24 { 495, 93, /* 0.37 */ },
25 { 663, 89, /* 0.35 */ },
26 { 851, 86, /* 0.34 */ },
27 { 1058, 83, /* 0.33 */ },
28 { 1284, 81, /* 0.32 */ },
29 { 1529, 78, /* 0.31 */ },
30 { 1793, 76, /* 0.30 */ },
31 { 2076, 74, /* 0.29 */ },
32 { 2378, 72, /* 0.28 */ },
33 { 2699, 71, /* 0.28 */ },
34 { 3039, 69, /* 0.27 */ },
35 { 3399, 68, /* 0.27 */ },
36 { 3778, 66, /* 0.26 */ },
37 { 4177, 65, /* 0.26 */ },
38 { 4596, 64, /* 0.25 */ },
39 { 5036, 62, /* 0.25 */ },
40 { 5497, 61, /* 0.24 */ },
41 { 5979, 60, /* 0.24 */ },
42 { 6483, 59, /* 0.23 */ },
43 { 7009, 58, /* 0.23 */ },
44 { 7558, 57, /* 0.22 */ },
45 { 8130, 56, /* 0.22 */ },
46 { 8726, 55, /* 0.22 */ },
47 { 9346, 54, /* 0.21 */ },
48 { 9991, 53, /* 0.21 */ },
49 { 10661, 52, /* 0.21 */ },
50 { 11358, 52, /* 0.20 */ },
51 { 12082, 51, /* 0.20 */ },
52 { 12834, 50, /* 0.20 */ },
53 { 13614, 49, /* 0.19 */ },
54 { 14424, 48, /* 0.19 */ },
55 { 15265, 48, /* 0.19 */ },
56 { 16137, 47, /* 0.19 */ },
57 { 17042, 46, /* 0.18 */ },
58 { 17981, 45, /* 0.18 */ },
59 { 18955, 45, /* 0.18 */ },
60 { 19965, 44, /* 0.17 */ },
61 { 21013, 43, /* 0.17 */ },
62 { 22101, 43, /* 0.17 */ },
63 { 23230, 42, /* 0.17 */ },
64 { 24402, 41, /* 0.16 */ },
65 { 25618, 41, /* 0.16 */ },
66 { 26881, 40, /* 0.16 */ },
67 { 28193, 39, /* 0.16 */ },
68 { 29557, 39, /* 0.15 */ },
69 { 30975, 38, /* 0.15 */ },
70 { 32450, 38, /* 0.15 */ },
71 { 33986, 37, /* 0.15 */ },
72 { 35586, 36, /* 0.14 */ },
73 { 37253, 36, /* 0.14 */ },
74 { 38992, 35, /* 0.14 */ },
75 { 40808, 35, /* 0.14 */ },
76 { 42707, 34, /* 0.13 */ },
77 { 44694, 33, /* 0.13 */ },
78 { 46776, 33, /* 0.13 */ },
79 { 48961, 32, /* 0.13 */ },
80 { 51258, 32, /* 0.13 */ },
81 { 53677, 31, /* 0.12 */ },
82 { 56230, 30, /* 0.12 */ },
83 { 58932, 30, /* 0.12 */ },
84 { 61799, 29, /* 0.12 */ },
85 { 64851, 28, /* 0.11 */ },
86 { 68113, 28, /* 0.11 */ },
87 { 71617, 27, /* 0.11 */ },
88 { 75401, 26, /* 0.10 */ },
89 { 79517, 26, /* 0.10 */ },
90 { 84035, 25, /* 0.10 */ },
91 { 89053, 24, /* 0.10 */ },
92};
93
94#define HSTCP_AIMD_MAX ARRAY_SIZE(hstcp_aimd_vals)
95
96struct hstcp {
97 u32 ai;
98};
99
Stephen Hemminger738980f2006-06-05 17:30:56 -0700100static int max_ssthresh = 100;
101module_param(max_ssthresh, int, 0644);
102MODULE_PARM_DESC(max_ssthresh, "limited slow start threshold (RFC3742)");
103
Arnaldo Carvalho de Melo6687e982005-08-10 04:03:31 -0300104static void hstcp_init(struct sock *sk)
John Heffnera628d292005-06-23 12:24:58 -0700105{
Arnaldo Carvalho de Melo6687e982005-08-10 04:03:31 -0300106 struct tcp_sock *tp = tcp_sk(sk);
107 struct hstcp *ca = inet_csk_ca(sk);
John Heffnera628d292005-06-23 12:24:58 -0700108
109 ca->ai = 0;
110
111 /* Ensure the MD arithmetic works. This is somewhat pedantic,
112 * since I don't think we will see a cwnd this large. :) */
113 tp->snd_cwnd_clamp = min_t(u32, tp->snd_cwnd_clamp, 0xffffffff/128);
114}
115
Arnaldo Carvalho de Melo6687e982005-08-10 04:03:31 -0300116static void hstcp_cong_avoid(struct sock *sk, u32 adk, u32 rtt,
Stephen Hemmingerbd6af702005-11-17 14:11:18 -0800117 u32 in_flight, int data_acked)
John Heffnera628d292005-06-23 12:24:58 -0700118{
Arnaldo Carvalho de Melo6687e982005-08-10 04:03:31 -0300119 struct tcp_sock *tp = tcp_sk(sk);
120 struct hstcp *ca = inet_csk_ca(sk);
John Heffnera628d292005-06-23 12:24:58 -0700121
Stephen Hemmingerf4805ed2005-11-10 16:53:30 -0800122 if (!tcp_is_cwnd_limited(sk, in_flight))
John Heffnera628d292005-06-23 12:24:58 -0700123 return;
124
Stephen Hemminger738980f2006-06-05 17:30:56 -0700125 if (tp->snd_cwnd <= tp->snd_ssthresh) {
126 /* RFC3742: limited slow start
127 * the window is increased by 1/K MSS for each arriving ACK,
128 * for K = int(cwnd/(0.5 max_ssthresh))
129 */
130 if (max_ssthresh > 0 && tp->snd_cwnd > max_ssthresh) {
131 u32 k = max(tp->snd_cwnd / (max_ssthresh >> 1), 1U);
132 if (++tp->snd_cwnd_cnt >= k) {
133 if (tp->snd_cwnd < tp->snd_cwnd_clamp)
134 tp->snd_cwnd++;
135 tp->snd_cwnd_cnt = 0;
136 }
137 } else {
138 if (tp->snd_cwnd < tp->snd_cwnd_clamp)
139 tp->snd_cwnd++;
140 }
141 } else {
Xiaoliang (David) Wei6150c222006-07-11 13:03:28 -0700142 /* Update AIMD parameters.
143 *
144 * We want to guarantee that:
145 * hstcp_aimd_vals[ca->ai-1].cwnd <
146 * snd_cwnd <=
147 * hstcp_aimd_vals[ca->ai].cwnd
148 */
John Heffnera628d292005-06-23 12:24:58 -0700149 if (tp->snd_cwnd > hstcp_aimd_vals[ca->ai].cwnd) {
150 while (tp->snd_cwnd > hstcp_aimd_vals[ca->ai].cwnd &&
Patrick McHardy4a1ff6e2006-03-12 20:34:53 -0800151 ca->ai < HSTCP_AIMD_MAX - 1)
John Heffnera628d292005-06-23 12:24:58 -0700152 ca->ai++;
Xiaoliang (David) Wei6150c222006-07-11 13:03:28 -0700153 } else if (ca->ai && tp->snd_cwnd <= hstcp_aimd_vals[ca->ai-1].cwnd) {
154 while (ca->ai && tp->snd_cwnd <= hstcp_aimd_vals[ca->ai-1].cwnd)
John Heffnera628d292005-06-23 12:24:58 -0700155 ca->ai--;
156 }
157
158 /* Do additive increase */
159 if (tp->snd_cwnd < tp->snd_cwnd_clamp) {
Stephen Hemmingerfb80a6e2006-06-02 17:51:08 -0700160 /* cwnd = cwnd + a(w) / cwnd */
161 tp->snd_cwnd_cnt += ca->ai + 1;
John Heffnera628d292005-06-23 12:24:58 -0700162 if (tp->snd_cwnd_cnt >= tp->snd_cwnd) {
John Heffnera628d292005-06-23 12:24:58 -0700163 tp->snd_cwnd_cnt -= tp->snd_cwnd;
John Heffner5528e562006-05-05 17:41:44 -0700164 tp->snd_cwnd++;
John Heffnera628d292005-06-23 12:24:58 -0700165 }
166 }
167 }
168}
169
Arnaldo Carvalho de Melo6687e982005-08-10 04:03:31 -0300170static u32 hstcp_ssthresh(struct sock *sk)
John Heffnera628d292005-06-23 12:24:58 -0700171{
Arnaldo Carvalho de Melo6687e982005-08-10 04:03:31 -0300172 const struct tcp_sock *tp = tcp_sk(sk);
173 const struct hstcp *ca = inet_csk_ca(sk);
John Heffnera628d292005-06-23 12:24:58 -0700174
175 /* Do multiplicative decrease */
176 return max(tp->snd_cwnd - ((tp->snd_cwnd * hstcp_aimd_vals[ca->ai].md) >> 8), 2U);
177}
178
179
180static struct tcp_congestion_ops tcp_highspeed = {
181 .init = hstcp_init,
182 .ssthresh = hstcp_ssthresh,
183 .cong_avoid = hstcp_cong_avoid,
184 .min_cwnd = tcp_reno_min_cwnd,
185
186 .owner = THIS_MODULE,
187 .name = "highspeed"
188};
189
190static int __init hstcp_register(void)
191{
Alexey Dobriyan74975d42006-08-25 17:10:33 -0700192 BUILD_BUG_ON(sizeof(struct hstcp) > ICSK_CA_PRIV_SIZE);
John Heffnera628d292005-06-23 12:24:58 -0700193 return tcp_register_congestion_control(&tcp_highspeed);
194}
195
196static void __exit hstcp_unregister(void)
197{
198 tcp_unregister_congestion_control(&tcp_highspeed);
199}
200
201module_init(hstcp_register);
202module_exit(hstcp_unregister);
203
204MODULE_AUTHOR("John Heffner");
205MODULE_LICENSE("GPL");
206MODULE_DESCRIPTION("High Speed TCP");