time.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. #ifndef _TIME_H
  3. #define _TIME_H
  4. #include <linux/typecheck.h>
  5. #include <linux/types.h>
  6. unsigned long get_timer(unsigned long base);
  7. /*
  8. * Return the current value of a monotonically increasing microsecond timer.
  9. * Granularity may be larger than 1us if hardware does not support this.
  10. */
  11. unsigned long timer_get_us(void);
  12. /*
  13. * timer_test_add_offset()
  14. *
  15. * Allow tests to add to the time reported through lib/time.c functions
  16. * offset: number of milliseconds to advance the system time
  17. */
  18. void timer_test_add_offset(unsigned long offset);
  19. /**
  20. * usec_to_tick() - convert microseconds to clock ticks
  21. *
  22. * @usec: duration in microseconds
  23. * Return: duration in clock ticks
  24. */
  25. uint64_t usec_to_tick(unsigned long usec);
  26. /*
  27. * These inlines deal with timer wrapping correctly. You are
  28. * strongly encouraged to use them
  29. * 1. Because people otherwise forget
  30. * 2. Because if the timer wrap changes in future you won't have to
  31. * alter your driver code.
  32. *
  33. * time_after(a,b) returns true if the time a is after time b.
  34. *
  35. * Do this with "<0" and ">=0" to only test the sign of the result. A
  36. * good compiler would generate better code (and a really good compiler
  37. * wouldn't care). Gcc is currently neither.
  38. */
  39. #define time_after(a,b) \
  40. (typecheck(unsigned long, a) && \
  41. typecheck(unsigned long, b) && \
  42. ((long)((b) - (a)) < 0))
  43. #define time_before(a,b) time_after(b,a)
  44. #define time_after_eq(a,b) \
  45. (typecheck(unsigned long, a) && \
  46. typecheck(unsigned long, b) && \
  47. ((long)((a) - (b)) >= 0))
  48. #define time_before_eq(a,b) time_after_eq(b,a)
  49. /*
  50. * Calculate whether a is in the range of [b, c].
  51. */
  52. #define time_in_range(a,b,c) \
  53. (time_after_eq(a,b) && \
  54. time_before_eq(a,c))
  55. /*
  56. * Calculate whether a is in the range of [b, c).
  57. */
  58. #define time_in_range_open(a,b,c) \
  59. (time_after_eq(a,b) && \
  60. time_before(a,c))
  61. #endif /* _TIME_H */