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