sch_sfb.c 17 KB

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