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