2 * TCP Illinois congestion control.
4 * http://www.ews.uiuc.edu/~shaoliu/tcpillinois/index.html
6 * The algorithm is described in:
7 * "TCP-Illinois: A Loss and Delay-Based Congestion Control Algorithm
8 * for High-Speed Networks"
9 * http://www.ews.uiuc.edu/~shaoliu/papersandslides/liubassri06perf.pdf
11 * Implemented from description in paper and ns-2 simulation.
12 * Copyright (C) 2007 Stephen Hemminger <shemminger@linux-foundation.org>
15 #include <linux/module.h>
16 #include <linux/skbuff.h>
17 #include <linux/inet_diag.h>
18 #include <asm/div64.h>
22 #define ALPHA_SCALE (1u<<ALPHA_SHIFT)
23 #define ALPHA_MIN ((3*ALPHA_SCALE)/10) /* ~0.3 */
24 #define ALPHA_MAX (10*ALPHA_SCALE) /* 10.0 */
25 #define ALPHA_BASE ALPHA_SCALE /* 1.0 */
28 #define BETA_SCALE (1u<<BETA_SHIFT)
29 #define BETA_MIN (BETA_SCALE/8) /* 0.8 */
30 #define BETA_MAX (BETA_SCALE/2)
31 #define BETA_BASE BETA_MAX /* 0.5 */
35 static int win_thresh __read_mostly = 15;
36 module_param(win_thresh, int, 0644);
37 MODULE_PARM_DESC(win_thresh, "Window threshold for starting adaptive sizing");
39 #define MAX_RTT 0x7fffffff
41 /* TCP Illinois Parameters */
51 static void tcp_illinois_init(struct sock *sk)
53 struct tcp_illinois *ca = inet_csk_ca(sk);
55 ca->last_alpha = ALPHA_BASE;
56 ca->min_rtt = 0x7fffffff;
60 * Keep track of min, max and average RTT
62 static void tcp_illinois_rtt_calc(struct sock *sk, u32 rtt)
64 struct tcp_illinois *ca = inet_csk_ca(sk);
66 if (rtt < ca->min_rtt)
68 if (rtt > ca->max_rtt)
71 if (++ca->rtt_cnt == 1)
77 /* max queuing delay */
78 static inline u32 max_delay(const struct tcp_illinois *ca)
80 return ca->max_rtt - ca->min_rtt;
83 /* average queueing delay */
84 static u32 avg_delay(struct tcp_illinois *ca)
86 u64 avg_rtt = ca->sum_rtt;
88 do_div(avg_rtt, ca->rtt_cnt);
93 return avg_rtt - ca->min_rtt;
97 * Compute value of alpha used for additive increase.
98 * If small window then use 1.0, equivalent to Reno.
100 * For larger windows, adjust based on average delay.
101 * A. If average delay is at minimum (we are uncongested),
102 * then use large alpha (10.0) to increase faster.
103 * B. If average delay is at maximum (getting congested)
104 * then use small alpha (1.0)
106 * The result is a convex window growth curve.
108 static u32 alpha(const struct sock *sk)
110 struct tcp_sock *tp = tcp_sk(sk);
111 struct tcp_illinois *ca = inet_csk_ca(sk);
112 u32 dm = max_delay(ca);
113 u32 da = avg_delay(ca);
116 if (tp->snd_cwnd < win_thresh)
117 return ALPHA_BASE; /* same as Reno (1.0) */
121 /* Don't let noise force agressive response */
122 if (ca->rtt_low < THETA) {
124 return ca->last_alpha;
134 * (dm - d1) amin amax
135 * k1 = -------------------
139 * k2 = ---------------- - d1
150 a = (dm * ALPHA_MAX) / (dm - (da * (ALPHA_MAX - ALPHA_MIN)) / ALPHA_MIN);
156 * Increase window in response to successful acknowledgment.
158 static void tcp_illinois_cong_avoid(struct sock *sk, u32 ack, u32 rtt,
159 u32 in_flight, int flag)
161 struct tcp_sock *tp = tcp_sk(sk);
163 /* RFC2861 only increase cwnd if fully utilized */
164 if (!tcp_is_cwnd_limited(sk, in_flight))
168 if (tp->snd_cwnd <= tp->snd_ssthresh)
172 /* additive increase cwnd += alpha / cwnd */
173 if ((tp->snd_cwnd_cnt * alpha(sk)) >> ALPHA_SHIFT >= tp->snd_cwnd) {
174 if (tp->snd_cwnd < tp->snd_cwnd_clamp)
176 tp->snd_cwnd_cnt = 0;
183 * Beta used for multiplicative decrease.
184 * For small window sizes returns same value as Reno (0.5)
186 * If delay is small (10% of max) then beta = 1/8
187 * If delay is up to 80% of max then beta = 1/2
188 * In between is a linear function
190 static inline u32 beta(struct sock *sk)
192 struct tcp_sock *tp = tcp_sk(sk);
193 struct tcp_illinois *ca = inet_csk_ca(sk);
194 u32 dm = max_delay(ca);
195 u32 da = avg_delay(ca);
198 if (tp->snd_cwnd < win_thresh)
205 if (da >= d3 || d3 <= d2)
212 * k3 = -------------------
221 return (BETA_MIN * d3 - BETA_MAX * d2 + (BETA_MAX - BETA_MIN) * da)
225 static u32 tcp_illinois_ssthresh(struct sock *sk)
227 struct tcp_sock *tp = tcp_sk(sk);
229 /* Multiplicative decrease */
230 return max((tp->snd_cwnd * beta(sk)) >> BETA_SHIFT, 2U);
233 /* Extract info for TCP socket info provided via netlink.
234 * We aren't really doing Vegas, but we can provide RTT info
236 static void tcp_illinois_get_info(struct sock *sk, u32 ext,
239 const struct tcp_illinois *ca = inet_csk_ca(sk);
241 if (ext & (1 << (INET_DIAG_VEGASINFO - 1))) {
242 struct tcpvegas_info info = {
244 .tcpv_rttcnt = ca->rtt_cnt,
245 .tcpv_minrtt = ca->min_rtt,
247 u64 avg_rtt = ca->sum_rtt;
248 do_div(avg_rtt, ca->rtt_cnt);
249 info.tcpv_rtt = avg_rtt;
251 nla_put(skb, INET_DIAG_VEGASINFO, sizeof(info), &info);
255 static struct tcp_congestion_ops tcp_illinois = {
256 .init = tcp_illinois_init,
257 .ssthresh = tcp_illinois_ssthresh,
258 .min_cwnd = tcp_reno_min_cwnd,
259 .cong_avoid = tcp_illinois_cong_avoid,
260 .rtt_sample = tcp_illinois_rtt_calc,
261 .get_info = tcp_illinois_get_info,
263 .owner = THIS_MODULE,
267 static int __init tcp_illinois_register(void)
269 BUILD_BUG_ON(sizeof(struct tcp_illinois) > ICSK_CA_PRIV_SIZE);
270 return tcp_register_congestion_control(&tcp_illinois);
273 static void __exit tcp_illinois_unregister(void)
275 tcp_unregister_congestion_control(&tcp_illinois);
278 module_init(tcp_illinois_register);
279 module_exit(tcp_illinois_unregister);
281 MODULE_AUTHOR("Stephen Hemminger, Shao Liu");
282 MODULE_LICENSE("GPL");
283 MODULE_DESCRIPTION("TCP Illinois");
284 MODULE_VERSION("0.3");