]> git.saurik.com Git - apple/xnu.git/blobdiff - osfmk/kern/clock.h
xnu-7195.50.7.100.1.tar.gz
[apple/xnu.git] / osfmk / kern / clock.h
index ed8218d17d8a2196836ffd4182299aa37dbb0661..44cd5533d19f24f795f8c162b33d32f147e0782d 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (c) 2000-2008 Apple Inc. All rights reserved.
  *
  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
- * 
+ *
  * This file contains Original Code and/or Modifications of Original Code
  * as defined in and that are subject to the Apple Public Source License
  * Version 2.0 (the 'License'). You may not use this file except in
  * unlawful or unlicensed copies of an Apple operating system, or to
  * circumvent, violate, or enable the circumvention or violation of, any
  * terms of an Apple operating system software license agreement.
- * 
+ *
  * Please obtain a copy of the License at
  * http://www.opensource.apple.com/apsl/ and read it before using this file.
- * 
+ *
  * The Original Code and all software distributed under the License are
  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
@@ -22,7 +22,7 @@
  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
  * Please see the License for the specific language governing rights and
  * limitations under the License.
- * 
+ *
  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
  */
 /*
 /*
  */
 
-#ifndef        _KERN_CLOCK_H_
-#define        _KERN_CLOCK_H_
+#ifndef _KERN_CLOCK_H_
+#define _KERN_CLOCK_H_
 
 #include <stdint.h>
 #include <mach/mach_types.h>
 #include <mach/clock_types.h>
 #include <mach/message.h>
 #include <mach/mach_time.h>
+#include <mach/boolean.h>
 
 #include <kern/kern_types.h>
 
 #include <sys/cdefs.h>
 
-#ifdef __LP64__
 
-typedef unsigned long          clock_sec_t;
-typedef unsigned int           clock_usec_t, clock_nsec_t;
+#ifdef  __LP64__
+
+typedef unsigned long           clock_sec_t;
+typedef unsigned int            clock_usec_t, clock_nsec_t;
 
-#else  /* __LP64__ */
+#else   /* __LP64__ */
 
-typedef uint32_t                       clock_sec_t;
-typedef uint32_t                       clock_usec_t, clock_nsec_t;
+typedef uint32_t                        clock_sec_t;
+typedef uint32_t                        clock_usec_t, clock_nsec_t;
 
-#endif /* __LP64__ */
+#endif  /* __LP64__ */
 
-#ifdef MACH_KERNEL_PRIVATE
+#ifdef  MACH_KERNEL_PRIVATE
 
 #include <kern/queue.h>
 
@@ -64,257 +66,280 @@ typedef uint32_t                  clock_usec_t, clock_nsec_t;
  * Clock operations list structure. Contains vectors to machine
  * dependent clock routines.
  */
