]> git.sesse.net Git - bcachefs-tools-debian/blob - c_src/include/linux/jiffies.h
rust: bump rpassword to v7.x
[bcachefs-tools-debian] / c_src / include / linux / jiffies.h
1 #ifndef _LINUX_JIFFIES_H
2 #define _LINUX_JIFFIES_H
3
4 #include <time.h>
5 #include <linux/kernel.h>
6 #include <linux/time64.h>
7 #include <linux/typecheck.h>
8 #include <linux/types.h>
9
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)
15
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)
21
22 #define time_in_range(a,b,c) \
23         (time_after_eq(a,b) && \
24          time_before_eq(a,c))
25
26 #define time_in_range_open(a,b,c) \
27         (time_after_eq(a,b) && \
28          time_before(a,c))
29
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)
35
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)
41
42 #define time_in_range64(a, b, c) \
43         (time_after_eq64(a, b) && \
44          time_before_eq64(a, c))
45
46 #define time_is_before_jiffies(a) time_after(jiffies, a)
47
48 #define HZ              1000
49
50 static inline u64 jiffies_to_nsecs(const unsigned long j)
51 {
52         return (u64)j * NSEC_PER_MSEC;
53 }
54
55 static inline unsigned jiffies_to_msecs(const unsigned long j)
56 {
57         return j;
58 }
59
60 static inline unsigned long msecs_to_jiffies(const unsigned int m)
61 {
62         return m;
63 }
64
65 static inline unsigned long nsecs_to_jiffies(u64 n)
66 {
67         return n / NSEC_PER_MSEC;
68 }
69
70 static inline u64 sched_clock(void)
71 {
72         struct timespec ts;
73
74         clock_gettime(CLOCK_MONOTONIC_COARSE, &ts);
75
76         return ((s64) ts.tv_sec * NSEC_PER_SEC) + ts.tv_nsec;
77 }
78
79 static inline u64 local_clock(void)
80 {
81         return sched_clock();
82 }
83
84 static inline u64 ktime_get_ns(void)
85 {
86         return sched_clock();
87 }
88
89 #define jiffies                 nsecs_to_jiffies(sched_clock())
90
91 #endif