PageRenderTime 31ms CodeModel.GetById 1ms RepoModel.GetById 1ms app.codeStats 0ms

/net/sched/sch_cbq.c

https://github.com/mstsirkin/kvm
C | 2075 lines | 1517 code | 328 blank | 230 comment | 368 complexity | 40545c61b241cfeb56eff9bbb4c28be1 MD5 | raw file
  1. /*
  2. * net/sched/sch_cbq.c Class-Based Queueing 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. * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
  10. *
  11. */
  12. #include <linux/module.h>
  13. #include <linux/slab.h>
  14. #include <linux/types.h>
  15. #include <linux/kernel.h>
  16. #include <linux/string.h>
  17. #include <linux/errno.h>
  18. #include <linux/skbuff.h>
  19. #include <net/netlink.h>
  20. #include <net/pkt_sched.h>
  21. /* Class-Based Queueing (CBQ) algorithm.
  22. =======================================
  23. Sources: [1] Sally Floyd and Van Jacobson, "Link-sharing and Resource
  24. Management Models for Packet Networks",
  25. IEEE/ACM Transactions on Networking, Vol.3, No.4, 1995
  26. [2] Sally Floyd, "Notes on CBQ and Guaranteed Service", 1995
  27. [3] Sally Floyd, "Notes on Class-Based Queueing: Setting
  28. Parameters", 1996
  29. [4] Sally Floyd and Michael Speer, "Experimental Results
  30. for Class-Based Queueing", 1998, not published.
  31. -----------------------------------------------------------------------
  32. Algorithm skeleton was taken from NS simulator cbq.cc.
  33. If someone wants to check this code against the LBL version,
  34. he should take into account that ONLY the skeleton was borrowed,
  35. the implementation is different. Particularly:
  36. --- The WRR algorithm is different. Our version looks more
  37. reasonable (I hope) and works when quanta are allowed to be
  38. less than MTU, which is always the case when real time classes
  39. have small rates. Note, that the statement of [3] is
  40. incomplete, delay may actually be estimated even if class
  41. per-round allotment is less than MTU. Namely, if per-round
  42. allotment is W*r_i, and r_1+...+r_k = r < 1
  43. delay_i <= ([MTU/(W*r_i)]*W*r + W*r + k*MTU)/B
  44. In the worst case we have IntServ estimate with D = W*r+k*MTU
  45. and C = MTU*r. The proof (if correct at all) is trivial.
  46. --- It seems that cbq-2.0 is not very accurate. At least, I cannot
  47. interpret some places, which look like wrong translations
  48. from NS. Anyone is advised to find these differences
  49. and explain to me, why I am wrong 8).
  50. --- Linux has no EOI event, so that we cannot estimate true class
  51. idle time. Workaround is to consider the next dequeue event
  52. as sign that previous packet is finished. This is wrong because of
  53. internal device queueing, but on a permanently loaded link it is true.
  54. Moreover, combined with clock integrator, this scheme looks
  55. very close to an ideal solution. */
  56. struct cbq_sched_data;
  57. struct cbq_class {
  58. struct Qdisc_class_common common;
  59. struct cbq_class *next_alive; /* next class with backlog in this priority band */
  60. /* Parameters */
  61. unsigned char priority; /* class priority */
  62. unsigned char priority2; /* priority to be used after overlimit */
  63. unsigned char ewma_log; /* time constant for idle time calculation */
  64. unsigned char ovl_strategy;
  65. #ifdef CONFIG_NET_CLS_ACT
  66. unsigned char police;
  67. #endif
  68. u32 defmap;
  69. /* Link-sharing scheduler parameters */
  70. long maxidle; /* Class parameters: see below. */
  71. long offtime;
  72. long minidle;
  73. u32 avpkt;
  74. struct qdisc_rate_table *R_tab;
  75. /* Overlimit strategy parameters */
  76. void (*overlimit)(struct cbq_class *cl);
  77. psched_tdiff_t penalty;
  78. /* General scheduler (WRR) parameters */
  79. long allot;
  80. long quantum; /* Allotment per WRR round */
  81. long weight; /* Relative allotment: see below */
  82. struct Qdisc *qdisc; /* Ptr to CBQ discipline */
  83. struct cbq_class *split; /* Ptr to split node */
  84. struct cbq_class *share; /* Ptr to LS parent in the class tree */
  85. struct cbq_class *tparent; /* Ptr to tree parent in the class tree */
  86. struct cbq_class *borrow; /* NULL if class is bandwidth limited;
  87. parent otherwise */
  88. struct cbq_class *sibling; /* Sibling chain */
  89. struct cbq_class *children; /* Pointer to children chain */
  90. struct Qdisc *q; /* Elementary queueing discipline */
  91. /* Variables */
  92. unsigned char cpriority; /* Effective priority */
  93. unsigned char delayed;
  94. unsigned char level; /* level of the class in hierarchy:
  95. 0 for leaf classes, and maximal
  96. level of children + 1 for nodes.
  97. */
  98. psched_time_t last; /* Last end of service */
  99. psched_time_t undertime;
  100. long avgidle;
  101. long deficit; /* Saved deficit for WRR */
  102. psched_time_t penalized;
  103. struct gnet_stats_basic_packed bstats;
  104. struct gnet_stats_queue qstats;
  105. struct gnet_stats_rate_est rate_est;
  106. struct tc_cbq_xstats xstats;
  107. struct tcf_proto *filter_list;
  108. int refcnt;
  109. int filters;
  110. struct cbq_class *defaults[TC_PRIO_MAX + 1];
  111. };
  112. struct cbq_sched_data {
  113. struct Qdisc_class_hash clhash; /* Hash table of all classes */
  114. int nclasses[TC_CBQ_MAXPRIO + 1];
  115. unsigned int quanta[TC_CBQ_MAXPRIO + 1];
  116. struct cbq_class link;
  117. unsigned int activemask;
  118. struct cbq_class *active[TC_CBQ_MAXPRIO + 1]; /* List of all classes
  119. with backlog */
  120. #ifdef CONFIG_NET_CLS_ACT
  121. struct cbq_class *rx_class;
  122. #endif
  123. struct cbq_class *tx_class;
  124. struct cbq_class *tx_borrowed;
  125. int tx_len;
  126. psched_time_t now; /* Cached timestamp */
  127. psched_time_t now_rt; /* Cached real time */
  128. unsigned int pmask;
  129. struct hrtimer delay_timer;
  130. struct qdisc_watchdog watchdog; /* Watchdog timer,
  131. started when CBQ has
  132. backlog, but cannot
  133. transmit just now */
  134. psched_tdiff_t wd_expires;
  135. int toplevel;
  136. u32 hgenerator;
  137. };
  138. #define L2T(cl, len) qdisc_l2t((cl)->R_tab, len)
  139. static inline struct cbq_class *
  140. cbq_class_lookup(struct cbq_sched_data *q, u32 classid)
  141. {
  142. struct Qdisc_class_common *clc;
  143. clc = qdisc_class_find(&q->clhash, classid);
  144. if (clc == NULL)
  145. return NULL;
  146. return container_of(clc, struct cbq_class, common);
  147. }
  148. #ifdef CONFIG_NET_CLS_ACT
  149. static struct cbq_class *
  150. cbq_reclassify(struct sk_buff *skb, struct cbq_class *this)
  151. {
  152. struct cbq_class *cl;
  153. for (cl = this->tparent; cl; cl = cl->tparent) {
  154. struct cbq_class *new = cl->defaults[TC_PRIO_BESTEFFORT];
  155. if (new != NULL && new != this)
  156. return new;
  157. }
  158. return NULL;
  159. }
  160. #endif
  161. /* Classify packet. The procedure is pretty complicated, but
  162. * it allows us to combine link sharing and priority scheduling
  163. * transparently.
  164. *
  165. * Namely, you can put link sharing rules (f.e. route based) at root of CBQ,
  166. * so that it resolves to split nodes. Then packets are classified
  167. * by logical priority, or a more specific classifier may be attached
  168. * to the split node.
  169. */
  170. static struct cbq_class *
  171. cbq_classify(struct sk_buff *skb, struct Qdisc *sch, int *qerr)
  172. {
  173. struct cbq_sched_data *q = qdisc_priv(sch);
  174. struct cbq_class *head = &q->link;
  175. struct cbq_class **defmap;
  176. struct cbq_class *cl = NULL;
  177. u32 prio = skb->priority;
  178. struct tcf_result res;
  179. /*
  180. * Step 1. If skb->priority points to one of our classes, use it.
  181. */
  182. if (TC_H_MAJ(prio ^ sch->handle) == 0 &&
  183. (cl = cbq_class_lookup(q, prio)) != NULL)
  184. return cl;
  185. *qerr = NET_XMIT_SUCCESS | __NET_XMIT_BYPASS;
  186. for (;;) {
  187. int result = 0;
  188. defmap = head->defaults;
  189. /*
  190. * Step 2+n. Apply classifier.
  191. */
  192. if (!head->filter_list ||
  193. (result = tc_classify_compat(skb, head->filter_list, &res)) < 0)
  194. goto fallback;
  195. cl = (void *)res.class;
  196. if (!cl) {
  197. if (TC_H_MAJ(res.classid))
  198. cl = cbq_class_lookup(q, res.classid);
  199. else if ((cl = defmap[res.classid & TC_PRIO_MAX]) == NULL)
  200. cl = defmap[TC_PRIO_BESTEFFORT];
  201. if (cl == NULL || cl->level >= head->level)
  202. goto fallback;
  203. }
  204. #ifdef CONFIG_NET_CLS_ACT
  205. switch (result) {
  206. case TC_ACT_QUEUED:
  207. case TC_ACT_STOLEN:
  208. *qerr = NET_XMIT_SUCCESS | __NET_XMIT_STOLEN;
  209. case TC_ACT_SHOT:
  210. return NULL;
  211. case TC_ACT_RECLASSIFY:
  212. return cbq_reclassify(skb, cl);
  213. }
  214. #endif
  215. if (cl->level == 0)
  216. return cl;
  217. /*
  218. * Step 3+n. If classifier selected a link sharing class,
  219. * apply agency specific classifier.
  220. * Repeat this procdure until we hit a leaf node.
  221. */
  222. head = cl;
  223. }
  224. fallback:
  225. cl = head;
  226. /*
  227. * Step 4. No success...
  228. */
  229. if (TC_H_MAJ(prio) == 0 &&
  230. !(cl = head->defaults[prio & TC_PRIO_MAX]) &&
  231. !(cl = head->defaults[TC_PRIO_BESTEFFORT]))
  232. return head;
  233. return cl;
  234. }
  235. /*
  236. * A packet has just been enqueued on the empty class.
  237. * cbq_activate_class adds it to the tail of active class list
  238. * of its priority band.
  239. */
  240. static inline void cbq_activate_class(struct cbq_class *cl)
  241. {
  242. struct cbq_sched_data *q = qdisc_priv(cl->qdisc);
  243. int prio = cl->cpriority;
  244. struct cbq_class *cl_tail;
  245. cl_tail = q->active[prio];
  246. q->active[prio] = cl;
  247. if (cl_tail != NULL) {
  248. cl->next_alive = cl_tail->next_alive;
  249. cl_tail->next_alive = cl;
  250. } else {
  251. cl->next_alive = cl;
  252. q->activemask |= (1<<prio);
  253. }
  254. }
  255. /*
  256. * Unlink class from active chain.
  257. * Note that this same procedure is done directly in cbq_dequeue*
  258. * during round-robin procedure.
  259. */
  260. static void cbq_deactivate_class(struct cbq_class *this)
  261. {
  262. struct cbq_sched_data *q = qdisc_priv(this->qdisc);
  263. int prio = this->cpriority;
  264. struct cbq_class *cl;
  265. struct cbq_class *cl_prev = q->active[prio];
  266. do {
  267. cl = cl_prev->next_alive;
  268. if (cl == this) {
  269. cl_prev->next_alive = cl->next_alive;
  270. cl->next_alive = NULL;
  271. if (cl == q->active[prio]) {
  272. q->active[prio] = cl_prev;
  273. if (cl == q->active[prio]) {
  274. q->active[prio] = NULL;
  275. q->activemask &= ~(1<<prio);
  276. return;
  277. }
  278. }
  279. return;
  280. }
  281. } while ((cl_prev = cl) != q->active[prio]);
  282. }
  283. static void
  284. cbq_mark_toplevel(struct cbq_sched_data *q, struct cbq_class *cl)
  285. {
  286. int toplevel = q->toplevel;
  287. if (toplevel > cl->level && !(qdisc_is_throttled(cl->q))) {
  288. psched_time_t now;
  289. psched_tdiff_t incr;
  290. now = psched_get_time();
  291. incr = now - q->now_rt;
  292. now = q->now + incr;
  293. do {
  294. if (cl->undertime < now) {
  295. q->toplevel = cl->level;
  296. return;
  297. }
  298. } while ((cl = cl->borrow) != NULL && toplevel > cl->level);
  299. }
  300. }
  301. static int
  302. cbq_enqueue(struct sk_buff *skb, struct Qdisc *sch)
  303. {
  304. struct cbq_sched_data *q = qdisc_priv(sch);
  305. int uninitialized_var(ret);
  306. struct cbq_class *cl = cbq_classify(skb, sch, &ret);
  307. #ifdef CONFIG_NET_CLS_ACT
  308. q->rx_class = cl;
  309. #endif
  310. if (cl == NULL) {
  311. if (ret & __NET_XMIT_BYPASS)
  312. sch->qstats.drops++;
  313. kfree_skb(skb);
  314. return ret;
  315. }
  316. #ifdef CONFIG_NET_CLS_ACT
  317. cl->q->__parent = sch;
  318. #endif
  319. ret = qdisc_enqueue(skb, cl->q);
  320. if (ret == NET_XMIT_SUCCESS) {
  321. sch->q.qlen++;
  322. cbq_mark_toplevel(q, cl);
  323. if (!cl->next_alive)
  324. cbq_activate_class(cl);
  325. return ret;
  326. }
  327. if (net_xmit_drop_count(ret)) {
  328. sch->qstats.drops++;
  329. cbq_mark_toplevel(q, cl);
  330. cl->qstats.drops++;
  331. }
  332. return ret;
  333. }
  334. /* Overlimit actions */
  335. /* TC_CBQ_OVL_CLASSIC: (default) penalize leaf class by adding offtime */
  336. static void cbq_ovl_classic(struct cbq_class *cl)
  337. {
  338. struct cbq_sched_data *q = qdisc_priv(cl->qdisc);
  339. psched_tdiff_t delay = cl->undertime - q->now;
  340. if (!cl->delayed) {
  341. delay += cl->offtime;
  342. /*
  343. * Class goes to sleep, so that it will have no
  344. * chance to work avgidle. Let's forgive it 8)
  345. *
  346. * BTW cbq-2.0 has a crap in this
  347. * place, apparently they forgot to shift it by cl->ewma_log.
  348. */
  349. if (cl->avgidle < 0)
  350. delay -= (-cl->avgidle) - ((-cl->avgidle) >> cl->ewma_log);
  351. if (cl->avgidle < cl->minidle)
  352. cl->avgidle = cl->minidle;
  353. if (delay <= 0)
  354. delay = 1;
  355. cl->undertime = q->now + delay;
  356. cl->xstats.overactions++;
  357. cl->delayed = 1;
  358. }
  359. if (q->wd_expires == 0 || q->wd_expires > delay)
  360. q->wd_expires = delay;
  361. /* Dirty work! We must schedule wakeups based on
  362. * real available rate, rather than leaf rate,
  363. * which may be tiny (even zero).
  364. */
  365. if (q->toplevel == TC_CBQ_MAXLEVEL) {
  366. struct cbq_class *b;
  367. psched_tdiff_t base_delay = q->wd_expires;
  368. for (b = cl->borrow; b; b = b->borrow) {
  369. delay = b->undertime - q->now;
  370. if (delay < base_delay) {
  371. if (delay <= 0)
  372. delay = 1;
  373. base_delay = delay;
  374. }
  375. }
  376. q->wd_expires = base_delay;
  377. }
  378. }
  379. /* TC_CBQ_OVL_RCLASSIC: penalize by offtime classes in hierarchy, when
  380. * they go overlimit
  381. */
  382. static void cbq_ovl_rclassic(struct cbq_class *cl)
  383. {
  384. struct cbq_sched_data *q = qdisc_priv(cl->qdisc);
  385. struct cbq_class *this = cl;
  386. do {
  387. if (cl->level > q->toplevel) {
  388. cl = NULL;
  389. break;
  390. }
  391. } while ((cl = cl->borrow) != NULL);
  392. if (cl == NULL)
  393. cl = this;
  394. cbq_ovl_classic(cl);
  395. }
  396. /* TC_CBQ_OVL_DELAY: delay until it will go to underlimit */
  397. static void cbq_ovl_delay(struct cbq_class *cl)
  398. {
  399. struct cbq_sched_data *q = qdisc_priv(cl->qdisc);
  400. psched_tdiff_t delay = cl->undertime - q->now;
  401. if (test_bit(__QDISC_STATE_DEACTIVATED,
  402. &qdisc_root_sleeping(cl->qdisc)->state))
  403. return;
  404. if (!cl->delayed) {
  405. psched_time_t sched = q->now;
  406. ktime_t expires;
  407. delay += cl->offtime;
  408. if (cl->avgidle < 0)
  409. delay -= (-cl->avgidle) - ((-cl->avgidle) >> cl->ewma_log);
  410. if (cl->avgidle < cl->minidle)
  411. cl->avgidle = cl->minidle;
  412. cl->undertime = q->now + delay;
  413. if (delay > 0) {
  414. sched += delay + cl->penalty;
  415. cl->penalized = sched;
  416. cl->cpriority = TC_CBQ_MAXPRIO;
  417. q->pmask |= (1<<TC_CBQ_MAXPRIO);
  418. expires = ktime_set(0, 0);
  419. expires = ktime_add_ns(expires, PSCHED_TICKS2NS(sched));
  420. if (hrtimer_try_to_cancel(&q->delay_timer) &&
  421. ktime_to_ns(ktime_sub(
  422. hrtimer_get_expires(&q->delay_timer),
  423. expires)) > 0)
  424. hrtimer_set_expires(&q->delay_timer, expires);
  425. hrtimer_restart(&q->delay_timer);
  426. cl->delayed = 1;
  427. cl->xstats.overactions++;
  428. return;
  429. }
  430. delay = 1;
  431. }
  432. if (q->wd_expires == 0 || q->wd_expires > delay)
  433. q->wd_expires = delay;
  434. }
  435. /* TC_CBQ_OVL_LOWPRIO: penalize class by lowering its priority band */
  436. static void cbq_ovl_lowprio(struct cbq_class *cl)
  437. {
  438. struct cbq_sched_data *q = qdisc_priv(cl->qdisc);
  439. cl->penalized = q->now + cl->penalty;
  440. if (cl->cpriority != cl->priority2) {
  441. cl->cpriority = cl->priority2;
  442. q->pmask |= (1<<cl->cpriority);
  443. cl->xstats.overactions++;
  444. }
  445. cbq_ovl_classic(cl);
  446. }
  447. /* TC_CBQ_OVL_DROP: penalize class by dropping */
  448. static void cbq_ovl_drop(struct cbq_class *cl)
  449. {
  450. if (cl->q->ops->drop)
  451. if (cl->q->ops->drop(cl->q))
  452. cl->qdisc->q.qlen--;
  453. cl->xstats.overactions++;
  454. cbq_ovl_classic(cl);
  455. }
  456. static psched_tdiff_t cbq_undelay_prio(struct cbq_sched_data *q, int prio,
  457. psched_time_t now)
  458. {
  459. struct cbq_class *cl;
  460. struct cbq_class *cl_prev = q->active[prio];
  461. psched_time_t sched = now;
  462. if (cl_prev == NULL)
  463. return 0;
  464. do {
  465. cl = cl_prev->next_alive;
  466. if (now - cl->penalized > 0) {
  467. cl_prev->next_alive = cl->next_alive;
  468. cl->next_alive = NULL;
  469. cl->cpriority = cl->priority;
  470. cl->delayed = 0;
  471. cbq_activate_class(cl);
  472. if (cl == q->active[prio]) {
  473. q->active[prio] = cl_prev;
  474. if (cl == q->active[prio]) {
  475. q->active[prio] = NULL;
  476. return 0;
  477. }
  478. }
  479. cl = cl_prev->next_alive;
  480. } else if (sched - cl->penalized > 0)
  481. sched = cl->penalized;
  482. } while ((cl_prev = cl) != q->active[prio]);
  483. return sched - now;
  484. }
  485. static enum hrtimer_restart cbq_undelay(struct hrtimer *timer)
  486. {
  487. struct cbq_sched_data *q = container_of(timer, struct cbq_sched_data,
  488. delay_timer);
  489. struct Qdisc *sch = q->watchdog.qdisc;
  490. psched_time_t now;
  491. psched_tdiff_t delay = 0;
  492. unsigned int pmask;
  493. now = psched_get_time();
  494. pmask = q->pmask;
  495. q->pmask = 0;
  496. while (pmask) {
  497. int prio = ffz(~pmask);
  498. psched_tdiff_t tmp;
  499. pmask &= ~(1<<prio);
  500. tmp = cbq_undelay_prio(q, prio, now);
  501. if (tmp > 0) {
  502. q->pmask |= 1<<prio;
  503. if (tmp < delay || delay == 0)
  504. delay = tmp;
  505. }
  506. }
  507. if (delay) {
  508. ktime_t time;
  509. time = ktime_set(0, 0);
  510. time = ktime_add_ns(time, PSCHED_TICKS2NS(now + delay));
  511. hrtimer_start(&q->delay_timer, time, HRTIMER_MODE_ABS);
  512. }
  513. qdisc_unthrottled(sch);
  514. __netif_schedule(qdisc_root(sch));
  515. return HRTIMER_NORESTART;
  516. }
  517. #ifdef CONFIG_NET_CLS_ACT
  518. static int cbq_reshape_fail(struct sk_buff *skb, struct Qdisc *child)
  519. {
  520. struct Qdisc *sch = child->__parent;
  521. struct cbq_sched_data *q = qdisc_priv(sch);
  522. struct cbq_class *cl = q->rx_class;
  523. q->rx_class = NULL;
  524. if (cl && (cl = cbq_reclassify(skb, cl)) != NULL) {
  525. int ret;
  526. cbq_mark_toplevel(q, cl);
  527. q->rx_class = cl;
  528. cl->q->__parent = sch;
  529. ret = qdisc_enqueue(skb, cl->q);
  530. if (ret == NET_XMIT_SUCCESS) {
  531. sch->q.qlen++;
  532. if (!cl->next_alive)
  533. cbq_activate_class(cl);
  534. return 0;
  535. }
  536. if (net_xmit_drop_count(ret))
  537. sch->qstats.drops++;
  538. return 0;
  539. }
  540. sch->qstats.drops++;
  541. return -1;
  542. }
  543. #endif
  544. /*
  545. * It is mission critical procedure.
  546. *
  547. * We "regenerate" toplevel cutoff, if transmitting class
  548. * has backlog and it is not regulated. It is not part of
  549. * original CBQ description, but looks more reasonable.
  550. * Probably, it is wrong. This question needs further investigation.
  551. */
  552. static inline void
  553. cbq_update_toplevel(struct cbq_sched_data *q, struct cbq_class *cl,
  554. struct cbq_class *borrowed)
  555. {
  556. if (cl && q->toplevel >= borrowed->level) {
  557. if (cl->q->q.qlen > 1) {
  558. do {
  559. if (borrowed->undertime == PSCHED_PASTPERFECT) {
  560. q->toplevel = borrowed->level;
  561. return;
  562. }
  563. } while ((borrowed = borrowed->borrow) != NULL);
  564. }
  565. #if 0
  566. /* It is not necessary now. Uncommenting it
  567. will save CPU cycles, but decrease fairness.
  568. */
  569. q->toplevel = TC_CBQ_MAXLEVEL;
  570. #endif
  571. }
  572. }
  573. static void
  574. cbq_update(struct cbq_sched_data *q)
  575. {
  576. struct cbq_class *this = q->tx_class;
  577. struct cbq_class *cl = this;
  578. int len = q->tx_len;
  579. q->tx_class = NULL;
  580. for ( ; cl; cl = cl->share) {
  581. long avgidle = cl->avgidle;
  582. long idle;
  583. cl->bstats.packets++;
  584. cl->bstats.bytes += len;
  585. /*
  586. * (now - last) is total time between packet right edges.
  587. * (last_pktlen/rate) is "virtual" busy time, so that
  588. *
  589. * idle = (now - last) - last_pktlen/rate
  590. */
  591. idle = q->now - cl->last;
  592. if ((unsigned long)idle > 128*1024*1024) {
  593. avgidle = cl->maxidle;
  594. } else {
  595. idle -= L2T(cl, len);
  596. /* true_avgidle := (1-W)*true_avgidle + W*idle,
  597. * where W=2^{-ewma_log}. But cl->avgidle is scaled:
  598. * cl->avgidle == true_avgidle/W,
  599. * hence:
  600. */
  601. avgidle += idle - (avgidle>>cl->ewma_log);
  602. }
  603. if (avgidle <= 0) {
  604. /* Overlimit or at-limit */
  605. if (avgidle < cl->minidle)
  606. avgidle = cl->minidle;
  607. cl->avgidle = avgidle;
  608. /* Calculate expected time, when this class
  609. * will be allowed to send.
  610. * It will occur, when:
  611. * (1-W)*true_avgidle + W*delay = 0, i.e.
  612. * idle = (1/W - 1)*(-true_avgidle)
  613. * or
  614. * idle = (1 - W)*(-cl->avgidle);
  615. */
  616. idle = (-avgidle) - ((-avgidle) >> cl->ewma_log);
  617. /*
  618. * That is not all.
  619. * To maintain the rate allocated to the class,
  620. * we add to undertime virtual clock,
  621. * necessary to complete transmitted packet.
  622. * (len/phys_bandwidth has been already passed
  623. * to the moment of cbq_update)
  624. */
  625. idle -= L2T(&q->link, len);
  626. idle += L2T(cl, len);
  627. cl->undertime = q->now + idle;
  628. } else {
  629. /* Underlimit */
  630. cl->undertime = PSCHED_PASTPERFECT;
  631. if (avgidle > cl->maxidle)
  632. cl->avgidle = cl->maxidle;
  633. else
  634. cl->avgidle = avgidle;
  635. }
  636. cl->last = q->now;
  637. }
  638. cbq_update_toplevel(q, this, q->tx_borrowed);
  639. }
  640. static inline struct cbq_class *
  641. cbq_under_limit(struct cbq_class *cl)
  642. {
  643. struct cbq_sched_data *q = qdisc_priv(cl->qdisc);
  644. struct cbq_class *this_cl = cl;
  645. if (cl->tparent == NULL)
  646. return cl;
  647. if (cl->undertime == PSCHED_PASTPERFECT || q->now >= cl->undertime) {
  648. cl->delayed = 0;
  649. return cl;
  650. }
  651. do {
  652. /* It is very suspicious place. Now overlimit
  653. * action is generated for not bounded classes
  654. * only if link is completely congested.
  655. * Though it is in agree with ancestor-only paradigm,
  656. * it looks very stupid. Particularly,
  657. * it means that this chunk of code will either
  658. * never be called or result in strong amplification
  659. * of burstiness. Dangerous, silly, and, however,
  660. * no another solution exists.
  661. */
  662. cl = cl->borrow;
  663. if (!cl) {
  664. this_cl->qstats.overlimits++;
  665. this_cl->overlimit(this_cl);
  666. return NULL;
  667. }
  668. if (cl->level > q->toplevel)
  669. return NULL;
  670. } while (cl->undertime != PSCHED_PASTPERFECT && q->now < cl->undertime);
  671. cl->delayed = 0;
  672. return cl;
  673. }
  674. static inline struct sk_buff *
  675. cbq_dequeue_prio(struct Qdisc *sch, int prio)
  676. {
  677. struct cbq_sched_data *q = qdisc_priv(sch);
  678. struct cbq_class *cl_tail, *cl_prev, *cl;
  679. struct sk_buff *skb;
  680. int deficit;
  681. cl_tail = cl_prev = q->active[prio];
  682. cl = cl_prev->next_alive;
  683. do {
  684. deficit = 0;
  685. /* Start round */
  686. do {
  687. struct cbq_class *borrow = cl;
  688. if (cl->q->q.qlen &&
  689. (borrow = cbq_under_limit(cl)) == NULL)
  690. goto skip_class;
  691. if (cl->deficit <= 0) {
  692. /* Class exhausted its allotment per
  693. * this round. Switch to the next one.
  694. */
  695. deficit = 1;
  696. cl->deficit += cl->quantum;
  697. goto next_class;
  698. }
  699. skb = cl->q->dequeue(cl->q);
  700. /* Class did not give us any skb :-(
  701. * It could occur even if cl->q->q.qlen != 0
  702. * f.e. if cl->q == "tbf"
  703. */
  704. if (skb == NULL)
  705. goto skip_class;
  706. cl->deficit -= qdisc_pkt_len(skb);
  707. q->tx_class = cl;
  708. q->tx_borrowed = borrow;
  709. if (borrow != cl) {
  710. #ifndef CBQ_XSTATS_BORROWS_BYTES
  711. borrow->xstats.borrows++;
  712. cl->xstats.borrows++;
  713. #else
  714. borrow->xstats.borrows += qdisc_pkt_len(skb);
  715. cl->xstats.borrows += qdisc_pkt_len(skb);
  716. #endif
  717. }
  718. q->tx_len = qdisc_pkt_len(skb);
  719. if (cl->deficit <= 0) {
  720. q->active[prio] = cl;
  721. cl = cl->next_alive;
  722. cl->deficit += cl->quantum;
  723. }
  724. return skb;
  725. skip_class:
  726. if (cl->q->q.qlen == 0 || prio != cl->cpriority) {
  727. /* Class is empty or penalized.
  728. * Unlink it from active chain.
  729. */
  730. cl_prev->next_alive = cl->next_alive;
  731. cl->next_alive = NULL;
  732. /* Did cl_tail point to it? */
  733. if (cl == cl_tail) {
  734. /* Repair it! */
  735. cl_tail = cl_prev;
  736. /* Was it the last class in this band? */
  737. if (cl == cl_tail) {
  738. /* Kill the band! */
  739. q->active[prio] = NULL;
  740. q->activemask &= ~(1<<prio);
  741. if (cl->q->q.qlen)
  742. cbq_activate_class(cl);
  743. return NULL;
  744. }
  745. q->active[prio] = cl_tail;
  746. }
  747. if (cl->q->q.qlen)
  748. cbq_activate_class(cl);
  749. cl = cl_prev;
  750. }
  751. next_class:
  752. cl_prev = cl;
  753. cl = cl->next_alive;
  754. } while (cl_prev != cl_tail);
  755. } while (deficit);
  756. q->active[prio] = cl_prev;
  757. return NULL;
  758. }
  759. static inline struct sk_buff *
  760. cbq_dequeue_1(struct Qdisc *sch)
  761. {
  762. struct cbq_sched_data *q = qdisc_priv(sch);
  763. struct sk_buff *skb;
  764. unsigned int activemask;
  765. activemask = q->activemask & 0xFF;
  766. while (activemask) {
  767. int prio = ffz(~activemask);
  768. activemask &= ~(1<<prio);
  769. skb = cbq_dequeue_prio(sch, prio);
  770. if (skb)
  771. return skb;
  772. }
  773. return NULL;
  774. }
  775. static struct sk_buff *
  776. cbq_dequeue(struct Qdisc *sch)
  777. {
  778. struct sk_buff *skb;
  779. struct cbq_sched_data *q = qdisc_priv(sch);
  780. psched_time_t now;
  781. psched_tdiff_t incr;
  782. now = psched_get_time();
  783. incr = now - q->now_rt;
  784. if (q->tx_class) {
  785. psched_tdiff_t incr2;
  786. /* Time integrator. We calculate EOS time
  787. * by adding expected packet transmission time.
  788. * If real time is greater, we warp artificial clock,
  789. * so that:
  790. *
  791. * cbq_time = max(real_time, work);
  792. */
  793. incr2 = L2T(&q->link, q->tx_len);
  794. q->now += incr2;
  795. cbq_update(q);
  796. if ((incr -= incr2) < 0)
  797. incr = 0;
  798. }
  799. q->now += incr;
  800. q->now_rt = now;
  801. for (;;) {
  802. q->wd_expires = 0;
  803. skb = cbq_dequeue_1(sch);
  804. if (skb) {
  805. qdisc_bstats_update(sch, skb);
  806. sch->q.qlen--;
  807. qdisc_unthrottled(sch);
  808. return skb;
  809. }
  810. /* All the classes are overlimit.
  811. *
  812. * It is possible, if:
  813. *
  814. * 1. Scheduler is empty.
  815. * 2. Toplevel cutoff inhibited borrowing.
  816. * 3. Root class is overlimit.
  817. *
  818. * Reset 2d and 3d conditions and retry.
  819. *
  820. * Note, that NS and cbq-2.0 are buggy, peeking
  821. * an arbitrary class is appropriate for ancestor-only
  822. * sharing, but not for toplevel algorithm.
  823. *
  824. * Our version is better, but slower, because it requires
  825. * two passes, but it is unavoidable with top-level sharing.
  826. */
  827. if (q->toplevel == TC_CBQ_MAXLEVEL &&
  828. q->link.undertime == PSCHED_PASTPERFECT)
  829. break;
  830. q->toplevel = TC_CBQ_MAXLEVEL;
  831. q->link.undertime = PSCHED_PASTPERFECT;
  832. }
  833. /* No packets in scheduler or nobody wants to give them to us :-(
  834. * Sigh... start watchdog timer in the last case.
  835. */
  836. if (sch->q.qlen) {
  837. sch->qstats.overlimits++;
  838. if (q->wd_expires)
  839. qdisc_watchdog_schedule(&q->watchdog,
  840. now + q->wd_expires);
  841. }
  842. return NULL;
  843. }
  844. /* CBQ class maintanance routines */
  845. static void cbq_adjust_levels(struct cbq_class *this)
  846. {
  847. if (this == NULL)
  848. return;
  849. do {
  850. int level = 0;
  851. struct cbq_class *cl;
  852. cl = this->children;
  853. if (cl) {
  854. do {
  855. if (cl->level > level)
  856. level = cl->level;
  857. } while ((cl = cl->sibling) != this->children);
  858. }
  859. this->level = level + 1;
  860. } while ((this = this->tparent) != NULL);
  861. }
  862. static void cbq_normalize_quanta(struct cbq_sched_data *q, int prio)
  863. {
  864. struct cbq_class *cl;
  865. struct hlist_node *n;
  866. unsigned int h;
  867. if (q->quanta[prio] == 0)
  868. return;
  869. for (h = 0; h < q->clhash.hashsize; h++) {
  870. hlist_for_each_entry(cl, n, &q->clhash.hash[h], common.hnode) {
  871. /* BUGGGG... Beware! This expression suffer of
  872. * arithmetic overflows!
  873. */
  874. if (cl->priority == prio) {
  875. cl->quantum = (cl->weight*cl->allot*q->nclasses[prio])/
  876. q->quanta[prio];
  877. }
  878. if (cl->quantum <= 0 || cl->quantum>32*qdisc_dev(cl->qdisc)->mtu) {
  879. pr_warning("CBQ: class %08x has bad quantum==%ld, repaired.\n",
  880. cl->common.classid, cl->quantum);
  881. cl->quantum = qdisc_dev(cl->qdisc)->mtu/2 + 1;
  882. }
  883. }
  884. }
  885. }
  886. static void cbq_sync_defmap(struct cbq_class *cl)
  887. {
  888. struct cbq_sched_data *q = qdisc_priv(cl->qdisc);
  889. struct cbq_class *split = cl->split;
  890. unsigned int h;
  891. int i;
  892. if (split == NULL)
  893. return;
  894. for (i = 0; i <= TC_PRIO_MAX; i++) {
  895. if (split->defaults[i] == cl && !(cl->defmap & (1<<i)))
  896. split->defaults[i] = NULL;
  897. }
  898. for (i = 0; i <= TC_PRIO_MAX; i++) {
  899. int level = split->level;
  900. if (split->defaults[i])
  901. continue;
  902. for (h = 0; h < q->clhash.hashsize; h++) {
  903. struct hlist_node *n;
  904. struct cbq_class *c;
  905. hlist_for_each_entry(c, n, &q->clhash.hash[h],
  906. common.hnode) {
  907. if (c->split == split && c->level < level &&
  908. c->defmap & (1<<i)) {
  909. split->defaults[i] = c;
  910. level = c->level;
  911. }
  912. }
  913. }
  914. }
  915. }
  916. static void cbq_change_defmap(struct cbq_class *cl, u32 splitid, u32 def, u32 mask)
  917. {
  918. struct cbq_class *split = NULL;
  919. if (splitid == 0) {
  920. split = cl->split;
  921. if (!split)
  922. return;
  923. splitid = split->common.classid;
  924. }
  925. if (split == NULL || split->common.classid != splitid) {
  926. for (split = cl->tparent; split; split = split->tparent)
  927. if (split->common.classid == splitid)
  928. break;
  929. }
  930. if (split == NULL)
  931. return;
  932. if (cl->split != split) {
  933. cl->defmap = 0;
  934. cbq_sync_defmap(cl);
  935. cl->split = split;
  936. cl->defmap = def & mask;
  937. } else
  938. cl->defmap = (cl->defmap & ~mask) | (def & mask);
  939. cbq_sync_defmap(cl);
  940. }
  941. static void cbq_unlink_class(struct cbq_class *this)
  942. {
  943. struct cbq_class *cl, **clp;
  944. struct cbq_sched_data *q = qdisc_priv(this->qdisc);
  945. qdisc_class_hash_remove(&q->clhash, &this->common);
  946. if (this->tparent) {
  947. clp = &this->sibling;
  948. cl = *clp;
  949. do {
  950. if (cl == this) {
  951. *clp = cl->sibling;
  952. break;
  953. }
  954. clp = &cl->sibling;
  955. } while ((cl = *clp) != this->sibling);
  956. if (this->tparent->children == this) {
  957. this->tparent->children = this->sibling;
  958. if (this->sibling == this)
  959. this->tparent->children = NULL;
  960. }
  961. } else {
  962. WARN_ON(this->sibling != this);
  963. }
  964. }
  965. static void cbq_link_class(struct cbq_class *this)
  966. {
  967. struct cbq_sched_data *q = qdisc_priv(this->qdisc);
  968. struct cbq_class *parent = this->tparent;
  969. this->sibling = this;
  970. qdisc_class_hash_insert(&q->clhash, &this->common);
  971. if (parent == NULL)
  972. return;
  973. if (parent->children == NULL) {
  974. parent->children = this;
  975. } else {
  976. this->sibling = parent->children->sibling;
  977. parent->children->sibling = this;
  978. }
  979. }
  980. static unsigned int cbq_drop(struct Qdisc *sch)
  981. {
  982. struct cbq_sched_data *q = qdisc_priv(sch);
  983. struct cbq_class *cl, *cl_head;
  984. int prio;
  985. unsigned int len;
  986. for (prio = TC_CBQ_MAXPRIO; prio >= 0; prio--) {
  987. cl_head = q->active[prio];
  988. if (!cl_head)
  989. continue;
  990. cl = cl_head;
  991. do {
  992. if (cl->q->ops->drop && (len = cl->q->ops->drop(cl->q))) {
  993. sch->q.qlen--;
  994. if (!cl->q->q.qlen)
  995. cbq_deactivate_class(cl);
  996. return len;
  997. }
  998. } while ((cl = cl->next_alive) != cl_head);
  999. }
  1000. return 0;
  1001. }
  1002. static void
  1003. cbq_reset(struct Qdisc *sch)
  1004. {
  1005. struct cbq_sched_data *q = qdisc_priv(sch);
  1006. struct cbq_class *cl;
  1007. struct hlist_node *n;
  1008. int prio;
  1009. unsigned int h;
  1010. q->activemask = 0;
  1011. q->pmask = 0;
  1012. q->tx_class = NULL;
  1013. q->tx_borrowed = NULL;
  1014. qdisc_watchdog_cancel(&q->watchdog);
  1015. hrtimer_cancel(&q->delay_timer);
  1016. q->toplevel = TC_CBQ_MAXLEVEL;
  1017. q->now = psched_get_time();
  1018. q->now_rt = q->now;
  1019. for (prio = 0; prio <= TC_CBQ_MAXPRIO; prio++)
  1020. q->active[prio] = NULL;
  1021. for (h = 0; h < q->clhash.hashsize; h++) {
  1022. hlist_for_each_entry(cl, n, &q->clhash.hash[h], common.hnode) {
  1023. qdisc_reset(cl->q);
  1024. cl->next_alive = NULL;
  1025. cl->undertime = PSCHED_PASTPERFECT;
  1026. cl->avgidle = cl->maxidle;
  1027. cl->deficit = cl->quantum;
  1028. cl->cpriority = cl->priority;
  1029. }
  1030. }
  1031. sch->q.qlen = 0;
  1032. }
  1033. static int cbq_set_lss(struct cbq_class *cl, struct tc_cbq_lssopt *lss)
  1034. {
  1035. if (lss->change & TCF_CBQ_LSS_FLAGS) {
  1036. cl->share = (lss->flags & TCF_CBQ_LSS_ISOLATED) ? NULL : cl->tparent;
  1037. cl->borrow = (lss->flags & TCF_CBQ_LSS_BOUNDED) ? NULL : cl->tparent;
  1038. }
  1039. if (lss->change & TCF_CBQ_LSS_EWMA)
  1040. cl->ewma_log = lss->ewma_log;
  1041. if (lss->change & TCF_CBQ_LSS_AVPKT)
  1042. cl->avpkt = lss->avpkt;
  1043. if (lss->change & TCF_CBQ_LSS_MINIDLE)
  1044. cl->minidle = -(long)lss->minidle;
  1045. if (lss->change & TCF_CBQ_LSS_MAXIDLE) {
  1046. cl->maxidle = lss->maxidle;
  1047. cl->avgidle = lss->maxidle;
  1048. }
  1049. if (lss->change & TCF_CBQ_LSS_OFFTIME)
  1050. cl->offtime = lss->offtime;
  1051. return 0;
  1052. }
  1053. static void cbq_rmprio(struct cbq_sched_data *q, struct cbq_class *cl)
  1054. {
  1055. q->nclasses[cl->priority]--;
  1056. q->quanta[cl->priority] -= cl->weight;
  1057. cbq_normalize_quanta(q, cl->priority);
  1058. }
  1059. static void cbq_addprio(struct cbq_sched_data *q, struct cbq_class *cl)
  1060. {
  1061. q->nclasses[cl->priority]++;
  1062. q->quanta[cl->priority] += cl->weight;
  1063. cbq_normalize_quanta(q, cl->priority);
  1064. }
  1065. static int cbq_set_wrr(struct cbq_class *cl, struct tc_cbq_wrropt *wrr)
  1066. {
  1067. struct cbq_sched_data *q = qdisc_priv(cl->qdisc);
  1068. if (wrr->allot)
  1069. cl->allot = wrr->allot;
  1070. if (wrr->weight)
  1071. cl->weight = wrr->weight;
  1072. if (wrr->priority) {
  1073. cl->priority = wrr->priority - 1;
  1074. cl->cpriority = cl->priority;
  1075. if (cl->priority >= cl->priority2)
  1076. cl->priority2 = TC_CBQ_MAXPRIO - 1;
  1077. }
  1078. cbq_addprio(q, cl);
  1079. return 0;
  1080. }
  1081. static int cbq_set_overlimit(struct cbq_class *cl, struct tc_cbq_ovl *ovl)
  1082. {
  1083. switch (ovl->strategy) {
  1084. case TC_CBQ_OVL_CLASSIC:
  1085. cl->overlimit = cbq_ovl_classic;
  1086. break;
  1087. case TC_CBQ_OVL_DELAY:
  1088. cl->overlimit = cbq_ovl_delay;
  1089. break;
  1090. case TC_CBQ_OVL_LOWPRIO:
  1091. if (ovl->priority2 - 1 >= TC_CBQ_MAXPRIO ||
  1092. ovl->priority2 - 1 <= cl->priority)
  1093. return -EINVAL;
  1094. cl->priority2 = ovl->priority2 - 1;
  1095. cl->overlimit = cbq_ovl_lowprio;
  1096. break;
  1097. case TC_CBQ_OVL_DROP:
  1098. cl->overlimit = cbq_ovl_drop;
  1099. break;
  1100. case TC_CBQ_OVL_RCLASSIC:
  1101. cl->overlimit = cbq_ovl_rclassic;
  1102. break;
  1103. default:
  1104. return -EINVAL;
  1105. }
  1106. cl->penalty = ovl->penalty;
  1107. return 0;
  1108. }
  1109. #ifdef CONFIG_NET_CLS_ACT
  1110. static int cbq_set_police(struct cbq_class *cl, struct tc_cbq_police *p)
  1111. {
  1112. cl->police = p->police;
  1113. if (cl->q->handle) {
  1114. if (p->police == TC_POLICE_RECLASSIFY)
  1115. cl->q->reshape_fail = cbq_reshape_fail;
  1116. else
  1117. cl->q->reshape_fail = NULL;
  1118. }
  1119. return 0;
  1120. }
  1121. #endif
  1122. static int cbq_set_fopt(struct cbq_class *cl, struct tc_cbq_fopt *fopt)
  1123. {
  1124. cbq_change_defmap(cl, fopt->split, fopt->defmap, fopt->defchange);
  1125. return 0;
  1126. }
  1127. static const struct nla_policy cbq_policy[TCA_CBQ_MAX + 1] = {
  1128. [TCA_CBQ_LSSOPT] = { .len = sizeof(struct tc_cbq_lssopt) },
  1129. [TCA_CBQ_WRROPT] = { .len = sizeof(struct tc_cbq_wrropt) },
  1130. [TCA_CBQ_FOPT] = { .len = sizeof(struct tc_cbq_fopt) },
  1131. [TCA_CBQ_OVL_STRATEGY] = { .len = sizeof(struct tc_cbq_ovl) },
  1132. [TCA_CBQ_RATE] = { .len = sizeof(struct tc_ratespec) },
  1133. [TCA_CBQ_RTAB] = { .type = NLA_BINARY, .len = TC_RTAB_SIZE },
  1134. [TCA_CBQ_POLICE] = { .len = sizeof(struct tc_cbq_police) },
  1135. };
  1136. static int cbq_init(struct Qdisc *sch, struct nlattr *opt)
  1137. {
  1138. struct cbq_sched_data *q = qdisc_priv(sch);
  1139. struct nlattr *tb[TCA_CBQ_MAX + 1];
  1140. struct tc_ratespec *r;
  1141. int err;
  1142. err = nla_parse_nested(tb, TCA_CBQ_MAX, opt, cbq_policy);
  1143. if (err < 0)
  1144. return err;
  1145. if (tb[TCA_CBQ_RTAB] == NULL || tb[TCA_CBQ_RATE] == NULL)
  1146. return -EINVAL;
  1147. r = nla_data(tb[TCA_CBQ_RATE]);
  1148. if ((q->link.R_tab = qdisc_get_rtab(r, tb[TCA_CBQ_RTAB])) == NULL)
  1149. return -EINVAL;
  1150. err = qdisc_class_hash_init(&q->clhash);
  1151. if (err < 0)
  1152. goto put_rtab;
  1153. q->link.refcnt = 1;
  1154. q->link.sibling = &q->link;
  1155. q->link.common.classid = sch->handle;
  1156. q->link.qdisc = sch;
  1157. q->link.q = qdisc_create_dflt(sch->dev_queue, &pfifo_qdisc_ops,
  1158. sch->handle);
  1159. if (!q->link.q)
  1160. q->link.q = &noop_qdisc;
  1161. q->link.priority = TC_CBQ_MAXPRIO - 1;
  1162. q->link.priority2 = TC_CBQ_MAXPRIO - 1;
  1163. q->link.cpriority = TC_CBQ_MAXPRIO - 1;
  1164. q->link.ovl_strategy = TC_CBQ_OVL_CLASSIC;
  1165. q->link.overlimit = cbq_ovl_classic;
  1166. q->link.allot = psched_mtu(qdisc_dev(sch));
  1167. q->link.quantum = q->link.allot;
  1168. q->link.weight = q->link.R_tab->rate.rate;
  1169. q->link.ewma_log = TC_CBQ_DEF_EWMA;
  1170. q->link.avpkt = q->link.allot/2;
  1171. q->link.minidle = -0x7FFFFFFF;
  1172. qdisc_watchdog_init(&q->watchdog, sch);
  1173. hrtimer_init(&q->delay_timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
  1174. q->delay_timer.function = cbq_undelay;
  1175. q->toplevel = TC_CBQ_MAXLEVEL;
  1176. q->now = psched_get_time();
  1177. q->now_rt = q->now;
  1178. cbq_link_class(&q->link);
  1179. if (tb[TCA_CBQ_LSSOPT])
  1180. cbq_set_lss(&q->link, nla_data(tb[TCA_CBQ_LSSOPT]));
  1181. cbq_addprio(q, &q->link);
  1182. return 0;
  1183. put_rtab:
  1184. qdisc_put_rtab(q->link.R_tab);
  1185. return err;
  1186. }
  1187. static int cbq_dump_rate(struct sk_buff *skb, struct cbq_class *cl)
  1188. {
  1189. unsigned char *b = skb_tail_pointer(skb);
  1190. NLA_PUT(skb, TCA_CBQ_RATE, sizeof(cl->R_tab->rate), &cl->R_tab->rate);
  1191. return skb->len;
  1192. nla_put_failure:
  1193. nlmsg_trim(skb, b);
  1194. return -1;
  1195. }
  1196. static int cbq_dump_lss(struct sk_buff *skb, struct cbq_class *cl)
  1197. {
  1198. unsigned char *b = skb_tail_pointer(skb);
  1199. struct tc_cbq_lssopt opt;
  1200. opt.flags = 0;
  1201. if (cl->borrow == NULL)
  1202. opt.flags |= TCF_CBQ_LSS_BOUNDED;
  1203. if (cl->share == NULL)
  1204. opt.flags |= TCF_CBQ_LSS_ISOLATED;
  1205. opt.ewma_log = cl->ewma_log;
  1206. opt.level = cl->level;
  1207. opt.avpkt = cl->avpkt;
  1208. opt.maxidle = cl->maxidle;
  1209. opt.minidle = (u32)(-cl->minidle);
  1210. opt.offtime = cl->offtime;
  1211. opt.change = ~0;
  1212. NLA_PUT(skb, TCA_CBQ_LSSOPT, sizeof(opt), &opt);
  1213. return skb->len;
  1214. nla_put_failure:
  1215. nlmsg_trim(skb, b);
  1216. return -1;
  1217. }
  1218. static int cbq_dump_wrr(struct sk_buff *skb, struct cbq_class *cl)
  1219. {
  1220. unsigned char *b = skb_tail_pointer(skb);
  1221. struct tc_cbq_wrropt opt;
  1222. opt.flags = 0;
  1223. opt.allot = cl->allot;
  1224. opt.priority = cl->priority + 1;
  1225. opt.cpriority = cl->cpriority + 1;
  1226. opt.weight = cl->weight;
  1227. NLA_PUT(skb, TCA_CBQ_WRROPT, sizeof(opt), &opt);
  1228. return skb->len;
  1229. nla_put_failure:
  1230. nlmsg_trim(skb, b);
  1231. return -1;
  1232. }
  1233. static int cbq_dump_ovl(struct sk_buff *skb, struct cbq_class *cl)
  1234. {
  1235. unsigned char *b = skb_tail_pointer(skb);
  1236. struct tc_cbq_ovl opt;
  1237. opt.strategy = cl->ovl_strategy;
  1238. opt.priority2 = cl->priority2 + 1;
  1239. opt.pad = 0;
  1240. opt.penalty = cl->penalty;
  1241. NLA_PUT(skb, TCA_CBQ_OVL_STRATEGY, sizeof(opt), &opt);
  1242. return skb->len;
  1243. nla_put_failure:
  1244. nlmsg_trim(skb, b);
  1245. return -1;
  1246. }
  1247. static int cbq_dump_fopt(struct sk_buff *skb, struct cbq_class *cl)
  1248. {
  1249. unsigned char *b = skb_tail_pointer(skb);
  1250. struct tc_cbq_fopt opt;
  1251. if (cl->split || cl->defmap) {
  1252. opt.split = cl->split ? cl->split->common.classid : 0;
  1253. opt.defmap = cl->defmap;
  1254. opt.defchange = ~0;
  1255. NLA_PUT(skb, TCA_CBQ_FOPT, sizeof(opt), &opt);
  1256. }
  1257. return skb->len;
  1258. nla_put_failure:
  1259. nlmsg_trim(skb, b);
  1260. return -1;
  1261. }
  1262. #ifdef CONFIG_NET_CLS_ACT
  1263. static int cbq_dump_police(struct sk_buff *skb, struct cbq_class *cl)
  1264. {
  1265. unsigned char *b = skb_tail_pointer(skb);
  1266. struct tc_cbq_police opt;
  1267. if (cl->police) {
  1268. opt.police = cl->police;
  1269. opt.__res1 = 0;
  1270. opt.__res2 = 0;
  1271. NLA_PUT(skb, TCA_CBQ_POLICE, sizeof(opt), &opt);
  1272. }
  1273. return skb->len;
  1274. nla_put_failure:
  1275. nlmsg_trim(skb, b);
  1276. return -1;
  1277. }
  1278. #endif
  1279. static int cbq_dump_attr(struct sk_buff *skb, struct cbq_class *cl)
  1280. {
  1281. if (cbq_dump_lss(skb, cl) < 0 ||
  1282. cbq_dump_rate(skb, cl) < 0 ||
  1283. cbq_dump_wrr(skb, cl) < 0 ||
  1284. cbq_dump_ovl(skb, cl) < 0 ||
  1285. #ifdef CONFIG_NET_CLS_ACT
  1286. cbq_dump_police(skb, cl) < 0 ||
  1287. #endif
  1288. cbq_dump_fopt(skb, cl) < 0)
  1289. return -1;
  1290. return 0;
  1291. }
  1292. static int cbq_dump(struct Qdisc *sch, struct sk_buff *skb)
  1293. {
  1294. struct cbq_sched_data *q = qdisc_priv(sch);
  1295. struct nlattr *nest;
  1296. nest = nla_nest_start(skb, TCA_OPTIONS);
  1297. if (nest == NULL)
  1298. goto nla_put_failure;
  1299. if (cbq_dump_attr(skb, &q->link) < 0)
  1300. goto nla_put_failure;
  1301. nla_nest_end(skb, nest);
  1302. return skb->len;
  1303. nla_put_failure:
  1304. nla_nest_cancel(skb, nest);
  1305. return -1;
  1306. }
  1307. static int
  1308. cbq_dump_stats(struct Qdisc *sch, struct gnet_dump *d)
  1309. {
  1310. struct cbq_sched_data *q = qdisc_priv(sch);
  1311. q->link.xstats.avgidle = q->link.avgidle;
  1312. return gnet_stats_copy_app(d, &q->link.xstats, sizeof(q->link.xstats));
  1313. }
  1314. static int
  1315. cbq_dump_class(struct Qdisc *sch, unsigned long arg,
  1316. struct sk_buff *skb, struct tcmsg *tcm)
  1317. {
  1318. struct cbq_class *cl = (struct cbq_class *)arg;
  1319. struct nlattr *nest;
  1320. if (cl->tparent)
  1321. tcm->tcm_parent = cl->tparent->common.classid;
  1322. else
  1323. tcm->tcm_parent = TC_H_ROOT;
  1324. tcm->tcm_handle = cl->common.classid;
  1325. tcm->tcm_info = cl->q->handle;
  1326. nest = nla_nest_start(skb, TCA_OPTIONS);
  1327. if (nest == NULL)
  1328. goto nla_put_failure;
  1329. if (cbq_dump_attr(skb, cl) < 0)
  1330. goto nla_put_failure;
  1331. nla_nest_end(skb, nest);
  1332. return skb->len;
  1333. nla_put_failure:
  1334. nla_nest_cancel(skb, nest);
  1335. return -1;
  1336. }
  1337. static int
  1338. cbq_dump_class_stats(struct Qdisc *sch, unsigned long arg,
  1339. struct gnet_dump *d)
  1340. {
  1341. struct cbq_sched_data *q = qdisc_priv(sch);
  1342. struct cbq_class *cl = (struct cbq_class *)arg;
  1343. cl->qstats.qlen = cl->q->q.qlen;
  1344. cl->xstats.avgidle = cl->avgidle;
  1345. cl->xstats.undertime = 0;
  1346. if (cl->undertime != PSCHED_PASTPERFECT)
  1347. cl->xstats.undertime = cl->undertime - q->now;
  1348. if (gnet_stats_copy_basic(d, &cl->bstats) < 0 ||
  1349. gnet_stats_copy_rate_est(d, &cl->bstats, &cl->rate_est) < 0 ||
  1350. gnet_stats_copy_queue(d, &cl->qstats) < 0)
  1351. return -1;
  1352. return gnet_stats_copy_app(d, &cl->xstats, sizeof(cl->xstats));
  1353. }
  1354. static int cbq_graft(struct Qdisc *sch, unsigned long arg, struct Qdisc *new,
  1355. struct Qdisc **old)
  1356. {
  1357. struct cbq_class *cl = (struct cbq_class *)arg;
  1358. if (new == NULL) {
  1359. new = qdisc_create_dflt(sch->dev_queue,
  1360. &pfifo_qdisc_ops, cl->common.classid);
  1361. if (new == NULL)
  1362. return -ENOBUFS;
  1363. } else {
  1364. #ifdef CONFIG_NET_CLS_ACT
  1365. if (cl->police == TC_POLICE_RECLASSIFY)
  1366. new->reshape_fail = cbq_reshape_fail;
  1367. #endif
  1368. }
  1369. sch_tree_lock(sch);
  1370. *old = cl->q;
  1371. cl->q = new;
  1372. qdisc_tree_decrease_qlen(*old, (*old)->q.qlen);
  1373. qdisc_reset(*old);
  1374. sch_tree_unlock(sch);
  1375. return 0;
  1376. }
  1377. static struct Qdisc *cbq_leaf(struct Qdisc *sch, unsigned long arg)
  1378. {
  1379. struct cbq_class *cl = (struct cbq_class *)arg;
  1380. return cl->q;
  1381. }
  1382. static void cbq_qlen_notify(struct Qdisc *sch, unsigned long arg)
  1383. {
  1384. struct cbq_class *cl = (struct cbq_class *)arg;
  1385. if (cl->q->q.qlen == 0)
  1386. cbq_deactivate_class(cl);
  1387. }
  1388. static unsigned long cbq_get(struct Qdisc *sch, u32 classid)
  1389. {
  1390. struct cbq_sched_data *q = qdisc_priv(sch);
  1391. struct cbq_class *cl = cbq_class_lookup(q, classid);
  1392. if (cl) {
  1393. cl->refcnt++;
  1394. return (unsigned long)cl;
  1395. }
  1396. return 0;
  1397. }
  1398. static void cbq_destroy_class(struct Qdisc *sch, struct cbq_class *cl)
  1399. {
  1400. struct cbq_sched_data *q = qdisc_priv(sch);
  1401. WARN_ON(cl->filters);
  1402. tcf_destroy_chain(&cl->filter_list);
  1403. qdisc_destroy(cl->q);
  1404. qdisc_put_rtab(cl->R_tab);
  1405. gen_kill_estimator(&cl->bstats, &cl->rate_est);
  1406. if (cl != &q->link)
  1407. kfree(cl);
  1408. }
  1409. static void cbq_destroy(struct Qdisc *sch)
  1410. {
  1411. struct cbq_sched_data *q = qdisc_priv(sch);
  1412. struct hlist_node *n, *next;
  1413. struct cbq_class *cl;
  1414. unsigned int h;
  1415. #ifdef CONFIG_NET_CLS_ACT
  1416. q->rx_class = NULL;
  1417. #endif
  1418. /*
  1419. * Filters must be destroyed first because we don't destroy the
  1420. * classes from root to leafs which means that filters can still
  1421. * be bound to classes which have been destroyed already. --TGR '04
  1422. */
  1423. for (h = 0; h < q->clhash.hashsize; h++) {
  1424. hlist_for_each_entry(cl, n, &q->clhash.hash[h], common.hnode)
  1425. tcf_destroy_chain(&cl->filter_list);
  1426. }
  1427. for (h = 0; h < q->clhash.hashsize; h++) {
  1428. hlist_for_each_entry_safe(cl, n, next, &q->clhash.hash[h],
  1429. common.hnode)
  1430. cbq_destroy_class(sch, cl);
  1431. }
  1432. qdisc_class_hash_destroy(&q->clhash);
  1433. }
  1434. static void cbq_put(struct Qdisc *sch, unsigned long arg)
  1435. {
  1436. struct cbq_class *cl = (struct cbq_class *)arg;
  1437. if (--cl->refcnt == 0) {
  1438. #ifdef CONFIG_NET_CLS_ACT
  1439. spinlock_t *root_lock = qdisc_root_sleeping_lock(sch);
  1440. struct cbq_sched_data *q = qdisc_priv(sch);
  1441. spin_lock_bh(root_lock);
  1442. if (q->rx_class == cl)
  1443. q->rx_class = NULL;
  1444. spin_unlock_bh(root_lock);
  1445. #endif
  1446. cbq_destroy_class(sch, cl);
  1447. }
  1448. }
  1449. static int
  1450. cbq_change_class(struct Qdisc *sch, u32 classid, u32 parentid, struct nlattr **tca,
  1451. unsigned long *arg)
  1452. {
  1453. int err;
  1454. struct cbq_sched_data *q = qdisc_priv(sch);
  1455. struct cbq_class *cl = (struct cbq_class *)*arg;
  1456. struct nlattr *opt = tca[TCA_OPTIONS];
  1457. struct nlattr *tb[TCA_CBQ_MAX + 1];
  1458. struct cbq_class *parent;
  1459. struct qdisc_rate_table *rtab = NULL;
  1460. if (opt == NULL)
  1461. return -EINVAL;
  1462. err = nla_parse_nested(tb, TCA_CBQ_MAX, opt, cbq_policy);
  1463. if (err < 0)
  1464. return err;
  1465. if (cl) {
  1466. /* Check parent */
  1467. if (parentid) {
  1468. if (cl->tparent &&
  1469. cl->tparent->common.classid != parentid)
  1470. return -EINVAL;
  1471. if (!cl->tparent && parentid != TC_H_ROOT)
  1472. return -EINVAL;
  1473. }
  1474. if (tb[TCA_CBQ_RATE]) {
  1475. rtab = qdisc_get_rtab(nla_data(tb[TCA_CBQ_RATE]),
  1476. tb[TCA_CBQ_RTAB]);
  1477. if (rtab == NULL)
  1478. return -EINVAL;
  1479. }
  1480. if (tca[TCA_RATE]) {
  1481. err = gen_replace_estimator(&cl->bstats, &cl->rate_est,
  1482. qdisc_root_sleeping_lock(sch),
  1483. tca[TCA_RATE]);
  1484. if (err) {
  1485. if (rtab)
  1486. qdisc_put_rtab(rtab);
  1487. return err;
  1488. }
  1489. }
  1490. /* Change class parameters */
  1491. sch_tree_lock(sch);
  1492. if (cl->next_alive != NULL)
  1493. cbq_deactivate_class(cl);
  1494. if (rtab) {
  1495. qdisc_put_rtab(cl->R_tab);
  1496. cl->R_tab = rtab;
  1497. }
  1498. if (tb[TCA_CBQ_LSSOPT])
  1499. cbq_set_lss(cl, nla_data(tb[TCA_CBQ_LSSOPT]));
  1500. if (tb[TCA_CBQ_WRROPT]) {
  1501. cbq_rmprio(q, cl);
  1502. cbq_set_wrr(cl, nla_data(tb[TCA_CBQ_WRROPT]));
  1503. }
  1504. if (tb[TCA_CBQ_OVL_STRATEGY])
  1505. cbq_set_overlimit(cl, nla_data(tb[TCA_CBQ_OVL_STRATEGY]));
  1506. #ifdef CONFIG_NET_CLS_ACT
  1507. if (tb[TCA_CBQ_POLICE])
  1508. cbq_set_police(cl, nla_data(tb[TCA_CBQ_POLICE]));
  1509. #endif
  1510. if (tb[TCA_CBQ_FOPT])
  1511. cbq_set_fopt(cl, nla_data(tb[TCA_CBQ_FOPT]));
  1512. if (cl->q->q.qlen)
  1513. cbq_activate_class(cl);
  1514. sch_tree_unlock(sch);
  1515. return 0;
  1516. }
  1517. if (parentid == TC_H_ROOT)
  1518. return -EINVAL;
  1519. if (tb[TCA_CBQ_WRROPT] == NULL || tb[TCA_CBQ_RATE] == NULL ||
  1520. tb[TCA_CBQ_LSSOPT] == NULL)
  1521. return -EINVAL;
  1522. rtab = qdisc_get_rtab(nla_data(tb[TCA_CBQ_RATE]), tb[TCA_CBQ_RTAB]);
  1523. if (rtab == NULL)
  1524. return -EINVAL;
  1525. if (classid) {
  1526. err = -EINVAL;
  1527. if (TC_H_MAJ(classid ^ sch->handle) ||
  1528. cbq_class_lookup(q, classid))
  1529. goto failure;
  1530. } else {
  1531. int i;
  1532. classid = TC_H_MAKE(sch->handle, 0x8000);
  1533. for (i = 0; i < 0x8000; i++) {
  1534. if (++q->hgenerator >= 0x8000)
  1535. q->hgenerator = 1;
  1536. if (cbq_class_lookup(q, classid|q->hgenerator) == NULL)
  1537. break;
  1538. }
  1539. err = -ENOSR;
  1540. if (i >= 0x8000)
  1541. goto failure;
  1542. classid = classid|q->hgenerator;
  1543. }
  1544. parent = &q->link;
  1545. if (parentid) {
  1546. parent = cbq_class_lookup(q, parentid);
  1547. err = -EINVAL;
  1548. if (parent == NULL)
  1549. goto failure;
  1550. }
  1551. err = -ENOBUFS;
  1552. cl = kzalloc(sizeof(*cl), GFP_KERNEL);
  1553. if (cl == NULL)
  1554. goto failure;
  1555. if (tca[TCA_RATE]) {
  1556. err = gen_new_estimator(&cl->bstats, &cl->rate_est,
  1557. qdisc_root_sleeping_lock(sch),
  1558. tca[TCA_RATE]);
  1559. if (err) {
  1560. kfree(cl);
  1561. goto failure;
  1562. }
  1563. }
  1564. cl->R_tab = rtab;
  1565. rtab = NULL;
  1566. cl->refcnt = 1;
  1567. cl->q = qdisc_create_dflt(sch->dev_queue, &pfifo_qdisc_ops, classid);
  1568. if (!cl->q)
  1569. cl->q = &noop_qdisc;
  1570. cl->common.classid = classid;
  1571. cl->tparent = parent;
  1572. cl->qdisc = sch;
  1573. cl->allot = parent->allot;
  1574. cl->quantum = cl->allot;
  1575. cl->weight = cl->R_tab->rate.rate;
  1576. sch_tree_lock(sch);
  1577. cbq_link_class(cl);
  1578. cl->borrow = cl->tparent;
  1579. if (cl->tparent != &q->link)
  1580. cl->share = cl->tparent;
  1581. cbq_adjust_levels(parent);
  1582. cl->minidle = -0x7FFFFFFF;
  1583. cbq_set_lss(cl, nla_data(tb[TCA_CBQ_LSSOPT]));
  1584. cbq_set_wrr(cl, nla_data(tb[TCA_CBQ_WRROPT]));
  1585. if (cl->ewma_log == 0)
  1586. cl->ewma_log = q->link.ewma_log;
  1587. if (cl->maxidle == 0)
  1588. cl->maxidle = q->link.maxidle;
  1589. if (cl->avpkt == 0)
  1590. cl->avpkt = q->link.avpkt;
  1591. cl->overlimit = cbq_ovl_classic;
  1592. if (tb[TCA_CBQ_OVL_STRATEGY])
  1593. cbq_set_overlimit(cl, nla_data(tb[TCA_CBQ_OVL_STRATEGY]));
  1594. #ifdef CONFIG_NET_CLS_ACT
  1595. if (tb[TCA_CBQ_POLICE])
  1596. cbq_set_police(cl, nla_data(tb[TCA_CBQ_POLICE]));
  1597. #endif
  1598. if (tb[TCA_CBQ_FOPT])
  1599. cbq_set_fopt(cl, nla_data(tb[TCA_CBQ_FOPT]));
  1600. sch_tree_unlock(sch);
  1601. qdisc_class_hash_grow(sch, &q->clhash);
  1602. *arg = (unsigned long)cl;
  1603. return 0;
  1604. failure:
  1605. qdisc_put_rtab(rtab);
  1606. return err;
  1607. }
  1608. static int cbq_delete(struct Qdisc *sch, unsigned long arg)
  1609. {
  1610. struct cbq_sched_data *q = qdisc_priv(sch);
  1611. struct cbq_class *cl = (struct cbq_class *)arg;
  1612. unsigned int qlen;
  1613. if (cl->filters || cl->children || cl == &q->link)
  1614. return -EBUSY;
  1615. sch_tree_lock(sch);
  1616. qlen = cl->q->q.qlen;
  1617. qdisc_reset(cl->q);
  1618. qdisc_tree_decrease_qlen(cl->q, qlen);
  1619. if (cl->next_alive)
  1620. cbq_deactivate_class(cl);
  1621. if (q->tx_borrowed == cl)
  1622. q->tx_borrowed = q->tx_class;
  1623. if (q->tx_class == cl) {
  1624. q->tx_class = NULL;
  1625. q->tx_borrowed = NULL;
  1626. }
  1627. #ifdef CONFIG_NET_CLS_ACT
  1628. if (q->rx_class == cl)
  1629. q->rx_class = NULL;
  1630. #endif
  1631. cbq_unlink_class(cl);
  1632. cbq_adjust_levels(cl->tparent);
  1633. cl->defmap = 0;
  1634. cbq_sync_defmap(cl);
  1635. cbq_rmprio(q, cl);
  1636. sch_tree_unlock(sch);
  1637. BUG_ON(--cl->refcnt == 0);
  1638. /*
  1639. * This shouldn't happen: we "hold" one cops->get() when called
  1640. * from tc_ctl_tclass; the destroy method is done from cops->put().
  1641. */
  1642. return 0;
  1643. }
  1644. static struct tcf_proto **cbq_find_tcf(struct Qdisc *sch, unsigned long arg)
  1645. {
  1646. struct cbq_sched_data *q = qdisc_priv(sch);
  1647. struct cbq_class *cl = (struct cbq_class *)arg;
  1648. if (cl == NULL)
  1649. cl = &q->link;
  1650. return &cl->filter_list;
  1651. }
  1652. static unsigned long cbq_bind_filter(struct Qdisc *sch, unsigned long parent,
  1653. u32 classid)
  1654. {
  1655. struct cbq_sched_data *q = qdisc_priv(sch);
  1656. struct cbq_class *p = (struct cbq_class *)parent;
  1657. struct cbq_class *cl = cbq_class_lookup(q, classid);
  1658. if (cl) {
  1659. if (p && p->level <= cl->level)
  1660. return 0;
  1661. cl->filters++;
  1662. return (unsigned long)cl;
  1663. }
  1664. return 0;
  1665. }
  1666. static void cbq_unbind_filter(struct Qdisc *sch, unsigned long arg)
  1667. {
  1668. struct cbq_class *cl = (struct cbq_class *)arg;
  1669. cl->filters--;
  1670. }
  1671. static void cbq_walk(struct Qdisc *sch, struct qdisc_walker *arg)
  1672. {
  1673. struct cbq_sched_data *q = qdisc_priv(sch);
  1674. struct cbq_class *cl;
  1675. struct hlist_node *n;
  1676. unsigned int h;
  1677. if (arg->stop)
  1678. return;
  1679. for (h = 0; h < q->clhash.hashsize; h++) {
  1680. hlist_for_each_entry(cl, n, &q->clhash.hash[h], common.hnode) {
  1681. if (arg->count < arg->skip) {
  1682. arg->count++;
  1683. continue;
  1684. }
  1685. if (arg->fn(sch, (unsigned long)cl, arg) < 0) {
  1686. arg->stop = 1;
  1687. return;
  1688. }
  1689. arg->count++;
  1690. }
  1691. }
  1692. }
  1693. static const struct Qdisc_class_ops cbq_class_ops = {
  1694. .graft = cbq_graft,
  1695. .leaf = cbq_leaf,
  1696. .qlen_notify = cbq_qlen_notify,
  1697. .get = cbq_get,
  1698. .put = cbq_put,
  1699. .change = cbq_change_class,
  1700. .delete = cbq_delete,
  1701. .walk = cbq_walk,
  1702. .tcf_chain = cbq_find_tcf,
  1703. .bind_tcf = cbq_bind_filter,
  1704. .unbind_tcf = cbq_unbind_filter,
  1705. .dump = cbq_dump_class,
  1706. .dump_stats = cbq_dump_class_stats,
  1707. };
  1708. static struct Qdisc_ops cbq_qdisc_ops __read_mostly = {
  1709. .next = NULL,
  1710. .cl_ops = &cbq_class_ops,
  1711. .id = "cbq",
  1712. .priv_size = sizeof(struct cbq_sched_data),
  1713. .enqueue = cbq_enqueue,
  1714. .dequeue = cbq_dequeue,
  1715. .peek = qdisc_peek_dequeued,
  1716. .drop = cbq_drop,
  1717. .init = cbq_init,
  1718. .reset = cbq_reset,
  1719. .destroy = cbq_destroy,
  1720. .change = NULL,
  1721. .dump = cbq_dump,
  1722. .dump_stats = cbq_dump_stats,
  1723. .owner = THIS_MODULE,
  1724. };
  1725. static int __init cbq_module_init(void)
  1726. {
  1727. return register_qdisc(&cbq_qdisc_ops);
  1728. }
  1729. static void __exit cbq_module_exit(void)
  1730. {
  1731. unregister_qdisc(&cbq_qdisc_ops);
  1732. }
  1733. module_init(cbq_module_init)
  1734. module_exit(cbq_module_exit)
  1735. MODULE_LICENSE("GPL");