Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
5c83545f CC |
2 | #ifndef _TIMEKEEPING_INTERNAL_H |
3 | #define _TIMEKEEPING_INTERNAL_H | |
19d0070a | 4 | |
3a978377 | 5 | #include <linux/clocksource.h> |
19d0070a | 6 | #include <linux/spinlock.h> |
5c83545f CC |
7 | #include <linux/time.h> |
8 | ||
19d0070a TG |
9 | /* |
10 | * timekeeping debug functions | |
11 | */ | |
5c83545f | 12 | #ifdef CONFIG_DEBUG_FS |
96f9a366 JL |
13 | |
14 | DECLARE_PER_CPU(unsigned long, timekeeping_mg_floor_swaps); | |
15 | ||
16 | static inline void timekeeping_inc_mg_floor_swaps(void) | |
17 | { | |
18 | this_cpu_inc(timekeeping_mg_floor_swaps); | |
19 | } | |
20 | ||
985e6950 | 21 | extern void tk_debug_account_sleep_time(const struct timespec64 *t); |
96f9a366 | 22 | |
5c83545f | 23 | #else |
96f9a366 | 24 | |
5c83545f | 25 | #define tk_debug_account_sleep_time(x) |
96f9a366 JL |
26 | |
27 | static inline void timekeeping_inc_mg_floor_swaps(void) | |
28 | { | |
29 | } | |
30 | ||
5c83545f CC |
31 | #endif |
32 | ||
76031d95 | 33 | static inline u64 clocksource_delta(u64 now, u64 last, u64 mask, u64 max_delta) |
09ec5442 | 34 | { |
a5a1d1c2 | 35 | u64 ret = (now - last) & mask; |
09ec5442 | 36 | |
1f45f1f3 | 37 | /* |
76031d95 TG |
38 | * Prevent time going backwards by checking the result against |
39 | * @max_delta. If greater, return 0. | |
1f45f1f3 | 40 | */ |
76031d95 | 41 | return ret > max_delta ? 0 : ret; |
09ec5442 | 42 | } |
3a978377 | 43 | |
19d0070a | 44 | /* Semi public for serialization of non timekeeper VDSO updates. */ |
dbdcf8c4 TG |
45 | unsigned long timekeeper_lock_irqsave(void); |
46 | void timekeeper_unlock_irqrestore(unsigned long flags); | |
19d0070a | 47 | |
5c83545f | 48 | #endif /* _TIMEKEEPING_INTERNAL_H */ |