time-utils.h 562 B

12345678910111213141516171819202122232425262728
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright 2023 Red Hat
  4. */
  5. #ifndef UDS_TIME_UTILS_H
  6. #define UDS_TIME_UTILS_H
  7. #include <linux/ktime.h>
  8. #include <linux/time.h>
  9. #include <linux/types.h>
  10. static inline s64 ktime_to_seconds(ktime_t reltime)
  11. {
  12. return reltime / NSEC_PER_SEC;
  13. }
  14. static inline ktime_t current_time_ns(clockid_t clock)
  15. {
  16. return clock == CLOCK_MONOTONIC ? ktime_get_ns() : ktime_get_real_ns();
  17. }
  18. static inline ktime_t current_time_us(void)
  19. {
  20. return current_time_ns(CLOCK_REALTIME) / NSEC_PER_USEC;
  21. }
  22. #endif /* UDS_TIME_UTILS_H */