xref: /linux/kernel/time/timekeeping_internal.h (revision f4cdf7ca9a1fdcca413157df19753f388a5a224e)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _TIMEKEEPING_INTERNAL_H
3 #define _TIMEKEEPING_INTERNAL_H
4 
5 #include <linux/clocksource.h>
6 #include <linux/spinlock.h>
7 #include <linux/time.h>
8 
9 struct timekeeper;
10 
11 /*
12  * timekeeping debug functions
13  */
14 #ifdef CONFIG_DEBUG_FS
15 
16 DECLARE_PER_CPU(unsigned long, timekeeping_mg_floor_swaps);
17 
18 static inline void timekeeping_inc_mg_floor_swaps(void)
19 {
20 	this_cpu_inc(timekeeping_mg_floor_swaps);
21 }
22 
23 extern void tk_debug_account_sleep_time(const struct timespec64 *t);
24 
25 #else
26 
27 #define tk_debug_account_sleep_time(x)
28 
29 static inline void timekeeping_inc_mg_floor_swaps(void)
30 {
31 }
32 
33 #endif
34 
35 static inline u64 clocksource_delta(u64 now, u64 last, u64 mask, u64 max_delta)
36 {
37 	u64 ret = (now - last) & mask;
38 
39 	/*
40 	 * Prevent time going backwards by checking the result against
41 	 * @max_delta. If greater, return 0.
42 	 */
43 	return ret > max_delta ? 0 : ret;
44 }
45 
46 /* Semi public for serialization of non timekeeper VDSO updates. */
47 unsigned long timekeeper_lock_irqsave(void);
48 void timekeeper_unlock_irqrestore(unsigned long flags);
49 
50 /* NTP specific interface to access the current seconds value */
51 long ktime_get_ntp_seconds(unsigned int id);
52 
53 #ifdef CONFIG_GENERIC_GETTIMEOFDAY
54 
55 extern void update_vsyscall(struct timekeeper *tk);
56 extern void update_vsyscall_tz(void);
57 extern void vdso_time_update_aux(struct timekeeper *tk);
58 
59 #else
60 
61 static inline void update_vsyscall(struct timekeeper *tk)
62 {
63 }
64 static inline void update_vsyscall_tz(void)
65 {
66 }
67 static inline void vdso_time_update_aux(struct timekeeper *tk)
68 {
69 }
70 #endif
71 
72 #endif /* _TIMEKEEPING_INTERNAL_H */
73