xref: /openbsd/sys/dev/pci/drm/include/linux/jiffies.h (revision 9342ba5e)
1 /* Public domain. */
2 
3 #ifndef _LINUX_JIFFIES_H
4 #define _LINUX_JIFFIES_H
5 
6 #include <sys/types.h>
7 #include <sys/param.h>
8 #include <sys/time.h>
9 #include <sys/limits.h>
10 #include <sys/kernel.h>
11 
12 extern volatile unsigned long jiffies;
13 #define jiffies_64 jiffies /* XXX */
14 #undef HZ
15 #define HZ	hz
16 
17 #define MAX_JIFFY_OFFSET	((INT_MAX >> 1) - 1)
18 
19 #define time_in_range(x, min, max) ((x) >= (min) && (x) <= (max))
20 
21 static inline unsigned int
jiffies_to_msecs(const unsigned long x)22 jiffies_to_msecs(const unsigned long x)
23 {
24 	return (((uint64_t)(x)) * 1000 / hz);
25 }
26 
27 static inline unsigned int
jiffies_to_usecs(const unsigned long x)28 jiffies_to_usecs(const unsigned long x)
29 {
30 	return (((uint64_t)(x)) * 1000000 / hz);
31 }
32 
33 static inline unsigned int
jiffies_to_nsecs(const unsigned long x)34 jiffies_to_nsecs(const unsigned long x)
35 {
36 	return (((uint64_t)(x)) * 1000000000 / hz);
37 }
38 
39 #define msecs_to_jiffies(x)	(((uint64_t)(x)) * hz / 1000)
40 #define usecs_to_jiffies(x)	(((uint64_t)(x)) * hz / 1000000)
41 #define nsecs_to_jiffies(x)	(((uint64_t)(x)) * hz / 1000000000)
42 #define nsecs_to_jiffies64(x)	(((uint64_t)(x)) * hz / 1000000000)
43 
44 static inline uint64_t
get_jiffies_64(void)45 get_jiffies_64(void)
46 {
47 	return jiffies;
48 }
49 
50 static inline int
time_after(const unsigned long a,const unsigned long b)51 time_after(const unsigned long a, const unsigned long b)
52 {
53 	return((long)(b - a) < 0);
54 }
55 #define time_before(a,b)	time_after(b,a)
56 
57 static inline int
time_after_eq(const unsigned long a,const unsigned long b)58 time_after_eq(const unsigned long a, const unsigned long b)
59 {
60 	return((long)(b - a) <= 0);
61 }
62 
63 static inline int
time_after_eq64(const unsigned long long a,const unsigned long long b)64 time_after_eq64(const unsigned long long a, const unsigned long long b)
65 {
66 	return((long long)(b - a) <= 0);
67 }
68 
69 #define time_after32(a,b)	((int32_t)((uint32_t)(b) - (uint32_t)(a)) < 0)
70 
71 #endif
72