1
2
3
4
5
6
7
8
9
10
11
12
13#include <linux/module.h>
14#include <net/tcp.h>
15
16
17struct hybla {
18 u8 hybla_en;
19 u32 snd_cwnd_cents;
20 u32 rho;
21 u32 rho2;
22 u32 rho_3ls;
23 u32 rho2_7ls;
24 u32 minrtt;
25};
26
27
28
29static int rtt0 = 25;
30module_param(rtt0, int, 0644);
31MODULE_PARM_DESC(rtt0, "reference rout trip time (ms)");
32
33
34
35static inline void hybla_recalc_param (struct sock *sk)
36{
37 struct hybla *ca = inet_csk_ca(sk);
38
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;
43}
44
45static void hybla_init(struct sock *sk)
46{
47 struct tcp_sock *tp = tcp_sk(sk);
48 struct hybla *ca = inet_csk_ca(sk);
49
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;
58
59
60 hybla_recalc_param(sk);
61
62
63 ca->minrtt = tp->srtt;
64 tp->snd_cwnd = ca->rho;
65}
66
67static void hybla_state(struct sock *sk, u8 ca_state)
68{
69 struct hybla *ca = inet_csk_ca(sk);
70 ca->hybla_en = (ca_state == TCP_CA_Open);
71}
72
73static inline u32 hybla_fraction(u32 odds)
74{
75 static const u32 fractions[] = {
76 128, 139, 152, 165, 181, 197, 215, 234,
77 };
78
79 return (odds < ARRAY_SIZE(fractions)) ? fractions[odds] : 128;
80}
81
82
83
84
85
86
87
88static void hybla_cong_avoid(struct sock *sk, u32 ack,
89 u32 in_flight, int flag)
90{
91 struct tcp_sock *tp = tcp_sk(sk);
92 struct hybla *ca = inet_csk_ca(sk);
93 u32 increment, odd, rho_fractions;
94 int is_slowstart = 0;
95
96
97 if (tp->srtt < ca->minrtt){
98 hybla_recalc_param(sk);
99 ca->minrtt = tp->srtt;
100 }
101
102 if (!tcp_is_cwnd_limited(sk, in_flight))
103 return;
104
105 if (!ca->hybla_en)
106 return tcp_reno_cong_avoid(sk, ack, in_flight, flag);
107
108 if (ca->rho == 0)
109 hybla_recalc_param(sk);
110
111 rho_fractions = ca->rho_3ls - (ca->rho << 3);
112
113 if (tp->snd_cwnd < tp->snd_ssthresh) {
114
115
116
117
118
119
120
121
122
123
124
125
126
127 is_slowstart = 1;
128 increment = ((1 << ca->rho) * hybla_fraction(rho_fractions))
129 - 128;
130 } else {
131
132
133
134
135
136
137 increment = ca->rho2_7ls / tp->snd_cwnd;
138 if (increment < 128)
139 tp->snd_cwnd_cnt++;
140 }
141
142 odd = increment % 128;
143 tp->snd_cwnd += increment >> 7;
144 ca->snd_cwnd_cents += odd;
145
146
147 while (ca->snd_cwnd_cents >= 128) {
148 tp->snd_cwnd++;
149 ca->snd_cwnd_cents -= 128;
150 tp->snd_cwnd_cnt = 0;
151 }
152
153
154 if (is_slowstart)
155 tp->snd_cwnd = min(tp->snd_cwnd, tp->snd_ssthresh);
156
157 tp->snd_cwnd = min_t(u32, tp->snd_cwnd, tp->snd_cwnd_clamp);
158}
159
160static struct tcp_congestion_ops tcp_hybla = {
161 .init = hybla_init,
162 .ssthresh = tcp_reno_ssthresh,
163 .min_cwnd = tcp_reno_min_cwnd,
164 .cong_avoid = hybla_cong_avoid,
165 .set_state = hybla_state,
166
167 .owner = THIS_MODULE,
168 .name = "hybla"
169};
170
171static int __init hybla_register(void)
172{
173 BUILD_BUG_ON(sizeof(struct hybla) > ICSK_CA_PRIV_SIZE);
174 return tcp_register_congestion_control(&tcp_hybla);
175}
176
177static void __exit hybla_unregister(void)
178{
179 tcp_unregister_congestion_control(&tcp_hybla);
180}
181
182module_init(hybla_register);
183module_exit(hybla_unregister);
184
185MODULE_AUTHOR("Daniele Lacamera");
186MODULE_LICENSE("GPL");
187MODULE_DESCRIPTION("TCP Hybla");
188