blob: bcbb52db22565971d1a4885bd8e177c21265e6a5 [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
4/*
5 * timekeeping debug functions
6 */
Thomas Gleixner3a978372014-07-16 21:05:10 +00007#include <linux/clocksource.h>
Colin Cross5c835452013-05-21 22:32:14 -07008#include <linux/time.h>
9
10#ifdef CONFIG_DEBUG_FS
Ondrej Mosnacek985e6952018-07-13 14:06:42 +020011extern void tk_debug_account_sleep_time(const struct timespec64 *t);
Colin Cross5c835452013-05-21 22:32:14 -070012#else
13#define tk_debug_account_sleep_time(x)
14#endif
15
Thomas Gleixner09ec5442014-07-16 21:05:12 +000016#ifdef CONFIG_CLOCKSOURCE_VALIDATE_LAST_CYCLE
Thomas Gleixnera5a1d1c2016-12-21 20:32:01 +010017static inline u64 clocksource_delta(u64 now, u64 last, u64 mask)
Thomas Gleixner09ec5442014-07-16 21:05:12 +000018{
Thomas Gleixnera5a1d1c2016-12-21 20:32:01 +010019 u64 ret = (now - last) & mask;
Thomas Gleixner09ec5442014-07-16 21:05:12 +000020
Yang Yingliang1f45f1f2015-10-31 18:20:55 +080021 /*
22 * Prevent time going backwards by checking the MSB of mask in
23 * the result. If set, return 0.
24 */
25 return ret & ~(mask >> 1) ? 0 : ret;
Thomas Gleixner09ec5442014-07-16 21:05:12 +000026}
27#else
Thomas Gleixnera5a1d1c2016-12-21 20:32:01 +010028static inline u64 clocksource_delta(u64 now, u64 last, u64 mask)
Thomas Gleixner3a978372014-07-16 21:05:10 +000029{
30 return (now - last) & mask;
31}
Thomas Gleixner09ec5442014-07-16 21:05:12 +000032#endif
Thomas Gleixner3a978372014-07-16 21:05:10 +000033
Colin Cross5c835452013-05-21 22:32:14 -070034#endif /* _TIMEKEEPING_INTERNAL_H */