diff options
author | Michal Kazior <michal.kazior@tieto.com> | 2016-04-22 08:15:59 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2016-04-25 16:44:27 -0400 |
commit | d068ca2ae2e614b9a418fb3b5f1fd4cf996ff032 (patch) | |
tree | 4ac7b0884a377dffb3bbb9aa0c301b0babb0ccd1 | |
parent | 79bdc4c862af7cf11a135a6fdf8093622043c862 (diff) |
codel: split into multiple files
It was impossible to include codel.h for the
purpose of having access to codel_params or
codel_vars structure definitions and using them
for embedding in other more complex structures.
This splits allows codel.h itself to be treated
like any other header file while codel_qdisc.h and
codel_impl.h contain function definitions with
logic that was previously in codel.h.
This copies over copyrights and doesn't involve
code changes other than adding a few additional
include directives to net/sched/sch*codel.c.
Signed-off-by: Michal Kazior <michal.kazior@tieto.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | include/net/codel.h | 223 | ||||
-rw-r--r-- | include/net/codel_impl.h | 255 | ||||
-rw-r--r-- | include/net/codel_qdisc.h | 73 | ||||
-rw-r--r-- | net/sched/sch_codel.c | 2 | ||||
-rw-r--r-- | net/sched/sch_fq_codel.c | 2 |
5 files changed, 332 insertions, 223 deletions
diff --git a/include/net/codel.h b/include/net/codel.h index 06ac687b4909..a6e428f80135 100644 --- a/include/net/codel.h +++ b/include/net/codel.h | |||
@@ -87,27 +87,6 @@ static inline codel_time_t codel_get_time(void) | |||
87 | ((s32)((a) - (b)) >= 0)) | 87 | ((s32)((a) - (b)) >= 0)) |
88 | #define codel_time_before_eq(a, b) codel_time_after_eq(b, a) | 88 | #define codel_time_before_eq(a, b) codel_time_after_eq(b, a) |
89 | 89 | ||
90 | /* Qdiscs using codel plugin must use codel_skb_cb in their own cb[] */ | ||
91 | struct codel_skb_cb { | ||
92 | codel_time_t enqueue_time; | ||
93 | }; | ||
94 | |||
95 | static struct codel_skb_cb *get_codel_cb(const struct sk_buff *skb) | ||
96 | { | ||
97 | qdisc_cb_private_validate(skb, sizeof(struct codel_skb_cb)); | ||
98 | return (struct codel_skb_cb *)qdisc_skb_cb(skb)->data; | ||
99 | } | ||
100 | |||
101 | static codel_time_t codel_get_enqueue_time(const struct sk_buff *skb) | ||
102 | { | ||
103 | return get_codel_cb(skb)->enqueue_time; | ||
104 | } | ||
105 | |||
106 | static void codel_set_enqueue_time(struct sk_buff *skb) | ||
107 | { | ||
108 | get_codel_cb(skb)->enqueue_time = codel_get_time(); | ||
109 | } | ||
110 | |||
111 | static inline u32 codel_time_to_us(codel_time_t val) | 90 | static inline u32 codel_time_to_us(codel_time_t val) |
112 | { | 91 | { |
113 | u64 valns = ((u64)val << CODEL_SHIFT); | 92 | u64 valns = ((u64)val << CODEL_SHIFT); |
@@ -176,212 +155,10 @@ struct codel_stats { | |||
176 | 155 | ||
177 | #define CODEL_DISABLED_THRESHOLD INT_MAX | 156 | #define CODEL_DISABLED_THRESHOLD INT_MAX |
178 | 157 | ||
179 | static void codel_params_init(struct codel_params *params) | ||
180 | { | ||
181 | params->interval = MS2TIME(100); | ||
182 | params->target = MS2TIME(5); | ||
183 | params->ce_threshold = CODEL_DISABLED_THRESHOLD; | ||
184 | params->ecn = false; | ||
185 | } | ||
186 | |||
187 | static void codel_vars_init(struct codel_vars *vars) | ||
188 | { | ||
189 | memset(vars, 0, sizeof(*vars)); | ||
190 | } | ||
191 | |||
192 | static void codel_stats_init(struct codel_stats *stats) | ||
193 | { | ||
194 | stats->maxpacket = 0; | ||
195 | } | ||
196 | |||
197 | /* | ||
198 | * http://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Iterative_methods_for_reciprocal_square_roots | ||
199 | * new_invsqrt = (invsqrt / 2) * (3 - count * invsqrt^2) | ||
200 | * | ||
201 | * Here, invsqrt is a fixed point number (< 1.0), 32bit mantissa, aka Q0.32 | ||
202 | */ | ||
203 | static void codel_Newton_step(struct codel_vars *vars) | ||
204 | { | ||
205 | u32 invsqrt = ((u32)vars->rec_inv_sqrt) << REC_INV_SQRT_SHIFT; | ||
206 | u32 invsqrt2 = ((u64)invsqrt * invsqrt) >> 32; | ||
207 | u64 val = (3LL << 32) - ((u64)vars->count * invsqrt2); | ||
208 | |||
209 | val >>= 2; /* avoid overflow in following multiply */ | ||
210 | val = (val * invsqrt) >> (32 - 2 + 1); | ||
211 | |||
212 | vars->rec_inv_sqrt = val >> REC_INV_SQRT_SHIFT; | ||
213 | } | ||
214 | |||
215 | /* | ||
216 | * CoDel control_law is t + interval/sqrt(count) | ||
217 | * We maintain in rec_inv_sqrt the reciprocal value of sqrt(count) to avoid | ||
218 | * both sqrt() and divide operation. | ||
219 | */ | ||
220 | static codel_time_t codel_control_law(codel_time_t t, | ||
221 | codel_time_t interval, | ||
222 | u32 rec_inv_sqrt) | ||
223 | { | ||
224 | return t + reciprocal_scale(interval, rec_inv_sqrt << REC_INV_SQRT_SHIFT); | ||
225 | } | ||
226 | |||
227 | typedef u32 (*codel_skb_len_t)(const struct sk_buff *skb); | 158 | typedef u32 (*codel_skb_len_t)(const struct sk_buff *skb); |
228 | typedef codel_time_t (*codel_skb_time_t)(const struct sk_buff *skb); | 159 | typedef codel_time_t (*codel_skb_time_t)(const struct sk_buff *skb); |
229 | typedef void (*codel_skb_drop_t)(struct sk_buff *skb, void *ctx); | 160 | typedef void (*codel_skb_drop_t)(struct sk_buff *skb, void *ctx); |
230 | typedef struct sk_buff * (*codel_skb_dequeue_t)(struct codel_vars *vars, | 161 | typedef struct sk_buff * (*codel_skb_dequeue_t)(struct codel_vars *vars, |
231 | void *ctx); | 162 | void *ctx); |
232 | 163 | ||
233 | static bool codel_should_drop(const struct sk_buff *skb, | ||
234 | void *ctx, | ||
235 | struct codel_vars *vars, | ||
236 | struct codel_params *params, | ||
237 | struct codel_stats *stats, | ||
238 | codel_skb_len_t skb_len_func, | ||
239 | codel_skb_time_t skb_time_func, | ||
240 | u32 *backlog, | ||
241 | codel_time_t now) | ||
242 | { | ||
243 | bool ok_to_drop; | ||
244 | u32 skb_len; | ||
245 | |||
246 | if (!skb) { | ||
247 | vars->first_above_time = 0; | ||
248 | return false; | ||
249 | } | ||
250 | |||
251 | skb_len = skb_len_func(skb); | ||
252 | vars->ldelay = now - skb_time_func(skb); | ||
253 | |||
254 | if (unlikely(skb_len > stats->maxpacket)) | ||
255 | stats->maxpacket = skb_len; | ||
256 | |||
257 | if (codel_time_before(vars->ldelay, params->target) || | ||
258 | *backlog <= params->mtu) { | ||
259 | /* went below - stay below for at least interval */ | ||
260 | vars->first_above_time = 0; | ||
261 | return false; | ||
262 | } | ||
263 | ok_to_drop = false; | ||
264 | if (vars->first_above_time == 0) { | ||
265 | /* just went above from below. If we stay above | ||
266 | * for at least interval we'll say it's ok to drop | ||
267 | */ | ||
268 | vars->first_above_time = now + params->interval; | ||
269 | } else if (codel_time_after(now, vars->first_above_time)) { | ||
270 | ok_to_drop = true; | ||
271 | } | ||
272 | return ok_to_drop; | ||
273 | } | ||
274 | |||
275 | static struct sk_buff *codel_dequeue(void *ctx, | ||
276 | u32 *backlog, | ||
277 | struct codel_params *params, | ||
278 | struct codel_vars *vars, | ||
279 | struct codel_stats *stats, | ||
280 | codel_skb_len_t skb_len_func, | ||
281 | codel_skb_time_t skb_time_func, | ||
282 | codel_skb_drop_t drop_func, | ||
283 | codel_skb_dequeue_t dequeue_func) | ||
284 | { | ||
285 | struct sk_buff *skb = dequeue_func(vars, ctx); | ||
286 | codel_time_t now; | ||
287 | bool drop; | ||
288 | |||
289 | if (!skb) { | ||
290 | vars->dropping = false; | ||
291 | return skb; | ||
292 | } | ||
293 | now = codel_get_time(); | ||
294 | drop = codel_should_drop(skb, ctx, vars, params, stats, | ||
295 | skb_len_func, skb_time_func, backlog, now); | ||
296 | if (vars->dropping) { | ||
297 | if (!drop) { | ||
298 | /* sojourn time below target - leave dropping state */ | ||
299 | vars->dropping = false; | ||
300 | } else if (codel_time_after_eq(now, vars->drop_next)) { | ||
301 | /* It's time for the next drop. Drop the current | ||
302 | * packet and dequeue the next. The dequeue might | ||
303 | * take us out of dropping state. | ||
304 | * If not, schedule the next drop. | ||
305 | * A large backlog might result in drop rates so high | ||
306 | * that the next drop should happen now, | ||
307 | * hence the while loop. | ||
308 | */ | ||
309 | while (vars->dropping && | ||
310 | codel_time_after_eq(now, vars->drop_next)) { | ||
311 | vars->count++; /* dont care of possible wrap | ||
312 | * since there is no more divide | ||
313 | */ | ||
314 | codel_Newton_step(vars); | ||
315 | if (params->ecn && INET_ECN_set_ce(skb)) { | ||
316 | stats->ecn_mark++; | ||
317 | vars->drop_next = | ||
318 | codel_control_law(vars->drop_next, | ||
319 | params->interval, | ||
320 | vars->rec_inv_sqrt); | ||
321 | goto end; | ||
322 | } | ||
323 | stats->drop_len += skb_len_func(skb); | ||
324 | drop_func(skb, ctx); | ||
325 | stats->drop_count++; | ||
326 | skb = dequeue_func(vars, ctx); | ||
327 | if (!codel_should_drop(skb, ctx, | ||
328 | vars, params, stats, | ||
329 | skb_len_func, | ||
330 | skb_time_func, | ||
331 | backlog, now)) { | ||
332 | /* leave dropping state */ | ||
333 | vars->dropping = false; | ||
334 | } else { | ||
335 | /* and schedule the next drop */ | ||
336 | vars->drop_next = | ||
337 | codel_control_law(vars->drop_next, | ||
338 | params->interval, | ||
339 | vars->rec_inv_sqrt); | ||
340 | } | ||
341 | } | ||
342 | } | ||
343 | } else if (drop) { | ||
344 | u32 delta; | ||
345 | |||
346 | if (params->ecn && INET_ECN_set_ce(skb)) { | ||
347 | stats->ecn_mark++; | ||
348 | } else { | ||
349 | stats->drop_len += skb_len_func(skb); | ||
350 | drop_func(skb, ctx); | ||
351 | stats->drop_count++; | ||
352 | |||
353 | skb = dequeue_func(vars, ctx); | ||
354 | drop = codel_should_drop(skb, ctx, vars, params, | ||
355 | stats, skb_len_func, | ||
356 | skb_time_func, backlog, now); | ||
357 | } | ||
358 | vars->dropping = true; | ||
359 | /* if min went above target close to when we last went below it | ||
360 | * assume that the drop rate that controlled the queue on the | ||
361 | * last cycle is a good starting point to control it now. | ||
362 | */ | ||
363 | delta = vars->count - vars->lastcount; | ||
364 | if (delta > 1 && | ||
365 | codel_time_before(now - vars->drop_next, | ||
366 | 16 * params->interval)) { | ||
367 | vars->count = delta; | ||
368 | /* we dont care if rec_inv_sqrt approximation | ||
369 | * is not very precise : | ||
370 | * Next Newton steps will correct it quadratically. | ||
371 | */ | ||
372 | codel_Newton_step(vars); | ||
373 | } else { | ||
374 | vars->count = 1; | ||
375 | vars->rec_inv_sqrt = ~0U >> REC_INV_SQRT_SHIFT; | ||
376 | } | ||
377 | vars->lastcount = vars->count; | ||
378 | vars->drop_next = codel_control_law(now, params->interval, | ||
379 | vars->rec_inv_sqrt); | ||
380 | } | ||
381 | end: | ||
382 | if (skb && codel_time_after(vars->ldelay, params->ce_threshold) && | ||
383 | INET_ECN_set_ce(skb)) | ||
384 | stats->ce_mark++; | ||
385 | return skb; | ||
386 | } | ||
387 | #endif | 164 | #endif |
diff --git a/include/net/codel_impl.h b/include/net/codel_impl.h new file mode 100644 index 000000000000..d289b91dcd65 --- /dev/null +++ b/include/net/codel_impl.h | |||
@@ -0,0 +1,255 @@ | |||
1 | #ifndef __NET_SCHED_CODEL_IMPL_H | ||
2 | #define __NET_SCHED_CODEL_IMPL_H | ||
3 | |||
4 | /* | ||
5 | * Codel - The Controlled-Delay Active Queue Management algorithm | ||
6 | * | ||
7 | * Copyright (C) 2011-2012 Kathleen Nichols <nichols@pollere.com> | ||
8 | * Copyright (C) 2011-2012 Van Jacobson <van@pollere.net> | ||
9 | * Copyright (C) 2012 Michael D. Taht <dave.taht@bufferbloat.net> | ||
10 | * Copyright (C) 2012,2015 Eric Dumazet <edumazet@google.com> | ||
11 | * | ||
12 | * Redistribution and use in source and binary forms, with or without | ||
13 | * modification, are permitted provided that the following conditions | ||
14 | * are met: | ||
15 | * 1. Redistributions of source code must retain the above copyright | ||
16 | * notice, this list of conditions, and the following disclaimer, | ||
17 | * without modification. | ||
18 | * 2. Redistributions in binary form must reproduce the above copyright | ||
19 | * notice, this list of conditions and the following disclaimer in the | ||
20 | * documentation and/or other materials provided with the distribution. | ||
21 | * 3. The names of the authors may not be used to endorse or promote products | ||
22 | * derived from this software without specific prior written permission. | ||
23 | * | ||
24 | * Alternatively, provided that this notice is retained in full, this | ||
25 | * software may be distributed under the terms of the GNU General | ||
26 | * Public License ("GPL") version 2, in which case the provisions of the | ||
27 | * GPL apply INSTEAD OF those given above. | ||
28 | * | ||
29 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
30 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
31 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
32 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
33 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
34 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
35 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
36 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
37 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
38 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
39 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH | ||
40 | * DAMAGE. | ||
41 | * | ||
42 | */ | ||
43 | |||
44 | /* Controlling Queue Delay (CoDel) algorithm | ||
45 | * ========================================= | ||
46 | * Source : Kathleen Nichols and Van Jacobson | ||
47 | * http://queue.acm.org/detail.cfm?id=2209336 | ||
48 | * | ||
49 | * Implemented on linux by Dave Taht and Eric Dumazet | ||
50 | */ | ||
51 | |||
52 | static void codel_params_init(struct codel_params *params) | ||
53 | { | ||
54 | params->interval = MS2TIME(100); | ||
55 | params->target = MS2TIME(5); | ||
56 | params->ce_threshold = CODEL_DISABLED_THRESHOLD; | ||
57 | params->ecn = false; | ||
58 | } | ||
59 | |||
60 | static void codel_vars_init(struct codel_vars *vars) | ||
61 | { | ||
62 | memset(vars, 0, sizeof(*vars)); | ||
63 | } | ||
64 | |||
65 | static void codel_stats_init(struct codel_stats *stats) | ||
66 | { | ||
67 | stats->maxpacket = 0; | ||
68 | } | ||
69 | |||
70 | /* | ||
71 | * http://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Iterative_methods_for_reciprocal_square_roots | ||
72 | * new_invsqrt = (invsqrt / 2) * (3 - count * invsqrt^2) | ||
73 | * | ||
74 | * Here, invsqrt is a fixed point number (< 1.0), 32bit mantissa, aka Q0.32 | ||
75 | */ | ||
76 | static void codel_Newton_step(struct codel_vars *vars) | ||
77 | { | ||
78 | u32 invsqrt = ((u32)vars->rec_inv_sqrt) << REC_INV_SQRT_SHIFT; | ||
79 | u32 invsqrt2 = ((u64)invsqrt * invsqrt) >> 32; | ||
80 | u64 val = (3LL << 32) - ((u64)vars->count * invsqrt2); | ||
81 | |||
82 | val >>= 2; /* avoid overflow in following multiply */ | ||
83 | val = (val * invsqrt) >> (32 - 2 + 1); | ||
84 | |||
85 | vars->rec_inv_sqrt = val >> REC_INV_SQRT_SHIFT; | ||
86 | } | ||
87 | |||
88 | /* | ||
89 | * CoDel control_law is t + interval/sqrt(count) | ||
90 | * We maintain in rec_inv_sqrt the reciprocal value of sqrt(count) to avoid | ||
91 | * both sqrt() and divide operation. | ||
92 | */ | ||
93 | static codel_time_t codel_control_law(codel_time_t t, | ||
94 | codel_time_t interval, | ||
95 | u32 rec_inv_sqrt) | ||
96 | { | ||
97 | return t + reciprocal_scale(interval, rec_inv_sqrt << REC_INV_SQRT_SHIFT); | ||
98 | } | ||
99 | |||
100 | static bool codel_should_drop(const struct sk_buff *skb, | ||
101 | void *ctx, | ||
102 | struct codel_vars *vars, | ||
103 | struct codel_params *params, | ||
104 | struct codel_stats *stats, | ||
105 | codel_skb_len_t skb_len_func, | ||
106 | codel_skb_time_t skb_time_func, | ||
107 | u32 *backlog, | ||
108 | codel_time_t now) | ||
109 | { | ||
110 | bool ok_to_drop; | ||
111 | u32 skb_len; | ||
112 | |||
113 | if (!skb) { | ||
114 | vars->first_above_time = 0; | ||
115 | return false; | ||
116 | } | ||
117 | |||
118 | skb_len = skb_len_func(skb); | ||
119 | vars->ldelay = now - skb_time_func(skb); | ||
120 | |||
121 | if (unlikely(skb_len > stats->maxpacket)) | ||
122 | stats->maxpacket = skb_len; | ||
123 | |||
124 | if (codel_time_before(vars->ldelay, params->target) || | ||
125 | *backlog <= params->mtu) { | ||
126 | /* went below - stay below for at least interval */ | ||
127 | vars->first_above_time = 0; | ||
128 | return false; | ||
129 | } | ||
130 | ok_to_drop = false; | ||
131 | if (vars->first_above_time == 0) { | ||
132 | /* just went above from below. If we stay above | ||
133 | * for at least interval we'll say it's ok to drop | ||
134 | */ | ||
135 | vars->first_above_time = now + params->interval; | ||
136 | } else if (codel_time_after(now, vars->first_above_time)) { | ||
137 | ok_to_drop = true; | ||
138 | } | ||
139 | return ok_to_drop; | ||
140 | } | ||
141 | |||
142 | static struct sk_buff *codel_dequeue(void *ctx, | ||
143 | u32 *backlog, | ||
144 | struct codel_params *params, | ||
145 | struct codel_vars *vars, | ||
146 | struct codel_stats *stats, | ||
147 | codel_skb_len_t skb_len_func, | ||
148 | codel_skb_time_t skb_time_func, | ||
149 | codel_skb_drop_t drop_func, | ||
150 | codel_skb_dequeue_t dequeue_func) | ||
151 | { | ||
152 | struct sk_buff *skb = dequeue_func(vars, ctx); | ||
153 | codel_time_t now; | ||
154 | bool drop; | ||
155 | |||
156 | if (!skb) { | ||
157 | vars->dropping = false; | ||
158 | return skb; | ||
159 | } | ||
160 | now = codel_get_time(); | ||
161 | drop = codel_should_drop(skb, ctx, vars, params, stats, | ||
162 | skb_len_func, skb_time_func, backlog, now); | ||
163 | if (vars->dropping) { | ||
164 | if (!drop) { | ||
165 | /* sojourn time below target - leave dropping state */ | ||
166 | vars->dropping = false; | ||
167 | } else if (codel_time_after_eq(now, vars->drop_next)) { | ||
168 | /* It's time for the next drop. Drop the current | ||
169 | * packet and dequeue the next. The dequeue might | ||
170 | * take us out of dropping state. | ||
171 | * If not, schedule the next drop. | ||
172 | * A large backlog might result in drop rates so high | ||
173 | * that the next drop should happen now, | ||
174 | * hence the while loop. | ||
175 | */ | ||
176 | while (vars->dropping && | ||
177 | codel_time_after_eq(now, vars->drop_next)) { | ||
178 | vars->count++; /* dont care of possible wrap | ||
179 | * since there is no more divide | ||
180 | */ | ||
181 | codel_Newton_step(vars); | ||
182 | if (params->ecn && INET_ECN_set_ce(skb)) { | ||
183 | stats->ecn_mark++; | ||
184 | vars->drop_next = | ||
185 | codel_control_law(vars->drop_next, | ||
186 | params->interval, | ||
187 | vars->rec_inv_sqrt); | ||
188 | goto end; | ||
189 | } | ||
190 | stats->drop_len += skb_len_func(skb); | ||
191 | drop_func(skb, ctx); | ||
192 | stats->drop_count++; | ||
193 | skb = dequeue_func(vars, ctx); | ||
194 | if (!codel_should_drop(skb, ctx, | ||
195 | vars, params, stats, | ||
196 | skb_len_func, | ||
197 | skb_time_func, | ||
198 | backlog, now)) { | ||
199 | /* leave dropping state */ | ||
200 | vars->dropping = false; | ||
201 | } else { | ||
202 | /* and schedule the next drop */ | ||
203 | vars->drop_next = | ||
204 | codel_control_law(vars->drop_next, | ||
205 | params->interval, | ||
206 | vars->rec_inv_sqrt); | ||
207 | } | ||
208 | } | ||
209 | } | ||
210 | } else if (drop) { | ||
211 | u32 delta; | ||
212 | |||
213 | if (params->ecn && INET_ECN_set_ce(skb)) { | ||
214 | stats->ecn_mark++; | ||
215 | } else { | ||
216 | stats->drop_len += skb_len_func(skb); | ||
217 | drop_func(skb, ctx); | ||
218 | stats->drop_count++; | ||
219 | |||
220 | skb = dequeue_func(vars, ctx); | ||
221 | drop = codel_should_drop(skb, ctx, vars, params, | ||
222 | stats, skb_len_func, | ||
223 | skb_time_func, backlog, now); | ||
224 | } | ||
225 | vars->dropping = true; | ||
226 | /* if min went above target close to when we last went below it | ||
227 | * assume that the drop rate that controlled the queue on the | ||
228 | * last cycle is a good starting point to control it now. | ||
229 | */ | ||
230 | delta = vars->count - vars->lastcount; | ||
231 | if (delta > 1 && | ||
232 | codel_time_before(now - vars->drop_next, | ||
233 | 16 * params->interval)) { | ||
234 | vars->count = delta; | ||
235 | /* we dont care if rec_inv_sqrt approximation | ||
236 | * is not very precise : | ||
237 | * Next Newton steps will correct it quadratically. | ||
238 | */ | ||
239 | codel_Newton_step(vars); | ||
240 | } else { | ||
241 | vars->count = 1; | ||
242 | vars->rec_inv_sqrt = ~0U >> REC_INV_SQRT_SHIFT; | ||
243 | } | ||
244 | vars->lastcount = vars->count; | ||
245 | vars->drop_next = codel_control_law(now, params->interval, | ||
246 | vars->rec_inv_sqrt); | ||
247 | } | ||
248 | end: | ||
249 | if (skb && codel_time_after(vars->ldelay, params->ce_threshold) && | ||
250 | INET_ECN_set_ce(skb)) | ||
251 | stats->ce_mark++; | ||
252 | return skb; | ||
253 | } | ||
254 | |||
255 | #endif | ||
diff --git a/include/net/codel_qdisc.h b/include/net/codel_qdisc.h new file mode 100644 index 000000000000..8144d9cd2908 --- /dev/null +++ b/include/net/codel_qdisc.h | |||
@@ -0,0 +1,73 @@ | |||
1 | #ifndef __NET_SCHED_CODEL_QDISC_H | ||
2 | #define __NET_SCHED_CODEL_QDISC_H | ||
3 | |||
4 | /* | ||
5 | * Codel - The Controlled-Delay Active Queue Management algorithm | ||
6 | * | ||
7 | * Copyright (C) 2011-2012 Kathleen Nichols <nichols@pollere.com> | ||
8 | * Copyright (C) 2011-2012 Van Jacobson <van@pollere.net> | ||
9 | * Copyright (C) 2012 Michael D. Taht <dave.taht@bufferbloat.net> | ||
10 | * Copyright (C) 2012,2015 Eric Dumazet <edumazet@google.com> | ||
11 | * | ||
12 | * Redistribution and use in source and binary forms, with or without | ||
13 | * modification, are permitted provided that the following conditions | ||
14 | * are met: | ||
15 | * 1. Redistributions of source code must retain the above copyright | ||
16 | * notice, this list of conditions, and the following disclaimer, | ||
17 | * without modification. | ||
18 | * 2. Redistributions in binary form must reproduce the above copyright | ||
19 | * notice, this list of conditions and the following disclaimer in the | ||
20 | * documentation and/or other materials provided with the distribution. | ||
21 | * 3. The names of the authors may not be used to endorse or promote products | ||
22 | * derived from this software without specific prior written permission. | ||
23 | * | ||
24 | * Alternatively, provided that this notice is retained in full, this | ||
25 | * software may be distributed under the terms of the GNU General | ||
26 | * Public License ("GPL") version 2, in which case the provisions of the | ||
27 | * GPL apply INSTEAD OF those given above. | ||
28 | * | ||
29 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
30 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
31 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
32 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
33 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
34 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
35 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
36 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
37 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
38 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
39 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH | ||
40 | * DAMAGE. | ||
41 | * | ||
42 | */ | ||
43 | |||
44 | /* Controlling Queue Delay (CoDel) algorithm | ||
45 | * ========================================= | ||
46 | * Source : Kathleen Nichols and Van Jacobson | ||
47 | * http://queue.acm.org/detail.cfm?id=2209336 | ||
48 | * | ||
49 | * Implemented on linux by Dave Taht and Eric Dumazet | ||
50 | */ | ||
51 | |||
52 | /* Qdiscs using codel plugin must use codel_skb_cb in their own cb[] */ | ||
53 | struct codel_skb_cb { | ||
54 | codel_time_t enqueue_time; | ||
55 | }; | ||
56 | |||
57 | static struct codel_skb_cb *get_codel_cb(const struct sk_buff *skb) | ||
58 | { | ||
59 | qdisc_cb_private_validate(skb, sizeof(struct codel_skb_cb)); | ||
60 | return (struct codel_skb_cb *)qdisc_skb_cb(skb)->data; | ||
61 | } | ||
62 | |||
63 | static codel_time_t codel_get_enqueue_time(const struct sk_buff *skb) | ||
64 | { | ||
65 | return get_codel_cb(skb)->enqueue_time; | ||
66 | } | ||
67 | |||
68 | static void codel_set_enqueue_time(struct sk_buff *skb) | ||
69 | { | ||
70 | get_codel_cb(skb)->enqueue_time = codel_get_time(); | ||
71 | } | ||
72 | |||
73 | #endif | ||
diff --git a/net/sched/sch_codel.c b/net/sched/sch_codel.c index 512a94abe351..dddf3bb65a32 100644 --- a/net/sched/sch_codel.c +++ b/net/sched/sch_codel.c | |||
@@ -49,6 +49,8 @@ | |||
49 | #include <linux/prefetch.h> | 49 | #include <linux/prefetch.h> |
50 | #include <net/pkt_sched.h> | 50 | #include <net/pkt_sched.h> |
51 | #include <net/codel.h> | 51 | #include <net/codel.h> |
52 | #include <net/codel_impl.h> | ||
53 | #include <net/codel_qdisc.h> | ||
52 | 54 | ||
53 | 55 | ||
54 | #define DEFAULT_CODEL_LIMIT 1000 | 56 | #define DEFAULT_CODEL_LIMIT 1000 |
diff --git a/net/sched/sch_fq_codel.c b/net/sched/sch_fq_codel.c index dcf7266e6901..a5e420b3d4ab 100644 --- a/net/sched/sch_fq_codel.c +++ b/net/sched/sch_fq_codel.c | |||
@@ -24,6 +24,8 @@ | |||
24 | #include <net/netlink.h> | 24 | #include <net/netlink.h> |
25 | #include <net/pkt_sched.h> | 25 | #include <net/pkt_sched.h> |
26 | #include <net/codel.h> | 26 | #include <net/codel.h> |
27 | #include <net/codel_impl.h> | ||
28 | #include <net/codel_qdisc.h> | ||
27 | 29 | ||
28 | /* Fair Queue CoDel. | 30 | /* Fair Queue CoDel. |
29 | * | 31 | * |