-struct clock_ops {
-       int             (*c_config)(void);              /* configuration */
+struct  clock_ops {
+       int             (*c_config)(void);              /* configuration */
 
-       int             (*c_init)(void);                /* initialize */
+       int             (*c_init)(void);                /* initialize */
 
-       kern_return_t   (*c_gettime)(   /* get time */
-                               mach_timespec_t                 *cur_time);
+       kern_return_t   (*c_gettime)(   /* get time */
+               mach_timespec_t                 *cur_time);
 
-       kern_return_t   (*c_getattr)(   /* get attributes */
-                               clock_flavor_t                  flavor,
-                               clock_attr_t                    attr,
-                               mach_msg_type_number_t  *count);
+       kern_return_t   (*c_getattr)(   /* get attributes */
+               clock_flavor_t                  flavor,
+               clock_attr_t                    attr,
+               mach_msg_type_number_t  *count);
 };
-typedef struct clock_ops       *clock_ops_t;
-typedef struct clock_ops       clock_ops_data_t;
+typedef const struct clock_ops  *clock_ops_t;
+typedef struct clock_ops        clock_ops_data_t;
 
 /*
  * Actual clock object data structure. Contains the machine
  * dependent operations list and clock operation ports.
  */
-struct clock {
-       clock_ops_t                     cl_ops;                 /* operations list */
-       struct ipc_port         *cl_service;    /* service port */
-       struct ipc_port         *cl_control;    /* control port */
+struct  clock {
+       clock_ops_t             cl_ops;         /* operations list */
+       struct ipc_port         *cl_service;    /* service port */
+       struct ipc_port         *cl_control;    /* control port */
 };
-typedef struct clock           clock_data_t;
+typedef struct clock            clock_data_t;
 
 /*
  * Configure the clock system.
  */
-extern void            clock_config(void);
-extern void            clock_oldconfig(void);
+extern void             clock_config(void);
+extern void             clock_oldconfig(void);
 
 /*
  * Initialize the clock system.
  */
-extern void            clock_init(void);
-extern void            clock_oldinit(void);
+extern void             clock_init(void);
+extern void             clock_oldinit(void);
 
-extern void            clock_timebase_init(void);
+extern void             clock_timebase_init(void);
 
 /*
  * Initialize the clock ipc service facility.
  */
-extern void            clock_service_create(void);
-
-extern void                    clock_gettimeofday_set_commpage(
-                                               uint64_t                                abstime,
-                                               uint64_t                                epoch,
-                                               uint64_t                                offset,
-                                               clock_sec_t                             *secs,
-                                               clock_usec_t                    *microsecs);
+extern void             clock_service_create(void);
 
-extern void                    machine_delay_until(
-                                               uint64_t                deadline);
+extern void clock_gettimeofday_set_commpage(
+       uint64_t                                abstime,
+       uint64_t                                sec,
+       uint64_t                                frac,
+       uint64_t                                scale,
+       uint64_t                                tick_per_sec);
 
-extern uint32_t                hz_tick_interval;
+extern void                     machine_delay_until(uint64_t interval,
+    uint64_t                deadline);
 
-extern void            absolutetime_to_nanotime(
-                                       uint64_t                abstime,
-                                       clock_sec_t             *secs,
-                                       clock_nsec_t    *nanosecs);
+extern uint32_t         hz_tick_interval;
 
-extern void            nanotime_to_absolutetime(
-                                       clock_sec_t             secs,
-                                       clock_nsec_t    nanosecs,
-                                       uint64_t                *result);
+extern void             nanotime_to_absolutetime(
+       clock_sec_t             secs,
+       clock_nsec_t    nanosecs,
+       uint64_t                *result);
 
 #endif /* MACH_KERNEL_PRIVATE */
 
 __BEGIN_DECLS
 
-#ifdef XNU_KERNEL_PRIVATE
+#ifdef  XNU_KERNEL_PRIVATE
 
-extern void                    clock_adjtime(
-                                               long            *secs,
-                                               int                     *microsecs);
+extern void                     clock_adjtime(
+       long            *secs,
+       int                     *microsecs);
 
-extern void                    clock_initialize_calendar(void);
+extern void                     clock_initialize_calendar(void);
 
-extern void                    clock_wakeup_calendar(void);
+extern void                     clock_wakeup_calendar(void);
 
-extern void                    clock_gettimeofday(
-                                               clock_sec_t                     *secs,
-                                               clock_usec_t            *microsecs);
+extern void                     clock_update_calendar(void);
 
-extern void                    clock_set_calendar_microtime(
-                                               clock_sec_t                     secs,
-                                               clock_usec_t            microsecs);
+extern void                     clock_get_calendar_uptime(clock_sec_t           *secs);
 
-extern void                    clock_get_boottime_nanotime(
-                                               clock_sec_t                     *secs,
-                                               clock_nsec_t            *nanosecs);
+extern void clock_gettimeofday_new(clock_sec_t          *secs,
+    clock_usec_t    *microsecs);
+extern void                     clock_gettimeofday(
+       clock_sec_t                     *secs,
+       clock_usec_t            *microsecs);
 
-extern void                    absolutetime_to_microtime(
-                                               uint64_t                        abstime,
-                                               clock_sec_t                     *secs,
-                                               clock_usec_t            *microsecs);
+extern void                     clock_gettimeofday_and_absolute_time(
+       clock_sec_t                     *secs,
+       clock_usec_t            *microsecs,
+       uint64_t                        *absolute_time);
 
-extern void                    clock_deadline_for_periodic_event(
-                                               uint64_t                        interval,
-                                               uint64_t                        abstime,
-                                               uint64_t                        *deadline);
 
-#if    CONFIG_DTRACE
+extern void                     clock_set_calendar_microtime(
+       clock_sec_t                     secs,
+       clock_usec_t            microsecs);
 
-extern void                    clock_get_calendar_nanotime_nowait(
-                                               clock_sec_t                     *secs,
-                                               clock_nsec_t            *nanosecs);
+extern void                     clock_get_boottime_nanotime(
+       clock_sec_t                     *secs,
+       clock_nsec_t            *nanosecs);
 
-#endif /* CONFIG_DTRACE */
+extern void                     clock_get_boottime_microtime(
+       clock_sec_t                     *secs,
+       clock_nsec_t            *microsecs);
 
-#endif /* XNU_KERNEL_PRIVATE */
+extern void                     absolutetime_to_microtime(
+       uint64_t                        abstime,
+       clock_sec_t                     *secs,
+       clock_usec_t            *microsecs);
 
-extern void                    clock_get_calendar_microtime(
-                                               clock_sec_t                     *secs,
-                                               clock_usec_t            *microsecs);
+extern void                     clock_deadline_for_periodic_event(
+       uint64_t                        interval,
+       uint64_t                        abstime,
+       uint64_t                        *deadline);
 
-extern void                    clock_get_calendar_nanotime(
-                                               clock_sec_t                     *secs,
-                                               clock_nsec_t            *nanosecs);
+#if     CONFIG_DTRACE
 
-extern void                    clock_get_system_microtime(
-                                               clock_sec_t                     *secs,
-                                               clock_usec_t            *microsecs);
+extern void                     clock_get_calendar_nanotime_nowait(
+       clock_sec_t                     *secs,
+       clock_nsec_t            *nanosecs);
 
-extern void                    clock_get_system_nanotime(
-                                               clock_sec_t                     *secs,
-                                               clock_nsec_t            *nanosecs);
+#endif  /* CONFIG_DTRACE */
 
-extern void                            clock_timebase_info(
-                                                       mach_timebase_info_t    info);
+boolean_t kdp_clock_is_locked(void);
 
-extern void                            clock_get_uptime(
-                                                       uint64_t                *result);
+#endif  /* XNU_KERNEL_PRIVATE */
 
-extern void                            clock_interval_to_deadline(
-                                                       uint32_t                interval,
-                                                       uint32_t                scale_factor,
-                                                       uint64_t                *result);
+extern void                     clock_get_calendar_microtime(
+       clock_sec_t                     *secs,
+       clock_usec_t            *microsecs);
 
-extern void                            clock_interval_to_absolutetime_interval(
-                                                       uint32_t                interval,
-                                                       uint32_t                scale_factor,
-                                                       uint64_t                *result);
+extern void                     clock_get_calendar_absolute_and_microtime(
+       clock_sec_t                     *secs,
+       clock_usec_t            *microsecs,
+       uint64_t                *abstime);
 
-extern void                            clock_absolutetime_interval_to_deadline(
-                                                       uint64_t                abstime,
-                                                       uint64_t                *result);
+extern void                     clock_get_calendar_nanotime(
+       clock_sec_t                     *secs,
+       clock_nsec_t            *nanosecs);
 
-extern void                            clock_delay_until(
-                                                       uint64_t                deadline);
+extern void                     clock_get_system_microtime(
+       clock_sec_t                     *secs,
+       clock_usec_t            *microsecs);
 
-extern void                            absolutetime_to_nanoseconds(
-                                                       uint64_t                abstime,
-                                                       uint64_t                *result);
+extern void                     clock_get_system_nanotime(
+       clock_sec_t                     *secs,
+       clock_nsec_t            *nanosecs);
 
-extern void             nanoseconds_to_absolutetime(
-                                                       uint64_t                nanoseconds,
-                                                       uint64_t                *result);
+extern void                             clock_timebase_info(
+       mach_timebase_info_t    info);
 
-#ifdef KERNEL_PRIVATE
+extern void                             clock_get_uptime(
+       uint64_t                *result);
 
-/*
- * Obsolete interfaces.
- */
+extern void                             clock_interval_to_deadline(
+       uint32_t                interval,
+       uint32_t                scale_factor,
+       uint64_t                *result);
 
-#ifndef        __LP64__
-
-#define MACH_TIMESPEC_SEC_MAX          (0 - 1)
-#define MACH_TIMESPEC_NSEC_MAX         (NSEC_PER_SEC - 1)
-
-#define MACH_TIMESPEC_MAX      ((mach_timespec_t) {                            \
-                                                                       MACH_TIMESPEC_SEC_MAX,          \
-                                                                       MACH_TIMESPEC_NSEC_MAX } )
-#define MACH_TIMESPEC_ZERO     ((mach_timespec_t) { 0, 0 } )
-
-#define ADD_MACH_TIMESPEC_NSEC(t1, nsec)               \
-  do {                                                                                 \
-       (t1)->tv_nsec += (clock_res_t)(nsec);           \
-       if ((clock_res_t)(nsec) > 0 &&                          \
-                       (t1)->tv_nsec >= NSEC_PER_SEC) {        \
-               (t1)->tv_nsec -= NSEC_PER_SEC;                  \
-               (t1)->tv_sec += 1;                                              \
-       }                                                                                       \
-       else if ((clock_res_t)(nsec) < 0 &&                     \
-                                (t1)->tv_nsec < 0) {                   \
-               (t1)->tv_nsec += NSEC_PER_SEC;                  \
-               (t1)->tv_sec -= 1;                                              \
-       }                                                                                       \
-  } while (0)
+extern void                             nanoseconds_to_deadline(
+       uint64_t                interval,
+       uint64_t                *result);
 
