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