blob: 4ca2787d1642e2f52bf985607ca3b03785cf9a50 [file] [log] [blame]
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef _TIMEKEEPING_INTERNAL_H
3#define _TIMEKEEPING_INTERNAL_H
Olivier Deprez157378f2022-04-04 15:47:50 +02004
5#include <linux/clocksource.h>
6#include <linux/spinlock.h>
7#include <linux/time.h>
8
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00009/*
10 * timekeeping debug functions
11 */
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000012#ifdef CONFIG_DEBUG_FS
13extern void tk_debug_account_sleep_time(const struct timespec64 *t);
14#else
15#define tk_debug_account_sleep_time(x)
16#endif
17
18#ifdef CONFIG_CLOCKSOURCE_VALIDATE_LAST_CYCLE
19static inline u64 clocksource_delta(u64 now, u64 last, u64 mask)
20{
21 u64 ret = (now - last) & mask;
22
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;
28}
29#else
30static inline u64 clocksource_delta(u64 now, u64 last, u64 mask)
31{
32 return (now - last) & mask;
33}
34#endif
35
Olivier Deprez157378f2022-04-04 15:47:50 +020036/* Semi public for serialization of non timekeeper VDSO updates. */
37extern raw_spinlock_t timekeeper_lock;
38
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000039#endif /* _TIMEKEEPING_INTERNAL_H */