sch_sfb.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  1. /*
  2. * net/sched/sch_sfb.c Stochastic Fair Blue
  3. *
  4. * Copyright (c) 2008-2011 Juliusz Chroboczek <jch@pps.jussieu.fr>
  5. * Copyright (c) 2011 Eric Dumazet <eric.dumazet@gmail.com>
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * version 2 as published by the Free Software Foundation.
  10. *
  11. * W. Feng, D. Kandlur, D. Saha, K. Shin. Blue:
  12. * A New Class of Active Queue Management Algorithms.
  13. * U. Michigan CSE-TR-387-99, April 1999.
  14. *
  15. * http://www.thefengs.com/wuchang/blue/CSE-TR-387-99.pdf
  16. *
  17. */
  18. #include <linux/module.h>
  19. #include <linux/types.h>
  20. #include <linux/kernel.h>
  21. #include <linux/errno.h>
  22. #include <linux/skbuff.h>
  23. #include <linux/random.h>
  24. #include <linux/jhash.h>
  25. #include <net/ip.h>
  26. #include <net/pkt_sched.h>
  27. #include <net/inet_ecn.h>
  28. /*
  29. * SFB uses two B[l][n] : L x N arrays of bins (L levels, N bins per level)
  30. * This implementation uses L = 8 and N = 16
  31. * This permits us to split one 32bit hash (provided per packet by rxhash or
  32. * external classifier) into 8 subhashes of 4 bits.
  33. */
  34. #define SFB_BUCKET_SHIFT 4
  35. #define SFB_NUMBUCKETS (1 << SFB_BUCKET_SHIFT) /* N bins per Level */
  36. #define SFB_BUCKET_MASK (SFB_NUMBUCKETS - 1)
  37. #define SFB_LEVELS (32 / SFB_BUCKET_SHIFT) /* L */
  38. /* SFB algo uses a virtual queue, named "bin" */
  39. struct sfb_bucket {
  40. u16 qlen; /* length of virtual queue */
  41. u16 p_mark; /* marking probability */
  42. };
  43. /* We use a double buffering right before hash change
  44. * (Section 4.4 of SFB reference : moving hash functions)
  45. */
  46. struct sfb_bins {
  47. u32 perturbation; /* jhash perturbation */
  48. struct sfb_bucket bins[SFB_LEVELS][SFB_NUMBUCKETS];
  49. };
  50. struct sfb_sched_data {
  51. struct Qdisc *qdisc;
  52. struct tcf_proto __rcu *filter_list;
  53. unsigned long rehash_interval;
  54. unsigned long warmup_time; /* double buffering warmup time in jiffies */
  55. u32 max;
  56. u32 bin_size; /* maximum queue length per bin */
  57. u32 increment; /* d1 */
  58. u32 decrement; /* d2 */
  59. u32 limit; /* HARD maximal queue length */
  60. u32 penalty_rate;
  61. u32 penalty_burst;
  62. u32 tokens_avail;
  63. unsigned long rehash_time;
  64. unsigned long token_time;
  65. u8 slot; /* current active bins (0 or 1) */
  66. bool double_buffering;
  67. struct sfb_bins bins[2];
  68. struct {
  69. u32 earlydrop;
  70. u32 penaltydrop;
  71. u32 bucketdrop;
  72. u32 queuedrop;
  73. u32 childdrop; /* drops in child qdisc */
  74. u32 marked; /* ECN mark */
  75. } stats;
  76. };
  77. /*
  78. * Each queued skb might be hashed on one or two bins
  79. * We store in skb_cb the two hash values.
  80. * (A zero value means double buffering was not used)
  81. */
  82. struct sfb_skb_cb {
  83. u32 hashes[2];
  84. };
  85. static inline struct sfb_skb_cb *sfb_skb_cb(const struct sk_buff *skb)
  86. {
  87. qdisc_cb_private_validate(skb, sizeof(struct sfb_skb_cb));
  88. return (struct sfb_skb_cb *)qdisc_skb_cb(skb)->data;
  89. }
  90. /*
  91. * If using 'internal' SFB flow classifier, hash comes from skb rxhash
  92. * If using external classifier, hash comes from the classid.
  93. */
  94. static u32 sfb_hash(const struct sk_buff *skb, u32 slot)
  95. {
  96. return sfb_skb_cb(skb)->hashes[slot];
  97. }
  98. /* Probabilities are coded as Q0.16 fixed-point values,
  99. * with 0xFFFF representing 65535/65536 (almost 1.0)
  100. * Addition and subtraction are saturating in [0, 65535]
  101. */
  102. static u32 prob_plus(u32 p1, u32 p2)
  103. {
  104. u32 res = p1 + p2;
  105. return min_t(u32, res, SFB_MAX_PROB);
  106. }
  107. static u32 prob_minus(u32 p1, u32 p2)
  108. {
  109. return p1 > p2 ? p1 - p2 : 0;
  110. }
  111. static void increment_one_qlen(u32 sfbhash, u32 slot, struct sfb_sched_data *q)
  112. {
  113. int i;
  114. struct sfb_bucket *b = &q->bins[slot].bins[0][0];
  115. for (i = 0; i < SFB_LEVELS; i++) {
  116. u32 hash = sfbhash & SFB_BUCKET_MASK;
  117. sfbhash >>= SFB_BUCKET_SHIFT;
  118. if (b[hash].qlen < 0xFFFF)
  119. b[hash].qlen++;
  120. b += SFB_NUMBUCKETS; /* next level */
  121. }
  122. }
  123. static void increment_qlen(const struct sk_buff *skb, struct sfb_sched_data *q)
  124. {
  125. u32 sfbhash;
  126. sfbhash = sfb_hash(skb, 0);
  127. if (sfbhash)
  128. increment_one_qlen(sfbhash, 0, q);
  129. sfbhash = sfb_hash(skb, 1);
  130. if (sfbhash)
  131. increment_one_qlen(sfbhash, 1, q);
  132. }
  133. static void decrement_one_qlen(u32 sfbhash, u32 slot,
  134. struct sfb_sched_data *q)
  135. {
  136. int i;
  137. struct sfb_bucket *b = &q->bins[slot].bins[0][0];
  138. for (i = 0; i < SFB_LEVELS; i++) {
  139. u32 hash = sfbhash & SFB_BUCKET_MASK;
  140. sfbhash >>= SFB_BUCKET_SHIFT;
  141. if (b[hash].qlen > 0)
  142. b[hash].qlen--;
  143. b += SFB_NUMBUCKETS; /* next level */
  144. }
  145. }
  146. static void decrement_qlen(const struct sk_buff *skb, struct sfb_sched_data *q)
  147. {
  148. u32 sfbhash;
  149. sfbhash = sfb_hash(skb, 0);
  150. if (sfbhash)
  151. decrement_one_qlen(sfbhash, 0, q);
  152. sfbhash = sfb_hash(skb, 1);
  153. if (sfbhash)
  154. decrement_one_qlen(sfbhash, 1, q);
  155. }
  156. static void decrement_prob(struct sfb_bucket *b, struct sfb_sched_data *q)
  157. {
  158. b->p_mark = prob_minus(b->p_mark, q->decrement);
  159. }
  160. static void increment_prob(struct sfb_bucket *b, struct sfb_sched_data *q)
  161. {
  162. b->p_mark = prob_plus(b->p_mark, q->increment);
  163. }
  164. static void sfb_zero_all_buckets(struct sfb_sched_data *q)
  165. {
  166. memset(&q->bins, 0, sizeof(q->bins));
  167. }
  168. /*
  169. * compute max qlen, max p_mark, and avg p_mark
  170. */
  171. static u32 sfb_compute_qlen(u32 *prob_r, u32 *avgpm_r, const struct sfb_sched_data *q)
  172. {
  173. int i;
  174. u32 qlen = 0, prob = 0, totalpm = 0;
  175. const struct sfb_bucket *b = &q->bins[q->slot].bins[0][0];
  176. for (i = 0; i < SFB_LEVELS * SFB_NUMBUCKETS; i++) {
  177. if (qlen < b->qlen)
  178. qlen = b->qlen;
  179. totalpm += b->p_mark;
  180. if (prob < b->p_mark)
  181. prob = b->p_mark;
  182. b++;
  183. }
  184. *prob_r = prob;
  185. *avgpm_r = totalpm / (SFB_LEVELS * SFB_NUMBUCKETS);
  186. return qlen;
  187. }
  188. static void sfb_init_perturbation(u32 slot, struct sfb_sched_data *q)
  189. {
  190. q->bins[slot].perturbation = prandom_u32();
  191. }
  192. static void sfb_swap_slot(struct sfb_sched_data *q)
  193. {
  194. sfb_init_perturbation(q->slot, q);
  195. q->slot ^= 1;
  196. q->double_buffering = false;
  197. }
  198. /* Non elastic flows are allowed to use part of the bandwidth, expressed
  199. * in "penalty_rate" packets per second, with "penalty_burst" burst
  200. */
  201. static bool sfb_rate_limit(struct sk_buff *skb, struct sfb_sched_data *q)
  202. {
  203. if (q->penalty_rate == 0 || q->penalty_burst == 0)
  204. return true;
  205. if (q->tokens_avail < 1) {
  206. unsigned long age = min(10UL * HZ, jiffies - q->token_time);
  207. q->tokens_avail = (age * q->penalty_rate) / HZ;
  208. if (q->tokens_avail > q->penalty_burst)
  209. q->tokens_avail = q->penalty_burst;
  210. q->token_time = jiffies;
  211. if (q->tokens_avail < 1)
  212. return true;
  213. }
  214. q->tokens_avail--;
  215. return false;
  216. }
  217. static bool sfb_classify(struct sk_buff *skb, struct tcf_proto *fl,
  218. int *qerr, u32 *salt)
  219. {
  220. struct tcf_result res;
  221. int result;
  222. result = tc_classify(skb, fl, &res, false);
  223. if (result >= 0) {
  224. #ifdef CONFIG_NET_CLS_ACT
  225. switch (result) {
  226. case TC_ACT_STOLEN:
  227. case TC_ACT_QUEUED:
  228. *qerr = NET_XMIT_SUCCESS | __NET_XMIT_STOLEN;
  229. case TC_ACT_SHOT:
  230. return false;
  231. }
  232. #endif
  233. *salt = TC_H_MIN(res.classid);
  234. return true;
  235. }
  236. return false;
  237. }
  238. static int sfb_enqueue(struct sk_buff *skb, struct Qdisc *sch,
  239. struct sk_buff **to_free)
  240. {
  241. struct sfb_sched_data *q = qdisc_priv(sch);
  242. struct Qdisc *child = q->qdisc;
  243. struct tcf_proto *fl;
  244. int i;
  245. u32 p_min = ~0;
  246. u32 minqlen = ~0;
  247. u32 r, sfbhash;
  248. u32 slot = q->slot;
  249. int ret = NET_XMIT_SUCCESS | __NET_XMIT_BYPASS;
  250. if (unlikely(sch->q.qlen >= q->limit)) {
  251. qdisc_qstats_overlimit(sch);
  252. q->stats.queuedrop++;
  253. goto drop;
  254. }
  255. if (q->rehash_interval > 0) {
  256. unsigned long limit = q->rehash_time + q->rehash_interval;
  257. if (unlikely(time_after(jiffies, limit))) {
  258. sfb_swap_slot(q);
  259. q->rehash_time = jiffies;
  260. } else if (unlikely(!q->double_buffering && q->warmup_time > 0 &&
  261. time_after(jiffies, limit - q->warmup_time))) {
  262. q->double_buffering = true;
  263. }
  264. }
  265. fl = rcu_dereference_bh(q->filter_list);
  266. if (fl) {
  267. u32 salt;
  268. /* If using external classifiers, get result and record it. */
  269. if (!sfb_classify(skb, fl, &ret, &salt))
  270. goto other_drop;
  271. sfbhash = jhash_1word(salt, q->bins[slot].perturbation);
  272. } else {
  273. sfbhash = skb_get_hash_perturb(skb, q->bins[slot].perturbation);
  274. }
  275. if (!sfbhash)
  276. sfbhash = 1;
  277. sfb_skb_cb(skb)->hashes[slot] = sfbhash;
  278. for (i = 0; i < SFB_LEVELS; i++) {
  279. u32 hash = sfbhash & SFB_BUCKET_MASK;
  280. struct sfb_bucket *b = &q->bins[slot].bins[i][hash];
  281. sfbhash >>= SFB_BUCKET_SHIFT;
  282. if (b->qlen == 0)
  283. decrement_prob(b, q);
  284. else if (b->qlen >= q->bin_size)
  285. increment_prob(b, q);
  286. if (minqlen > b->qlen)
  287. minqlen = b->qlen;
  288. if (p_min > b->p_mark)
  289. p_min = b->p_mark;
  290. }
  291. slot ^= 1;
  292. sfb_skb_cb(skb)->hashes[slot] = 0;
  293. if (unlikely(minqlen >= q->max)) {
  294. qdisc_qstats_overlimit(sch);
  295. q->stats.bucketdrop++;
  296. goto drop;
  297. }
  298. if (unlikely(p_min >= SFB_MAX_PROB)) {
  299. /* Inelastic flow */
  300. if (q->double_buffering) {
  301. sfbhash = skb_get_hash_perturb(skb,
  302. q->bins[slot].perturbation);
  303. if (!sfbhash)
  304. sfbhash = 1;
  305. sfb_skb_cb(skb)->hashes[slot] = sfbhash;
  306. for (i = 0; i < SFB_LEVELS; i++) {
  307. u32 hash = sfbhash & SFB_BUCKET_MASK;
  308. struct sfb_bucket *b = &q->bins[slot].bins[i][hash];
  309. sfbhash >>= SFB_BUCKET_SHIFT;
  310. if (b->qlen == 0)
  311. decrement_prob(b, q);
  312. else if (b->qlen >= q->bin_size)
  313. increment_prob(b, q);
  314. }
  315. }
  316. if (sfb_rate_limit(skb, q)) {
  317. qdisc_qstats_overlimit(sch);
  318. q->stats.penaltydrop++;
  319. goto drop;
  320. }
  321. goto enqueue;
  322. }
  323. r = prandom_u32() & SFB_MAX_PROB;
  324. if (unlikely(r < p_min)) {
  325. if (unlikely(p_min > SFB_MAX_PROB / 2)) {
  326. /* If we're marking that many packets, then either
  327. * this flow is unresponsive, or we're badly congested.
  328. * In either case, we want to start dropping packets.
  329. */
  330. if (r < (p_min - SFB_MAX_PROB / 2) * 2) {
  331. q->stats.earlydrop++;
  332. goto drop;
  333. }
  334. }
  335. if (INET_ECN_set_ce(skb)) {
  336. q->stats.marked++;
  337. } else {
  338. q->stats.earlydrop++;
  339. goto drop;
  340. }
  341. }
  342. enqueue:
  343. ret = qdisc_enqueue(skb, child, to_free);
  344. if (likely(ret == NET_XMIT_SUCCESS)) {
  345. sch->q.qlen++;
  346. increment_qlen(skb, q);
  347. } else if (net_xmit_drop_count(ret)) {
  348. q->stats.childdrop++;
  349. qdisc_qstats_drop(sch);
  350. }
  351. return ret;
  352. drop:
  353. qdisc_drop(skb, sch, to_free);
  354. return NET_XMIT_CN;
  355. other_drop:
  356. if (ret & __NET_XMIT_BYPASS)
  357. qdisc_qstats_drop(sch);
  358. kfree_skb(skb);
  359. return ret;
  360. }
  361. static struct sk_buff *sfb_dequeue(struct Qdisc *sch)
  362. {
  363. struct sfb_sched_data *q = qdisc_priv(sch);
  364. struct Qdisc *child = q->qdisc;
  365. struct sk_buff *skb;
  366. skb = child->dequeue(q->qdisc);
  367. if (skb) {
  368. qdisc_bstats_update(sch, skb);
  369. sch->q.qlen--;
  370. decrement_qlen(skb, q);
  371. }
  372. return skb;
  373. }
  374. static struct sk_buff *sfb_peek(struct Qdisc *sch)
  375. {
  376. struct sfb_sched_data *q = qdisc_priv(sch);
  377. struct Qdisc *child = q->qdisc;
  378. return child->ops->peek(child);
  379. }
  380. /* No sfb_drop -- impossible since the child doesn't return the dropped skb. */
  381. static void sfb_reset(struct Qdisc *sch)
  382. {
  383. struct sfb_sched_data *q = qdisc_priv(sch);
  384. qdisc_reset(q->qdisc);
  385. sch->q.qlen = 0;
  386. q->slot = 0;
  387. q->double_buffering = false;
  388. sfb_zero_all_buckets(q);
  389. sfb_init_perturbation(0, q);
  390. }
  391. static void sfb_destroy(struct Qdisc *sch)
  392. {
  393. struct sfb_sched_data *q = qdisc_priv(sch);
  394. tcf_destroy_chain(&q->filter_list);
  395. qdisc_destroy(q->qdisc);
  396. }
  397. static const struct nla_policy sfb_policy[TCA_SFB_MAX + 1] = {
  398. [TCA_SFB_PARMS] = { .len = sizeof(struct tc_sfb_qopt) },
  399. };
  400. static const struct tc_sfb_qopt sfb_default_ops = {
  401. .rehash_interval = 600 * MSEC_PER_SEC,
  402. .warmup_time = 60 * MSEC_PER_SEC,
  403. .limit = 0,
  404. .max = 25,
  405. .bin_size = 20,
  406. .increment = (SFB_MAX_PROB + 500) / 1000, /* 0.1 % */
  407. .decrement = (SFB_MAX_PROB + 3000) / 6000,
  408. .penalty_rate = 10,
  409. .penalty_burst = 20,
  410. };
  411. static int sfb_change(struct Qdisc *sch, struct nlattr *opt)
  412. {
  413. struct sfb_sched_data *q = qdisc_priv(sch);
  414. struct Qdisc *child;
  415. struct nlattr *tb[TCA_SFB_MAX + 1];
  416. const struct tc_sfb_qopt *ctl = &sfb_default_ops;
  417. u32 limit;
  418. int err;
  419. if (opt) {
  420. err = nla_parse_nested(tb, TCA_SFB_MAX, opt, sfb_policy);
  421. if (err < 0)
  422. return -EINVAL;
  423. if (tb[TCA_SFB_PARMS] == NULL)
  424. return -EINVAL;
  425. ctl = nla_data(tb[TCA_SFB_PARMS]);
  426. }
  427. limit = ctl->limit;
  428. if (limit == 0)
  429. limit = qdisc_dev(sch)->tx_queue_len;
  430. child = fifo_create_dflt(sch, &pfifo_qdisc_ops, limit);
  431. if (IS_ERR(child))
  432. return PTR_ERR(child);
  433. sch_tree_lock(sch);
  434. qdisc_tree_reduce_backlog(q->qdisc, q->qdisc->q.qlen,
  435. q->qdisc->qstats.backlog);
  436. qdisc_destroy(q->qdisc);
  437. q->qdisc = child;
  438. q->rehash_interval = msecs_to_jiffies(ctl->rehash_interval);
  439. q->warmup_time = msecs_to_jiffies(ctl->warmup_time);
  440. q->rehash_time = jiffies;
  441. q->limit = limit;
  442. q->increment = ctl->increment;
  443. q->decrement = ctl->decrement;
  444. q->max = ctl->max;
  445. q->bin_size = ctl->bin_size;
  446. q->penalty_rate = ctl->penalty_rate;
  447. q->penalty_burst = ctl->penalty_burst;
  448. q->tokens_avail = ctl->penalty_burst;
  449. q->token_time = jiffies;
  450. q->slot = 0;
  451. q->double_buffering = false;
  452. sfb_zero_all_buckets(q);
  453. sfb_init_perturbation(0, q);
  454. sfb_init_perturbation(1, q);
  455. sch_tree_unlock(sch);
  456. return 0;
  457. }
  458. static int sfb_init(struct Qdisc *sch, struct nlattr *opt)
  459. {
  460. struct sfb_sched_data *q = qdisc_priv(sch);
  461. q->qdisc = &noop_qdisc;
  462. return sfb_change(sch, opt);
  463. }
  464. static int sfb_dump(struct Qdisc *sch, struct sk_buff *skb)
  465. {
  466. struct sfb_sched_data *q = qdisc_priv(sch);
  467. struct nlattr *opts;
  468. struct tc_sfb_qopt opt = {
  469. .rehash_interval = jiffies_to_msecs(q->rehash_interval),
  470. .warmup_time = jiffies_to_msecs(q->warmup_time),
  471. .limit = q->limit,
  472. .max = q->max,
  473. .bin_size = q->bin_size,
  474. .increment = q->increment,
  475. .decrement = q->decrement,
  476. .penalty_rate = q->penalty_rate,
  477. .penalty_burst = q->penalty_burst,
  478. };
  479. sch->qstats.backlog = q->qdisc->qstats.backlog;
  480. opts = nla_nest_start(skb, TCA_OPTIONS);
  481. if (opts == NULL)
  482. goto nla_put_failure;
  483. if (nla_put(skb, TCA_SFB_PARMS, sizeof(opt), &opt))
  484. goto nla_put_failure;
  485. return nla_nest_end(skb, opts);
  486. nla_put_failure:
  487. nla_nest_cancel(skb, opts);
  488. return -EMSGSIZE;
  489. }
  490. static int sfb_dump_stats(struct Qdisc *sch, struct gnet_dump *d)
  491. {
  492. struct sfb_sched_data *q = qdisc_priv(sch);
  493. struct tc_sfb_xstats st = {
  494. .earlydrop = q->stats.earlydrop,
  495. .penaltydrop = q->stats.penaltydrop,
  496. .bucketdrop = q->stats.bucketdrop,
  497. .queuedrop = q->stats.queuedrop,
  498. .childdrop = q->stats.childdrop,
  499. .marked = q->stats.marked,
  500. };
  501. st.maxqlen = sfb_compute_qlen(&st.maxprob, &st.avgprob, q);
  502. return gnet_stats_copy_app(d, &st, sizeof(st));
  503. }
  504. static int sfb_dump_class(struct Qdisc *sch, unsigned long cl,
  505. struct sk_buff *skb, struct tcmsg *tcm)
  506. {
  507. return -ENOSYS;
  508. }
  509. static int sfb_graft(struct Qdisc *sch, unsigned long arg, struct Qdisc *new,
  510. struct Qdisc **old)
  511. {
  512. struct sfb_sched_data *q = qdisc_priv(sch);
  513. if (new == NULL)
  514. new = &noop_qdisc;
  515. *old = qdisc_replace(sch, new, &q->qdisc);
  516. return 0;
  517. }
  518. static struct Qdisc *sfb_leaf(struct Qdisc *sch, unsigned long arg)
  519. {
  520. struct sfb_sched_data *q = qdisc_priv(sch);
  521. return q->qdisc;
  522. }
  523. static unsigned long sfb_get(struct Qdisc *sch, u32 classid)
  524. {
  525. return 1;
  526. }
  527. static void sfb_put(struct Qdisc *sch, unsigned long arg)
  528. {
  529. }
  530. static int sfb_change_class(struct Qdisc *sch, u32 classid, u32 parentid,
  531. struct nlattr **tca, unsigned long *arg)
  532. {
  533. return -ENOSYS;
  534. }
  535. static int sfb_delete(struct Qdisc *sch, unsigned long cl)
  536. {
  537. return -ENOSYS;
  538. }
  539. static void sfb_walk(struct Qdisc *sch, struct qdisc_walker *walker)
  540. {
  541. if (!walker->stop) {
  542. if (walker->count >= walker->skip)
  543. if (walker->fn(sch, 1, walker) < 0) {
  544. walker->stop = 1;
  545. return;
  546. }
  547. walker->count++;
  548. }
  549. }
  550. static struct tcf_proto __rcu **sfb_find_tcf(struct Qdisc *sch,
  551. unsigned long cl)
  552. {
  553. struct sfb_sched_data *q = qdisc_priv(sch);
  554. if (cl)
  555. return NULL;
  556. return &q->filter_list;
  557. }
  558. static unsigned long sfb_bind(struct Qdisc *sch, unsigned long parent,
  559. u32 classid)
  560. {
  561. return 0;
  562. }
  563. static const struct Qdisc_class_ops sfb_class_ops = {
  564. .graft = sfb_graft,
  565. .leaf = sfb_leaf,
  566. .get = sfb_get,
  567. .put = sfb_put,
  568. .change = sfb_change_class,
  569. .delete = sfb_delete,
  570. .walk = sfb_walk,
  571. .tcf_chain = sfb_find_tcf,
  572. .bind_tcf = sfb_bind,
  573. .unbind_tcf = sfb_put,
  574. .dump = sfb_dump_class,
  575. };
  576. static struct Qdisc_ops sfb_qdisc_ops __read_mostly = {
  577. .id = "sfb",
  578. .priv_size = sizeof(struct sfb_sched_data),
  579. .cl_ops = &sfb_class_ops,
  580. .enqueue = sfb_enqueue,
  581. .dequeue = sfb_dequeue,
  582. .peek = sfb_peek,
  583. .init = sfb_init,
  584. .reset = sfb_reset,
  585. .destroy = sfb_destroy,
  586. .change = sfb_change,
  587. .dump = sfb_dump,
  588. .dump_stats = sfb_dump_stats,
  589. .owner = THIS_MODULE,
  590. };
  591. static int __init sfb_module_init(void)
  592. {
  593. return register_qdisc(&sfb_qdisc_ops);
  594. }
  595. static void __exit sfb_module_exit(void)
  596. {
  597. unregister_qdisc(&sfb_qdisc_ops);
  598. }
  599. module_init(sfb_module_init)
  600. module_exit(sfb_module_exit)
  601. MODULE_DESCRIPTION("Stochastic Fair Blue queue discipline");
  602. MODULE_AUTHOR("Juliusz Chroboczek");
  603. MODULE_AUTHOR("Eric Dumazet");
  604. MODULE_LICENSE("GPL");