xref: /OK3568_Linux_fs/kernel/kernel/time/timekeeping_internal.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun #ifndef _TIMEKEEPING_INTERNAL_H
3*4882a593Smuzhiyun #define _TIMEKEEPING_INTERNAL_H
4*4882a593Smuzhiyun 
5*4882a593Smuzhiyun #include <linux/clocksource.h>
6*4882a593Smuzhiyun #include <linux/spinlock.h>
7*4882a593Smuzhiyun #include <linux/time.h>
8*4882a593Smuzhiyun 
9*4882a593Smuzhiyun /*
10*4882a593Smuzhiyun  * timekeeping debug functions
11*4882a593Smuzhiyun  */
12*4882a593Smuzhiyun #ifdef CONFIG_DEBUG_FS
13*4882a593Smuzhiyun extern void tk_debug_account_sleep_time(const struct timespec64 *t);
14*4882a593Smuzhiyun #else
15*4882a593Smuzhiyun #define tk_debug_account_sleep_time(x)
16*4882a593Smuzhiyun #endif
17*4882a593Smuzhiyun 
18*4882a593Smuzhiyun #ifdef CONFIG_CLOCKSOURCE_VALIDATE_LAST_CYCLE
clocksource_delta(u64 now,u64 last,u64 mask)19*4882a593Smuzhiyun static inline u64 clocksource_delta(u64 now, u64 last, u64 mask)
20*4882a593Smuzhiyun {
21*4882a593Smuzhiyun 	u64 ret = (now - last) & mask;
22*4882a593Smuzhiyun 
23*4882a593Smuzhiyun 	/*
24*4882a593Smuzhiyun 	 * Prevent time going backwards by checking the MSB of mask in
25*4882a593Smuzhiyun 	 * the result. If set, return 0.
26*4882a593Smuzhiyun 	 */
27*4882a593Smuzhiyun 	return ret & ~(mask >> 1) ? 0 : ret;
28*4882a593Smuzhiyun }
29*4882a593Smuzhiyun #else
clocksource_delta(u64 now,u64 last,u64 mask)30*4882a593Smuzhiyun static inline u64 clocksource_delta(u64 now, u64 last, u64 mask)
31*4882a593Smuzhiyun {
32*4882a593Smuzhiyun 	return (now - last) & mask;
33*4882a593Smuzhiyun }
34*4882a593Smuzhiyun #endif
35*4882a593Smuzhiyun 
36*4882a593Smuzhiyun /* Semi public for serialization of non timekeeper VDSO updates. */
37*4882a593Smuzhiyun extern raw_spinlock_t timekeeper_lock;
38*4882a593Smuzhiyun 
39*4882a593Smuzhiyun #endif /* _TIMEKEEPING_INTERNAL_H */
40