blob: 4ca2787d1642e2f52bf985607ca3b03785cf9a50 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Colin Cross5c835452013-05-21 22:32:14 -07002#ifndef _TIMEKEEPING_INTERNAL_H
3#define _TIMEKEEPING_INTERNAL_H
Thomas Gleixner19d00702020-08-04 17:01:23 +02004
5#include <linux/clocksource.h>
6#include <linux/spinlock.h>
7#include <linux/time.h>
8
Colin Cross5c835452013-05-21 22:32:14 -07009/*
10 * timekeeping debug functions
11 */
Colin Cross5c835452013-05-21 22:32:14 -070012#ifdef CONFIG_DEBUG_FS
Ondrej Mosnacek985e6952018-07-13 14:06:42 +020013extern void tk_debug_account_sleep_time(const struct timespec64 *t);
Colin Cross5c835452013-05-21 22:32:14 -070014#else
15#define tk_debug_account_sleep_time(x)
16#endif
17
Thomas Gleixner09ec5442014-07-16 21:05:12 +000018#ifdef CONFIG_CLOCKSOURCE_VALIDATE_LAST_CYCLE
Thomas Gleixnera5a1d1c2016-12-21 20:32:01 +010019static inline u64 clocksource_delta(u64 now, u64 last, u64 mask)
Thomas Gleixner09ec5442014-07-16 21:05:12 +000020{
Thomas Gleixnera5a1d1c2016-12-21 20:32:01 +010021 u64 ret = (now - last) & mask;
Thomas Gleixner09ec5442014-07-16 21:05:12 +000022
Yang Yingliang1f45f1f2015-10-31 18:20:55 +080023 /*
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 Gleixner09ec5442014-07-16 21:05:12 +000028}
29#else
Thomas Gleixnera5a1d1c2016-12-21 20:32:01 +010030static inline u64 clocksource_delta(u64 now, u64 last, u64 mask)
Thomas Gleixner3a978372014-07-16 21:05:10 +000031{
32 return (now - last) & mask;
33}
Thomas Gleixner09ec5442014-07-16 21:05:12 +000034#endif
Thomas Gleixner3a978372014-07-16 21:05:10 +000035
Thomas Gleixner19d00702020-08-04 17:01:23 +020036/* Semi public for serialization of non timekeeper VDSO updates. */
37extern raw_spinlock_t timekeeper_lock;
38
Colin Cross5c835452013-05-21 22:32:14 -070039#endif /* _TIMEKEEPING_INTERNAL_H */