timekeeping_internal.h 784 B

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