Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * net/sched/sch_generic.c Generic packet scheduler routines. | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or | |
5 | * modify it under the terms of the GNU General Public License | |
6 | * as published by the Free Software Foundation; either version | |
7 | * 2 of the License, or (at your option) any later version. | |
8 | * | |
9 | * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru> | |
10 | * Jamal Hadi Salim, <hadi@cyberus.ca> 990601 | |
11 | * - Ingress support | |
12 | */ | |
13 | ||
1da177e4 | 14 | #include <linux/bitops.h> |
1da177e4 LT |
15 | #include <linux/module.h> |
16 | #include <linux/types.h> | |
17 | #include <linux/kernel.h> | |
18 | #include <linux/sched.h> | |
19 | #include <linux/string.h> | |
1da177e4 | 20 | #include <linux/errno.h> |
1da177e4 LT |
21 | #include <linux/netdevice.h> |
22 | #include <linux/skbuff.h> | |
23 | #include <linux/rtnetlink.h> | |
24 | #include <linux/init.h> | |
25 | #include <linux/rcupdate.h> | |
26 | #include <linux/list.h> | |
5a0e3ad6 | 27 | #include <linux/slab.h> |
07ce76aa | 28 | #include <linux/if_vlan.h> |
292f1c7f | 29 | #include <net/sch_generic.h> |
1da177e4 | 30 | #include <net/pkt_sched.h> |
7fee226a | 31 | #include <net/dst.h> |
1da177e4 | 32 | |
34aedd3f | 33 | /* Qdisc to use by default */ |
34 | const struct Qdisc_ops *default_qdisc_ops = &pfifo_fast_ops; | |
35 | EXPORT_SYMBOL(default_qdisc_ops); | |
36 | ||
1da177e4 LT |
37 | /* Main transmission queue. */ |
38 | ||
0463d4ae | 39 | /* Modifications to data participating in scheduling must be protected with |
5fb66229 | 40 | * qdisc_lock(qdisc) spinlock. |
0463d4ae PM |
41 | * |
42 | * The idea is the following: | |
c7e4f3bb DM |
43 | * - enqueue, dequeue are serialized via qdisc root lock |
44 | * - ingress filtering is also serialized via qdisc root lock | |
0463d4ae | 45 | * - updates to tree and tree walking are only done under the rtnl mutex. |
1da177e4 | 46 | */ |
1da177e4 | 47 | |
37437bb2 | 48 | static inline int dev_requeue_skb(struct sk_buff *skb, struct Qdisc *q) |
c716a81a | 49 | { |
6252352d | 50 | q->gso_skb = skb; |
53e91503 | 51 | q->qstats.requeues++; |
bbd8a0d3 | 52 | q->q.qlen++; /* it's still part of the queue */ |
37437bb2 | 53 | __netif_schedule(q); |
6252352d | 54 | |
c716a81a JHS |
55 | return 0; |
56 | } | |
57 | ||
55a93b3e ED |
58 | static void try_bulk_dequeue_skb(struct Qdisc *q, |
59 | struct sk_buff *skb, | |
b8358d70 JDB |
60 | const struct netdev_queue *txq, |
61 | int *packets) | |
5772e9a3 | 62 | { |
55a93b3e | 63 | int bytelimit = qdisc_avail_bulklimit(txq) - skb->len; |
5772e9a3 JDB |
64 | |
65 | while (bytelimit > 0) { | |
55a93b3e | 66 | struct sk_buff *nskb = q->dequeue(q); |
5772e9a3 | 67 | |
55a93b3e | 68 | if (!nskb) |
5772e9a3 JDB |
69 | break; |
70 | ||
55a93b3e ED |
71 | bytelimit -= nskb->len; /* covers GSO len */ |
72 | skb->next = nskb; | |
73 | skb = nskb; | |
b8358d70 | 74 | (*packets)++; /* GSO counts as one pkt */ |
5772e9a3 | 75 | } |
55a93b3e | 76 | skb->next = NULL; |
5772e9a3 JDB |
77 | } |
78 | ||
79 | /* Note that dequeue_skb can possibly return a SKB list (via skb->next). | |
80 | * A requeued skb (via q->gso_skb) can also be a SKB list. | |
81 | */ | |
b8358d70 JDB |
82 | static struct sk_buff *dequeue_skb(struct Qdisc *q, bool *validate, |
83 | int *packets) | |
c716a81a | 84 | { |
554794de | 85 | struct sk_buff *skb = q->gso_skb; |
1abbe139 | 86 | const struct netdev_queue *txq = q->dev_queue; |
554794de | 87 | |
b8358d70 | 88 | *packets = 1; |
55a93b3e | 89 | *validate = true; |
ebf05982 | 90 | if (unlikely(skb)) { |
ebf05982 | 91 | /* check the reason of requeuing without tx lock first */ |
10c51b56 | 92 | txq = skb_get_tx_queue(txq->dev, skb); |
73466498 | 93 | if (!netif_xmit_frozen_or_stopped(txq)) { |
6252352d | 94 | q->gso_skb = NULL; |
bbd8a0d3 KK |
95 | q->q.qlen--; |
96 | } else | |
ebf05982 | 97 | skb = NULL; |
55a93b3e ED |
98 | /* skb in gso_skb were already validated */ |
99 | *validate = false; | |
ebf05982 | 100 | } else { |
5772e9a3 JDB |
101 | if (!(q->flags & TCQ_F_ONETXQUEUE) || |
102 | !netif_xmit_frozen_or_stopped(txq)) { | |
1abbe139 | 103 | skb = q->dequeue(q); |
5772e9a3 | 104 | if (skb && qdisc_may_bulk(q)) |
b8358d70 | 105 | try_bulk_dequeue_skb(q, skb, txq, packets); |
50cbe9ab | 106 | } |
ebf05982 | 107 | } |
c716a81a JHS |
108 | return skb; |
109 | } | |
110 | ||
10297b99 | 111 | /* |
10770bc2 JDB |
112 | * Transmit possibly several skbs, and handle the return status as |
113 | * required. Holding the __QDISC___STATE_RUNNING bit guarantees that | |
114 | * only one CPU can execute this function. | |
6c1361a6 KK |
115 | * |
116 | * Returns to the caller: | |
117 | * 0 - queue is empty or throttled. | |
118 | * >0 - queue is not empty. | |
6c1361a6 | 119 | */ |
bbd8a0d3 KK |
120 | int sch_direct_xmit(struct sk_buff *skb, struct Qdisc *q, |
121 | struct net_device *dev, struct netdev_queue *txq, | |
55a93b3e | 122 | spinlock_t *root_lock, bool validate) |
1da177e4 | 123 | { |
5f1a485d | 124 | int ret = NETDEV_TX_BUSY; |
7698b4fc DM |
125 | |
126 | /* And release qdisc */ | |
127 | spin_unlock(root_lock); | |
c716a81a | 128 | |
55a93b3e ED |
129 | /* Note that we validate skb (GSO, checksum, ...) outside of locks */ |
130 | if (validate) | |
131 | skb = validate_xmit_skb_list(skb, dev); | |
572a9d7b | 132 | |
3dcd493f | 133 | if (likely(skb)) { |
55a93b3e ED |
134 | HARD_TX_LOCK(dev, txq, smp_processor_id()); |
135 | if (!netif_xmit_frozen_or_stopped(txq)) | |
136 | skb = dev_hard_start_xmit(skb, dev, txq, &ret); | |
c716a81a | 137 | |
55a93b3e | 138 | HARD_TX_UNLOCK(dev, txq); |
3dcd493f LP |
139 | } else { |
140 | spin_lock(root_lock); | |
141 | return qdisc_qlen(q); | |
55a93b3e | 142 | } |
7698b4fc | 143 | spin_lock(root_lock); |
c716a81a | 144 | |
9a1654ba JP |
145 | if (dev_xmit_complete(ret)) { |
146 | /* Driver sent out skb successfully or skb was consumed */ | |
6c1361a6 | 147 | ret = qdisc_qlen(q); |
9a1654ba | 148 | } else { |
6c1361a6 | 149 | /* Driver returned NETDEV_TX_BUSY - requeue skb */ |
e87cc472 JP |
150 | if (unlikely(ret != NETDEV_TX_BUSY)) |
151 | net_warn_ratelimited("BUG %s code %d qlen %d\n", | |
152 | dev->name, ret, q->q.qlen); | |
6c1361a6 | 153 | |
37437bb2 | 154 | ret = dev_requeue_skb(skb, q); |
6c1361a6 | 155 | } |
c716a81a | 156 | |
73466498 | 157 | if (ret && netif_xmit_frozen_or_stopped(txq)) |
37437bb2 DM |
158 | ret = 0; |
159 | ||
6c1361a6 | 160 | return ret; |
1da177e4 LT |
161 | } |
162 | ||
bbd8a0d3 KK |
163 | /* |
164 | * NOTE: Called under qdisc_lock(q) with locally disabled BH. | |
165 | * | |
9bf2b8c2 | 166 | * __QDISC___STATE_RUNNING guarantees only one CPU can process |
bbd8a0d3 KK |
167 | * this qdisc at a time. qdisc_lock(q) serializes queue accesses for |
168 | * this queue. | |
169 | * | |
170 | * netif_tx_lock serializes accesses to device driver. | |
171 | * | |
172 | * qdisc_lock(q) and netif_tx_lock are mutually exclusive, | |
173 | * if one is grabbed, another must be free. | |
174 | * | |
175 | * Note, that this procedure can be called by a watchdog timer | |
176 | * | |
177 | * Returns to the caller: | |
178 | * 0 - queue is empty or throttled. | |
179 | * >0 - queue is not empty. | |
180 | * | |
181 | */ | |
b8358d70 | 182 | static inline int qdisc_restart(struct Qdisc *q, int *packets) |
bbd8a0d3 KK |
183 | { |
184 | struct netdev_queue *txq; | |
185 | struct net_device *dev; | |
186 | spinlock_t *root_lock; | |
187 | struct sk_buff *skb; | |
55a93b3e | 188 | bool validate; |
bbd8a0d3 KK |
189 | |
190 | /* Dequeue packet */ | |
b8358d70 | 191 | skb = dequeue_skb(q, &validate, packets); |
bbd8a0d3 KK |
192 | if (unlikely(!skb)) |
193 | return 0; | |
10c51b56 | 194 | |
bbd8a0d3 KK |
195 | root_lock = qdisc_lock(q); |
196 | dev = qdisc_dev(q); | |
10c51b56 | 197 | txq = skb_get_tx_queue(dev, skb); |
bbd8a0d3 | 198 | |
55a93b3e | 199 | return sch_direct_xmit(skb, q, dev, txq, root_lock, validate); |
bbd8a0d3 KK |
200 | } |
201 | ||
37437bb2 | 202 | void __qdisc_run(struct Qdisc *q) |
48d83325 | 203 | { |
d5b8aa1d | 204 | int quota = weight_p; |
b8358d70 | 205 | int packets; |
2ba2506c | 206 | |
b8358d70 | 207 | while (qdisc_restart(q, &packets)) { |
2ba2506c | 208 | /* |
d5b8aa1d | 209 | * Ordered by possible occurrence: Postpone processing if |
210 | * 1. we've exceeded packet quota | |
211 | * 2. another process needs the CPU; | |
2ba2506c | 212 | */ |
b8358d70 JDB |
213 | quota -= packets; |
214 | if (quota <= 0 || need_resched()) { | |
37437bb2 | 215 | __netif_schedule(q); |
d90df3ad | 216 | break; |
2ba2506c HX |
217 | } |
218 | } | |
48d83325 | 219 | |
bc135b23 | 220 | qdisc_run_end(q); |
48d83325 HX |
221 | } |
222 | ||
9d21493b ED |
223 | unsigned long dev_trans_start(struct net_device *dev) |
224 | { | |
07ce76aa | 225 | unsigned long val, res; |
9d21493b ED |
226 | unsigned int i; |
227 | ||
07ce76aa | 228 | if (is_vlan_dev(dev)) |
229 | dev = vlan_dev_real_dev(dev); | |
230 | res = dev->trans_start; | |
9d21493b ED |
231 | for (i = 0; i < dev->num_tx_queues; i++) { |
232 | val = netdev_get_tx_queue(dev, i)->trans_start; | |
233 | if (val && time_after(val, res)) | |
234 | res = val; | |
235 | } | |
236 | dev->trans_start = res; | |
07ce76aa | 237 | |
9d21493b ED |
238 | return res; |
239 | } | |
240 | EXPORT_SYMBOL(dev_trans_start); | |
241 | ||
1da177e4 LT |
242 | static void dev_watchdog(unsigned long arg) |
243 | { | |
244 | struct net_device *dev = (struct net_device *)arg; | |
245 | ||
932ff279 | 246 | netif_tx_lock(dev); |
e8a0464c | 247 | if (!qdisc_tx_is_noop(dev)) { |
1da177e4 LT |
248 | if (netif_device_present(dev) && |
249 | netif_running(dev) && | |
250 | netif_carrier_ok(dev)) { | |
9d21493b | 251 | int some_queue_timedout = 0; |
e8a0464c | 252 | unsigned int i; |
9d21493b | 253 | unsigned long trans_start; |
e8a0464c DM |
254 | |
255 | for (i = 0; i < dev->num_tx_queues; i++) { | |
256 | struct netdev_queue *txq; | |
257 | ||
258 | txq = netdev_get_tx_queue(dev, i); | |
9d21493b ED |
259 | /* |
260 | * old device drivers set dev->trans_start | |
261 | */ | |
262 | trans_start = txq->trans_start ? : dev->trans_start; | |
73466498 | 263 | if (netif_xmit_stopped(txq) && |
9d21493b ED |
264 | time_after(jiffies, (trans_start + |
265 | dev->watchdog_timeo))) { | |
266 | some_queue_timedout = 1; | |
ccf5ff69 | 267 | txq->trans_timeout++; |
e8a0464c DM |
268 | break; |
269 | } | |
270 | } | |
338f7566 | 271 | |
9d21493b | 272 | if (some_queue_timedout) { |
9d21493b | 273 | WARN_ONCE(1, KERN_INFO "NETDEV WATCHDOG: %s (%s): transmit queue %u timed out\n", |
3019de12 | 274 | dev->name, netdev_drivername(dev), i); |
d314774c | 275 | dev->netdev_ops->ndo_tx_timeout(dev); |
1da177e4 | 276 | } |
e8a0464c DM |
277 | if (!mod_timer(&dev->watchdog_timer, |
278 | round_jiffies(jiffies + | |
279 | dev->watchdog_timeo))) | |
1da177e4 LT |
280 | dev_hold(dev); |
281 | } | |
282 | } | |
932ff279 | 283 | netif_tx_unlock(dev); |
1da177e4 LT |
284 | |
285 | dev_put(dev); | |
286 | } | |
287 | ||
1da177e4 LT |
288 | void __netdev_watchdog_up(struct net_device *dev) |
289 | { | |
d314774c | 290 | if (dev->netdev_ops->ndo_tx_timeout) { |
1da177e4 LT |
291 | if (dev->watchdog_timeo <= 0) |
292 | dev->watchdog_timeo = 5*HZ; | |
60468d5b VP |
293 | if (!mod_timer(&dev->watchdog_timer, |
294 | round_jiffies(jiffies + dev->watchdog_timeo))) | |
1da177e4 LT |
295 | dev_hold(dev); |
296 | } | |
297 | } | |
298 | ||
299 | static void dev_watchdog_up(struct net_device *dev) | |
300 | { | |
1da177e4 | 301 | __netdev_watchdog_up(dev); |
1da177e4 LT |
302 | } |
303 | ||
304 | static void dev_watchdog_down(struct net_device *dev) | |
305 | { | |
932ff279 | 306 | netif_tx_lock_bh(dev); |
1da177e4 | 307 | if (del_timer(&dev->watchdog_timer)) |
15333061 | 308 | dev_put(dev); |
932ff279 | 309 | netif_tx_unlock_bh(dev); |
1da177e4 LT |
310 | } |
311 | ||
bea3348e SH |
312 | /** |
313 | * netif_carrier_on - set carrier | |
314 | * @dev: network device | |
315 | * | |
316 | * Device has detected that carrier. | |
317 | */ | |
0a242efc DV |
318 | void netif_carrier_on(struct net_device *dev) |
319 | { | |
bfaae0f0 | 320 | if (test_and_clear_bit(__LINK_STATE_NOCARRIER, &dev->state)) { |
b4730016 DM |
321 | if (dev->reg_state == NETREG_UNINITIALIZED) |
322 | return; | |
2d3b479d | 323 | atomic_inc(&dev->carrier_changes); |
0a242efc | 324 | linkwatch_fire_event(dev); |
bfaae0f0 JG |
325 | if (netif_running(dev)) |
326 | __netdev_watchdog_up(dev); | |
327 | } | |
0a242efc | 328 | } |
62e3ba1b | 329 | EXPORT_SYMBOL(netif_carrier_on); |
0a242efc | 330 | |
bea3348e SH |
331 | /** |
332 | * netif_carrier_off - clear carrier | |
333 | * @dev: network device | |
334 | * | |
335 | * Device has detected loss of carrier. | |
336 | */ | |
0a242efc DV |
337 | void netif_carrier_off(struct net_device *dev) |
338 | { | |
b4730016 DM |
339 | if (!test_and_set_bit(__LINK_STATE_NOCARRIER, &dev->state)) { |
340 | if (dev->reg_state == NETREG_UNINITIALIZED) | |
341 | return; | |
2d3b479d | 342 | atomic_inc(&dev->carrier_changes); |
0a242efc | 343 | linkwatch_fire_event(dev); |
b4730016 | 344 | } |
0a242efc | 345 | } |
62e3ba1b | 346 | EXPORT_SYMBOL(netif_carrier_off); |
0a242efc | 347 | |
1da177e4 LT |
348 | /* "NOOP" scheduler: the best scheduler, recommended for all interfaces |
349 | under all circumstances. It is difficult to invent anything faster or | |
350 | cheaper. | |
351 | */ | |
352 | ||
82d567c2 | 353 | static int noop_enqueue(struct sk_buff *skb, struct Qdisc *qdisc) |
1da177e4 LT |
354 | { |
355 | kfree_skb(skb); | |
356 | return NET_XMIT_CN; | |
357 | } | |
358 | ||
82d567c2 | 359 | static struct sk_buff *noop_dequeue(struct Qdisc *qdisc) |
1da177e4 LT |
360 | { |
361 | return NULL; | |
362 | } | |
363 | ||
20fea08b | 364 | struct Qdisc_ops noop_qdisc_ops __read_mostly = { |
1da177e4 LT |
365 | .id = "noop", |
366 | .priv_size = 0, | |
367 | .enqueue = noop_enqueue, | |
368 | .dequeue = noop_dequeue, | |
99c0db26 | 369 | .peek = noop_dequeue, |
1da177e4 LT |
370 | .owner = THIS_MODULE, |
371 | }; | |
372 | ||
7698b4fc | 373 | static struct netdev_queue noop_netdev_queue = { |
7698b4fc | 374 | .qdisc = &noop_qdisc, |
9f3ffae0 | 375 | .qdisc_sleeping = &noop_qdisc, |
7698b4fc DM |
376 | }; |
377 | ||
1da177e4 LT |
378 | struct Qdisc noop_qdisc = { |
379 | .enqueue = noop_enqueue, | |
380 | .dequeue = noop_dequeue, | |
381 | .flags = TCQ_F_BUILTIN, | |
10297b99 | 382 | .ops = &noop_qdisc_ops, |
1da177e4 | 383 | .list = LIST_HEAD_INIT(noop_qdisc.list), |
83874000 | 384 | .q.lock = __SPIN_LOCK_UNLOCKED(noop_qdisc.q.lock), |
7698b4fc | 385 | .dev_queue = &noop_netdev_queue, |
7b5edbc4 | 386 | .busylock = __SPIN_LOCK_UNLOCKED(noop_qdisc.busylock), |
1da177e4 | 387 | }; |
62e3ba1b | 388 | EXPORT_SYMBOL(noop_qdisc); |
1da177e4 | 389 | |
d66d6c31 PS |
390 | static int noqueue_init(struct Qdisc *qdisc, struct nlattr *opt) |
391 | { | |
392 | /* register_qdisc() assigns a default of noop_enqueue if unset, | |
393 | * but __dev_queue_xmit() treats noqueue only as such | |
394 | * if this is NULL - so clear it here. */ | |
395 | qdisc->enqueue = NULL; | |
396 | return 0; | |
397 | } | |
398 | ||
399 | struct Qdisc_ops noqueue_qdisc_ops __read_mostly = { | |
1da177e4 LT |
400 | .id = "noqueue", |
401 | .priv_size = 0, | |
d66d6c31 | 402 | .init = noqueue_init, |
1da177e4 LT |
403 | .enqueue = noop_enqueue, |
404 | .dequeue = noop_dequeue, | |
99c0db26 | 405 | .peek = noop_dequeue, |
1da177e4 LT |
406 | .owner = THIS_MODULE, |
407 | }; | |
408 | ||
cc7ec456 ED |
409 | static const u8 prio2band[TC_PRIO_MAX + 1] = { |
410 | 1, 2, 2, 2, 1, 2, 0, 0 , 1, 1, 1, 1, 1, 1, 1, 1 | |
411 | }; | |
d3678b46 DM |
412 | |
413 | /* 3-band FIFO queue: old style, but should be a bit faster than | |
414 | generic prio+fifo combination. | |
415 | */ | |
416 | ||
417 | #define PFIFO_FAST_BANDS 3 | |
418 | ||
fd3ae5e8 KK |
419 | /* |
420 | * Private data for a pfifo_fast scheduler containing: | |
421 | * - queues for the three band | |
422 | * - bitmap indicating which of the bands contain skbs | |
423 | */ | |
424 | struct pfifo_fast_priv { | |
425 | u32 bitmap; | |
426 | struct sk_buff_head q[PFIFO_FAST_BANDS]; | |
427 | }; | |
428 | ||
429 | /* | |
430 | * Convert a bitmap to the first band number where an skb is queued, where: | |
431 | * bitmap=0 means there are no skbs on any band. | |
432 | * bitmap=1 means there is an skb on band 0. | |
433 | * bitmap=7 means there are skbs on all 3 bands, etc. | |
434 | */ | |
435 | static const int bitmap2band[] = {-1, 0, 1, 0, 2, 0, 1, 0}; | |
436 | ||
437 | static inline struct sk_buff_head *band2list(struct pfifo_fast_priv *priv, | |
438 | int band) | |
d3678b46 | 439 | { |
fd3ae5e8 | 440 | return priv->q + band; |
d3678b46 DM |
441 | } |
442 | ||
cc7ec456 | 443 | static int pfifo_fast_enqueue(struct sk_buff *skb, struct Qdisc *qdisc) |
321090e7 | 444 | { |
a453e068 KK |
445 | if (skb_queue_len(&qdisc->q) < qdisc_dev(qdisc)->tx_queue_len) { |
446 | int band = prio2band[skb->priority & TC_PRIO_MAX]; | |
447 | struct pfifo_fast_priv *priv = qdisc_priv(qdisc); | |
448 | struct sk_buff_head *list = band2list(priv, band); | |
1da177e4 | 449 | |
fd3ae5e8 | 450 | priv->bitmap |= (1 << band); |
d3678b46 | 451 | qdisc->q.qlen++; |
821d24ae | 452 | return __qdisc_enqueue_tail(skb, qdisc, list); |
d3678b46 | 453 | } |
821d24ae TG |
454 | |
455 | return qdisc_drop(skb, qdisc); | |
1da177e4 LT |
456 | } |
457 | ||
cc7ec456 | 458 | static struct sk_buff *pfifo_fast_dequeue(struct Qdisc *qdisc) |
1da177e4 | 459 | { |
fd3ae5e8 KK |
460 | struct pfifo_fast_priv *priv = qdisc_priv(qdisc); |
461 | int band = bitmap2band[priv->bitmap]; | |
1da177e4 | 462 | |
fd3ae5e8 KK |
463 | if (likely(band >= 0)) { |
464 | struct sk_buff_head *list = band2list(priv, band); | |
465 | struct sk_buff *skb = __qdisc_dequeue_head(qdisc, list); | |
466 | ||
467 | qdisc->q.qlen--; | |
468 | if (skb_queue_empty(list)) | |
469 | priv->bitmap &= ~(1 << band); | |
470 | ||
471 | return skb; | |
d3678b46 | 472 | } |
f87a9c3d | 473 | |
1da177e4 LT |
474 | return NULL; |
475 | } | |
476 | ||
cc7ec456 | 477 | static struct sk_buff *pfifo_fast_peek(struct Qdisc *qdisc) |
99c0db26 | 478 | { |
fd3ae5e8 KK |
479 | struct pfifo_fast_priv *priv = qdisc_priv(qdisc); |
480 | int band = bitmap2band[priv->bitmap]; | |
481 | ||
482 | if (band >= 0) { | |
483 | struct sk_buff_head *list = band2list(priv, band); | |
99c0db26 | 484 | |
fd3ae5e8 | 485 | return skb_peek(list); |
99c0db26 JP |
486 | } |
487 | ||
488 | return NULL; | |
489 | } | |
490 | ||
cc7ec456 | 491 | static void pfifo_fast_reset(struct Qdisc *qdisc) |
1da177e4 | 492 | { |
d3678b46 | 493 | int prio; |
fd3ae5e8 | 494 | struct pfifo_fast_priv *priv = qdisc_priv(qdisc); |
d3678b46 DM |
495 | |
496 | for (prio = 0; prio < PFIFO_FAST_BANDS; prio++) | |
fd3ae5e8 | 497 | __qdisc_reset_queue(qdisc, band2list(priv, prio)); |
d3678b46 | 498 | |
fd3ae5e8 | 499 | priv->bitmap = 0; |
821d24ae | 500 | qdisc->qstats.backlog = 0; |
d3678b46 | 501 | qdisc->q.qlen = 0; |
1da177e4 LT |
502 | } |
503 | ||
d3678b46 DM |
504 | static int pfifo_fast_dump(struct Qdisc *qdisc, struct sk_buff *skb) |
505 | { | |
506 | struct tc_prio_qopt opt = { .bands = PFIFO_FAST_BANDS }; | |
507 | ||
cc7ec456 | 508 | memcpy(&opt.priomap, prio2band, TC_PRIO_MAX + 1); |
1b34ec43 DM |
509 | if (nla_put(skb, TCA_OPTIONS, sizeof(opt), &opt)) |
510 | goto nla_put_failure; | |
d3678b46 DM |
511 | return skb->len; |
512 | ||
513 | nla_put_failure: | |
514 | return -1; | |
515 | } | |
516 | ||
517 | static int pfifo_fast_init(struct Qdisc *qdisc, struct nlattr *opt) | |
518 | { | |
519 | int prio; | |
fd3ae5e8 | 520 | struct pfifo_fast_priv *priv = qdisc_priv(qdisc); |
d3678b46 DM |
521 | |
522 | for (prio = 0; prio < PFIFO_FAST_BANDS; prio++) | |
ab34f648 | 523 | __skb_queue_head_init(band2list(priv, prio)); |
d3678b46 | 524 | |
23624935 ED |
525 | /* Can by-pass the queue discipline */ |
526 | qdisc->flags |= TCQ_F_CAN_BYPASS; | |
d3678b46 DM |
527 | return 0; |
528 | } | |
529 | ||
6ec1c69a | 530 | struct Qdisc_ops pfifo_fast_ops __read_mostly = { |
d3678b46 | 531 | .id = "pfifo_fast", |
fd3ae5e8 | 532 | .priv_size = sizeof(struct pfifo_fast_priv), |
d3678b46 DM |
533 | .enqueue = pfifo_fast_enqueue, |
534 | .dequeue = pfifo_fast_dequeue, | |
99c0db26 | 535 | .peek = pfifo_fast_peek, |
d3678b46 DM |
536 | .init = pfifo_fast_init, |
537 | .reset = pfifo_fast_reset, | |
538 | .dump = pfifo_fast_dump, | |
1da177e4 LT |
539 | .owner = THIS_MODULE, |
540 | }; | |
1f27cde3 | 541 | EXPORT_SYMBOL(pfifo_fast_ops); |
1da177e4 | 542 | |
23d3b8bf ED |
543 | static struct lock_class_key qdisc_tx_busylock; |
544 | ||
5ce2d488 | 545 | struct Qdisc *qdisc_alloc(struct netdev_queue *dev_queue, |
d2a7f269 | 546 | const struct Qdisc_ops *ops) |
1da177e4 LT |
547 | { |
548 | void *p; | |
549 | struct Qdisc *sch; | |
d276055c | 550 | unsigned int size = QDISC_ALIGN(sizeof(*sch)) + ops->priv_size; |
3d54b82f | 551 | int err = -ENOBUFS; |
23d3b8bf | 552 | struct net_device *dev = dev_queue->dev; |
1da177e4 | 553 | |
f2cd2d3e ED |
554 | p = kzalloc_node(size, GFP_KERNEL, |
555 | netdev_queue_numa_node_read(dev_queue)); | |
556 | ||
1da177e4 | 557 | if (!p) |
3d54b82f | 558 | goto errout; |
3d54b82f | 559 | sch = (struct Qdisc *) QDISC_ALIGN((unsigned long) p); |
d276055c ED |
560 | /* if we got non aligned memory, ask more and do alignment ourself */ |
561 | if (sch != p) { | |
562 | kfree(p); | |
563 | p = kzalloc_node(size + QDISC_ALIGNTO - 1, GFP_KERNEL, | |
564 | netdev_queue_numa_node_read(dev_queue)); | |
565 | if (!p) | |
566 | goto errout; | |
567 | sch = (struct Qdisc *) QDISC_ALIGN((unsigned long) p); | |
568 | sch->padded = (char *) sch - (char *) p; | |
569 | } | |
1da177e4 LT |
570 | INIT_LIST_HEAD(&sch->list); |
571 | skb_queue_head_init(&sch->q); | |
23d3b8bf | 572 | |
79640a4c | 573 | spin_lock_init(&sch->busylock); |
23d3b8bf ED |
574 | lockdep_set_class(&sch->busylock, |
575 | dev->qdisc_tx_busylock ?: &qdisc_tx_busylock); | |
576 | ||
1da177e4 LT |
577 | sch->ops = ops; |
578 | sch->enqueue = ops->enqueue; | |
579 | sch->dequeue = ops->dequeue; | |
bb949fbd | 580 | sch->dev_queue = dev_queue; |
23d3b8bf | 581 | dev_hold(dev); |
1da177e4 | 582 | atomic_set(&sch->refcnt, 1); |
3d54b82f TG |
583 | |
584 | return sch; | |
585 | errout: | |
01e123d7 | 586 | return ERR_PTR(err); |
3d54b82f TG |
587 | } |
588 | ||
3511c913 | 589 | struct Qdisc *qdisc_create_dflt(struct netdev_queue *dev_queue, |
d2a7f269 | 590 | const struct Qdisc_ops *ops, |
591 | unsigned int parentid) | |
3d54b82f TG |
592 | { |
593 | struct Qdisc *sch; | |
10297b99 | 594 | |
6da7c8fc | 595 | if (!try_module_get(ops->owner)) |
596 | goto errout; | |
597 | ||
5ce2d488 | 598 | sch = qdisc_alloc(dev_queue, ops); |
3d54b82f TG |
599 | if (IS_ERR(sch)) |
600 | goto errout; | |
9f9afec4 | 601 | sch->parent = parentid; |
3d54b82f | 602 | |
1da177e4 LT |
603 | if (!ops->init || ops->init(sch, NULL) == 0) |
604 | return sch; | |
605 | ||
0fbbeb1b | 606 | qdisc_destroy(sch); |
3d54b82f | 607 | errout: |
1da177e4 LT |
608 | return NULL; |
609 | } | |
62e3ba1b | 610 | EXPORT_SYMBOL(qdisc_create_dflt); |
1da177e4 | 611 | |
5fb66229 | 612 | /* Under qdisc_lock(qdisc) and BH! */ |
1da177e4 LT |
613 | |
614 | void qdisc_reset(struct Qdisc *qdisc) | |
615 | { | |
20fea08b | 616 | const struct Qdisc_ops *ops = qdisc->ops; |
1da177e4 LT |
617 | |
618 | if (ops->reset) | |
619 | ops->reset(qdisc); | |
67305ebc | 620 | |
bbd8a0d3 | 621 | if (qdisc->gso_skb) { |
3f3c7eec | 622 | kfree_skb_list(qdisc->gso_skb); |
bbd8a0d3 KK |
623 | qdisc->gso_skb = NULL; |
624 | qdisc->q.qlen = 0; | |
625 | } | |
1da177e4 | 626 | } |
62e3ba1b | 627 | EXPORT_SYMBOL(qdisc_reset); |
1da177e4 | 628 | |
5d944c64 ED |
629 | static void qdisc_rcu_free(struct rcu_head *head) |
630 | { | |
631 | struct Qdisc *qdisc = container_of(head, struct Qdisc, rcu_head); | |
632 | ||
73c20a8b | 633 | if (qdisc_is_percpu_stats(qdisc)) { |
22e0f8b9 | 634 | free_percpu(qdisc->cpu_bstats); |
73c20a8b JF |
635 | free_percpu(qdisc->cpu_qstats); |
636 | } | |
22e0f8b9 | 637 | |
5d944c64 ED |
638 | kfree((char *) qdisc - qdisc->padded); |
639 | } | |
640 | ||
1e0d5a57 | 641 | void qdisc_destroy(struct Qdisc *qdisc) |
1da177e4 | 642 | { |
8a34c5dc DM |
643 | const struct Qdisc_ops *ops = qdisc->ops; |
644 | ||
1e0d5a57 DM |
645 | if (qdisc->flags & TCQ_F_BUILTIN || |
646 | !atomic_dec_and_test(&qdisc->refcnt)) | |
647 | return; | |
648 | ||
3a682fbd | 649 | #ifdef CONFIG_NET_SCHED |
f6e0b239 JP |
650 | qdisc_list_del(qdisc); |
651 | ||
a2da570d | 652 | qdisc_put_stab(rtnl_dereference(qdisc->stab)); |
3a682fbd | 653 | #endif |
8a34c5dc DM |
654 | gen_kill_estimator(&qdisc->bstats, &qdisc->rate_est); |
655 | if (ops->reset) | |
656 | ops->reset(qdisc); | |
657 | if (ops->destroy) | |
658 | ops->destroy(qdisc); | |
659 | ||
660 | module_put(ops->owner); | |
661 | dev_put(qdisc_dev(qdisc)); | |
662 | ||
3f3c7eec | 663 | kfree_skb_list(qdisc->gso_skb); |
5d944c64 ED |
664 | /* |
665 | * gen_estimator est_timer() might access qdisc->q.lock, | |
666 | * wait a RCU grace period before freeing qdisc. | |
667 | */ | |
668 | call_rcu(&qdisc->rcu_head, qdisc_rcu_free); | |
1da177e4 | 669 | } |
62e3ba1b | 670 | EXPORT_SYMBOL(qdisc_destroy); |
1da177e4 | 671 | |
589983cd PM |
672 | /* Attach toplevel qdisc to device queue. */ |
673 | struct Qdisc *dev_graft_qdisc(struct netdev_queue *dev_queue, | |
674 | struct Qdisc *qdisc) | |
675 | { | |
676 | struct Qdisc *oqdisc = dev_queue->qdisc_sleeping; | |
677 | spinlock_t *root_lock; | |
678 | ||
679 | root_lock = qdisc_lock(oqdisc); | |
680 | spin_lock_bh(root_lock); | |
681 | ||
682 | /* Prune old scheduler */ | |
683 | if (oqdisc && atomic_read(&oqdisc->refcnt) <= 1) | |
684 | qdisc_reset(oqdisc); | |
685 | ||
686 | /* ... and graft new one */ | |
687 | if (qdisc == NULL) | |
688 | qdisc = &noop_qdisc; | |
689 | dev_queue->qdisc_sleeping = qdisc; | |
690 | rcu_assign_pointer(dev_queue->qdisc, &noop_qdisc); | |
691 | ||
692 | spin_unlock_bh(root_lock); | |
693 | ||
694 | return oqdisc; | |
695 | } | |
b8970f0b | 696 | EXPORT_SYMBOL(dev_graft_qdisc); |
589983cd | 697 | |
e8a0464c DM |
698 | static void attach_one_default_qdisc(struct net_device *dev, |
699 | struct netdev_queue *dev_queue, | |
700 | void *_unused) | |
701 | { | |
3e692f21 PS |
702 | struct Qdisc *qdisc; |
703 | const struct Qdisc_ops *ops = default_qdisc_ops; | |
e8a0464c | 704 | |
3e692f21 PS |
705 | if (dev->priv_flags & IFF_NO_QUEUE) |
706 | ops = &noqueue_qdisc_ops; | |
707 | ||
708 | qdisc = qdisc_create_dflt(dev_queue, ops, TC_H_ROOT); | |
709 | if (!qdisc) { | |
710 | netdev_info(dev, "activation failed\n"); | |
711 | return; | |
e8a0464c | 712 | } |
3e692f21 | 713 | if (!netif_is_multiqueue(dev)) |
4eaf3b84 | 714 | qdisc->flags |= TCQ_F_ONETXQUEUE | TCQ_F_NOPARENT; |
e8a0464c DM |
715 | dev_queue->qdisc_sleeping = qdisc; |
716 | } | |
717 | ||
6ec1c69a DM |
718 | static void attach_default_qdiscs(struct net_device *dev) |
719 | { | |
720 | struct netdev_queue *txq; | |
721 | struct Qdisc *qdisc; | |
722 | ||
723 | txq = netdev_get_tx_queue(dev, 0); | |
724 | ||
4b469955 | 725 | if (!netif_is_multiqueue(dev) || |
4b469955 | 726 | dev->priv_flags & IFF_NO_QUEUE) { |
6ec1c69a DM |
727 | netdev_for_each_tx_queue(dev, attach_one_default_qdisc, NULL); |
728 | dev->qdisc = txq->qdisc_sleeping; | |
729 | atomic_inc(&dev->qdisc->refcnt); | |
730 | } else { | |
3511c913 | 731 | qdisc = qdisc_create_dflt(txq, &mq_qdisc_ops, TC_H_ROOT); |
6ec1c69a | 732 | if (qdisc) { |
6ec1c69a | 733 | dev->qdisc = qdisc; |
e57a784d | 734 | qdisc->ops->attach(qdisc); |
6ec1c69a DM |
735 | } |
736 | } | |
737 | } | |
738 | ||
e8a0464c DM |
739 | static void transition_one_qdisc(struct net_device *dev, |
740 | struct netdev_queue *dev_queue, | |
741 | void *_need_watchdog) | |
742 | { | |
83874000 | 743 | struct Qdisc *new_qdisc = dev_queue->qdisc_sleeping; |
e8a0464c DM |
744 | int *need_watchdog_p = _need_watchdog; |
745 | ||
a9312ae8 DM |
746 | if (!(new_qdisc->flags & TCQ_F_BUILTIN)) |
747 | clear_bit(__QDISC_STATE_DEACTIVATED, &new_qdisc->state); | |
748 | ||
83874000 | 749 | rcu_assign_pointer(dev_queue->qdisc, new_qdisc); |
3e692f21 | 750 | if (need_watchdog_p) { |
9d21493b | 751 | dev_queue->trans_start = 0; |
e8a0464c | 752 | *need_watchdog_p = 1; |
9d21493b | 753 | } |
e8a0464c DM |
754 | } |
755 | ||
1da177e4 LT |
756 | void dev_activate(struct net_device *dev) |
757 | { | |
e8a0464c | 758 | int need_watchdog; |
b0e1e646 | 759 | |
1da177e4 | 760 | /* No queueing discipline is attached to device; |
6da7c8fc | 761 | * create default one for devices, which need queueing |
762 | * and noqueue_qdisc for virtual interfaces | |
1da177e4 LT |
763 | */ |
764 | ||
6ec1c69a DM |
765 | if (dev->qdisc == &noop_qdisc) |
766 | attach_default_qdiscs(dev); | |
af356afa | 767 | |
cacaddf5 TC |
768 | if (!netif_carrier_ok(dev)) |
769 | /* Delay activation until next carrier-on event */ | |
770 | return; | |
771 | ||
e8a0464c DM |
772 | need_watchdog = 0; |
773 | netdev_for_each_tx_queue(dev, transition_one_qdisc, &need_watchdog); | |
24824a09 ED |
774 | if (dev_ingress_queue(dev)) |
775 | transition_one_qdisc(dev, dev_ingress_queue(dev), NULL); | |
e8a0464c DM |
776 | |
777 | if (need_watchdog) { | |
860e9538 | 778 | netif_trans_update(dev); |
1da177e4 LT |
779 | dev_watchdog_up(dev); |
780 | } | |
b0e1e646 | 781 | } |
b8970f0b | 782 | EXPORT_SYMBOL(dev_activate); |
b0e1e646 | 783 | |
e8a0464c DM |
784 | static void dev_deactivate_queue(struct net_device *dev, |
785 | struct netdev_queue *dev_queue, | |
786 | void *_qdisc_default) | |
b0e1e646 | 787 | { |
e8a0464c | 788 | struct Qdisc *qdisc_default = _qdisc_default; |
970565bb | 789 | struct Qdisc *qdisc; |
970565bb | 790 | |
46e5da40 | 791 | qdisc = rtnl_dereference(dev_queue->qdisc); |
b0e1e646 | 792 | if (qdisc) { |
83874000 DM |
793 | spin_lock_bh(qdisc_lock(qdisc)); |
794 | ||
a9312ae8 DM |
795 | if (!(qdisc->flags & TCQ_F_BUILTIN)) |
796 | set_bit(__QDISC_STATE_DEACTIVATED, &qdisc->state); | |
797 | ||
f7a54c13 | 798 | rcu_assign_pointer(dev_queue->qdisc, qdisc_default); |
b0e1e646 | 799 | qdisc_reset(qdisc); |
d3b753db | 800 | |
83874000 | 801 | spin_unlock_bh(qdisc_lock(qdisc)); |
b0e1e646 | 802 | } |
1da177e4 LT |
803 | } |
804 | ||
4335cd2d | 805 | static bool some_qdisc_is_busy(struct net_device *dev) |
e8a0464c DM |
806 | { |
807 | unsigned int i; | |
808 | ||
809 | for (i = 0; i < dev->num_tx_queues; i++) { | |
810 | struct netdev_queue *dev_queue; | |
7698b4fc | 811 | spinlock_t *root_lock; |
e2627c8c | 812 | struct Qdisc *q; |
e8a0464c DM |
813 | int val; |
814 | ||
815 | dev_queue = netdev_get_tx_queue(dev, i); | |
b9a3b110 | 816 | q = dev_queue->qdisc_sleeping; |
5fb66229 | 817 | root_lock = qdisc_lock(q); |
e8a0464c | 818 | |
4335cd2d | 819 | spin_lock_bh(root_lock); |
e8a0464c | 820 | |
bc135b23 | 821 | val = (qdisc_is_running(q) || |
b9a3b110 | 822 | test_bit(__QDISC_STATE_SCHED, &q->state)); |
e8a0464c | 823 | |
4335cd2d | 824 | spin_unlock_bh(root_lock); |
e8a0464c DM |
825 | |
826 | if (val) | |
827 | return true; | |
828 | } | |
829 | return false; | |
830 | } | |
831 | ||
3137663d ED |
832 | /** |
833 | * dev_deactivate_many - deactivate transmissions on several devices | |
834 | * @head: list of devices to deactivate | |
835 | * | |
836 | * This function returns only when all outstanding transmissions | |
837 | * have completed, unless all devices are in dismantle phase. | |
838 | */ | |
44345724 | 839 | void dev_deactivate_many(struct list_head *head) |
1da177e4 | 840 | { |
44345724 | 841 | struct net_device *dev; |
3137663d | 842 | bool sync_needed = false; |
41a23b07 | 843 | |
5cde2829 | 844 | list_for_each_entry(dev, head, close_list) { |
44345724 OP |
845 | netdev_for_each_tx_queue(dev, dev_deactivate_queue, |
846 | &noop_qdisc); | |
847 | if (dev_ingress_queue(dev)) | |
848 | dev_deactivate_queue(dev, dev_ingress_queue(dev), | |
849 | &noop_qdisc); | |
850 | ||
851 | dev_watchdog_down(dev); | |
3137663d | 852 | sync_needed |= !dev->dismantle; |
44345724 | 853 | } |
1da177e4 | 854 | |
3137663d ED |
855 | /* Wait for outstanding qdisc-less dev_queue_xmit calls. |
856 | * This is avoided if all devices are in dismantle phase : | |
857 | * Caller will call synchronize_net() for us | |
858 | */ | |
859 | if (sync_needed) | |
860 | synchronize_net(); | |
1da177e4 | 861 | |
d4828d85 | 862 | /* Wait for outstanding qdisc_run calls. */ |
5cde2829 | 863 | list_for_each_entry(dev, head, close_list) |
44345724 OP |
864 | while (some_qdisc_is_busy(dev)) |
865 | yield(); | |
866 | } | |
867 | ||
868 | void dev_deactivate(struct net_device *dev) | |
869 | { | |
870 | LIST_HEAD(single); | |
871 | ||
5cde2829 | 872 | list_add(&dev->close_list, &single); |
44345724 | 873 | dev_deactivate_many(&single); |
5f04d506 | 874 | list_del(&single); |
1da177e4 | 875 | } |
b8970f0b | 876 | EXPORT_SYMBOL(dev_deactivate); |
1da177e4 | 877 | |
b0e1e646 DM |
878 | static void dev_init_scheduler_queue(struct net_device *dev, |
879 | struct netdev_queue *dev_queue, | |
e8a0464c | 880 | void *_qdisc) |
b0e1e646 | 881 | { |
e8a0464c DM |
882 | struct Qdisc *qdisc = _qdisc; |
883 | ||
46e5da40 | 884 | rcu_assign_pointer(dev_queue->qdisc, qdisc); |
b0e1e646 | 885 | dev_queue->qdisc_sleeping = qdisc; |
b0e1e646 DM |
886 | } |
887 | ||
1da177e4 LT |
888 | void dev_init_scheduler(struct net_device *dev) |
889 | { | |
af356afa | 890 | dev->qdisc = &noop_qdisc; |
e8a0464c | 891 | netdev_for_each_tx_queue(dev, dev_init_scheduler_queue, &noop_qdisc); |
24824a09 ED |
892 | if (dev_ingress_queue(dev)) |
893 | dev_init_scheduler_queue(dev, dev_ingress_queue(dev), &noop_qdisc); | |
1da177e4 | 894 | |
b24b8a24 | 895 | setup_timer(&dev->watchdog_timer, dev_watchdog, (unsigned long)dev); |
1da177e4 LT |
896 | } |
897 | ||
e8a0464c DM |
898 | static void shutdown_scheduler_queue(struct net_device *dev, |
899 | struct netdev_queue *dev_queue, | |
900 | void *_qdisc_default) | |
1da177e4 | 901 | { |
b0e1e646 | 902 | struct Qdisc *qdisc = dev_queue->qdisc_sleeping; |
e8a0464c | 903 | struct Qdisc *qdisc_default = _qdisc_default; |
b0e1e646 DM |
904 | |
905 | if (qdisc) { | |
f7a54c13 | 906 | rcu_assign_pointer(dev_queue->qdisc, qdisc_default); |
b0e1e646 | 907 | dev_queue->qdisc_sleeping = qdisc_default; |
1da177e4 | 908 | |
1da177e4 | 909 | qdisc_destroy(qdisc); |
10297b99 | 910 | } |
b0e1e646 DM |
911 | } |
912 | ||
913 | void dev_shutdown(struct net_device *dev) | |
914 | { | |
e8a0464c | 915 | netdev_for_each_tx_queue(dev, shutdown_scheduler_queue, &noop_qdisc); |
24824a09 ED |
916 | if (dev_ingress_queue(dev)) |
917 | shutdown_scheduler_queue(dev, dev_ingress_queue(dev), &noop_qdisc); | |
af356afa PM |
918 | qdisc_destroy(dev->qdisc); |
919 | dev->qdisc = &noop_qdisc; | |
920 | ||
547b792c | 921 | WARN_ON(timer_pending(&dev->watchdog_timer)); |
1da177e4 | 922 | } |
292f1c7f | 923 | |
01cb71d2 | 924 | void psched_ratecfg_precompute(struct psched_ratecfg *r, |
3e1e3aae ED |
925 | const struct tc_ratespec *conf, |
926 | u64 rate64) | |
292f1c7f | 927 | { |
01cb71d2 ED |
928 | memset(r, 0, sizeof(*r)); |
929 | r->overhead = conf->overhead; | |
3e1e3aae | 930 | r->rate_bytes_ps = max_t(u64, conf->rate, rate64); |
8a8e3d84 | 931 | r->linklayer = (conf->linklayer & TC_LINKLAYER_MASK); |
292f1c7f JP |
932 | r->mult = 1; |
933 | /* | |
130d3d68 ED |
934 | * The deal here is to replace a divide by a reciprocal one |
935 | * in fast path (a reciprocal divide is a multiply and a shift) | |
936 | * | |
937 | * Normal formula would be : | |
938 | * time_in_ns = (NSEC_PER_SEC * len) / rate_bps | |
939 | * | |
940 | * We compute mult/shift to use instead : | |
941 | * time_in_ns = (len * mult) >> shift; | |
942 | * | |
943 | * We try to get the highest possible mult value for accuracy, | |
944 | * but have to make sure no overflows will ever happen. | |
292f1c7f | 945 | */ |
130d3d68 ED |
946 | if (r->rate_bytes_ps > 0) { |
947 | u64 factor = NSEC_PER_SEC; | |
948 | ||
949 | for (;;) { | |
950 | r->mult = div64_u64(factor, r->rate_bytes_ps); | |
951 | if (r->mult & (1U << 31) || factor & (1ULL << 63)) | |
292f1c7f | 952 | break; |
130d3d68 ED |
953 | factor <<= 1; |
954 | r->shift++; | |
292f1c7f | 955 | } |
292f1c7f JP |
956 | } |
957 | } | |
958 | EXPORT_SYMBOL(psched_ratecfg_precompute); |