mach_clock.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * Copyright (C) 2006, 2007 Free Software Foundation, Inc.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2, or (at your option)
  7. * any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  17. *
  18. * Author: Barry deFreese and others.
  19. */
  20. #ifndef _KERN_MACH_CLOCK_H_
  21. #define _KERN_MACH_CLOCK_H_
  22. /*
  23. * Mach time-out and time-of-day facility.
  24. */
  25. #include <mach/machine/kern_return.h>
  26. #include <mach/time_value.h>
  27. #include <kern/host.h>
  28. #include <kern/queue.h>
  29. #include <sys/types.h>
  30. struct io_req;
  31. typedef struct io_req *io_req_t;
  32. /* Timers in kernel. */
  33. extern unsigned long elapsed_ticks; /* number of ticks elapsed since bootup */
  34. extern int hz; /* number of ticks per second */
  35. extern int tick; /* number of usec per tick */
  36. typedef void timer_func_t(void *);
  37. /* Time-out element. */
  38. struct timer_elt {
  39. queue_chain_t chain; /* chain in order of expiration */
  40. timer_func_t *fcn; /* function to call */
  41. void * param; /* with this parameter */
  42. unsigned long ticks; /* expiration time, in ticks */
  43. int set; /* unset | set | allocated */
  44. };
  45. #define TELT_UNSET 0 /* timer not set */
  46. #define TELT_SET 1 /* timer set */
  47. #define TELT_ALLOC 2 /* timer allocated from pool */
  48. typedef struct timer_elt timer_elt_data_t;
  49. typedef struct timer_elt *timer_elt_t;
  50. extern void clock_interrupt(
  51. int usec,
  52. boolean_t usermode,
  53. boolean_t basepri,
  54. vm_offset_t pc);
  55. extern void softclock (void);
  56. /* For `private' timer elements. */
  57. extern void set_timeout(
  58. timer_elt_t telt,
  59. unsigned int interval);
  60. extern boolean_t reset_timeout(timer_elt_t telt);
  61. #define set_timeout_setup(telt,fcn,param,interval) \
  62. ((telt)->fcn = (fcn), \
  63. (telt)->param = (param), \
  64. (telt)->private = TRUE, \
  65. set_timeout((telt), (interval)))
  66. #define reset_timeout_check(t) \
  67. MACRO_BEGIN \
  68. if ((t)->set) \
  69. reset_timeout((t)); \
  70. MACRO_END
  71. extern void init_timeout (void);
  72. /*
  73. * Record a timestamp in STAMP. Records values in the boot-time clock
  74. * frame.
  75. */
  76. extern void record_time_stamp (time_value_t *stamp);
  77. /*
  78. * Read a timestamp in STAMP into RESULT. Returns values in the
  79. * real-time clock frame.
  80. */
  81. extern void read_time_stamp (time_value_t *stamp, time_value_t *result);
  82. extern kern_return_t host_get_time(
  83. host_t host,
  84. time_value_t *current_time);
  85. extern kern_return_t host_set_time(
  86. host_t host,
  87. time_value_t new_time);
  88. extern kern_return_t host_adjust_time(
  89. host_t host,
  90. time_value_t new_adjustment,
  91. time_value_t *old_adjustment);
  92. extern void mapable_time_init (void);
  93. /* For public timer elements. */
  94. extern void timeout(timer_func_t *fcn, void *param, int interval);
  95. extern boolean_t untimeout(timer_func_t *fcn, const void *param);
  96. extern int timeopen(dev_t dev, int flag, io_req_t ior);
  97. extern void timeclose(dev_t dev, int flag);
  98. #endif /* _KERN_MACH_CLOCK_H_ */