sch_fq_codel.c 16 KB

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