1 #ifndef __NET_PKT_SCHED_H
2 #define __NET_PKT_SCHED_H
4 #define PSCHED_GETTIMEOFDAY 1
5 #define PSCHED_JIFFIES 2
8 #define PSCHED_CLOCK_SOURCE PSCHED_JIFFIES
10 #include <linux/config.h>
11 #include <linux/netdevice.h>
12 #include <linux/types.h>
13 #include <linux/pkt_sched.h>
14 #include <linux/rcupdate.h>
15 #include <net/pkt_cls.h>
16 #include <linux/module.h>
17 #include <linux/rtnetlink.h>
32 int (*fn)(struct Qdisc *, unsigned long cl, struct qdisc_walker *);
35 struct Qdisc_class_ops
37 /* Child qdisc manipulation */
38 int (*graft)(struct Qdisc *, unsigned long cl, struct Qdisc *, struct Qdisc **);
39 struct Qdisc * (*leaf)(struct Qdisc *, unsigned long cl);
41 /* Class manipulation routines */
42 unsigned long (*get)(struct Qdisc *, u32 classid);
43 void (*put)(struct Qdisc *, unsigned long);
44 int (*change)(struct Qdisc *, u32, u32, struct rtattr **, unsigned long *);
45 int (*delete)(struct Qdisc *, unsigned long);
46 void (*walk)(struct Qdisc *, struct qdisc_walker * arg);
48 /* Filter manipulation */
49 struct tcf_proto ** (*tcf_chain)(struct Qdisc *, unsigned long);
50 unsigned long (*bind_tcf)(struct Qdisc *, unsigned long, u32 classid);
51 void (*unbind_tcf)(struct Qdisc *, unsigned long);
53 /* rtnetlink specific */
54 int (*dump)(struct Qdisc *, unsigned long, struct sk_buff *skb, struct tcmsg*);
61 struct Qdisc_ops *next;
62 struct Qdisc_class_ops *cl_ops;
66 int (*enqueue)(struct sk_buff *, struct Qdisc *);
67 struct sk_buff * (*dequeue)(struct Qdisc *);
68 int (*requeue)(struct sk_buff *, struct Qdisc *);
69 unsigned int (*drop)(struct Qdisc *);
71 int (*init)(struct Qdisc *, struct rtattr *arg);
72 void (*reset)(struct Qdisc *);
73 void (*destroy)(struct Qdisc *);
74 int (*change)(struct Qdisc *, struct rtattr *arg);
76 int (*dump)(struct Qdisc *, struct sk_buff *);
81 extern rwlock_t qdisc_tree_lock;
85 int (*enqueue)(struct sk_buff *skb, struct Qdisc *dev);
86 struct sk_buff * (*dequeue)(struct Qdisc *dev);
88 #define TCQ_F_BUILTIN 1
89 #define TCQ_F_THROTTLED 2
90 #define TCQ_F_INGRES 4
91 struct Qdisc_ops *ops;
95 struct sk_buff_head q;
96 struct net_device *dev;
98 struct tc_stats stats;
99 spinlock_t *stats_lock;
100 struct rcu_head q_rcu;
101 int (*reshape_fail)(struct sk_buff *skb, struct Qdisc *q);
103 /* This field is deprecated, but it is still used by CBQ
104 * and it will live until better solution will be invented.
106 struct Qdisc *__parent;
111 struct qdisc_rate_table
113 struct tc_ratespec rate;
115 struct qdisc_rate_table *next;
119 static inline void sch_tree_lock(struct Qdisc *q)
121 write_lock(&qdisc_tree_lock);
122 spin_lock_bh(&q->dev->queue_lock);
125 static inline void sch_tree_unlock(struct Qdisc *q)
127 spin_unlock_bh(&q->dev->queue_lock);
128 write_unlock(&qdisc_tree_lock);
131 static inline void tcf_tree_lock(struct tcf_proto *tp)
133 write_lock(&qdisc_tree_lock);
134 spin_lock_bh(&tp->q->dev->queue_lock);
137 static inline void tcf_tree_unlock(struct tcf_proto *tp)
139 spin_unlock_bh(&tp->q->dev->queue_lock);
140 write_unlock(&qdisc_tree_lock);
144 static inline unsigned long
145 cls_set_class(struct tcf_proto *tp, unsigned long *clp, unsigned long cl)
147 unsigned long old_cl;
156 static inline unsigned long
157 __cls_set_class(unsigned long *clp, unsigned long cl)
159 unsigned long old_cl;
168 Timer resolution MUST BE < 10% of min_schedulable_packet_size/bandwidth
170 Normal IP packet size ~ 512byte, hence:
172 0.5Kbyte/1Mbyte/sec = 0.5msec, so that we need 50usec timer for
175 10msec resolution -> <50Kbit/sec.
177 The result: [34]86 is not good choice for QoS router :-(
179 The things are not so bad, because we may use artifical
180 clock evaluated by integration of network data flow
181 in the most critical places.
183 Note: we do not use fastgettimeofday.
184 The reason is that, when it is not the same thing as
185 gettimeofday, it returns invalid timestamp, which is
186 not updated, when net_bh is active.
188 So, use PSCHED_CLOCK_SOURCE = PSCHED_CPU on alpha and pentiums
189 with rtdsc. And PSCHED_JIFFIES on all other architectures, including [34]86
190 and pentiums without rtdsc.
191 You can use PSCHED_GETTIMEOFDAY on another architectures,
192 which have fast and precise clock source, but it is too expensive.
195 /* General note about internal clock.
197 Any clock source returns time intervals, measured in units
198 close to 1usec. With source PSCHED_GETTIMEOFDAY it is precisely
199 microseconds, otherwise something close but different chosen to minimize
200 arithmetic cost. Ratio usec/internal untis in form nominator/denominator
201 may be read from /proc/net/psched.
205 #if PSCHED_CLOCK_SOURCE == PSCHED_GETTIMEOFDAY
207 typedef struct timeval psched_time_t;
208 typedef long psched_tdiff_t;
210 #define PSCHED_GET_TIME(stamp) do_gettimeofday(&(stamp))
211 #define PSCHED_US2JIFFIE(usecs) (((usecs)+(1000000/HZ-1))/(1000000/HZ))
212 #define PSCHED_JIFFIE2US(delay) ((delay)*(1000000/HZ))
214 #else /* PSCHED_CLOCK_SOURCE != PSCHED_GETTIMEOFDAY */
216 typedef u64 psched_time_t;
217 typedef long psched_tdiff_t;
219 extern psched_time_t psched_time_base;
221 #if PSCHED_CLOCK_SOURCE == PSCHED_JIFFIES
224 #define PSCHED_JSCALE 14
225 #elif HZ >= 96 && HZ < 192
226 #define PSCHED_JSCALE 13
227 #elif HZ >= 192 && HZ < 384
228 #define PSCHED_JSCALE 12
229 #elif HZ >= 384 && HZ < 768
230 #define PSCHED_JSCALE 11
232 #define PSCHED_JSCALE 10
235 #define PSCHED_GET_TIME(stamp) ((stamp) = (get_jiffies_64()<<PSCHED_JSCALE))
236 #define PSCHED_US2JIFFIE(delay) (((delay)+(1<<PSCHED_JSCALE)-1)>>PSCHED_JSCALE)
237 #define PSCHED_JIFFIE2US(delay) ((delay)<<PSCHED_JSCALE)
239 #elif PSCHED_CLOCK_SOURCE == PSCHED_CPU
241 extern psched_tdiff_t psched_clock_per_hz;
242 extern int psched_clock_scale;
244 #define PSCHED_US2JIFFIE(delay) (((delay)+psched_clock_per_hz-1)/psched_clock_per_hz)
245 #define PSCHED_JIFFIE2US(delay) ((delay)*psched_clock_per_hz)
247 #ifdef CONFIG_X86_TSC
249 #define PSCHED_GET_TIME(stamp) \
252 (stamp) = __cur>>psched_clock_scale; \
255 #elif defined (__alpha__)
257 #define PSCHED_WATCHER u32
259 extern PSCHED_WATCHER psched_time_mark;
261 #define PSCHED_GET_TIME(stamp) \
263 __asm__ __volatile__ ("rpcc %0" : "r="(__res)); \
264 if (__res <= psched_time_mark) psched_time_base += 0x100000000UL; \
265 psched_time_mark = __res; \
266 (stamp) = (psched_time_base + __res)>>psched_clock_scale; \
271 #error PSCHED_CLOCK_SOURCE=PSCHED_CPU is not supported on this arch.
275 #endif /* PSCHED_CLOCK_SOURCE == PSCHED_JIFFIES */
277 #endif /* PSCHED_CLOCK_SOURCE == PSCHED_GETTIMEOFDAY */
279 #if PSCHED_CLOCK_SOURCE == PSCHED_GETTIMEOFDAY
280 #define PSCHED_TDIFF(tv1, tv2) \
282 int __delta_sec = (tv1).tv_sec - (tv2).tv_sec; \
283 int __delta = (tv1).tv_usec - (tv2).tv_usec; \
285 switch (__delta_sec) { \
289 __delta += 1000000; \
291 __delta += 1000000; \
297 extern int psched_tod_diff(int delta_sec, int bound);
299 #define PSCHED_TDIFF_SAFE(tv1, tv2, bound) \
301 int __delta_sec = (tv1).tv_sec - (tv2).tv_sec; \
302 int __delta = (tv1).tv_usec - (tv2).tv_usec; \
303 switch (__delta_sec) { \
305 __delta = psched_tod_diff(__delta_sec, bound); break; \
307 __delta += 1000000; \
309 __delta += 1000000; \
315 #define PSCHED_TLESS(tv1, tv2) (((tv1).tv_usec < (tv2).tv_usec && \
316 (tv1).tv_sec <= (tv2).tv_sec) || \
317 (tv1).tv_sec < (tv2).tv_sec)
319 #define PSCHED_TADD2(tv, delta, tv_res) \
321 int __delta = (tv).tv_usec + (delta); \
322 (tv_res).tv_sec = (tv).tv_sec; \
323 if (__delta > 1000000) { (tv_res).tv_sec++; __delta -= 1000000; } \
324 (tv_res).tv_usec = __delta; \
327 #define PSCHED_TADD(tv, delta) \
329 (tv).tv_usec += (delta); \
330 if ((tv).tv_usec > 1000000) { (tv).tv_sec++; \
331 (tv).tv_usec -= 1000000; } \
334 /* Set/check that time is in the "past perfect";
335 it depends on concrete representation of system time
338 #define PSCHED_SET_PASTPERFECT(t) ((t).tv_sec = 0)
339 #define PSCHED_IS_PASTPERFECT(t) ((t).tv_sec == 0)
341 #define PSCHED_AUDIT_TDIFF(t) ({ if ((t) > 2000000) (t) = 2000000; })
345 #define PSCHED_TDIFF(tv1, tv2) (long)((tv1) - (tv2))
346 #define PSCHED_TDIFF_SAFE(tv1, tv2, bound) \
347 min_t(long long, (tv1) - (tv2), bound)
350 #define PSCHED_TLESS(tv1, tv2) ((tv1) < (tv2))
351 #define PSCHED_TADD2(tv, delta, tv_res) ((tv_res) = (tv) + (delta))
352 #define PSCHED_TADD(tv, delta) ((tv) += (delta))
353 #define PSCHED_SET_PASTPERFECT(t) ((t) = 0)
354 #define PSCHED_IS_PASTPERFECT(t) ((t) == 0)
355 #define PSCHED_AUDIT_TDIFF(t)
361 struct tcf_police *next;
363 #ifdef CONFIG_NET_CLS_ACT
376 struct qdisc_rate_table *R_tab;
377 struct qdisc_rate_table *P_tab;
379 struct tc_stats stats;
380 spinlock_t *stats_lock;
383 #ifdef CONFIG_NET_CLS_ACT
385 #define ACT_P_CREATED 1
386 #define ACT_P_DELETED 1
387 #define tca_gen(name) \
388 struct tcf_##name *next; \
395 struct tc_stats stats; \
396 spinlock_t *stats_lock; \
403 struct tc_action_ops *ops;
404 __u32 type; /* for backward compat(TCA_OLD_COMPAT) */
406 struct tc_action *next;
409 #define TCA_CAP_NONE 0
412 struct tc_action_ops *next;
414 __u32 type; /* TBD to match kind */
415 __u32 capab; /* capabilities includes 4 bit version */
416 struct module *owner;
417 int (*act)(struct sk_buff **, struct tc_action *);
418 int (*get_stats)(struct sk_buff *, struct tc_action *);
419 int (*dump)(struct sk_buff *, struct tc_action *,int , int);
420 int (*cleanup)(struct tc_action *, int bind);
421 int (*lookup)(struct tc_action *, u32 );
422 int (*init)(struct rtattr *,struct rtattr *,struct tc_action *, int , int );
423 int (*walk)(struct sk_buff *, struct netlink_callback *, int , struct tc_action *);
426 extern int tcf_register_action(struct tc_action_ops *a);
427 extern int tcf_unregister_action(struct tc_action_ops *a);
428 extern void tcf_action_destroy(struct tc_action *a, int bind);
429 extern int tcf_action_exec(struct sk_buff *skb, struct tc_action *a);
430 extern int tcf_action_init(struct rtattr *rta, struct rtattr *est, struct tc_action *a,char *n, int ovr, int bind);
431 extern int tcf_action_init_1(struct rtattr *rta, struct rtattr *est, struct tc_action *a,char *n, int ovr, int bind);
432 extern int tcf_action_dump(struct sk_buff *skb, struct tc_action *a, int, int);
433 extern int tcf_action_dump_old(struct sk_buff *skb, struct tc_action *a, int, int);
434 extern int tcf_action_dump_1(struct sk_buff *skb, struct tc_action *a, int, int);
435 extern int tcf_action_copy_stats (struct sk_buff *,struct tc_action *);
436 extern int tcf_act_police_locate(struct rtattr *rta, struct rtattr *est,struct tc_action *,int , int );
437 extern int tcf_act_police_dump(struct sk_buff *, struct tc_action *, int, int);
438 extern int tcf_act_police(struct sk_buff **skb, struct tc_action *a);
441 extern int tcf_police(struct sk_buff *skb, struct tcf_police *p);
442 extern int qdisc_copy_stats(struct sk_buff *skb, struct tc_stats *st, spinlock_t *lock);
443 extern void tcf_police_destroy(struct tcf_police *p);
444 extern struct tcf_police * tcf_police_locate(struct rtattr *rta, struct rtattr *est);
445 extern int tcf_police_dump(struct sk_buff *skb, struct tcf_police *p);
447 static inline int tcf_police_release(struct tcf_police *p, int bind)
450 #ifdef CONFIG_NET_CLS_ACT
456 if (p->refcnt <= 0 && !p->bindcnt) {
457 tcf_police_destroy(p);
462 if (p && --p->refcnt == 0)
463 tcf_police_destroy(p);
469 extern struct Qdisc noop_qdisc;
470 extern struct Qdisc_ops noop_qdisc_ops;
471 extern struct Qdisc_ops pfifo_qdisc_ops;
472 extern struct Qdisc_ops bfifo_qdisc_ops;
474 int register_qdisc(struct Qdisc_ops *qops);
475 int unregister_qdisc(struct Qdisc_ops *qops);
476 struct Qdisc *qdisc_lookup(struct net_device *dev, u32 handle);
477 struct Qdisc *qdisc_lookup_class(struct net_device *dev, u32 handle);
478 void dev_init_scheduler(struct net_device *dev);
479 void dev_shutdown(struct net_device *dev);
480 void dev_activate(struct net_device *dev);
481 void dev_deactivate(struct net_device *dev);
482 void qdisc_reset(struct Qdisc *qdisc);
483 void qdisc_destroy(struct Qdisc *qdisc);
484 struct Qdisc * qdisc_create_dflt(struct net_device *dev, struct Qdisc_ops *ops);
485 int qdisc_new_estimator(struct tc_stats *stats, spinlock_t *stats_lock, struct rtattr *opt);
486 void qdisc_kill_estimator(struct tc_stats *stats);
487 struct qdisc_rate_table *qdisc_get_rtab(struct tc_ratespec *r, struct rtattr *tab);
488 void qdisc_put_rtab(struct qdisc_rate_table *tab);
490 extern int qdisc_restart(struct net_device *dev);
492 static inline void qdisc_run(struct net_device *dev)
494 while (!netif_queue_stopped(dev) &&
495 qdisc_restart(dev)<0)
499 /* Calculate maximal size of packet seen by hard_start_xmit
500 routine of this device.
502 static inline unsigned psched_mtu(struct net_device *dev)
504 unsigned mtu = dev->mtu;
505 return dev->hard_header ? mtu + dev->hard_header_len : mtu;