-#include <Availability.h>
+extern void                             clock_interval_to_absolutetime_interval(
+       uint32_t                interval,
+       uint32_t                scale_factor,
+       uint64_t                *result);
 
-/* Use mach_absolute_time() */
-extern mach_timespec_t clock_get_system_value(void) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_0, __MAC_10_8, __IPHONE_2_0, __IPHONE_NA);
+extern void                             clock_absolutetime_interval_to_deadline(
+       uint64_t                abstime,
+       uint64_t                *result);
 
-extern mach_timespec_t clock_get_calendar_value(void) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_0, __MAC_10_8, __IPHONE_2_0, __IPHONE_NA);
+extern void                             clock_continuoustime_interval_to_deadline(
+       uint64_t                abstime,
+       uint64_t                *result);
 
-#else  /* __LP64__ */
+extern void                             clock_delay_until(
+       uint64_t                deadline);
 
-#ifdef XNU_KERNEL_PRIVATE
+extern void                             absolutetime_to_nanoseconds(
+       uint64_t                abstime,
+       uint64_t                *result);
 
-#define MACH_TIMESPEC_ZERO     ((mach_timespec_t) { 0, 0 } )
+extern void                             nanoseconds_to_absolutetime(
+       uint64_t                nanoseconds,
+       uint64_t                *result);
 
