Initial import
[openvswitch] / datapath / linux-2.4 / compat-2.4 / include / linux / timer.h
1 #ifndef __LINUX_TIMER_WRAPPER_H
2 #define __LINUX_TIMER_WRAPPER_H 1
3
4 #include_next <linux/timer.h>
5 #include <asm/param.h>
6 #include <linux/smp.h>
7
8 extern unsigned long volatile jiffies;
9
10 static inline void setup_timer(struct timer_list * timer,
11                                 void (*function)(unsigned long),
12                                 unsigned long data)
13 {
14         timer->function = function;
15         timer->data = data;
16         init_timer(timer);
17 }
18
19 /**
20  * __round_jiffies - function to round jiffies to a full second
21  * @j: the time in (absolute) jiffies that should be rounded
22  * @cpu: the processor number on which the timeout will happen
23  *
24  * __round_jiffies() rounds an absolute time in the future (in jiffies)
25  * up or down to (approximately) full seconds. This is useful for timers
26  * for which the exact time they fire does not matter too much, as long as
27  * they fire approximately every X seconds.
28  *
29  * By rounding these timers to whole seconds, all such timers will fire
30  * at the same time, rather than at various times spread out. The goal
31  * of this is to have the CPU wake up less, which saves power.
32  *
33  * The exact rounding is skewed for each processor to avoid all
34  * processors firing at the exact same time, which could lead
35  * to lock contention or spurious cache line bouncing.
36  *
37  * The return value is the rounded version of the @j parameter.
38  */
39 static inline unsigned long __round_jiffies(unsigned long j, int cpu)
40 {
41         int rem;
42         unsigned long original = j;
43
44         /*
45          * We don't want all cpus firing their timers at once hitting the
46          * same lock or cachelines, so we skew each extra cpu with an extra
47          * 3 jiffies. This 3 jiffies came originally from the mm/ code which
48          * already did this.
49          * The skew is done by adding 3*cpunr, then round, then subtract this
50          * extra offset again.
51          */
52         j += cpu * 3;
53
54         rem = j % HZ;
55
56         /*
57          * If the target jiffie is just after a whole second (which can happen
58          * due to delays of the timer irq, long irq off times etc etc) then
59          * we should round down to the whole second, not up. Use 1/4th second
60          * as cutoff for this rounding as an extreme upper bound for this.
61          */
62         if (rem < HZ/4) /* round down */
63                 j = j - rem;
64         else /* round up */
65                 j = j - rem + HZ;
66
67         /* now that we have rounded, subtract the extra skew again */
68         j -= cpu * 3;
69
70         if (j <= jiffies) /* rounding ate our timeout entirely; */
71                 return original;
72         return j;
73 }
74
75
76 /**
77  * round_jiffies - function to round jiffies to a full second
78  * @j: the time in (absolute) jiffies that should be rounded
79  *
80  * round_jiffies() rounds an absolute time in the future (in jiffies)
81  * up or down to (approximately) full seconds. This is useful for timers
82  * for which the exact time they fire does not matter too much, as long as
83  * they fire approximately every X seconds.
84  *
85  * By rounding these timers to whole seconds, all such timers will fire
86  * at the same time, rather than at various times spread out. The goal
87  * of this is to have the CPU wake up less, which saves power.
88  *
89  * The return value is the rounded version of the @j parameter.
90  */
91 static inline unsigned long round_jiffies(unsigned long j)
92 {
93         return __round_jiffies(j, 0);  // FIXME
94 }
95
96 #endif