codel: generalize the implementation
[linux-2.6-block.git] / net / sched / sch_fq_codel.c
CommitLineData
4b549a2e
ED
1/*
2 * Fair Queue CoDel discipline
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
8 *
80ba92fa 9 * Copyright (C) 2012,2015 Eric Dumazet <edumazet@google.com>
4b549a2e
ED
10 */
11
12#include <linux/module.h>
13#include <linux/types.h>
14#include <linux/kernel.h>
15#include <linux/jiffies.h>
16#include <linux/string.h>
17#include <linux/in.h>
18#include <linux/errno.h>
19#include <linux/init.h>
20#include <linux/skbuff.h>
21#include <linux/jhash.h>
22#include <linux/slab.h>
23#include <linux/vmalloc.h>
24#include <net/netlink.h>
25#include <net/pkt_sched.h>
4b549a2e
ED
26#include <net/codel.h>
27
28/* Fair Queue CoDel.
29 *
30 * Principles :
31 * Packets are classified (internal classifier or external) on flows.
32 * This is a Stochastic model (as we use a hash, several flows
33 * might be hashed on same slot)
34 * Each flow has a CoDel managed queue.
35 * Flows are linked onto two (Round Robin) lists,
36 * so that new flows have priority on old ones.
37 *
38 * For a given flow, packets are not reordered (CoDel uses a FIFO)
39 * head drops only.
40 * ECN capability is on by default.
41 * Low memory footprint (64 bytes per flow)
42 */
43
44struct fq_codel_flow {
45 struct sk_buff *head;
46 struct sk_buff *tail;
47 struct list_head flowchain;
48 int deficit;
49 u32 dropped; /* number of drops (or ECN marks) on this flow */
50 struct codel_vars cvars;
51}; /* please try to keep this structure <= 64 bytes */
52
53struct fq_codel_sched_data {
25d8c0d5 54 struct tcf_proto __rcu *filter_list; /* optional external classifier */
4b549a2e
ED
55 struct fq_codel_flow *flows; /* Flows table [flows_cnt] */
56 u32 *backlogs; /* backlog table [flows_cnt] */
57 u32 flows_cnt; /* number of flows */
58 u32 perturbation; /* hash perturbation */
59 u32 quantum; /* psched_mtu(qdisc_dev(sch)); */
60 struct codel_params cparams;
61 struct codel_stats cstats;
62 u32 drop_overlimit;
63 u32 new_flow_count;
64
65 struct list_head new_flows; /* list of new flows */
66 struct list_head old_flows; /* list of old flows */
67};
68
69static unsigned int fq_codel_hash(const struct fq_codel_sched_data *q,
342db221 70 struct sk_buff *skb)
4b549a2e 71{
342db221 72 u32 hash = skb_get_hash_perturb(skb, q->perturbation);
8fc54f68
DB
73
74 return reciprocal_scale(hash, q->flows_cnt);
4b549a2e
ED
75}
76
77static unsigned int fq_codel_classify(struct sk_buff *skb, struct Qdisc *sch,
78 int *qerr)
79{
80 struct fq_codel_sched_data *q = qdisc_priv(sch);
25d8c0d5 81 struct tcf_proto *filter;
4b549a2e
ED
82 struct tcf_result res;
83 int result;
84
85 if (TC_H_MAJ(skb->priority) == sch->handle &&
86 TC_H_MIN(skb->priority) > 0 &&
87 TC_H_MIN(skb->priority) <= q->flows_cnt)
88 return TC_H_MIN(skb->priority);
89
69204cf7 90 filter = rcu_dereference_bh(q->filter_list);
25d8c0d5 91 if (!filter)
4b549a2e
ED
92 return fq_codel_hash(q, skb) + 1;
93
94 *qerr = NET_XMIT_SUCCESS | __NET_XMIT_BYPASS;
3b3ae880 95 result = tc_classify(skb, filter, &res, false);
4b549a2e
ED
96 if (result >= 0) {
97#ifdef CONFIG_NET_CLS_ACT
98 switch (result) {
99 case TC_ACT_STOLEN:
100 case TC_ACT_QUEUED:
101 *qerr = NET_XMIT_SUCCESS | __NET_XMIT_STOLEN;
102 case TC_ACT_SHOT:
103 return 0;
104 }
105#endif
106 if (TC_H_MIN(res.classid) <= q->flows_cnt)
107 return TC_H_MIN(res.classid);
108 }
109 return 0;
110}
111
112/* helper functions : might be changed when/if skb use a standard list_head */
113
114/* remove one skb from head of slot queue */
115static inline struct sk_buff *dequeue_head(struct fq_codel_flow *flow)
116{
117 struct sk_buff *skb = flow->head;
118
119 flow->head = skb->next;
120 skb->next = NULL;
121 return skb;
122}
123
124/* add skb to flow queue (tail add) */
125static inline void flow_queue_add(struct fq_codel_flow *flow,
126 struct sk_buff *skb)
127{
128 if (flow->head == NULL)
129 flow->head = skb;
130 else
131 flow->tail->next = skb;
132 flow->tail = skb;
133 skb->next = NULL;
134}
135
136static unsigned int fq_codel_drop(struct Qdisc *sch)
137{
138 struct fq_codel_sched_data *q = qdisc_priv(sch);
139 struct sk_buff *skb;
140 unsigned int maxbacklog = 0, idx = 0, i, len;
141 struct fq_codel_flow *flow;
142
143 /* Queue is full! Find the fat flow and drop packet from it.
144 * This might sound expensive, but with 1024 flows, we scan
145 * 4KB of memory, and we dont need to handle a complex tree
146 * in fast path (packet queue/enqueue) with many cache misses.
147 */
148 for (i = 0; i < q->flows_cnt; i++) {
149 if (q->backlogs[i] > maxbacklog) {
150 maxbacklog = q->backlogs[i];
151 idx = i;
152 }
153 }
154 flow = &q->flows[idx];
155 skb = dequeue_head(flow);
156 len = qdisc_pkt_len(skb);
157 q->backlogs[idx] -= len;
4b549a2e 158 sch->q.qlen--;
25331d6c
JF
159 qdisc_qstats_drop(sch);
160 qdisc_qstats_backlog_dec(sch, skb);
052cbda4 161 kfree_skb(skb);
4b549a2e
ED
162 flow->dropped++;
163 return idx;
164}
165
c0afd9ce
WC
166static unsigned int fq_codel_qdisc_drop(struct Qdisc *sch)
167{
168 unsigned int prev_backlog;
169
170 prev_backlog = sch->qstats.backlog;
171 fq_codel_drop(sch);
172 return prev_backlog - sch->qstats.backlog;
173}
174
4b549a2e
ED
175static int fq_codel_enqueue(struct sk_buff *skb, struct Qdisc *sch)
176{
177 struct fq_codel_sched_data *q = qdisc_priv(sch);
2ccccf5f 178 unsigned int idx, prev_backlog;
4b549a2e
ED
179 struct fq_codel_flow *flow;
180 int uninitialized_var(ret);
181
182 idx = fq_codel_classify(skb, sch, &ret);
183 if (idx == 0) {
184 if (ret & __NET_XMIT_BYPASS)
25331d6c 185 qdisc_qstats_drop(sch);
4b549a2e
ED
186 kfree_skb(skb);
187 return ret;
188 }
189 idx--;
190
191 codel_set_enqueue_time(skb);
192 flow = &q->flows[idx];
193 flow_queue_add(flow, skb);
194 q->backlogs[idx] += qdisc_pkt_len(skb);
25331d6c 195 qdisc_qstats_backlog_inc(sch, skb);
4b549a2e
ED
196
197 if (list_empty(&flow->flowchain)) {
198 list_add_tail(&flow->flowchain, &q->new_flows);
4b549a2e
ED
199 q->new_flow_count++;
200 flow->deficit = q->quantum;
201 flow->dropped = 0;
202 }
cd68ddd4 203 if (++sch->q.qlen <= sch->limit)
4b549a2e
ED
204 return NET_XMIT_SUCCESS;
205
2ccccf5f 206 prev_backlog = sch->qstats.backlog;
4b549a2e
ED
207 q->drop_overlimit++;
208 /* Return Congestion Notification only if we dropped a packet
209 * from this flow.
210 */
211 if (fq_codel_drop(sch) == idx)
212 return NET_XMIT_CN;
213
214 /* As we dropped a packet, better let upper stack know this */
2ccccf5f 215 qdisc_tree_reduce_backlog(sch, 1, prev_backlog - sch->qstats.backlog);
4b549a2e
ED
216 return NET_XMIT_SUCCESS;
217}
218
219/* This is the specific function called from codel_dequeue()
220 * to dequeue a packet from queue. Note: backlog is handled in
221 * codel, we dont need to reduce it here.
222 */
79bdc4c8 223static struct sk_buff *dequeue_func(struct codel_vars *vars, void *ctx)
4b549a2e 224{
79bdc4c8 225 struct Qdisc *sch = ctx;
865ec552 226 struct fq_codel_sched_data *q = qdisc_priv(sch);
4b549a2e
ED
227 struct fq_codel_flow *flow;
228 struct sk_buff *skb = NULL;
229
230 flow = container_of(vars, struct fq_codel_flow, cvars);
231 if (flow->head) {
232 skb = dequeue_head(flow);
865ec552 233 q->backlogs[flow - q->flows] -= qdisc_pkt_len(skb);
4b549a2e 234 sch->q.qlen--;
79bdc4c8 235 sch->qstats.backlog -= qdisc_pkt_len(skb);
4b549a2e
ED
236 }
237 return skb;
238}
239
79bdc4c8
MK
240static void drop_func(struct sk_buff *skb, void *ctx)
241{
242 struct Qdisc *sch = ctx;
243
244 qdisc_drop(skb, sch);
245}
246
4b549a2e
ED
247static struct sk_buff *fq_codel_dequeue(struct Qdisc *sch)
248{
249 struct fq_codel_sched_data *q = qdisc_priv(sch);
250 struct sk_buff *skb;
251 struct fq_codel_flow *flow;
252 struct list_head *head;
253 u32 prev_drop_count, prev_ecn_mark;
2ccccf5f 254 unsigned int prev_backlog;
4b549a2e
ED
255
256begin:
257 head = &q->new_flows;
258 if (list_empty(head)) {
259 head = &q->old_flows;
260 if (list_empty(head))
261 return NULL;
262 }
263 flow = list_first_entry(head, struct fq_codel_flow, flowchain);
264
265 if (flow->deficit <= 0) {
266 flow->deficit += q->quantum;
267 list_move_tail(&flow->flowchain, &q->old_flows);
268 goto begin;
269 }
270
271 prev_drop_count = q->cstats.drop_count;
272 prev_ecn_mark = q->cstats.ecn_mark;
2ccccf5f 273 prev_backlog = sch->qstats.backlog;
4b549a2e 274
79bdc4c8
MK
275 skb = codel_dequeue(sch, &sch->qstats.backlog, &q->cparams,
276 &flow->cvars, &q->cstats, qdisc_pkt_len,
277 codel_get_enqueue_time, drop_func, dequeue_func);
4b549a2e
ED
278
279 flow->dropped += q->cstats.drop_count - prev_drop_count;
280 flow->dropped += q->cstats.ecn_mark - prev_ecn_mark;
281
282 if (!skb) {
283 /* force a pass through old_flows to prevent starvation */
284 if ((head == &q->new_flows) && !list_empty(&q->old_flows))
285 list_move_tail(&flow->flowchain, &q->old_flows);
286 else
287 list_del_init(&flow->flowchain);
288 goto begin;
289 }
290 qdisc_bstats_update(sch, skb);
291 flow->deficit -= qdisc_pkt_len(skb);
2ccccf5f 292 /* We cant call qdisc_tree_reduce_backlog() if our qlen is 0,
4b549a2e
ED
293 * or HTB crashes. Defer it for next round.
294 */
295 if (q->cstats.drop_count && sch->q.qlen) {
2ccccf5f
WC
296 qdisc_tree_reduce_backlog(sch, q->cstats.drop_count,
297 q->cstats.drop_len);
4b549a2e 298 q->cstats.drop_count = 0;
2ccccf5f 299 q->cstats.drop_len = 0;
4b549a2e
ED
300 }
301 return skb;
302}
303
304static void fq_codel_reset(struct Qdisc *sch)
305{
3d0e0af4
ED
306 struct fq_codel_sched_data *q = qdisc_priv(sch);
307 int i;
4b549a2e 308
3d0e0af4
ED
309 INIT_LIST_HEAD(&q->new_flows);
310 INIT_LIST_HEAD(&q->old_flows);
311 for (i = 0; i < q->flows_cnt; i++) {
312 struct fq_codel_flow *flow = q->flows + i;
313
314 while (flow->head) {
315 struct sk_buff *skb = dequeue_head(flow);
316
317 qdisc_qstats_backlog_dec(sch, skb);
318 kfree_skb(skb);
319 }
320
321 INIT_LIST_HEAD(&flow->flowchain);
322 codel_vars_init(&flow->cvars);
323 }
324 memset(q->backlogs, 0, q->flows_cnt * sizeof(u32));
325 sch->q.qlen = 0;
4b549a2e
ED
326}
327
328static const struct nla_policy fq_codel_policy[TCA_FQ_CODEL_MAX + 1] = {
329 [TCA_FQ_CODEL_TARGET] = { .type = NLA_U32 },
330 [TCA_FQ_CODEL_LIMIT] = { .type = NLA_U32 },
331 [TCA_FQ_CODEL_INTERVAL] = { .type = NLA_U32 },
332 [TCA_FQ_CODEL_ECN] = { .type = NLA_U32 },
333 [TCA_FQ_CODEL_FLOWS] = { .type = NLA_U32 },
334 [TCA_FQ_CODEL_QUANTUM] = { .type = NLA_U32 },
80ba92fa 335 [TCA_FQ_CODEL_CE_THRESHOLD] = { .type = NLA_U32 },
4b549a2e
ED
336};
337
338static int fq_codel_change(struct Qdisc *sch, struct nlattr *opt)
339{
340 struct fq_codel_sched_data *q = qdisc_priv(sch);
341 struct nlattr *tb[TCA_FQ_CODEL_MAX + 1];
342 int err;
343
344 if (!opt)
345 return -EINVAL;
346
347 err = nla_parse_nested(tb, TCA_FQ_CODEL_MAX, opt, fq_codel_policy);
348 if (err < 0)
349 return err;
350 if (tb[TCA_FQ_CODEL_FLOWS]) {
351 if (q->flows)
352 return -EINVAL;
353 q->flows_cnt = nla_get_u32(tb[TCA_FQ_CODEL_FLOWS]);
354 if (!q->flows_cnt ||
355 q->flows_cnt > 65536)
356 return -EINVAL;
357 }
358 sch_tree_lock(sch);
359
360 if (tb[TCA_FQ_CODEL_TARGET]) {
361 u64 target = nla_get_u32(tb[TCA_FQ_CODEL_TARGET]);
362
363 q->cparams.target = (target * NSEC_PER_USEC) >> CODEL_SHIFT;
364 }
365
80ba92fa
ED
366 if (tb[TCA_FQ_CODEL_CE_THRESHOLD]) {
367 u64 val = nla_get_u32(tb[TCA_FQ_CODEL_CE_THRESHOLD]);
368
369 q->cparams.ce_threshold = (val * NSEC_PER_USEC) >> CODEL_SHIFT;
370 }
371
4b549a2e
ED
372 if (tb[TCA_FQ_CODEL_INTERVAL]) {
373 u64 interval = nla_get_u32(tb[TCA_FQ_CODEL_INTERVAL]);
374
375 q->cparams.interval = (interval * NSEC_PER_USEC) >> CODEL_SHIFT;
376 }
377
378 if (tb[TCA_FQ_CODEL_LIMIT])
379 sch->limit = nla_get_u32(tb[TCA_FQ_CODEL_LIMIT]);
380
381 if (tb[TCA_FQ_CODEL_ECN])
382 q->cparams.ecn = !!nla_get_u32(tb[TCA_FQ_CODEL_ECN]);
383
384 if (tb[TCA_FQ_CODEL_QUANTUM])
385 q->quantum = max(256U, nla_get_u32(tb[TCA_FQ_CODEL_QUANTUM]));
386
387 while (sch->q.qlen > sch->limit) {
388 struct sk_buff *skb = fq_codel_dequeue(sch);
389
2ccccf5f 390 q->cstats.drop_len += qdisc_pkt_len(skb);
4b549a2e
ED
391 kfree_skb(skb);
392 q->cstats.drop_count++;
393 }
2ccccf5f 394 qdisc_tree_reduce_backlog(sch, q->cstats.drop_count, q->cstats.drop_len);
4b549a2e 395 q->cstats.drop_count = 0;
2ccccf5f 396 q->cstats.drop_len = 0;
4b549a2e
ED
397
398 sch_tree_unlock(sch);
399 return 0;
400}
401
402static void *fq_codel_zalloc(size_t sz)
403{
404 void *ptr = kzalloc(sz, GFP_KERNEL | __GFP_NOWARN);
405
406 if (!ptr)
407 ptr = vzalloc(sz);
408 return ptr;
409}
410
411static void fq_codel_free(void *addr)
412{
4cb28970 413 kvfree(addr);
4b549a2e
ED
414}
415
416static void fq_codel_destroy(struct Qdisc *sch)
417{
418 struct fq_codel_sched_data *q = qdisc_priv(sch);
419
420 tcf_destroy_chain(&q->filter_list);
421 fq_codel_free(q->backlogs);
422 fq_codel_free(q->flows);
423}
424
425static int fq_codel_init(struct Qdisc *sch, struct nlattr *opt)
426{
427 struct fq_codel_sched_data *q = qdisc_priv(sch);
428 int i;
429
430 sch->limit = 10*1024;
431 q->flows_cnt = 1024;
432 q->quantum = psched_mtu(qdisc_dev(sch));
63862b5b 433 q->perturbation = prandom_u32();
4b549a2e
ED
434 INIT_LIST_HEAD(&q->new_flows);
435 INIT_LIST_HEAD(&q->old_flows);
79bdc4c8 436 codel_params_init(&q->cparams);
4b549a2e
ED
437 codel_stats_init(&q->cstats);
438 q->cparams.ecn = true;
79bdc4c8 439 q->cparams.mtu = psched_mtu(qdisc_dev(sch));
4b549a2e
ED
440
441 if (opt) {
442 int err = fq_codel_change(sch, opt);
443 if (err)
444 return err;
445 }
446
447 if (!q->flows) {
448 q->flows = fq_codel_zalloc(q->flows_cnt *
449 sizeof(struct fq_codel_flow));
450 if (!q->flows)
451 return -ENOMEM;
452 q->backlogs = fq_codel_zalloc(q->flows_cnt * sizeof(u32));
453 if (!q->backlogs) {
454 fq_codel_free(q->flows);
455 return -ENOMEM;
456 }
457 for (i = 0; i < q->flows_cnt; i++) {
458 struct fq_codel_flow *flow = q->flows + i;
459
460 INIT_LIST_HEAD(&flow->flowchain);
b379135c 461 codel_vars_init(&flow->cvars);
4b549a2e
ED
462 }
463 }
464 if (sch->limit >= 1)
465 sch->flags |= TCQ_F_CAN_BYPASS;
466 else
467 sch->flags &= ~TCQ_F_CAN_BYPASS;
468 return 0;
469}
470
471static int fq_codel_dump(struct Qdisc *sch, struct sk_buff *skb)
472{
473 struct fq_codel_sched_data *q = qdisc_priv(sch);
474 struct nlattr *opts;
475
476 opts = nla_nest_start(skb, TCA_OPTIONS);
477 if (opts == NULL)
478 goto nla_put_failure;
479
480 if (nla_put_u32(skb, TCA_FQ_CODEL_TARGET,
481 codel_time_to_us(q->cparams.target)) ||
482 nla_put_u32(skb, TCA_FQ_CODEL_LIMIT,
483 sch->limit) ||
484 nla_put_u32(skb, TCA_FQ_CODEL_INTERVAL,
485 codel_time_to_us(q->cparams.interval)) ||
486 nla_put_u32(skb, TCA_FQ_CODEL_ECN,
487 q->cparams.ecn) ||
488 nla_put_u32(skb, TCA_FQ_CODEL_QUANTUM,
489 q->quantum) ||
490 nla_put_u32(skb, TCA_FQ_CODEL_FLOWS,
491 q->flows_cnt))
492 goto nla_put_failure;
493
80ba92fa
ED
494 if (q->cparams.ce_threshold != CODEL_DISABLED_THRESHOLD &&
495 nla_put_u32(skb, TCA_FQ_CODEL_CE_THRESHOLD,
496 codel_time_to_us(q->cparams.ce_threshold)))
497 goto nla_put_failure;
498
d59b7d80 499 return nla_nest_end(skb, opts);
4b549a2e
ED
500
501nla_put_failure:
502 return -1;
503}
504
505static int fq_codel_dump_stats(struct Qdisc *sch, struct gnet_dump *d)
506{
507 struct fq_codel_sched_data *q = qdisc_priv(sch);
508 struct tc_fq_codel_xstats st = {
509 .type = TCA_FQ_CODEL_XSTATS_QDISC,
4b549a2e
ED
510 };
511 struct list_head *pos;
512
669d67bf
SL
513 st.qdisc_stats.maxpacket = q->cstats.maxpacket;
514 st.qdisc_stats.drop_overlimit = q->drop_overlimit;
515 st.qdisc_stats.ecn_mark = q->cstats.ecn_mark;
516 st.qdisc_stats.new_flow_count = q->new_flow_count;
80ba92fa 517 st.qdisc_stats.ce_mark = q->cstats.ce_mark;
669d67bf 518
4b549a2e
ED
519 list_for_each(pos, &q->new_flows)
520 st.qdisc_stats.new_flows_len++;
521
522 list_for_each(pos, &q->old_flows)
523 st.qdisc_stats.old_flows_len++;
524
525 return gnet_stats_copy_app(d, &st, sizeof(st));
526}
527
528static struct Qdisc *fq_codel_leaf(struct Qdisc *sch, unsigned long arg)
529{
530 return NULL;
531}
532
533static unsigned long fq_codel_get(struct Qdisc *sch, u32 classid)
534{
535 return 0;
536}
537
538static unsigned long fq_codel_bind(struct Qdisc *sch, unsigned long parent,
539 u32 classid)
540{
541 /* we cannot bypass queue discipline anymore */
542 sch->flags &= ~TCQ_F_CAN_BYPASS;
543 return 0;
544}
545
546static void fq_codel_put(struct Qdisc *q, unsigned long cl)
547{
548}
549
25d8c0d5
JF
550static struct tcf_proto __rcu **fq_codel_find_tcf(struct Qdisc *sch,
551 unsigned long cl)
4b549a2e
ED
552{
553 struct fq_codel_sched_data *q = qdisc_priv(sch);
554
555 if (cl)
556 return NULL;
557 return &q->filter_list;
558}
559
560static int fq_codel_dump_class(struct Qdisc *sch, unsigned long cl,
561 struct sk_buff *skb, struct tcmsg *tcm)
562{
563 tcm->tcm_handle |= TC_H_MIN(cl);
564 return 0;
565}
566
567static int fq_codel_dump_class_stats(struct Qdisc *sch, unsigned long cl,
568 struct gnet_dump *d)
569{
570 struct fq_codel_sched_data *q = qdisc_priv(sch);
571 u32 idx = cl - 1;
572 struct gnet_stats_queue qs = { 0 };
573 struct tc_fq_codel_xstats xstats;
574
575 if (idx < q->flows_cnt) {
576 const struct fq_codel_flow *flow = &q->flows[idx];
577 const struct sk_buff *skb = flow->head;
578
579 memset(&xstats, 0, sizeof(xstats));
580 xstats.type = TCA_FQ_CODEL_XSTATS_CLASS;
581 xstats.class_stats.deficit = flow->deficit;
582 xstats.class_stats.ldelay =
583 codel_time_to_us(flow->cvars.ldelay);
584 xstats.class_stats.count = flow->cvars.count;
585 xstats.class_stats.lastcount = flow->cvars.lastcount;
586 xstats.class_stats.dropping = flow->cvars.dropping;
587 if (flow->cvars.dropping) {
588 codel_tdiff_t delta = flow->cvars.drop_next -
589 codel_get_time();
590
591 xstats.class_stats.drop_next = (delta >= 0) ?
592 codel_time_to_us(delta) :
593 -codel_time_to_us(-delta);
594 }
595 while (skb) {
596 qs.qlen++;
597 skb = skb->next;
598 }
599 qs.backlog = q->backlogs[idx];
600 qs.drops = flow->dropped;
601 }
b0ab6f92 602 if (gnet_stats_copy_queue(d, NULL, &qs, 0) < 0)
4b549a2e
ED
603 return -1;
604 if (idx < q->flows_cnt)
605 return gnet_stats_copy_app(d, &xstats, sizeof(xstats));
606 return 0;
607}
608
609static void fq_codel_walk(struct Qdisc *sch, struct qdisc_walker *arg)
610{
611 struct fq_codel_sched_data *q = qdisc_priv(sch);
612 unsigned int i;
613
614 if (arg->stop)
615 return;
616
617 for (i = 0; i < q->flows_cnt; i++) {
618 if (list_empty(&q->flows[i].flowchain) ||
619 arg->count < arg->skip) {
620 arg->count++;
621 continue;
622 }
623 if (arg->fn(sch, i + 1, arg) < 0) {
624 arg->stop = 1;
625 break;
626 }
627 arg->count++;
628 }
629}
630
631static const struct Qdisc_class_ops fq_codel_class_ops = {
632 .leaf = fq_codel_leaf,
633 .get = fq_codel_get,
634 .put = fq_codel_put,
635 .tcf_chain = fq_codel_find_tcf,
636 .bind_tcf = fq_codel_bind,
637 .unbind_tcf = fq_codel_put,
638 .dump = fq_codel_dump_class,
639 .dump_stats = fq_codel_dump_class_stats,
640 .walk = fq_codel_walk,
641};
642
643static struct Qdisc_ops fq_codel_qdisc_ops __read_mostly = {
644 .cl_ops = &fq_codel_class_ops,
645 .id = "fq_codel",
646 .priv_size = sizeof(struct fq_codel_sched_data),
647 .enqueue = fq_codel_enqueue,
648 .dequeue = fq_codel_dequeue,
649 .peek = qdisc_peek_dequeued,
c0afd9ce 650 .drop = fq_codel_qdisc_drop,
4b549a2e
ED
651 .init = fq_codel_init,
652 .reset = fq_codel_reset,
653 .destroy = fq_codel_destroy,
654 .change = fq_codel_change,
655 .dump = fq_codel_dump,
656 .dump_stats = fq_codel_dump_stats,
657 .owner = THIS_MODULE,
658};
659
660static int __init fq_codel_module_init(void)
661{
662 return register_qdisc(&fq_codel_qdisc_ops);
663}
664
665static void __exit fq_codel_module_exit(void)
666{
667 unregister_qdisc(&fq_codel_qdisc_ops);
668}
669
670module_init(fq_codel_module_init)
671module_exit(fq_codel_module_exit)
672MODULE_AUTHOR("Eric Dumazet");
673MODULE_LICENSE("GPL");