-#endif /* XNU_KERNEL_PRIVATE */
-
-#endif /* __LP64__ */
+/*
+ * Absolute <-> Continuous Time conversion routines
+ *
+ * It is the caller's responsibility to ensure that these functions are
+ * synchronized with respect to updates to the continuous timebase.  The
+ * returned value is only valid until the next update to the continuous
+ * timebase.
+ *
+ * If the value to be returned by continuoustime_to_absolutetime would be
+ * negative, zero is returned.  This occurs when the provided continuous time
+ * is less the amount of the time the system spent asleep and /must/ be
+ * handled.
+ */
+extern uint64_t                 absolutetime_to_continuoustime(
+       uint64_t                abstime);
+extern uint64_t                 continuoustime_to_absolutetime(
+       uint64_t                conttime);
 
-extern void                            delay_for_interval(
-                                                       uint32_t                interval,
-                                                       uint32_t                scale_factor);
+extern uint64_t mach_absolutetime_asleep;
+extern uint64_t mach_absolutetime_last_sleep;
+#if HIBERNATION && HAS_CONTINUOUS_HWCLOCK
+extern uint64_t hwclock_conttime_offset;
+#endif
 
-#ifndef        MACH_KERNEL_PRIVATE
+#ifdef  KERNEL_PRIVATE
 
-#ifndef        __LP64__
+/*
+ * Obsolete interfaces.
+ */
 
