r6040: prefix all functions with r6040
[linux-2.6/linux-2.6-openrd.git] / net / ipv4 / tcp_hybla.c
blobbfcbd148a89d5daec4bf09b169010e6690c6f6c8
1 /*
2 * TCP HYBLA
4 * TCP-HYBLA Congestion control algorithm, based on:
5 * C.Caini, R.Firrincieli, "TCP-Hybla: A TCP Enhancement
6 * for Heterogeneous Networks",
7 * International Journal on satellite Communications,
8 * September 2004
9 * Daniele Lacamera
10 * root at danielinux.net
13 #include <linux/module.h>
14 #include <net/tcp.h>
16 /* Tcp Hybla structure. */
17 struct hybla {
18 u8 hybla_en;
19 u32 snd_cwnd_cents; /* Keeps increment values when it is <1, <<7 */
20 u32 rho; /* Rho parameter, integer part */
21 u32 rho2; /* Rho * Rho, integer part */
22 u32 rho_3ls; /* Rho parameter, <<3 */
23 u32 rho2_7ls; /* Rho^2, <<7 */
24 u32 minrtt; /* Minimum smoothed round trip time value seen */
27 /* Hybla reference round trip time (default= 1/40 sec = 25 ms),
28 expressed in jiffies */
29 static int rtt0 = 25;
30 module_param(rtt0, int, 0644);
31 MODULE_PARM_DESC(rtt0, "reference rout trip time (ms)");
34 /* This is called to refresh values for hybla parameters */
35 static inline void hybla_recalc_param (struct sock *sk)
37 struct hybla *ca = inet_csk_ca(sk);
39 ca->rho_3ls = max_t(u32, tcp_sk(sk)->srtt / msecs_to_jiffies(rtt0), 8);
40 ca->rho = ca->rho_3ls >> 3;
41 ca->rho2_7ls = (ca->rho_3ls * ca->rho_3ls) << 1;
42 ca->rho2 = ca->rho2_7ls >>7;
45 static void hybla_init(struct sock *sk)
47 struct tcp_sock *tp = tcp_sk(sk);
48 struct hybla *ca = inet_csk_ca(sk);
50 ca->rho = 0;
51 ca->rho2 = 0;
52 ca->rho_3ls = 0;
53 ca->rho2_7ls = 0;
54 ca->snd_cwnd_cents = 0;
55 ca->hybla_en = 1;
56 tp->snd_cwnd = 2;
57 tp->snd_cwnd_clamp = 65535;
59 /* 1st Rho measurement based on initial srtt */
60 hybla_recalc_param(sk);
62 /* set minimum rtt as this is the 1st ever seen */
63 ca->minrtt = tp->srtt;
64 tp->snd_cwnd = ca->rho;
67 static void hybla_state(struct sock *sk, u8 ca_state)
69 struct hybla *ca = inet_csk_ca(sk);
70 ca->hybla_en = (ca_state == TCP_CA_Open);
73 static inline u32 hybla_fraction(u32 odds)
75 static const u32 fractions[] = {
76 128, 139, 152, 165, 181, 197, 215, 234,
79 return (odds < ARRAY_SIZE(fractions)) ? fractions[odds] : 128;
82 /* TCP Hybla main routine.
83 * This is the algorithm behavior:
84 * o Recalc Hybla parameters if min_rtt has changed
85 * o Give cwnd a new value based on the model proposed
86 * o remember increments <1
88 static void hybla_cong_avoid(struct sock *sk, u32 ack, u32 in_flight)
90 struct tcp_sock *tp = tcp_sk(sk);
91 struct hybla *ca = inet_csk_ca(sk);
92 u32 increment, odd, rho_fractions;
93 int is_slowstart = 0;
95 /* Recalculate rho only if this srtt is the lowest */
96 if (tp->srtt < ca->minrtt){
97 hybla_recalc_param(sk);
98 ca->minrtt = tp->srtt;
101 if (!tcp_is_cwnd_limited(sk, in_flight))
102 return;
104 if (!ca->hybla_en) {
105 tcp_reno_cong_avoid(sk, ack, in_flight);
106 return;
109 if (ca->rho == 0)
110 hybla_recalc_param(sk);
112 rho_fractions = ca->rho_3ls - (ca->rho << 3);
114 if (tp->snd_cwnd < tp->snd_ssthresh) {
116 * slow start
117 * INC = 2^RHO - 1
118 * This is done by splitting the rho parameter
119 * into 2 parts: an integer part and a fraction part.
120 * Inrement<<7 is estimated by doing:
121 * [2^(int+fract)]<<7
122 * that is equal to:
123 * (2^int) * [(2^fract) <<7]
124 * 2^int is straightly computed as 1<<int,
125 * while we will use hybla_slowstart_fraction_increment() to
126 * calculate 2^fract in a <<7 value.
128 is_slowstart = 1;
129 increment = ((1 << ca->rho) * hybla_fraction(rho_fractions))
130 - 128;
131 } else {
133 * congestion avoidance
134 * INC = RHO^2 / W
135 * as long as increment is estimated as (rho<<7)/window
136 * it already is <<7 and we can easily count its fractions.
138 increment = ca->rho2_7ls / tp->snd_cwnd;
139 if (increment < 128)
140 tp->snd_cwnd_cnt++;
143 odd = increment % 128;
144 tp->snd_cwnd += increment >> 7;
145 ca->snd_cwnd_cents += odd;
147 /* check when fractions goes >=128 and increase cwnd by 1. */
148 while (ca->snd_cwnd_cents >= 128) {
149 tp->snd_cwnd++;
150 ca->snd_cwnd_cents -= 128;
151 tp->snd_cwnd_cnt = 0;
154 /* clamp down slowstart cwnd to ssthresh value. */
155 if (is_slowstart)
156 tp->snd_cwnd = min(tp->snd_cwnd, tp->snd_ssthresh);
158 tp->snd_cwnd = min_t(u32, tp->snd_cwnd, tp->snd_cwnd_clamp);
161 static struct tcp_congestion_ops tcp_hybla = {
162 .init = hybla_init,
163 .ssthresh = tcp_reno_ssthresh,
164 .min_cwnd = tcp_reno_min_cwnd,
165 .cong_avoid = hybla_cong_avoid,
166 .set_state = hybla_state,
168 .owner = THIS_MODULE,
169 .name = "hybla"
172 static int __init hybla_register(void)
174 BUILD_BUG_ON(sizeof(struct hybla) > ICSK_CA_PRIV_SIZE);
175 return tcp_register_congestion_control(&tcp_hybla);
178 static void __exit hybla_unregister(void)
180 tcp_unregister_congestion_control(&tcp_hybla);
183 module_init(hybla_register);
184 module_exit(hybla_unregister);
186 MODULE_AUTHOR("Daniele Lacamera");
187 MODULE_LICENSE("GPL");
188 MODULE_DESCRIPTION("TCP Hybla");