sch_fq_codel.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  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, prev_backlog;
  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. prev_backlog = sch->qstats.backlog;
  183. q->drop_overlimit++;
  184. /* Return Congestion Notification only if we dropped a packet
  185. * from this flow.
  186. */
  187. if (fq_codel_drop(sch) == idx)
  188. return NET_XMIT_CN;
  189. /* As we dropped a packet, better let upper stack know this */
  190. qdisc_tree_reduce_backlog(sch, 1, prev_backlog - sch->qstats.backlog);
  191. return NET_XMIT_SUCCESS;
  192. }
  193. /* This is the specific function called from codel_dequeue()
  194. * to dequeue a packet from queue. Note: backlog is handled in
  195. * codel, we dont need to reduce it here.
  196. */
  197. static struct sk_buff *dequeue(struct codel_vars *vars, struct Qdisc *sch)
  198. {
  199. struct fq_codel_sched_data *q = qdisc_priv(sch);
  200. struct fq_codel_flow *flow;
  201. struct sk_buff *skb = NULL;
  202. flow = container_of(vars, struct fq_codel_flow, cvars);
  203. if (flow->head) {
  204. skb = dequeue_head(flow);
  205. q->backlogs[flow - q->flows] -= qdisc_pkt_len(skb);
  206. sch->q.qlen--;
  207. }
  208. return skb;
  209. }
  210. static struct sk_buff *fq_codel_dequeue(struct Qdisc *sch)
  211. {
  212. struct fq_codel_sched_data *q = qdisc_priv(sch);
  213. struct sk_buff *skb;
  214. struct fq_codel_flow *flow;
  215. struct list_head *head;
  216. u32 prev_drop_count, prev_ecn_mark;
  217. unsigned int prev_backlog;
  218. begin:
  219. head = &q->new_flows;
  220. if (list_empty(head)) {
  221. head = &q->old_flows;
  222. if (list_empty(head))
  223. return NULL;
  224. }
  225. flow = list_first_entry(head, struct fq_codel_flow, flowchain);
  226. if (flow->deficit <= 0) {
  227. flow->deficit += q->quantum;
  228. list_move_tail(&flow->flowchain, &q->old_flows);
  229. goto begin;
  230. }
  231. prev_drop_count = q->cstats.drop_count;
  232. prev_ecn_mark = q->cstats.ecn_mark;
  233. prev_backlog = sch->qstats.backlog;
  234. skb = codel_dequeue(sch, &q->cparams, &flow->cvars, &q->cstats,
  235. dequeue);
  236. flow->dropped += q->cstats.drop_count - prev_drop_count;
  237. flow->dropped += q->cstats.ecn_mark - prev_ecn_mark;
  238. if (!skb) {
  239. /* force a pass through old_flows to prevent starvation */
  240. if ((head == &q->new_flows) && !list_empty(&q->old_flows))
  241. list_move_tail(&flow->flowchain, &q->old_flows);
  242. else
  243. list_del_init(&flow->flowchain);
  244. goto begin;
  245. }
  246. qdisc_bstats_update(sch, skb);
  247. flow->deficit -= qdisc_pkt_len(skb);
  248. /* We cant call qdisc_tree_reduce_backlog() if our qlen is 0,
  249. * or HTB crashes. Defer it for next round.
  250. */
  251. if (q->cstats.drop_count && sch->q.qlen) {
  252. qdisc_tree_reduce_backlog(sch, q->cstats.drop_count,
  253. q->cstats.drop_len);
  254. q->cstats.drop_count = 0;
  255. q->cstats.drop_len = 0;
  256. }
  257. return skb;
  258. }
  259. static void fq_codel_reset(struct Qdisc *sch)
  260. {
  261. struct fq_codel_sched_data *q = qdisc_priv(sch);
  262. int i;
  263. INIT_LIST_HEAD(&q->new_flows);
  264. INIT_LIST_HEAD(&q->old_flows);
  265. for (i = 0; i < q->flows_cnt; i++) {
  266. struct fq_codel_flow *flow = q->flows + i;
  267. while (flow->head) {
  268. struct sk_buff *skb = dequeue_head(flow);
  269. qdisc_qstats_backlog_dec(sch, skb);
  270. kfree_skb(skb);
  271. }
  272. INIT_LIST_HEAD(&flow->flowchain);
  273. codel_vars_init(&flow->cvars);
  274. }
  275. memset(q->backlogs, 0, q->flows_cnt * sizeof(u32));
  276. sch->q.qlen = 0;
  277. }
  278. static const struct nla_policy fq_codel_policy[TCA_FQ_CODEL_MAX + 1] = {
  279. [TCA_FQ_CODEL_TARGET] = { .type = NLA_U32 },
  280. [TCA_FQ_CODEL_LIMIT] = { .type = NLA_U32 },
  281. [TCA_FQ_CODEL_INTERVAL] = { .type = NLA_U32 },
  282. [TCA_FQ_CODEL_ECN] = { .type = NLA_U32 },
  283. [TCA_FQ_CODEL_FLOWS] = { .type = NLA_U32 },
  284. [TCA_FQ_CODEL_QUANTUM] = { .type = NLA_U32 },
  285. [TCA_FQ_CODEL_CE_THRESHOLD] = { .type = NLA_U32 },
  286. };
  287. static int fq_codel_change(struct Qdisc *sch, struct nlattr *opt)
  288. {
  289. struct fq_codel_sched_data *q = qdisc_priv(sch);
  290. struct nlattr *tb[TCA_FQ_CODEL_MAX + 1];
  291. int err;
  292. if (!opt)
  293. return -EINVAL;
  294. err = nla_parse_nested(tb, TCA_FQ_CODEL_MAX, opt, fq_codel_policy);
  295. if (err < 0)
  296. return err;
  297. if (tb[TCA_FQ_CODEL_FLOWS]) {
  298. if (q->flows)
  299. return -EINVAL;
  300. q->flows_cnt = nla_get_u32(tb[TCA_FQ_CODEL_FLOWS]);
  301. if (!q->flows_cnt ||
  302. q->flows_cnt > 65536)
  303. return -EINVAL;
  304. }
  305. sch_tree_lock(sch);
  306. if (tb[TCA_FQ_CODEL_TARGET]) {
  307. u64 target = nla_get_u32(tb[TCA_FQ_CODEL_TARGET]);
  308. q->cparams.target = (target * NSEC_PER_USEC) >> CODEL_SHIFT;
  309. }
  310. if (tb[TCA_FQ_CODEL_CE_THRESHOLD]) {
  311. u64 val = nla_get_u32(tb[TCA_FQ_CODEL_CE_THRESHOLD]);
  312. q->cparams.ce_threshold = (val * NSEC_PER_USEC) >> CODEL_SHIFT;
  313. }
  314. if (tb[TCA_FQ_CODEL_INTERVAL]) {
  315. u64 interval = nla_get_u32(tb[TCA_FQ_CODEL_INTERVAL]);
  316. q->cparams.interval = (interval * NSEC_PER_USEC) >> CODEL_SHIFT;
  317. }
  318. if (tb[TCA_FQ_CODEL_LIMIT])
  319. sch->limit = nla_get_u32(tb[TCA_FQ_CODEL_LIMIT]);
  320. if (tb[TCA_FQ_CODEL_ECN])
  321. q->cparams.ecn = !!nla_get_u32(tb[TCA_FQ_CODEL_ECN]);
  322. if (tb[TCA_FQ_CODEL_QUANTUM])
  323. q->quantum = max(256U, nla_get_u32(tb[TCA_FQ_CODEL_QUANTUM]));
  324. while (sch->q.qlen > sch->limit) {
  325. struct sk_buff *skb = fq_codel_dequeue(sch);
  326. q->cstats.drop_len += qdisc_pkt_len(skb);
  327. kfree_skb(skb);
  328. q->cstats.drop_count++;
  329. }
  330. qdisc_tree_reduce_backlog(sch, q->cstats.drop_count, q->cstats.drop_len);
  331. q->cstats.drop_count = 0;
  332. q->cstats.drop_len = 0;
  333. sch_tree_unlock(sch);
  334. return 0;
  335. }
  336. static void *fq_codel_zalloc(size_t sz)
  337. {
  338. void *ptr = kzalloc(sz, GFP_KERNEL | __GFP_NOWARN);
  339. if (!ptr)
  340. ptr = vzalloc(sz);
  341. return ptr;
  342. }
  343. static void fq_codel_free(void *addr)
  344. {
  345. kvfree(addr);
  346. }
  347. static void fq_codel_destroy(struct Qdisc *sch)
  348. {
  349. struct fq_codel_sched_data *q = qdisc_priv(sch);
  350. tcf_destroy_chain(&q->filter_list);
  351. fq_codel_free(q->backlogs);
  352. fq_codel_free(q->flows);
  353. }
  354. static int fq_codel_init(struct Qdisc *sch, struct nlattr *opt)
  355. {
  356. struct fq_codel_sched_data *q = qdisc_priv(sch);
  357. int i;
  358. sch->limit = 10*1024;
  359. q->flows_cnt = 1024;
  360. q->quantum = psched_mtu(qdisc_dev(sch));
  361. q->perturbation = prandom_u32();
  362. INIT_LIST_HEAD(&q->new_flows);
  363. INIT_LIST_HEAD(&q->old_flows);
  364. codel_params_init(&q->cparams, sch);
  365. codel_stats_init(&q->cstats);
  366. q->cparams.ecn = true;
  367. if (opt) {
  368. int err = fq_codel_change(sch, opt);
  369. if (err)
  370. return err;
  371. }
  372. if (!q->flows) {
  373. q->flows = fq_codel_zalloc(q->flows_cnt *
  374. sizeof(struct fq_codel_flow));
  375. if (!q->flows)
  376. return -ENOMEM;
  377. q->backlogs = fq_codel_zalloc(q->flows_cnt * sizeof(u32));
  378. if (!q->backlogs) {
  379. fq_codel_free(q->flows);
  380. return -ENOMEM;
  381. }
  382. for (i = 0; i < q->flows_cnt; i++) {
  383. struct fq_codel_flow *flow = q->flows + i;
  384. INIT_LIST_HEAD(&flow->flowchain);
  385. codel_vars_init(&flow->cvars);
  386. }
  387. }
  388. if (sch->limit >= 1)
  389. sch->flags |= TCQ_F_CAN_BYPASS;
  390. else
  391. sch->flags &= ~TCQ_F_CAN_BYPASS;
  392. return 0;
  393. }
  394. static int fq_codel_dump(struct Qdisc *sch, struct sk_buff *skb)
  395. {
  396. struct fq_codel_sched_data *q = qdisc_priv(sch);
  397. struct nlattr *opts;
  398. opts = nla_nest_start(skb, TCA_OPTIONS);
  399. if (opts == NULL)
  400. goto nla_put_failure;
  401. if (nla_put_u32(skb, TCA_FQ_CODEL_TARGET,
  402. codel_time_to_us(q->cparams.target)) ||
  403. nla_put_u32(skb, TCA_FQ_CODEL_LIMIT,
  404. sch->limit) ||
  405. nla_put_u32(skb, TCA_FQ_CODEL_INTERVAL,
  406. codel_time_to_us(q->cparams.interval)) ||
  407. nla_put_u32(skb, TCA_FQ_CODEL_ECN,
  408. q->cparams.ecn) ||
  409. nla_put_u32(skb, TCA_FQ_CODEL_QUANTUM,
  410. q->quantum) ||
  411. nla_put_u32(skb, TCA_FQ_CODEL_FLOWS,
  412. q->flows_cnt))
  413. goto nla_put_failure;
  414. if (q->cparams.ce_threshold != CODEL_DISABLED_THRESHOLD &&
  415. nla_put_u32(skb, TCA_FQ_CODEL_CE_THRESHOLD,
  416. codel_time_to_us(q->cparams.ce_threshold)))
  417. goto nla_put_failure;
  418. return nla_nest_end(skb, opts);
  419. nla_put_failure:
  420. return -1;
  421. }
  422. static int fq_codel_dump_stats(struct Qdisc *sch, struct gnet_dump *d)
  423. {
  424. struct fq_codel_sched_data *q = qdisc_priv(sch);
  425. struct tc_fq_codel_xstats st = {
  426. .type = TCA_FQ_CODEL_XSTATS_QDISC,
  427. };
  428. struct list_head *pos;
  429. st.qdisc_stats.maxpacket = q->cstats.maxpacket;
  430. st.qdisc_stats.drop_overlimit = q->drop_overlimit;
  431. st.qdisc_stats.ecn_mark = q->cstats.ecn_mark;
  432. st.qdisc_stats.new_flow_count = q->new_flow_count;
  433. st.qdisc_stats.ce_mark = q->cstats.ce_mark;
  434. list_for_each(pos, &q->new_flows)
  435. st.qdisc_stats.new_flows_len++;
  436. list_for_each(pos, &q->old_flows)
  437. st.qdisc_stats.old_flows_len++;
  438. return gnet_stats_copy_app(d, &st, sizeof(st));
  439. }
  440. static struct Qdisc *fq_codel_leaf(struct Qdisc *sch, unsigned long arg)
  441. {
  442. return NULL;
  443. }
  444. static unsigned long fq_codel_get(struct Qdisc *sch, u32 classid)
  445. {
  446. return 0;
  447. }
  448. static unsigned long fq_codel_bind(struct Qdisc *sch, unsigned long parent,
  449. u32 classid)
  450. {
  451. /* we cannot bypass queue discipline anymore */
  452. sch->flags &= ~TCQ_F_CAN_BYPASS;
  453. return 0;
  454. }
  455. static void fq_codel_put(struct Qdisc *q, unsigned long cl)
  456. {
  457. }
  458. static struct tcf_proto __rcu **fq_codel_find_tcf(struct Qdisc *sch,
  459. unsigned long cl)
  460. {
  461. struct fq_codel_sched_data *q = qdisc_priv(sch);
  462. if (cl)
  463. return NULL;
  464. return &q->filter_list;
  465. }
  466. static int fq_codel_dump_class(struct Qdisc *sch, unsigned long cl,
  467. struct sk_buff *skb, struct tcmsg *tcm)
  468. {
  469. tcm->tcm_handle |= TC_H_MIN(cl);
  470. return 0;
  471. }
  472. static int fq_codel_dump_class_stats(struct Qdisc *sch, unsigned long cl,
  473. struct gnet_dump *d)
  474. {
  475. struct fq_codel_sched_data *q = qdisc_priv(sch);
  476. u32 idx = cl - 1;
  477. struct gnet_stats_queue qs = { 0 };
  478. struct tc_fq_codel_xstats xstats;
  479. if (idx < q->flows_cnt) {
  480. const struct fq_codel_flow *flow = &q->flows[idx];
  481. const struct sk_buff *skb = flow->head;
  482. memset(&xstats, 0, sizeof(xstats));
  483. xstats.type = TCA_FQ_CODEL_XSTATS_CLASS;
  484. xstats.class_stats.deficit = flow->deficit;
  485. xstats.class_stats.ldelay =
  486. codel_time_to_us(flow->cvars.ldelay);
  487. xstats.class_stats.count = flow->cvars.count;
  488. xstats.class_stats.lastcount = flow->cvars.lastcount;
  489. xstats.class_stats.dropping = flow->cvars.dropping;
  490. if (flow->cvars.dropping) {
  491. codel_tdiff_t delta = flow->cvars.drop_next -
  492. codel_get_time();
  493. xstats.class_stats.drop_next = (delta >= 0) ?
  494. codel_time_to_us(delta) :
  495. -codel_time_to_us(-delta);
  496. }
  497. while (skb) {
  498. qs.qlen++;
  499. skb = skb->next;
  500. }
  501. qs.backlog = q->backlogs[idx];
  502. qs.drops = flow->dropped;
  503. }
  504. if (gnet_stats_copy_queue(d, NULL, &qs, 0) < 0)
  505. return -1;
  506. if (idx < q->flows_cnt)
  507. return gnet_stats_copy_app(d, &xstats, sizeof(xstats));
  508. return 0;
  509. }
  510. static void fq_codel_walk(struct Qdisc *sch, struct qdisc_walker *arg)
  511. {
  512. struct fq_codel_sched_data *q = qdisc_priv(sch);
  513. unsigned int i;
  514. if (arg->stop)
  515. return;
  516. for (i = 0; i < q->flows_cnt; i++) {
  517. if (list_empty(&q->flows[i].flowchain) ||
  518. arg->count < arg->skip) {
  519. arg->count++;
  520. continue;
  521. }
  522. if (arg->fn(sch, i + 1, arg) < 0) {
  523. arg->stop = 1;
  524. break;
  525. }
  526. arg->count++;
  527. }
  528. }
  529. static const struct Qdisc_class_ops fq_codel_class_ops = {
  530. .leaf = fq_codel_leaf,
  531. .get = fq_codel_get,
  532. .put = fq_codel_put,
  533. .tcf_chain = fq_codel_find_tcf,
  534. .bind_tcf = fq_codel_bind,
  535. .unbind_tcf = fq_codel_put,
  536. .dump = fq_codel_dump_class,
  537. .dump_stats = fq_codel_dump_class_stats,
  538. .walk = fq_codel_walk,
  539. };
  540. static struct Qdisc_ops fq_codel_qdisc_ops __read_mostly = {
  541. .cl_ops = &fq_codel_class_ops,
  542. .id = "fq_codel",
  543. .priv_size = sizeof(struct fq_codel_sched_data),
  544. .enqueue = fq_codel_enqueue,
  545. .dequeue = fq_codel_dequeue,
  546. .peek = qdisc_peek_dequeued,
  547. .drop = fq_codel_qdisc_drop,
  548. .init = fq_codel_init,
  549. .reset = fq_codel_reset,
  550. .destroy = fq_codel_destroy,
  551. .change = fq_codel_change,
  552. .dump = fq_codel_dump,
  553. .dump_stats = fq_codel_dump_stats,
  554. .owner = THIS_MODULE,
  555. };
  556. static int __init fq_codel_module_init(void)
  557. {
  558. return register_qdisc(&fq_codel_qdisc_ops);
  559. }
  560. static void __exit fq_codel_module_exit(void)
  561. {
  562. unregister_qdisc(&fq_codel_qdisc_ops);
  563. }
  564. module_init(fq_codel_module_init)
  565. module_exit(fq_codel_module_exit)
  566. MODULE_AUTHOR("Eric Dumazet");
  567. MODULE_LICENSE("GPL");