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