blob: b2cc9a8ed4e7eda826ad4919d9f0f395a5eac296 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef __NET_PKT_SCHED_H
2#define __NET_PKT_SCHED_H
3
Patrick McHardy538e43a2006-01-08 22:12:03 -08004#include <linux/jiffies.h>
Patrick McHardy641b9e02007-03-16 01:18:42 -07005#include <linux/ktime.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07006#include <net/sch_generic.h>
7
8struct qdisc_walker
9{
10 int stop;
11 int skip;
12 int count;
13 int (*fn)(struct Qdisc *, unsigned long cl, struct qdisc_walker *);
14};
15
16extern rwlock_t qdisc_tree_lock;
17
Thomas Graf3d54b822005-07-05 14:15:09 -070018#define QDISC_ALIGNTO 32
19#define QDISC_ALIGN(len) (((len) + QDISC_ALIGNTO-1) & ~(QDISC_ALIGNTO-1))
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
21static inline void *qdisc_priv(struct Qdisc *q)
22{
Thomas Graf3d54b822005-07-05 14:15:09 -070023 return (char *) q + QDISC_ALIGN(sizeof(struct Qdisc));
Linus Torvalds1da177e2005-04-16 15:20:36 -070024}
25
26/*
27 Timer resolution MUST BE < 10% of min_schedulable_packet_size/bandwidth
28
29 Normal IP packet size ~ 512byte, hence:
30
31 0.5Kbyte/1Mbyte/sec = 0.5msec, so that we need 50usec timer for
32 10Mbit ethernet.
33
34 10msec resolution -> <50Kbit/sec.
35
36 The result: [34]86 is not good choice for QoS router :-(
37
38 The things are not so bad, because we may use artifical
39 clock evaluated by integration of network data flow
40 in the most critical places.
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 */
42
Linus Torvalds1da177e2005-04-16 15:20:36 -070043typedef u64 psched_time_t;
44typedef long psched_tdiff_t;
45
Patrick McHardy641b9e02007-03-16 01:18:42 -070046/* Avoid doing 64 bit divide by 1000 */
47#define PSCHED_US2NS(x) ((s64)(x) << 10)
48#define PSCHED_NS2US(x) ((x) >> 10)
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
Patrick McHardy641b9e02007-03-16 01:18:42 -070050#define PSCHED_TICKS_PER_SEC PSCHED_NS2US(NSEC_PER_SEC)
Patrick McHardya0849802007-03-23 11:28:30 -070051#define PSCHED_PASTPERFECT 0
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
Patrick McHardy3bebcda2007-03-23 11:29:25 -070053static inline psched_time_t psched_get_time(void)
54{
55 return PSCHED_NS2US(ktime_to_ns(ktime_get()));
56}
57
Patrick McHardy03cc45c2007-03-23 11:29:11 -070058static inline psched_tdiff_t
59psched_tdiff_bounded(psched_time_t tv1, psched_time_t tv2, psched_time_t bound)
60{
61 return min(tv1 - tv2, bound);
62}
63
Patrick McHardy41794772007-03-16 01:19:15 -070064struct qdisc_watchdog {
65 struct hrtimer timer;
66 struct Qdisc *qdisc;
67};
68
69extern void qdisc_watchdog_init(struct qdisc_watchdog *wd, struct Qdisc *qdisc);
70extern void qdisc_watchdog_schedule(struct qdisc_watchdog *wd,
71 psched_time_t expires);
72extern void qdisc_watchdog_cancel(struct qdisc_watchdog *wd);
73
Linus Torvalds1da177e2005-04-16 15:20:36 -070074extern struct Qdisc_ops pfifo_qdisc_ops;
75extern struct Qdisc_ops bfifo_qdisc_ops;
76
77extern int register_qdisc(struct Qdisc_ops *qops);
78extern int unregister_qdisc(struct Qdisc_ops *qops);
79extern struct Qdisc *qdisc_lookup(struct net_device *dev, u32 handle);
80extern struct Qdisc *qdisc_lookup_class(struct net_device *dev, u32 handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -070081extern struct qdisc_rate_table *qdisc_get_rtab(struct tc_ratespec *r,
82 struct rtattr *tab);
83extern void qdisc_put_rtab(struct qdisc_rate_table *tab);
84
Herbert Xu48d83322006-06-19 23:57:59 -070085extern void __qdisc_run(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
87static inline void qdisc_run(struct net_device *dev)
88{
Herbert Xu48d83322006-06-19 23:57:59 -070089 if (!netif_queue_stopped(dev) &&
90 !test_and_set_bit(__LINK_STATE_QDISC_RUNNING, &dev->state))
91 __qdisc_run(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070092}
93
94extern int tc_classify(struct sk_buff *skb, struct tcf_proto *tp,
95 struct tcf_result *res);
96
97/* Calculate maximal size of packet seen by hard_start_xmit
98 routine of this device.
99 */
100static inline unsigned psched_mtu(struct net_device *dev)
101{
102 unsigned mtu = dev->mtu;
103 return dev->hard_header ? mtu + dev->hard_header_len : mtu;
104}
105
106#endif