xref: /openbsd/sys/dev/pci/drm/include/linux/jiffies.h (revision 3cab2bb3)
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 #define jiffies_to_msecs(x)	(((uint64_t)(x)) * 1000 / hz)
22 #define jiffies_to_usecs(x)	(((uint64_t)(x)) * 1000000 / hz)
23 #define msecs_to_jiffies(x)	(((uint64_t)(x)) * hz / 1000)
24 #define usecs_to_jiffies(x)	(((uint64_t)(x)) * hz / 1000000)
25 #define nsecs_to_jiffies(x)	(((uint64_t)(x)) * hz / 1000000000)
26 #define nsecs_to_jiffies64(x)	(((uint64_t)(x)) * hz / 1000000000)
27 #define get_jiffies_64()	jiffies
28 #define time_after(a,b)		((long)(b) - (long)(a) < 0)
29 #define time_after32(a,b)	((uint32_t)(b) - (uint32_t)(a) < 0)
30 #define time_after_eq(a,b)	((long)(b) - (long)(a) <= 0)
31 #define time_before(a,b)	((long)(a) - (long)(b) < 0)
32 
33 static inline unsigned long
34 timespec_to_jiffies(const struct timespec *ts)
35 {
36 	long long to_ticks;
37 
38 	to_ticks = (long long)hz * ts->tv_sec + ts->tv_nsec / (tick * 1000);
39 	if (to_ticks > INT_MAX)
40 		to_ticks = INT_MAX;
41 
42 	return ((int)to_ticks);
43 }
44 
45 #endif
46