timekeeping_internal.h 921 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _TIMEKEEPING_INTERNAL_H
  3. #define _TIMEKEEPING_INTERNAL_H
  4. #include <linux/clocksource.h>
  5. #include <linux/spinlock.h>
  6. #include <linux/time.h>
  7. /*
  8. * timekeeping debug functions
  9. */
  10. #ifdef CONFIG_DEBUG_FS
  11. extern void tk_debug_account_sleep_time(const struct timespec64 *t);
  12. #else
  13. #define tk_debug_account_sleep_time(x)
  14. #endif
  15. #ifdef CONFIG_CLOCKSOURCE_VALIDATE_LAST_CYCLE
  16. static inline u64 clocksource_delta(u64 now, u64 last, u64 mask)
  17. {
  18. u64 ret = (now - last) & mask;
  19. /*
  20. * Prevent time going backwards by checking the MSB of mask in
  21. * the result. If set, return 0.
  22. */
  23. return ret & ~(mask >> 1) ? 0 : ret;
  24. }
  25. #else
  26. static inline u64 clocksource_delta(u64 now, u64 last, u64 mask)
  27. {
  28. return (now - last) & mask;
  29. }
  30. #endif
  31. /* Semi public for serialization of non timekeeper VDSO updates. */
  32. extern raw_spinlock_t timekeeper_lock;
  33. #endif /* _TIMEKEEPING_INTERNAL_H */