Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Colin Cross | 5c83545 | 2013-05-21 22:32:14 -0700 | [diff] [blame] | 2 | #ifndef _TIMEKEEPING_INTERNAL_H |
| 3 | #define _TIMEKEEPING_INTERNAL_H |
Thomas Gleixner | 19d0070 | 2020-08-04 17:01:23 +0200 | [diff] [blame] | 4 | |
| 5 | #include <linux/clocksource.h> |
| 6 | #include <linux/spinlock.h> |
| 7 | #include <linux/time.h> |
| 8 | |
Colin Cross | 5c83545 | 2013-05-21 22:32:14 -0700 | [diff] [blame] | 9 | /* |
| 10 | * timekeeping debug functions |
| 11 | */ |
Colin Cross | 5c83545 | 2013-05-21 22:32:14 -0700 | [diff] [blame] | 12 | #ifdef CONFIG_DEBUG_FS |
Ondrej Mosnacek | 985e695 | 2018-07-13 14:06:42 +0200 | [diff] [blame] | 13 | extern void tk_debug_account_sleep_time(const struct timespec64 *t); |
Colin Cross | 5c83545 | 2013-05-21 22:32:14 -0700 | [diff] [blame] | 14 | #else |
| 15 | #define tk_debug_account_sleep_time(x) |
| 16 | #endif |
| 17 | |
Thomas Gleixner | 09ec544 | 2014-07-16 21:05:12 +0000 | [diff] [blame] | 18 | #ifdef CONFIG_CLOCKSOURCE_VALIDATE_LAST_CYCLE |
Thomas Gleixner | a5a1d1c | 2016-12-21 20:32:01 +0100 | [diff] [blame] | 19 | static inline u64 clocksource_delta(u64 now, u64 last, u64 mask) |
Thomas Gleixner | 09ec544 | 2014-07-16 21:05:12 +0000 | [diff] [blame] | 20 | { |
Thomas Gleixner | a5a1d1c | 2016-12-21 20:32:01 +0100 | [diff] [blame] | 21 | u64 ret = (now - last) & mask; |
Thomas Gleixner | 09ec544 | 2014-07-16 21:05:12 +0000 | [diff] [blame] | 22 | |
Yang Yingliang | 1f45f1f | 2015-10-31 18:20:55 +0800 | [diff] [blame] | 23 | /* |
| 24 | * Prevent time going backwards by checking the MSB of mask in |
| 25 | * the result. If set, return 0. |
| 26 | */ |
| 27 | return ret & ~(mask >> 1) ? 0 : ret; |
Thomas Gleixner | 09ec544 | 2014-07-16 21:05:12 +0000 | [diff] [blame] | 28 | } |
| 29 | #else |
Thomas Gleixner | a5a1d1c | 2016-12-21 20:32:01 +0100 | [diff] [blame] | 30 | static inline u64 clocksource_delta(u64 now, u64 last, u64 mask) |
Thomas Gleixner | 3a97837 | 2014-07-16 21:05:10 +0000 | [diff] [blame] | 31 | { |
| 32 | return (now - last) & mask; |
| 33 | } |
Thomas Gleixner | 09ec544 | 2014-07-16 21:05:12 +0000 | [diff] [blame] | 34 | #endif |
Thomas Gleixner | 3a97837 | 2014-07-16 21:05:10 +0000 | [diff] [blame] | 35 | |
Thomas Gleixner | 19d0070 | 2020-08-04 17:01:23 +0200 | [diff] [blame] | 36 | /* Semi public for serialization of non timekeeper VDSO updates. */ |
| 37 | extern raw_spinlock_t timekeeper_lock; |
| 38 | |
Colin Cross | 5c83545 | 2013-05-21 22:32:14 -0700 | [diff] [blame] | 39 | #endif /* _TIMEKEEPING_INTERNAL_H */ |