1
2
3
4
5
6
7
8
9
10
11
12
13#include <linux/mm.h>
14#include <linux/module.h>
15#include <linux/skbuff.h>
16#include <linux/inet_diag.h>
17
18#include <net/tcp.h>
19
20
21
22
23#define V_PARAM_SHIFT 1
24static const int beta = 3 << V_PARAM_SHIFT;
25
26
27struct veno {
28 u8 doing_veno_now;
29 u16 cntrtt;
30 u32 minrtt;
31 u32 basertt;
32 u32 inc;
33 u32 diff;
34};
35
36
37
38
39
40
41
42
43
44
45static inline void veno_enable(struct sock *sk)
46{
47 struct veno *veno = inet_csk_ca(sk);
48
49
50 veno->doing_veno_now = 1;
51
52 veno->minrtt = 0x7fffffff;
53}
54
55static inline void veno_disable(struct sock *sk)
56{
57 struct veno *veno = inet_csk_ca(sk);
58
59
60 veno->doing_veno_now = 0;
61}
62
63static void tcp_veno_init(struct sock *sk)
64{
65 struct veno *veno = inet_csk_ca(sk);
66
67 veno->basertt = 0x7fffffff;
68 veno->inc = 1;
69 veno_enable(sk);
70}
71
72
73static void tcp_veno_pkts_acked(struct sock *sk,
74 const struct ack_sample *sample)
75{
76 struct veno *veno = inet_csk_ca(sk);
77 u32 vrtt;
78
79 if (sample->rtt_us < 0)
80 return;
81
82
83 vrtt = sample->rtt_us + 1;
84
85
86 if (vrtt < veno->basertt)
87 veno->basertt = vrtt;
88
89
90
91
92 veno->minrtt = min(veno->minrtt, vrtt);
93 veno->cntrtt++;
94}
95
96static void tcp_veno_state(struct sock *sk, u8 ca_state)
97{
98 if (ca_state == TCP_CA_Open)
99 veno_enable(sk);
100 else
101 veno_disable(sk);
102}
103
104
105
106
107
108
109
110
111
112
113static void tcp_veno_cwnd_event(struct sock *sk, enum tcp_ca_event event)
114{
115 if (event == CA_EVENT_CWND_RESTART || event == CA_EVENT_TX_START)
116 tcp_veno_init(sk);
117}
118
119static void tcp_veno_cong_avoid(struct sock *sk, u32 ack, u32 acked)
120{
121 struct tcp_sock *tp = tcp_sk(sk);
122 struct veno *veno = inet_csk_ca(sk);
123
124 if (!veno->doing_veno_now) {
125 tcp_reno_cong_avoid(sk, ack, acked);
126 return;
127 }
128
129
130 if (!tcp_is_cwnd_limited(sk))
131 return;
132
133
134 if (veno->cntrtt <= 2) {
135
136
137
138 tcp_reno_cong_avoid(sk, ack, acked);
139 } else {
140 u64 target_cwnd;
141 u32 rtt;
142
143
144
145
146
147 rtt = veno->minrtt;
148
149 target_cwnd = (u64)tp->snd_cwnd * veno->basertt;
150 target_cwnd <<= V_PARAM_SHIFT;
151 do_div(target_cwnd, rtt);
152
153 veno->diff = (tp->snd_cwnd << V_PARAM_SHIFT) - target_cwnd;
154
155 if (tcp_in_slow_start(tp)) {
156
157 acked = tcp_slow_start(tp, acked);
158 if (!acked)
159 goto done;
160 }
161
162
163 if (veno->diff < beta) {
164
165
166
167 tcp_cong_avoid_ai(tp, tp->snd_cwnd, acked);
168 } else {
169
170
171
172 if (tp->snd_cwnd_cnt >= tp->snd_cwnd) {
173 if (veno->inc &&
174 tp->snd_cwnd < tp->snd_cwnd_clamp) {
175 tp->snd_cwnd++;
176 veno->inc = 0;
177 } else
178 veno->inc = 1;
179 tp->snd_cwnd_cnt = 0;
180 } else
181 tp->snd_cwnd_cnt += acked;
182 }
183done:
184 if (tp->snd_cwnd < 2)
185 tp->snd_cwnd = 2;
186 else if (tp->snd_cwnd > tp->snd_cwnd_clamp)
187 tp->snd_cwnd = tp->snd_cwnd_clamp;
188 }
189
190
191 veno->minrtt = 0x7fffffff;
192}
193
194
195static u32 tcp_veno_ssthresh(struct sock *sk)
196{
197 const struct tcp_sock *tp = tcp_sk(sk);
198 struct veno *veno = inet_csk_ca(sk);
199
200 if (veno->diff < beta)
201
202 return max(tp->snd_cwnd * 4 / 5, 2U);
203 else
204
205 return max(tp->snd_cwnd >> 1U, 2U);
206}
207
208static struct tcp_congestion_ops tcp_veno __read_mostly = {
209 .init = tcp_veno_init,
210 .ssthresh = tcp_veno_ssthresh,
211 .undo_cwnd = tcp_reno_undo_cwnd,
212 .cong_avoid = tcp_veno_cong_avoid,
213 .pkts_acked = tcp_veno_pkts_acked,
214 .set_state = tcp_veno_state,
215 .cwnd_event = tcp_veno_cwnd_event,
216
217 .owner = THIS_MODULE,
218 .name = "veno",
219};
220
221static int __init tcp_veno_register(void)
222{
223 BUILD_BUG_ON(sizeof(struct veno) > ICSK_CA_PRIV_SIZE);
224 tcp_register_congestion_control(&tcp_veno);
225 return 0;
226}
227
228static void __exit tcp_veno_unregister(void)
229{
230 tcp_unregister_congestion_control(&tcp_veno);
231}
232
233module_init(tcp_veno_register);
234module_exit(tcp_veno_unregister);
235
236MODULE_AUTHOR("Bin Zhou, Cheng Peng Fu");
237MODULE_LICENSE("GPL");
238MODULE_DESCRIPTION("TCP Veno");
239