-#ifndef        ABSOLUTETIME_SCALAR_TYPE
+#ifndef __LP64__
+
+#define MACH_TIMESPEC_SEC_MAX           (0 - 1)
+#define MACH_TIMESPEC_NSEC_MAX          (NSEC_PER_SEC - 1)
+
+#define MACH_TIMESPEC_MAX       ((mach_timespec_t) {                            \
+                                                                       MACH_TIMESPEC_SEC_MAX,          \
+                                                                       MACH_TIMESPEC_NSEC_MAX } )
+#define MACH_TIMESPEC_ZERO      ((mach_timespec_t) { 0, 0 } )
+
+#define ADD_MACH_TIMESPEC_NSEC(t1, nsec)                \
+  do {                                                                                  \
+       (t1)->tv_nsec += (clock_res_t)(nsec);           \
+       if ((clock_res_t)(nsec) > 0 &&                          \
+                       (t1)->tv_nsec >= NSEC_PER_SEC) {        \
+               (t1)->tv_nsec -= NSEC_PER_SEC;                  \
+               (t1)->tv_sec += 1;                                              \
+       }                                                                                       \
+       else if ((clock_res_t)(nsec) < 0 &&                     \
+                                (t1)->tv_nsec < 0) {                   \
+               (t1)->tv_nsec += NSEC_PER_SEC;                  \
+               (t1)->tv_sec -= 1;                                              \
+       }                                                                                       \
+  } while (0)
 
-#define clock_get_uptime(a)            \
-       clock_get_uptime(__OSAbsoluteTimePtr(a))
+#include <Availability.h>
 
-#define clock_interval_to_deadline(a, b, c)            \
-       clock_interval_to_deadline((a), (b), __OSAbsoluteTimePtr(c))
+/* Use mach_absolute_time() */
+extern mach_timespec_t  clock_get_system_value(void) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_0, __MAC_10_8, __IPHONE_2_0, __IPHONE_6_0);
 
-#define clock_interval_to_absolutetime_interval(a, b, c)       \
-       clock_interval_to_absolutetime_interval((a), (b), __OSAbsoluteTimePtr(c))
+extern mach_timespec_t  clock_get_calendar_value(void) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_0, __MAC_10_8, __IPHONE_2_0, __IPHONE_6_0);
 
-#define clock_absolutetime_interval_to_deadline(a, b)  \
-       clock_absolutetime_interval_to_deadline(__OSAbsoluteTime(a), __OSAbsoluteTimePtr(b))
+#else   /* __LP64__ */
 
-#define clock_deadline_for_periodic_event(a, b, c)     \
-       clock_deadline_for_periodic_event(__OSAbsoluteTime(a), __OSAbsoluteTime(b), __OSAbsoluteTimePtr(c))
+#ifdef  XNU_KERNEL_PRIVATE
 
-#define clock_delay_until(a)   \
-       clock_delay_until(__OSAbsoluteTime(a))
+#define MACH_TIMESPEC_ZERO      ((mach_timespec_t) { 0, 0 } )
 
-#define absolutetime_to_nanoseconds(a, b)      \
-       absolutetime_to_nanoseconds(__OSAbsoluteTime(a), (b))
+#endif  /* XNU_KERNEL_PRIVATE */
 
-#define nanoseconds_to_absolutetime(a, b)      \
-       nanoseconds_to_absolutetime((a), __OSAbsoluteTimePtr(b))
+#endif  /* __LP64__ */
 
-#endif /* ABSOLUTETIME_SCALAR_TYPE */
+extern void                             delay_for_interval(
+       uint32_t                interval,
+       uint32_t                scale_factor);
 
-#endif /* __LP64__ */
+extern void                             delay_for_interval_with_leeway(
+       uint32_t                interval,
+       uint32_t                leeway,
+       uint32_t                scale_factor);
 
-#endif /* MACH_KERNEL_PRIVATE */
+#ifdef  XNU_KERNEL_PRIVATE
+extern void delay(int usec);
+#endif  /* XNU_KERNEL_PRIVATE */
 
-#endif /* KERNEL_PRIVATE */
+#endif  /* KERNEL_PRIVATE */
 
 __END_DECLS
 
-#endif /* _KERN_CLOCK_H_ */
+#endif  /* _KERN_CLOCK_H_ */