backport-include: backport ktime_get_boottime_seconds
[openwrt/staging/blogic.git] / backport / backport-include / linux / timekeeping.h
1 #ifndef __BACKPORT_TIMEKEEPING_H
2 #define __BACKPORT_TIMEKEEPING_H
3 #include <linux/version.h>
4 #include <linux/types.h>
5
6 #if LINUX_VERSION_IS_GEQ(3,17,0)
7 #include_next <linux/timekeeping.h>
8 #endif
9
10 #if LINUX_VERSION_IS_LESS(3,17,0)
11 #define ktime_get_ns LINUX_BACKPORT(ktime_get_ns)
12 extern ktime_t ktime_get(void);
13 #define ktime_get_ns LINUX_BACKPORT(ktime_get_ns)
14 static inline u64 ktime_get_ns(void)
15 {
16 return ktime_to_ns(ktime_get());
17 }
18
19 extern ktime_t ktime_get_boottime(void);
20 #define ktime_get_boot_ns LINUX_BACKPORT(ktime_get_boot_ns)
21 static inline u64 ktime_get_boot_ns(void)
22 {
23 return ktime_to_ns(ktime_get_boottime());
24 }
25 #endif /* < 3.17 */
26
27 #if LINUX_VERSION_IS_LESS(4,18,0)
28 static inline time64_t ktime_get_boottime_seconds(void)
29 {
30 return ktime_divns(ktime_get_boottime(), NSEC_PER_SEC);
31 }
32 #endif /* < 4.18 */
33
34 #if LINUX_VERSION_IS_LESS(3,19,0)
35 static inline time64_t ktime_get_seconds(void)
36 {
37 struct timespec t;
38
39 ktime_get_ts(&t);
40
41 return t.tv_sec;
42 }
43
44 static inline time64_t ktime_get_real_seconds(void)
45 {
46 struct timeval tv;
47
48 do_gettimeofday(&tv);
49
50 return tv.tv_sec;
51 }
52 #endif
53
54 #if LINUX_VERSION_IS_LESS(3,17,0)
55 static inline void ktime_get_ts64(struct timespec64 *ts)
56 {
57 ktime_get_ts(ts);
58 }
59 #endif
60
61 #endif /* __BACKPORT_TIMEKEEPING_H */