blob: 5be76270ec4a8f155574aabe2812f9edefb80aec [file] [log] [blame]
Colin Cross5c835452013-05-21 22:32:14 -07001#ifndef _TIMEKEEPING_INTERNAL_H
2#define _TIMEKEEPING_INTERNAL_H
3/*
4 * timekeeping debug functions
5 */
Thomas Gleixner3a978372014-07-16 21:05:10 +00006#include <linux/clocksource.h>
Colin Cross5c835452013-05-21 22:32:14 -07007#include <linux/time.h>
8
9#ifdef CONFIG_DEBUG_FS
John Stultz7d489d12014-07-16 21:04:01 +000010extern void tk_debug_account_sleep_time(struct timespec64 *t);
Colin Cross5c835452013-05-21 22:32:14 -070011#else
12#define tk_debug_account_sleep_time(x)
13#endif
14
Thomas Gleixner09ec5442014-07-16 21:05:12 +000015#ifdef CONFIG_CLOCKSOURCE_VALIDATE_LAST_CYCLE
16static inline cycle_t clocksource_delta(cycle_t now, cycle_t last, cycle_t mask)
17{
18 cycle_t ret = (now - last) & mask;
19
Yang Yingliang1f45f1f2015-10-31 18:20:55 +080020 /*
21 * Prevent time going backwards by checking the MSB of mask in
22 * the result. If set, return 0.
23 */
24 return ret & ~(mask >> 1) ? 0 : ret;
Thomas Gleixner09ec5442014-07-16 21:05:12 +000025}
26#else
Thomas Gleixner3a978372014-07-16 21:05:10 +000027static inline cycle_t clocksource_delta(cycle_t now, cycle_t last, cycle_t mask)
28{
29 return (now - last) & mask;
30}
Thomas Gleixner09ec5442014-07-16 21:05:12 +000031#endif
Thomas Gleixner3a978372014-07-16 21:05:10 +000032
DengChaodee36652015-12-13 12:24:18 +080033extern time64_t __ktime_get_real_seconds(void);
34
Colin Cross5c835452013-05-21 22:32:14 -070035#endif /* _TIMEKEEPING_INTERNAL_H */