1 #ifndef _LINUX_JIFFIES_H
2 #define _LINUX_JIFFIES_H
5 #include <linux/kernel.h>
6 #include <linux/time64.h>
7 #include <linux/typecheck.h>
8 #include <linux/types.h>
10 #define time_after(a,b) \
11 (typecheck(unsigned long, a) && \
12 typecheck(unsigned long, b) && \
13 ((long)((b) - (a)) < 0))
14 #define time_before(a,b) time_after(b,a)
16 #define time_after_eq(a,b) \
17 (typecheck(unsigned long, a) && \
18 typecheck(unsigned long, b) && \
19 ((long)((a) - (b)) >= 0))
20 #define time_before_eq(a,b) time_after_eq(b,a)
22 #define time_in_range(a,b,c) \
23 (time_after_eq(a,b) && \
26 #define time_in_range_open(a,b,c) \
27 (time_after_eq(a,b) && \
30 #define time_after64(a,b) \
31 (typecheck(__u64, a) && \
32 typecheck(__u64, b) && \
33 ((__s64)((b) - (a)) < 0))
34 #define time_before64(a,b) time_after64(b,a)
36 #define time_after_eq64(a,b) \
37 (typecheck(__u64, a) && \
38 typecheck(__u64, b) && \
39 ((__s64)((a) - (b)) >= 0))
40 #define time_before_eq64(a,b) time_after_eq64(b,a)
42 #define time_in_range64(a, b, c) \
43 (time_after_eq64(a, b) && \
44 time_before_eq64(a, c))
46 #define time_is_before_jiffies(a) time_after(jiffies, a)
50 static inline u64 jiffies_to_nsecs(const unsigned long j)
52 return (u64)j * NSEC_PER_MSEC;
55 static inline unsigned jiffies_to_msecs(const unsigned long j)
60 static inline unsigned long msecs_to_jiffies(const unsigned int m)
65 static inline unsigned long nsecs_to_jiffies(u64 n)
67 return n / NSEC_PER_MSEC;
70 static inline u64 sched_clock(void)
74 clock_gettime(CLOCK_MONOTONIC_COARSE, &ts);
76 return ((s64) ts.tv_sec * NSEC_PER_SEC) + ts.tv_nsec;
79 static inline u64 local_clock(void)
84 static inline u64 ktime_get_ns(void)
89 #define jiffies nsecs_to_jiffies(sched_clock())