1 From 4b549a2ef4bef9965d97cbd992ba67930cd3e0fe Mon Sep 17 00:00:00 2001
2 From: Eric Dumazet <edumazet@google.com>
3 Date: Fri, 11 May 2012 09:30:50 +0000
4 Subject: [PATCH 38/41] fq_codel: Fair Queue Codel AQM
6 Fair Queue Codel packet scheduler
10 - Packets are classified (internal classifier or external) on flows.
11 - This is a Stochastic model (as we use a hash, several flows might
12 be hashed on same slot)
13 - Each flow has a CoDel managed queue.
14 - Flows are linked onto two (Round Robin) lists,
15 so that new flows have priority on old ones.
17 - For a given flow, packets are not reordered (CoDel uses a FIFO)
19 - ECN capability is on by default.
20 - Very low memory footprint (64 bytes per flow)
22 tc qdisc ... fq_codel [ limit PACKETS ] [ flows number ]
23 [ target TIME ] [ interval TIME ] [ noecn ]
26 defaults : 1024 flows, 10240 packets limit, quantum : device MTU
27 target : 5ms (CoDel default)
28 interval : 100ms (CoDel default)
30 Impressive results on load :
32 class htb 1:1 root leaf 10: prio 0 quantum 1514 rate 200000Kbit ceil 200000Kbit burst 1475b/8 mpu 0b overhead 0b cburst 1475b/8 mpu 0b overhead 0b level 0
33 Sent 43304920109 bytes 33063109 pkt (dropped 0, overlimits 0 requeues 0)
34 rate 201691Kbit 28595pps backlog 0b 312p requeues 0
35 lended: 33063109 borrowed: 0 giants: 0
36 tokens: -912 ctokens: -912
38 class fq_codel 10:1735 parent 10:
39 (dropped 1292, overlimits 0 requeues 0)
40 backlog 15140b 10p requeues 0
41 deficit 1514 count 1 lastcount 1 ldelay 7.1ms
42 class fq_codel 10:4524 parent 10:
43 (dropped 1291, overlimits 0 requeues 0)
44 backlog 16654b 11p requeues 0
45 deficit 1514 count 1 lastcount 1 ldelay 7.1ms
46 class fq_codel 10:4e74 parent 10:
47 (dropped 1290, overlimits 0 requeues 0)
48 backlog 6056b 4p requeues 0
49 deficit 1514 count 1 lastcount 1 ldelay 6.4ms dropping drop_next 92.0ms
50 class fq_codel 10:628a parent 10:
51 (dropped 1289, overlimits 0 requeues 0)
52 backlog 7570b 5p requeues 0
53 deficit 1514 count 1 lastcount 1 ldelay 5.4ms dropping drop_next 90.9ms
54 class fq_codel 10:a4b3 parent 10:
55 (dropped 302, overlimits 0 requeues 0)
56 backlog 16654b 11p requeues 0
57 deficit 1514 count 1 lastcount 1 ldelay 7.1ms
58 class fq_codel 10:c3c2 parent 10:
59 (dropped 1284, overlimits 0 requeues 0)
60 backlog 13626b 9p requeues 0
61 deficit 1514 count 1 lastcount 1 ldelay 5.9ms
62 class fq_codel 10:d331 parent 10:
63 (dropped 299, overlimits 0 requeues 0)
64 backlog 15140b 10p requeues 0
65 deficit 1514 count 1 lastcount 1 ldelay 7.0ms
66 class fq_codel 10:d526 parent 10:
67 (dropped 12160, overlimits 0 requeues 0)
68 backlog 35870b 211p requeues 0
69 deficit 1508 count 12160 lastcount 1 ldelay 15.3ms dropping drop_next 247us
70 class fq_codel 10:e2c6 parent 10:
71 (dropped 1288, overlimits 0 requeues 0)
72 backlog 15140b 10p requeues 0
73 deficit 1514 count 1 lastcount 1 ldelay 7.1ms
74 class fq_codel 10:eab5 parent 10:
75 (dropped 1285, overlimits 0 requeues 0)
76 backlog 16654b 11p requeues 0
77 deficit 1514 count 1 lastcount 1 ldelay 5.9ms
78 class fq_codel 10:f220 parent 10:
79 (dropped 1289, overlimits 0 requeues 0)
80 backlog 15140b 10p requeues 0
81 deficit 1514 count 1 lastcount 1 ldelay 7.1ms
83 qdisc htb 1: root refcnt 6 r2q 10 default 1 direct_packets_stat 0 ver 3.17
84 Sent 43331086547 bytes 33092812 pkt (dropped 0, overlimits 66063544 requeues 71)
85 rate 201697Kbit 28602pps backlog 0b 260p requeues 71
86 qdisc fq_codel 10: parent 1:1 limit 10240p flows 65536 target 5.0ms interval 100.0ms ecn
87 Sent 43331086547 bytes 33092812 pkt (dropped 949359, overlimits 0 requeues 0)
88 rate 201697Kbit 28602pps backlog 189352b 260p requeues 0
89 maxpacket 1514 drop_overlimit 0 new_flow_count 5582 ecn_mark 125593
90 new_flows_len 0 old_flows_len 11
92 PING 172.30.42.18 (172.30.42.18) 56(84) bytes of data.
93 64 bytes from 172.30.42.18: icmp_req=1 ttl=64 time=0.227 ms
94 64 bytes from 172.30.42.18: icmp_req=2 ttl=64 time=0.165 ms
95 64 bytes from 172.30.42.18: icmp_req=3 ttl=64 time=0.166 ms
96 64 bytes from 172.30.42.18: icmp_req=4 ttl=64 time=0.151 ms
97 64 bytes from 172.30.42.18: icmp_req=5 ttl=64 time=0.164 ms
98 64 bytes from 172.30.42.18: icmp_req=6 ttl=64 time=0.172 ms
99 64 bytes from 172.30.42.18: icmp_req=7 ttl=64 time=0.175 ms
100 64 bytes from 172.30.42.18: icmp_req=8 ttl=64 time=0.183 ms
101 64 bytes from 172.30.42.18: icmp_req=9 ttl=64 time=0.158 ms
102 64 bytes from 172.30.42.18: icmp_req=10 ttl=64 time=0.200 ms
104 10 packets transmitted, 10 received, 0% packet loss, time 8999ms
105 rtt min/avg/max/mdev = 0.151/0.176/0.227/0.022 ms
107 Much better than SFQ because of priority given to new flows, and fast
108 path dirtying less cache lines.
110 Signed-off-by: Eric Dumazet <edumazet@google.com>
111 Signed-off-by: David S. Miller <davem@davemloft.net>
113 include/linux/pkt_sched.h | 54 ++++
114 net/sched/Kconfig | 11 +
115 net/sched/Makefile | 1 +
116 net/sched/sch_fq_codel.c | 624 +++++++++++++++++++++++++++++++++++++++++++++
117 4 files changed, 690 insertions(+)
118 create mode 100644 net/sched/sch_fq_codel.c
120 --- a/include/linux/pkt_sched.h
121 +++ b/include/linux/pkt_sched.h
122 @@ -659,4 +659,58 @@ struct tc_codel_xstats {
123 __u32 dropping; /* are we in dropping state ? */
129 + TCA_FQ_CODEL_UNSPEC,
130 + TCA_FQ_CODEL_TARGET,
131 + TCA_FQ_CODEL_LIMIT,
132 + TCA_FQ_CODEL_INTERVAL,
134 + TCA_FQ_CODEL_FLOWS,
135 + TCA_FQ_CODEL_QUANTUM,
139 +#define TCA_FQ_CODEL_MAX (__TCA_FQ_CODEL_MAX - 1)
142 + TCA_FQ_CODEL_XSTATS_QDISC,
143 + TCA_FQ_CODEL_XSTATS_CLASS,
146 +struct tc_fq_codel_qd_stats {
147 + __u32 maxpacket; /* largest packet we've seen so far */
148 + __u32 drop_overlimit; /* number of time max qdisc
149 + * packet limit was hit
151 + __u32 ecn_mark; /* number of packets we ECN marked
152 + * instead of being dropped
154 + __u32 new_flow_count; /* number of time packets
155 + * created a 'new flow'
157 + __u32 new_flows_len; /* count of flows in new list */
158 + __u32 old_flows_len; /* count of flows in old list */
161 +struct tc_fq_codel_cl_stats {
163 + __u32 ldelay; /* in-queue delay seen by most recently
172 +struct tc_fq_codel_xstats {
175 + struct tc_fq_codel_qd_stats qdisc_stats;
176 + struct tc_fq_codel_cl_stats class_stats;
181 --- a/net/sched/Kconfig
182 +++ b/net/sched/Kconfig
183 @@ -261,6 +261,17 @@ config NET_SCH_CODEL
187 +config NET_SCH_FQ_CODEL
188 + tristate "Fair Queue Controlled Delay AQM (FQ_CODEL)"
190 + Say Y here if you want to use the FQ Controlled Delay (FQ_CODEL)
191 + packet scheduling algorithm.
193 + To compile this driver as a module, choose M here: the module
194 + will be called sch_fq_codel.
198 config NET_SCH_INGRESS
199 tristate "Ingress Qdisc"
200 depends on NET_CLS_ACT
201 --- a/net/sched/Makefile
202 +++ b/net/sched/Makefile
203 @@ -37,6 +37,7 @@ obj-$(CONFIG_NET_SCH_MQPRIO) += sch_mqpr
204 obj-$(CONFIG_NET_SCH_CHOKE) += sch_choke.o
205 obj-$(CONFIG_NET_SCH_QFQ) += sch_qfq.o
206 obj-$(CONFIG_NET_SCH_CODEL) += sch_codel.o
207 +obj-$(CONFIG_NET_SCH_FQ_CODEL) += sch_fq_codel.o
209 obj-$(CONFIG_NET_CLS_U32) += cls_u32.o
210 obj-$(CONFIG_NET_CLS_ROUTE4) += cls_route.o
212 +++ b/net/sched/sch_fq_codel.c
215 + * Fair Queue CoDel discipline
217 + * This program is free software; you can redistribute it and/or
218 + * modify it under the terms of the GNU General Public License
219 + * as published by the Free Software Foundation; either version
220 + * 2 of the License, or (at your option) any later version.
222 + * Copyright (C) 2012 Eric Dumazet <edumazet@google.com>
225 +#include <linux/module.h>
226 +#include <linux/types.h>
227 +#include <linux/kernel.h>
228 +#include <linux/jiffies.h>
229 +#include <linux/string.h>
230 +#include <linux/in.h>
231 +#include <linux/errno.h>
232 +#include <linux/init.h>
233 +#include <linux/skbuff.h>
234 +#include <linux/jhash.h>
235 +#include <linux/slab.h>
236 +#include <linux/vmalloc.h>
237 +#include <net/netlink.h>
238 +#include <net/pkt_sched.h>
239 +#include <net/flow_keys.h>
240 +#include <net/codel.h>
242 +/* Fair Queue CoDel.
245 + * Packets are classified (internal classifier or external) on flows.
246 + * This is a Stochastic model (as we use a hash, several flows
247 + * might be hashed on same slot)
248 + * Each flow has a CoDel managed queue.
249 + * Flows are linked onto two (Round Robin) lists,
250 + * so that new flows have priority on old ones.
252 + * For a given flow, packets are not reordered (CoDel uses a FIFO)
254 + * ECN capability is on by default.
255 + * Low memory footprint (64 bytes per flow)
258 +struct fq_codel_flow {
259 + struct sk_buff *head;
260 + struct sk_buff *tail;
261 + struct list_head flowchain;
263 + u32 dropped; /* number of drops (or ECN marks) on this flow */
264 + struct codel_vars cvars;
265 +}; /* please try to keep this structure <= 64 bytes */
267 +struct fq_codel_sched_data {
268 + struct tcf_proto *filter_list; /* optional external classifier */
269 + struct fq_codel_flow *flows; /* Flows table [flows_cnt] */
270 + u32 *backlogs; /* backlog table [flows_cnt] */
271 + u32 flows_cnt; /* number of flows */
272 + u32 perturbation; /* hash perturbation */
273 + u32 quantum; /* psched_mtu(qdisc_dev(sch)); */
274 + struct codel_params cparams;
275 + struct codel_stats cstats;
276 + u32 drop_overlimit;
277 + u32 new_flow_count;
279 + struct list_head new_flows; /* list of new flows */
280 + struct list_head old_flows; /* list of old flows */
283 +static unsigned int fq_codel_hash(const struct fq_codel_sched_data *q,
284 + const struct sk_buff *skb)
286 + struct flow_keys keys;
289 + skb_flow_dissect(skb, &keys);
290 + hash = jhash_3words((__force u32)keys.dst,
291 + (__force u32)keys.src ^ keys.ip_proto,
292 + (__force u32)keys.ports, q->perturbation);
293 + return ((u64)hash * q->flows_cnt) >> 32;
296 +static unsigned int fq_codel_classify(struct sk_buff *skb, struct Qdisc *sch,
299 + struct fq_codel_sched_data *q = qdisc_priv(sch);
300 + struct tcf_result res;
303 + if (TC_H_MAJ(skb->priority) == sch->handle &&
304 + TC_H_MIN(skb->priority) > 0 &&
305 + TC_H_MIN(skb->priority) <= q->flows_cnt)
306 + return TC_H_MIN(skb->priority);
308 + if (!q->filter_list)
309 + return fq_codel_hash(q, skb) + 1;
311 + *qerr = NET_XMIT_SUCCESS | __NET_XMIT_BYPASS;
312 + result = tc_classify(skb, q->filter_list, &res);
314 +#ifdef CONFIG_NET_CLS_ACT
316 + case TC_ACT_STOLEN:
317 + case TC_ACT_QUEUED:
318 + *qerr = NET_XMIT_SUCCESS | __NET_XMIT_STOLEN;
323 + if (TC_H_MIN(res.classid) <= q->flows_cnt)
324 + return TC_H_MIN(res.classid);
329 +/* helper functions : might be changed when/if skb use a standard list_head */
331 +/* remove one skb from head of slot queue */
332 +static inline struct sk_buff *dequeue_head(struct fq_codel_flow *flow)
334 + struct sk_buff *skb = flow->head;
336 + flow->head = skb->next;
341 +/* add skb to flow queue (tail add) */
342 +static inline void flow_queue_add(struct fq_codel_flow *flow,
343 + struct sk_buff *skb)
345 + if (flow->head == NULL)
348 + flow->tail->next = skb;
353 +static unsigned int fq_codel_drop(struct Qdisc *sch)
355 + struct fq_codel_sched_data *q = qdisc_priv(sch);
356 + struct sk_buff *skb;
357 + unsigned int maxbacklog = 0, idx = 0, i, len;
358 + struct fq_codel_flow *flow;
360 + /* Queue is full! Find the fat flow and drop packet from it.
361 + * This might sound expensive, but with 1024 flows, we scan
362 + * 4KB of memory, and we dont need to handle a complex tree
363 + * in fast path (packet queue/enqueue) with many cache misses.
365 + for (i = 0; i < q->flows_cnt; i++) {
366 + if (q->backlogs[i] > maxbacklog) {
367 + maxbacklog = q->backlogs[i];
371 + flow = &q->flows[idx];
372 + skb = dequeue_head(flow);
373 + len = qdisc_pkt_len(skb);
374 + q->backlogs[idx] -= len;
377 + sch->qstats.drops++;
378 + sch->qstats.backlog -= len;
383 +static int fq_codel_enqueue(struct sk_buff *skb, struct Qdisc *sch)
385 + struct fq_codel_sched_data *q = qdisc_priv(sch);
387 + struct fq_codel_flow *flow;
388 + int uninitialized_var(ret);
390 + idx = fq_codel_classify(skb, sch, &ret);
392 + if (ret & __NET_XMIT_BYPASS)
393 + sch->qstats.drops++;
399 + codel_set_enqueue_time(skb);
400 + flow = &q->flows[idx];
401 + flow_queue_add(flow, skb);
402 + q->backlogs[idx] += qdisc_pkt_len(skb);
403 + sch->qstats.backlog += qdisc_pkt_len(skb);
405 + if (list_empty(&flow->flowchain)) {
406 + list_add_tail(&flow->flowchain, &q->new_flows);
407 + codel_vars_init(&flow->cvars);
408 + q->new_flow_count++;
409 + flow->deficit = q->quantum;
412 + if (++sch->q.qlen < sch->limit)
413 + return NET_XMIT_SUCCESS;
415 + q->drop_overlimit++;
416 + /* Return Congestion Notification only if we dropped a packet
419 + if (fq_codel_drop(sch) == idx)
420 + return NET_XMIT_CN;
422 + /* As we dropped a packet, better let upper stack know this */
423 + qdisc_tree_decrease_qlen(sch, 1);
424 + return NET_XMIT_SUCCESS;
427 +/* This is the specific function called from codel_dequeue()
428 + * to dequeue a packet from queue. Note: backlog is handled in
429 + * codel, we dont need to reduce it here.
431 +static struct sk_buff *dequeue(struct codel_vars *vars, struct Qdisc *sch)
433 + struct fq_codel_flow *flow;
434 + struct sk_buff *skb = NULL;
436 + flow = container_of(vars, struct fq_codel_flow, cvars);
438 + skb = dequeue_head(flow);
439 + sch->qstats.backlog -= qdisc_pkt_len(skb);
445 +static struct sk_buff *fq_codel_dequeue(struct Qdisc *sch)
447 + struct fq_codel_sched_data *q = qdisc_priv(sch);
448 + struct sk_buff *skb;
449 + struct fq_codel_flow *flow;
450 + struct list_head *head;
451 + u32 prev_drop_count, prev_ecn_mark;
454 + head = &q->new_flows;
455 + if (list_empty(head)) {
456 + head = &q->old_flows;
457 + if (list_empty(head))
460 + flow = list_first_entry(head, struct fq_codel_flow, flowchain);
462 + if (flow->deficit <= 0) {
463 + flow->deficit += q->quantum;
464 + list_move_tail(&flow->flowchain, &q->old_flows);
468 + prev_drop_count = q->cstats.drop_count;
469 + prev_ecn_mark = q->cstats.ecn_mark;
471 + skb = codel_dequeue(sch, &q->cparams, &flow->cvars, &q->cstats,
472 + dequeue, &q->backlogs[flow - q->flows]);
474 + flow->dropped += q->cstats.drop_count - prev_drop_count;
475 + flow->dropped += q->cstats.ecn_mark - prev_ecn_mark;
478 + /* force a pass through old_flows to prevent starvation */
479 + if ((head == &q->new_flows) && !list_empty(&q->old_flows))
480 + list_move_tail(&flow->flowchain, &q->old_flows);
482 + list_del_init(&flow->flowchain);
485 + qdisc_bstats_update(sch, skb);
486 + flow->deficit -= qdisc_pkt_len(skb);
487 + /* We cant call qdisc_tree_decrease_qlen() if our qlen is 0,
488 + * or HTB crashes. Defer it for next round.
490 + if (q->cstats.drop_count && sch->q.qlen) {
491 + qdisc_tree_decrease_qlen(sch, q->cstats.drop_count);
492 + q->cstats.drop_count = 0;
497 +static void fq_codel_reset(struct Qdisc *sch)
499 + struct sk_buff *skb;
501 + while ((skb = fq_codel_dequeue(sch)) != NULL)
505 +static const struct nla_policy fq_codel_policy[TCA_FQ_CODEL_MAX + 1] = {
506 + [TCA_FQ_CODEL_TARGET] = { .type = NLA_U32 },
507 + [TCA_FQ_CODEL_LIMIT] = { .type = NLA_U32 },
508 + [TCA_FQ_CODEL_INTERVAL] = { .type = NLA_U32 },
509 + [TCA_FQ_CODEL_ECN] = { .type = NLA_U32 },
510 + [TCA_FQ_CODEL_FLOWS] = { .type = NLA_U32 },
511 + [TCA_FQ_CODEL_QUANTUM] = { .type = NLA_U32 },
514 +static int fq_codel_change(struct Qdisc *sch, struct nlattr *opt)
516 + struct fq_codel_sched_data *q = qdisc_priv(sch);
517 + struct nlattr *tb[TCA_FQ_CODEL_MAX + 1];
523 + err = nla_parse_nested(tb, TCA_FQ_CODEL_MAX, opt, fq_codel_policy);
526 + if (tb[TCA_FQ_CODEL_FLOWS]) {
529 + q->flows_cnt = nla_get_u32(tb[TCA_FQ_CODEL_FLOWS]);
530 + if (!q->flows_cnt ||
531 + q->flows_cnt > 65536)
534 + sch_tree_lock(sch);
536 + if (tb[TCA_FQ_CODEL_TARGET]) {
537 + u64 target = nla_get_u32(tb[TCA_FQ_CODEL_TARGET]);
539 + q->cparams.target = (target * NSEC_PER_USEC) >> CODEL_SHIFT;
542 + if (tb[TCA_FQ_CODEL_INTERVAL]) {
543 + u64 interval = nla_get_u32(tb[TCA_FQ_CODEL_INTERVAL]);
545 + q->cparams.interval = (interval * NSEC_PER_USEC) >> CODEL_SHIFT;
548 + if (tb[TCA_FQ_CODEL_LIMIT])
549 + sch->limit = nla_get_u32(tb[TCA_FQ_CODEL_LIMIT]);
551 + if (tb[TCA_FQ_CODEL_ECN])
552 + q->cparams.ecn = !!nla_get_u32(tb[TCA_FQ_CODEL_ECN]);
554 + if (tb[TCA_FQ_CODEL_QUANTUM])
555 + q->quantum = max(256U, nla_get_u32(tb[TCA_FQ_CODEL_QUANTUM]));
557 + while (sch->q.qlen > sch->limit) {
558 + struct sk_buff *skb = fq_codel_dequeue(sch);
561 + q->cstats.drop_count++;
563 + qdisc_tree_decrease_qlen(sch, q->cstats.drop_count);
564 + q->cstats.drop_count = 0;
566 + sch_tree_unlock(sch);
570 +static void *fq_codel_zalloc(size_t sz)
572 + void *ptr = kzalloc(sz, GFP_KERNEL | __GFP_NOWARN);
579 +static void fq_codel_free(void *addr)
582 + if (is_vmalloc_addr(addr))
589 +static void fq_codel_destroy(struct Qdisc *sch)
591 + struct fq_codel_sched_data *q = qdisc_priv(sch);
593 + tcf_destroy_chain(&q->filter_list);
594 + fq_codel_free(q->backlogs);
595 + fq_codel_free(q->flows);
598 +static int fq_codel_init(struct Qdisc *sch, struct nlattr *opt)
600 + struct fq_codel_sched_data *q = qdisc_priv(sch);
603 + sch->limit = 10*1024;
604 + q->flows_cnt = 1024;
605 + q->quantum = psched_mtu(qdisc_dev(sch));
606 + q->perturbation = net_random();
607 + INIT_LIST_HEAD(&q->new_flows);
608 + INIT_LIST_HEAD(&q->old_flows);
609 + codel_params_init(&q->cparams);
610 + codel_stats_init(&q->cstats);
611 + q->cparams.ecn = true;
614 + int err = fq_codel_change(sch, opt);
620 + q->flows = fq_codel_zalloc(q->flows_cnt *
621 + sizeof(struct fq_codel_flow));
624 + q->backlogs = fq_codel_zalloc(q->flows_cnt * sizeof(u32));
625 + if (!q->backlogs) {
626 + fq_codel_free(q->flows);
629 + for (i = 0; i < q->flows_cnt; i++) {
630 + struct fq_codel_flow *flow = q->flows + i;
632 + INIT_LIST_HEAD(&flow->flowchain);
635 + if (sch->limit >= 1)
636 + sch->flags |= TCQ_F_CAN_BYPASS;
638 + sch->flags &= ~TCQ_F_CAN_BYPASS;
642 +static int fq_codel_dump(struct Qdisc *sch, struct sk_buff *skb)
644 + struct fq_codel_sched_data *q = qdisc_priv(sch);
645 + struct nlattr *opts;
647 + opts = nla_nest_start(skb, TCA_OPTIONS);
649 + goto nla_put_failure;
651 + if (nla_put_u32(skb, TCA_FQ_CODEL_TARGET,
652 + codel_time_to_us(q->cparams.target)) ||
653 + nla_put_u32(skb, TCA_FQ_CODEL_LIMIT,
655 + nla_put_u32(skb, TCA_FQ_CODEL_INTERVAL,
656 + codel_time_to_us(q->cparams.interval)) ||
657 + nla_put_u32(skb, TCA_FQ_CODEL_ECN,
659 + nla_put_u32(skb, TCA_FQ_CODEL_QUANTUM,
661 + nla_put_u32(skb, TCA_FQ_CODEL_FLOWS,
663 + goto nla_put_failure;
665 + nla_nest_end(skb, opts);
672 +static int fq_codel_dump_stats(struct Qdisc *sch, struct gnet_dump *d)
674 + struct fq_codel_sched_data *q = qdisc_priv(sch);
675 + struct tc_fq_codel_xstats st = {
676 + .type = TCA_FQ_CODEL_XSTATS_QDISC,
677 + .qdisc_stats.maxpacket = q->cstats.maxpacket,
678 + .qdisc_stats.drop_overlimit = q->drop_overlimit,
679 + .qdisc_stats.ecn_mark = q->cstats.ecn_mark,
680 + .qdisc_stats.new_flow_count = q->new_flow_count,
682 + struct list_head *pos;
684 + list_for_each(pos, &q->new_flows)
685 + st.qdisc_stats.new_flows_len++;
687 + list_for_each(pos, &q->old_flows)
688 + st.qdisc_stats.old_flows_len++;
690 + return gnet_stats_copy_app(d, &st, sizeof(st));
693 +static struct Qdisc *fq_codel_leaf(struct Qdisc *sch, unsigned long arg)
698 +static unsigned long fq_codel_get(struct Qdisc *sch, u32 classid)
703 +static unsigned long fq_codel_bind(struct Qdisc *sch, unsigned long parent,
706 + /* we cannot bypass queue discipline anymore */
707 + sch->flags &= ~TCQ_F_CAN_BYPASS;
711 +static void fq_codel_put(struct Qdisc *q, unsigned long cl)
715 +static struct tcf_proto **fq_codel_find_tcf(struct Qdisc *sch, unsigned long cl)
717 + struct fq_codel_sched_data *q = qdisc_priv(sch);
721 + return &q->filter_list;
724 +static int fq_codel_dump_class(struct Qdisc *sch, unsigned long cl,
725 + struct sk_buff *skb, struct tcmsg *tcm)
727 + tcm->tcm_handle |= TC_H_MIN(cl);
731 +static int fq_codel_dump_class_stats(struct Qdisc *sch, unsigned long cl,
732 + struct gnet_dump *d)
734 + struct fq_codel_sched_data *q = qdisc_priv(sch);
736 + struct gnet_stats_queue qs = { 0 };
737 + struct tc_fq_codel_xstats xstats;
739 + if (idx < q->flows_cnt) {
740 + const struct fq_codel_flow *flow = &q->flows[idx];
741 + const struct sk_buff *skb = flow->head;
743 + memset(&xstats, 0, sizeof(xstats));
744 + xstats.type = TCA_FQ_CODEL_XSTATS_CLASS;
745 + xstats.class_stats.deficit = flow->deficit;
746 + xstats.class_stats.ldelay =
747 + codel_time_to_us(flow->cvars.ldelay);
748 + xstats.class_stats.count = flow->cvars.count;
749 + xstats.class_stats.lastcount = flow->cvars.lastcount;
750 + xstats.class_stats.dropping = flow->cvars.dropping;
751 + if (flow->cvars.dropping) {
752 + codel_tdiff_t delta = flow->cvars.drop_next -
755 + xstats.class_stats.drop_next = (delta >= 0) ?
756 + codel_time_to_us(delta) :
757 + -codel_time_to_us(-delta);
763 + qs.backlog = q->backlogs[idx];
764 + qs.drops = flow->dropped;
766 + if (gnet_stats_copy_queue(d, &qs) < 0)
768 + if (idx < q->flows_cnt)
769 + return gnet_stats_copy_app(d, &xstats, sizeof(xstats));
773 +static void fq_codel_walk(struct Qdisc *sch, struct qdisc_walker *arg)
775 + struct fq_codel_sched_data *q = qdisc_priv(sch);
781 + for (i = 0; i < q->flows_cnt; i++) {
782 + if (list_empty(&q->flows[i].flowchain) ||
783 + arg->count < arg->skip) {
787 + if (arg->fn(sch, i + 1, arg) < 0) {
795 +static const struct Qdisc_class_ops fq_codel_class_ops = {
796 + .leaf = fq_codel_leaf,
797 + .get = fq_codel_get,
798 + .put = fq_codel_put,
799 + .tcf_chain = fq_codel_find_tcf,
800 + .bind_tcf = fq_codel_bind,
801 + .unbind_tcf = fq_codel_put,
802 + .dump = fq_codel_dump_class,
803 + .dump_stats = fq_codel_dump_class_stats,
804 + .walk = fq_codel_walk,
807 +static struct Qdisc_ops fq_codel_qdisc_ops __read_mostly = {
808 + .cl_ops = &fq_codel_class_ops,
810 + .priv_size = sizeof(struct fq_codel_sched_data),
811 + .enqueue = fq_codel_enqueue,
812 + .dequeue = fq_codel_dequeue,
813 + .peek = qdisc_peek_dequeued,
814 + .drop = fq_codel_drop,
815 + .init = fq_codel_init,
816 + .reset = fq_codel_reset,
817 + .destroy = fq_codel_destroy,
818 + .change = fq_codel_change,
819 + .dump = fq_codel_dump,
820 + .dump_stats = fq_codel_dump_stats,
821 + .owner = THIS_MODULE,
824 +static int __init fq_codel_module_init(void)
826 + return register_qdisc(&fq_codel_qdisc_ops);
829 +static void __exit fq_codel_module_exit(void)
831 + unregister_qdisc(&fq_codel_qdisc_ops);
834 +module_init(fq_codel_module_init)
835 +module_exit(fq_codel_module_exit)
836 +MODULE_AUTHOR("Eric Dumazet");
837 +MODULE_LICENSE("GPL");