1
2
3
4
5
6
7
8
9#include <linux/module.h>
10#include <net/tcp.h>
11
12
13
14
15static const struct hstcp_aimd_val {
16 unsigned int cwnd;
17 unsigned int md;
18} hstcp_aimd_vals[] = {
19 { 38, 128, },
20 { 118, 112, },
21 { 221, 104, },
22 { 347, 98, },
23 { 495, 93, },
24 { 663, 89, },
25 { 851, 86, },
26 { 1058, 83, },
27 { 1284, 81, },
28 { 1529, 78, },
29 { 1793, 76, },
30 { 2076, 74, },
31 { 2378, 72, },
32 { 2699, 71, },
33 { 3039, 69, },
34 { 3399, 68, },
35 { 3778, 66, },
36 { 4177, 65, },
37 { 4596, 64, },
38 { 5036, 62, },
39 { 5497, 61, },
40 { 5979, 60, },
41 { 6483, 59, },
42 { 7009, 58, },
43 { 7558, 57, },
44 { 8130, 56, },
45 { 8726, 55, },
46 { 9346, 54, },
47 { 9991, 53, },
48 { 10661, 52, },
49 { 11358, 52, },
50 { 12082, 51, },
51 { 12834, 50, },
52 { 13614, 49, },
53 { 14424, 48, },
54 { 15265, 48, },
55 { 16137, 47, },
56 { 17042, 46, },
57 { 17981, 45, },
58 { 18955, 45, },
59 { 19965, 44, },
60 { 21013, 43, },
61 { 22101, 43, },
62 { 23230, 42, },
63 { 24402, 41, },
64 { 25618, 41, },
65 { 26881, 40, },
66 { 28193, 39, },
67 { 29557, 39, },
68 { 30975, 38, },
69 { 32450, 38, },
70 { 33986, 37, },
71 { 35586, 36, },
72 { 37253, 36, },
73 { 38992, 35, },
74 { 40808, 35, },
75 { 42707, 34, },
76 { 44694, 33, },
77 { 46776, 33, },
78 { 48961, 32, },
79 { 51258, 32, },
80 { 53677, 31, },
81 { 56230, 30, },
82 { 58932, 30, },
83 { 61799, 29, },
84 { 64851, 28, },
85 { 68113, 28, },
86 { 71617, 27, },
87 { 75401, 26, },
88 { 79517, 26, },
89 { 84035, 25, },
90 { 89053, 24, },
91};
92
93#define HSTCP_AIMD_MAX ARRAY_SIZE(hstcp_aimd_vals)
94
95struct hstcp {
96 u32 ai;
97};
98
99static void hstcp_init(struct sock *sk)
100{
101 struct tcp_sock *tp = tcp_sk(sk);
102 struct hstcp *ca = inet_csk_ca(sk);
103
104 ca->ai = 0;
105
106
107
108 tp->snd_cwnd_clamp = min_t(u32, tp->snd_cwnd_clamp, 0xffffffff/128);
109}
110
111static void hstcp_cong_avoid(struct sock *sk, u32 ack, u32 acked)
112{
113 struct tcp_sock *tp = tcp_sk(sk);
114 struct hstcp *ca = inet_csk_ca(sk);
115
116 if (!tcp_is_cwnd_limited(sk))
117 return;
118
119 if (tp->snd_cwnd <= tp->snd_ssthresh)
120 tcp_slow_start(tp, acked);
121 else {
122
123
124
125
126
127
128
129 if (tp->snd_cwnd > hstcp_aimd_vals[ca->ai].cwnd) {
130 while (tp->snd_cwnd > hstcp_aimd_vals[ca->ai].cwnd &&
131 ca->ai < HSTCP_AIMD_MAX - 1)
132 ca->ai++;
133 } else if (ca->ai && tp->snd_cwnd <= hstcp_aimd_vals[ca->ai-1].cwnd) {
134 while (ca->ai && tp->snd_cwnd <= hstcp_aimd_vals[ca->ai-1].cwnd)
135 ca->ai--;
136 }
137
138
139 if (tp->snd_cwnd < tp->snd_cwnd_clamp) {
140
141 tp->snd_cwnd_cnt += ca->ai + 1;
142 if (tp->snd_cwnd_cnt >= tp->snd_cwnd) {
143 tp->snd_cwnd_cnt -= tp->snd_cwnd;
144 tp->snd_cwnd++;
145 }
146 }
147 }
148}
149
150static u32 hstcp_ssthresh(struct sock *sk)
151{
152 const struct tcp_sock *tp = tcp_sk(sk);
153 const struct hstcp *ca = inet_csk_ca(sk);
154
155
156 return max(tp->snd_cwnd - ((tp->snd_cwnd * hstcp_aimd_vals[ca->ai].md) >> 8), 2U);
157}
158
159
160static struct tcp_congestion_ops tcp_highspeed __read_mostly = {
161 .init = hstcp_init,
162 .ssthresh = hstcp_ssthresh,
163 .cong_avoid = hstcp_cong_avoid,
164
165 .owner = THIS_MODULE,
166 .name = "highspeed"
167};
168
169static int __init hstcp_register(void)
170{
171 BUILD_BUG_ON(sizeof(struct hstcp) > ICSK_CA_PRIV_SIZE);
172 return tcp_register_congestion_control(&tcp_highspeed);
173}
174
175static void __exit hstcp_unregister(void)
176{
177 tcp_unregister_congestion_control(&tcp_highspeed);
178}
179
180module_init(hstcp_register);
181module_exit(hstcp_unregister);
182
183MODULE_AUTHOR("John Heffner");
184MODULE_LICENSE("GPL");
185MODULE_DESCRIPTION("High Speed TCP");
186